http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/default-object-wrapper.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/default-object-wrapper.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/default-object-wrapper.ftl new file mode 100644 index 0000000..bcf903d --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/default-object-wrapper.ftl @@ -0,0 +1,59 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#list array as item> +${item} +</#list> +${array?size} +${array[0]} +${array[1]} +<#list list as item> +${item} +</#list> +${list?size} +${list?hasContent?then('not empty', 'empty')} +${list[0]} +${map.key} +${map?api.get(objKey)} +${obj.foo} +<#if obj.foo?exists>hasfoo<#else>nofoo</#if> +<#if obj.baz?exists>hasbaz<#else>nobaz</#if> +${obj.bar[0]} +${obj.getFoo()} +${obj.overloaded(1?int)} +${obj.overloaded("String")} +${resourceBundle.message} +${resourceBundle("format", date)} +<#assign static = statics["org.apache.freemarker.test.templatesuite.models.BeanTestClass"]> +${static.staticMethod()} +${static.staticOverloaded(1)} +${static.staticOverloaded("String")} +${static.STATIC_FINAL_FIELD} +${static.STATIC_FIELD} +<#assign enum = enums["org.apache.freemarker.test.templatesuite.models.EnumTestClass"]> +${enum.ONE} +${enum.TWO} +${enum.THREE} +${(enum.ONE == enum.ONE)?string("true", "false")} +${(enum.ONE == enum.TWO)?string("true", "false")} +${enums["org.apache.freemarker.test.templatesuite.models.BeanTestClass"]?exists?string("true", "false")} +${obj.something} +${obj.publicInner.x} +${obj.publicInner.m()} +<@assertFails message="obj.privateInner.x">${obj.privateInner.x}</@> +<@assertFails message="obj.privateInner.m">${obj.privateInner.m()}</@> \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/default-xmlns.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/default-xmlns.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/default-xmlns.ftl new file mode 100644 index 0000000..4f01835 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/default-xmlns.ftl @@ -0,0 +1,28 @@ +<#ftl ns_prefixes={"D" : "http://x.com", "y" : "http://y.com"}> +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#assign r = doc.*[0]> +${r["N:t1"]?default('-')} = No NS +${r["t2"]?default('-')} = x NS +${r["y:t3"]?default('-')} = y NS +${r["./D:t4"]?default('-')} = x NS + +<#assign bool = doc["true()"]> +${bool?string} + http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/default.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/default.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/default.ftl new file mode 100644 index 0000000..6ecf8b3 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/default.ftl @@ -0,0 +1,34 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +${UNDEFINED!"foo"} + +<#assign duck = (FOO.BAR)!"luck"> +${duck} + +<#list UNDEFINED![] as item> + ${item} +</#list> + +${UNDEFINED![]?size} + +<#if UNDEFINED??> + UNDEFINED is defined. +<#else> + UNDEFINED is undefined. +</#if> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/encoding-builtins.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/encoding-builtins.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/encoding-builtins.ftl new file mode 100644 index 0000000..6ee2a26 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/encoding-builtins.ftl @@ -0,0 +1,52 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +FreeMarker: Encoding built-in tests + +<#assign x = "&<>\"'{}\\a/"> +html: [${x?html}] +xml: [${x?xml}] +xhtml: [${x?xhtml}] +rtf: [${x?rtf}] +<#assign x = "a&a<a>a\"a'a{a}a\\"> +html: [${x?html}] +xml: [${x?xml}] +xhtml: [${x?xhtml}] +rtf: [${x?rtf}] +<#assign x = "<<<<<"> +html: [${x?html}] +xml: [${x?xml}] +xhtml: [${x?xhtml}] +<#assign x = "{{{{{"> +rtf: [${x?rtf}] +<#assign x = ""> +html: [${x?html}] +xml: [${x?xml}] +xhtml: [${x?xhtml}] +rtf: [${x?rtf}] +<#assign x = "a"> +html: [${x?html}] +xml: [${x?xml}] +xhtml: [${x?xhtml}] +rtf: [${x?rtf}] +<#assign x = "&"> +html: [${x?html}] +xml: [${x?xml}] +xhtml: [${x?xhtml}] +<#assign x = "{"> +rtf: [${x?rtf}] \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/escapes.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/escapes.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/escapes.ftl new file mode 100644 index 0000000..20efc67 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/escapes.ftl @@ -0,0 +1,79 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#assign h=["","a","b","c"]> +<#assign g={"x":1,"y":2,"z":3}> +<#escape x as h[x]> +${1} +${2} +${3} +<#escape x as g[x]> +${"x"} +${"y"} +${"z"} +<#noescape>${1}</#noescape> +<#noescape><#noescape>${1}</#noescape></#noescape> +</#escape> +${1} +${2} +${3} +</#escape> +<#escape x as x?html> +${"<&>"} +<#escape x as x?xml> +${"<&>"} +</#escape> +${"<&>"} +</#escape> +--- +<#assign x = "<Mooo>"> +${x} = <Mooo> +<#escape x as x?upper_case> + ${x} = <MOOO> + <#escape x as x?html> + ${x} = <MOOO> + <#noescape> + ${x} = <MOOO> + </#noescape> + ${x} = <MOOO> + </#escape> + ${x} = <MOOO> + <#noescape> + ${x} = <Mooo> + <#escape x as x?html> + ${x} = <Mooo> + <#noescape> + ${x} = <Mooo> + </#noescape> + ${x} = <Mooo> + </#escape> + ${x} = <Mooo> + </#noescape> + ${x} = <MOOO> +</#escape> +<#escape az as ["red", "green", "blue"][az-1]> + ${1} ${2} ${3} +</#escape> +--- +<#assign s = 'A&B'> +<#escape x as '<' + x?html + '>[' + x?lower_case + '](' + x + ')'> + ${s} ${s + 2} + <#escape x as '{' + x?lower_case + '}' + x> + ${s} ${s + 2} + </#escape> +</#escape> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/exception.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/exception.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/exception.ftl new file mode 100644 index 0000000..83ae356 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/exception.ftl @@ -0,0 +1,31 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: Exception Test</title> +</head> +<body> + +<p>A simple test follows:</p> + +<p>${message} <br /> +${test}</p> + +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/exception2.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/exception2.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/exception2.ftl new file mode 100644 index 0000000..83ae356 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/exception2.ftl @@ -0,0 +1,31 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: Exception Test</title> +</head> +<body> + +<p>A simple test follows:</p> + +<p>${message} <br /> +${test}</p> + +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/exception3.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/exception3.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/exception3.ftl new file mode 100644 index 0000000..f386fec --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/exception3.ftl @@ -0,0 +1,31 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: Exception Test</title> +</head> +<body> + +<p>A simple test follows:</p> + +<p>${message} <br /> +${%@#$test}</p> + +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/existence-operators.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/existence-operators.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/existence-operators.ftl new file mode 100644 index 0000000..2f9bdce --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/existence-operators.ftl @@ -0,0 +1,141 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<@isIRE>${v}</@> +<@isIRE>${w}</@> +<@isNonFastIRE>${v}</@> <#-- To check that it isn't an IRE.FAST_INSTANCE --> + +<@assertEquals actual=v!'-' expected='-' /> +<@assertEquals actual=(v)!'-' expected='-' /> +<@assertEquals actual=(v!) expected='' /> +<@assertEquals actual=((v)!) expected='' /> +<@isNonFastIRE>${v}</@> <#-- To check that it isn't an IRE.FAST_INSTANCE --> +<@assertEquals actual=v?? expected=false /> +<@assertEquals actual=(v)?? expected=false /> +<@assertEquals actual=v?default('-') expected='-' /> +<@assertEquals actual=(v)?default('-') expected='-' /> +<@isNonFastIRE>${v}</@> <#-- To check that it isn't an IRE.FAST_INSTANCE --> +<@assertEquals actual=v?exists expected=false /> +<@assertEquals actual=(v)?exists expected=false /> +<@assertEquals actual=v?if_exists expected='' /> +<@assertEquals actual=(v)?if_exists expected='' /> +<@assertEquals actual=v?has_content expected=false /> +<@assertEquals actual=(v)?has_content expected=false /> + +<@assertEquals actual=v?default(w, '-') expected='-' /> +<@assertEquals actual=v!w!'-' expected='-' /> +<#assign w = 'W'> +<@assertEquals actual=v?default(w, '-') expected='W' /> +<@assertEquals actual=v!w!'-' expected='W' /> + +<#list ['V', 1.5] as v> + <@assertEquals actual=v!'-' expected=v /> + <@assertEquals actual=(v)!'-' expected=v /> + <@assert test=v?? /> + <@assert test=(v)?? /> + <@assertEquals actual=v?default('-') expected=v /> + <@assertEquals actual=(v)?default('-') expected=v /> + <@assert test=v?exists /> + <@assert test=(v)?exists /> + <@assertEquals actual=v?if_exists expected=v /> + <@assertEquals actual=(v)?if_exists expected=v /> + <@assert test=v?has_content /> + <@assert test=(v)?has_content /> +</#list> +<@assert test=!v?? /> +<@assert test=!v?exists /> +<@isNonFastIRE>${v}</@> <#-- To check that it isn't an IRE.FAST_INSTANCE --> + +<@isIRE>${u.v!'-'}</@> +<@assertEquals actual=(u.v)!'-' expected='-' /> +<@isIRE>${u.v??}</@> +<@assertEquals actual=(u.v)?? expected=false /> +<@isIRE>${u.v?default('-')}</@> +<@assertEquals actual=(u.v)?default('-') expected='-' /> +<@isIRE>${u.v?exists}</@> +<@assertEquals actual=(u.v)?exists expected=false /> +<@isIRE>${u.v?if_exists}</@> +<@assertEquals actual=(u.v)?if_exists expected='' /> +<@isIRE>${u.v?has_content}</@> +<@assertEquals actual=(u.v)?has_content expected=false /> + +<#assign u = { 'x': 'X' } > +<@assertEquals actual=u.v!'-' expected='-' /> +<@assertEquals actual=(u.v)!'-' expected='-' /> +<@assertEquals actual=u.v?? expected=false /> +<@assertEquals actual=(u.v)?? expected=false /> +<@assertEquals actual=u.v?default('-') expected='-' /> +<@assertEquals actual=(u.v)?default('-') expected='-' /> +<@assertEquals actual=u.v?exists expected=false /> +<@assertEquals actual=(u.v)?exists expected=false /> +<@assertEquals actual=u.v?if_exists expected='' /> +<@assertEquals actual=(u.v)?if_exists expected='' /> +<@assertEquals actual=u.v?has_content expected=false /> +<@assertEquals actual=(u.v)?has_content expected=false /> + +<#assign u = { 'v': 'V' } > +<@assertEquals actual=u.v!'-' expected='V' /> +<@assertEquals actual=(u.v)!'-' expected='V' /> +<@assert test=u.v?? /> +<@assert test=(u.v)?? /> +<@assertEquals actual=u.v?default('-') expected='V' /> +<@assertEquals actual=(u.v)?default('-') expected='V' /> +<@assert test=u.v?exists /> +<@assert test=(u.v)?exists /> +<@assertEquals actual=u.v?if_exists expected='V' /> +<@assertEquals actual=(u.v)?if_exists expected='V' /> +<@assert test=u.v?has_content /> +<@assert test=(u.v)?has_content /> + +<#list 1..4 as i> + <#if i == 3><#assign x = 'X'></#if> + <@assertEquals actual=((x!'-') == '-') expected=(i < 3) /> +</#list> + +<#macro attemptTest> + <#attempt> + ${fails} + <#recover> + <@assert test=isNonFastIREMessage(.error) /> + </#attempt> +</#macro> +<@attemptTest /> +${(callMacroFromExpression(attemptTest))!} + +<#macro interpretTest><@'$\{fails}'?interpret /></#macro> +<#attempt> + <@interpretTest /> +<#recover> + <@assert test=isNonFastIREMessage(.error) /> +</#attempt> +<#attempt> + ${(callMacroFromExpression(interpretTest))!} +<#recover> + <@assert test=isNonFastIREMessage(.error) /> +</#attempt> + +<@assertEquals actual='fails'?eval!'-' expected='-' /> +<@assertEquals actual=('fails')?eval!'-' expected='-' /> + +<#macro isIRE><@assertFails exception="InvalidReferenceException"><#nested></@></#macro> +<#macro isNonFastIRE><@assertFails exception="InvalidReferenceException" message="Tip:"><#nested></@></#macro> +<#function isNonFastIREMessage msg><#return msg?contains('Tip:') && msg?contains('null or missing')></#function> +<#function callMacroFromExpression m> + <#local captured><@m /></#local> + <#return captured> +</#function> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/hashconcat.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/hashconcat.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/hashconcat.ftl new file mode 100644 index 0000000..127d828 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/hashconcat.ftl @@ -0,0 +1,60 @@ +[#ftl] +[#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--] +[#assign a = {"a":1, "b":2, "c":3, "X": 4}] +[#assign b = {"d":10, "e":20, "f":30, "X": 40}] + +a: +[@dump a /] + +B: +[@dump b /] + +a + B: +[@dump a + b /] + +B + a: +[@dump b + a /] + +a + a: +[@dump a + a /] + +{} + a: +[@dump {} + a /] + +a + {}: +[@dump a + {} /] + +{} + {}: +[@dump {} + {} /] + +a + b + {} + b + {} + a: +[@dump a + b + {} + b + {} + a /] + + +[#macro dump s] +[#list s?keys as k] + ${k} = ${s[k]} +[/#list] + --- +[#list s?values as v] + ${v} +[/#list] + --- +[/#macro] \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/hashliteral.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/hashliteral.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/hashliteral.ftl new file mode 100644 index 0000000..0a02a3a --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/hashliteral.ftl @@ -0,0 +1,100 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: Hash Literal Test</title> +</head> +<body> + +<p>A simple test follows:</p> + +<p>${message}</p> + +<p>Now perform a hash assignment:</p> + +<#assign mymessage = "hello", foo="bar", one="1"> +<#assign test = { "test1": "test23", + "test45" : message, + mymessage : "hello all", + foo: one}> + +${test.test1} +${test.test45} +${test.hello} +${test.bar} + +<p>Now update the assignment and repeat:</p> + +<#assign mymessage = "world"> + +${test.test1} +${test.test45} +${test.hello} + +${test.bar} + +<p>Now reassign the list and repeat:</p> + +<#assign hash= {"temp" : "Temporary"}> +<#assign test = { "test1" : "test23", + "test45" : message, + mymessage : "hello all", + foo : one, + "hash" : hash[ "temp" ], + "true" : hash.temp, + "newhash" : hash}> + +${test.test1} +${test.test45} +${test.hello?if_exists} + +${test.bar} +${test.hash} +${test.true} +${test.newhash.temp} + +<p>Pathological case: zero item hash:</p> + +<#assign test = {}> +${test.test1?if_exists} + +<p>Hash of number literals:</p> +<#assign test = {"1" : 2}> +${test["1"]} + +<p>Hash concatenation:</p> +<#assign cc = { "a" : 1, "b" : 2 } + { "b" : 3, "c" : 4 }> +<#list cc?keys?sort as key> +${key} => ${cc[key]} +</#list> + +<p>Empty hash concatenation:</p> +${({} + { "a" : "foo" }).a}, ${({ "a" : "bar" } + {}).a} + +</body> +</html> +<@noOutput> + +<#assign m = { 'a': 1, 'b', 2, 'a': 3 }> +<@assertEquals expected="a, b" actual=m?keys?join(', ') /> +<@assertEquals expected="3, 2" actual=m?values?join(', ') /> +<@assertEquals expected=3 actual=m['a'] /> +<@assertEquals expected=2 actual=m['b'] /> + +</@noOutput> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/helloworld.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/helloworld.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/helloworld.ftl new file mode 100644 index 0000000..91816f6 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/helloworld.ftl @@ -0,0 +1,30 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: Exec Model Test</title> +</head> +<body> + +<p>A simple test follows:</p> + +<p>${exec( "java freemarker.test.HelloWorld" )}</p> + +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/identifier-escaping.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/identifier-escaping.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/identifier-escaping.ftl new file mode 100644 index 0000000..9b39235 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/identifier-escaping.ftl @@ -0,0 +1,81 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#macro m\-a data\-color> + <#local \.namespace = 123> + <a-b>${data\-color}<#nested \.namespace></a-b><#t> +</#macro> +<#macro "m-b2"></#macro> +<#macro "m/b2"></#macro> + +<@m\-a data\-color="red"; loop\-var>${loop\-var}</@> + +<#function f\-a p\-a> + <#return p\-a + " works"> +</#function> +${f\-a("f-a")} + +<#assign \-\-\-\.\: = 'dash-dash-dash etc.'> +${\-\-\-\.\:} +${.vars['---.:']} +<#assign hash = { '--moz-prop': 'propVal' }> +${hash.\-\-moz\-prop} +${hash['--moz-prop']} + +<#assign ls\:a = 1..3> +List: <#list ls\:a as \:i>${\:i}</#list> + +<#assign sw\-a=1> +Switch: <#switch sw\-a> + <#case 1>OK<#break> + <#default>Fails +</#switch> + +<#escape \-x as \-x?upper_case>${'escaped'}</#escape> + +<#if false && sw\-a == 1> + <#visit x\-y2 using x\-y1> + <#recurse x\-y2 using x\-y1> + <#import i\-a as i\-b> + <#include i\-c> +</#if> + +<#assign @as@_a = 'as1'> +${@as@_a} +<#assign 'as-c' = 'as2'> +${.vars['as-c']} +<#assign "as/b" = 'as3'> +${.vars["as/b"]} +<#assign "as'c" = 'as4'> +${.vars["as'c"]} +<#assign 'as"d' = 'as5'> +${.vars['as"d']} + +<#global g\-a=1 g\-b=2 "g-c"=3> + +<#macro catchAll x y attrs...> +<catchAll x=${x} y=${y}<#list attrs?keys?sort as k> ${k}=${attrs[k]}</#list> /> +</#macro> +<@catchAll x=1 y=2 z=3 data\-foo=4 a\:b\.c=5 /> + +<#macro dumpNS> + <#list .namespace?keys?sort as k> + ${k} = <#local v = .namespace[k]><#if v?is_string>${v}<#else>...</#if><#lt> + </#list> +</#macro> +<@dumpNS /> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/identifier-non-ascii.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/identifier-non-ascii.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/identifier-non-ascii.ftl new file mode 100644 index 0000000..59a4b0e --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/identifier-non-ascii.ftl @@ -0,0 +1,21 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#macro árvÃztűrÅTükörfúrógép ×ֶקס×>${×ֶקס×}</#macro> +<#assign íêµì´_í¤ë³´ë="Korean Keyboard"> +<@árvÃztűrÅTükörfúrógép íêµì´_í¤ë³´ë /> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/if.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/if.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/if.ftl new file mode 100644 index 0000000..97c3f4b --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/if.ftl @@ -0,0 +1,109 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#assign x = 1> + +- <#if x == 1>good</#if> +- <#if x == 1></#if>good +- <#if x == 1>goo${missing!'d'}</#if> +- <#if x == 0>wrong</#if>good + +- <#if x == 1>good<#else>wrong</#if> +- <#if x == 0>wrong<#else>good</#if> + +- <#if x == 1>good<#elseif x == 2>wrong<#else>wrong</#if> +- <#if x == 1>good<#elseif x == 1>wrong<#else>wrong</#if> +- <#if x == 0>wrong<#elseif x == 1>good<#else>wrong</#if> +- <#if x == 0>wrong<#elseif x == 2>wrong<#else>good</#if> + +- <#if x == 1>good<#elseif x == 1>wrong</#if> +- <#if x == 0>wrong<#elseif x == 1>good</#if> +- <#if x == 0>wrong<#elseif x == 2>wrong</#if>good +- <#if x == 0>wrong<#elseif x == 1><#else>wrong</#if>good + +<#-- Same with pre-calculable results, just in case later the dead code will be optimized out: --> +- <#if 1 == 1>good</#if> +- <#if 1 == 0>wrong</#if>good +- <#if 1 == 1>goo${missing!'d'}</#if> +- <#if 1 == 0>wrong</#if>good + +- <#if 1 == 1>good<#else>wrong</#if> +- <#if 1 == 0>wrong<#else>good</#if> + +- <#if 1 == 1>good<#elseif 1 == 2>wrong<#else>wrong</#if> +- <#if 1 == 1>good<#elseif 1 == 1>wrong<#else>wrong</#if> +- <#if 1 == 0>wrong<#elseif 1 == 1>good<#else>wrong</#if> +- <#if 1 == 0>wrong<#elseif 1 == 2>wrong<#else>good</#if> + +- <#if 1 == 1>good<#elseif 1 == 1>wrong</#if> +- <#if 1 == 0>wrong<#elseif 1 == 1>good</#if> +- <#if 1 == 0>wrong<#elseif 1 == 2>wrong</#if>good +- <#if 1 == 0>wrong<#elseif 1 == 1><#else>wrong</#if>good + +<#-- Varying branch choice of the same AST nodes: --> +<#list [1, 2, 3, 4] as x> +- <#if x == 1>1</#if> +- <#if x == 2>2</#if> +- <#if x == 3>3</#if> +- <#if x == 1>is 1<#else>isn't 1</#if> +- <#if x == 2>is 2<#else>isn't 2</#if> +- <#if x == 3>is 3<#else>isn't 3</#if> +- Finally, it's: <#if x == 1>1<#elseif x == 2>2<#elseif x == 3>3<#else>4</#if> +</#list> + +<#-- nested --> +<#list [1, 2, 3] as x><#list [1, 2, 3] as y> + <#assign y = x * x> + <#if x == 1> + 1: + <#if (x > y)> + > ${y} + <#elseif x == y> + == ${y} + <#else> + <= ${y} + </#if> + <#elseif x == 2> + 2: + <#if (x > y)> + > ${y} + <#elseif x == y> + == ${y} + <#else> + <= ${y} + </#if> + <#else> + 3: + <#if (x > y)> + > ${y} + <#elseif x == y> + == ${y} + <#else> + <= ${y} + </#if> + <#if x == 3 && y == 3> + End + </#if> + </#if> +</#list></#list> + +<#-- parsing errors --> +<@assertFails message="valid #if-#elseif-#else"><@"<#if t><#else><#elseif t2></#if>"?interpret /></@> +<@assertFails message="valid #if-#elseif-#else"><@"<#if t><#else><#else></#if>"?interpret /></@> +<@assertFails message="valid #if-#elseif-#else"><@"<#else></#else>"?interpret /></@> +<@assertFails message="valid #if-#elseif-#else"><@"<#elseif t></#elseif>"?interpret /></@> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/import.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/import.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/import.ftl new file mode 100644 index 0000000..bddd857 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/import.ftl @@ -0,0 +1,45 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +-- +<#-- import "/import_lib.ftl" as my --> +-- + +<#if mail?exists || test?exists> + <#stop "mail or test should not exist"> +</#if> + +${my.mail} +<@my.test foo="bar"/> + +<#assign mail="[email protected]"> +${my.mail} +<@my.test foo="bar"/> + +<#assign mail in my> + [email protected]<#t> +</#assign> +${my.mail} +<@my.test foo="bar"/> + +<#import "/import_lib.ftl" as my2> +${my2.mail} +<#assign mail="[email protected]" in my2> +${my.mail} + +${my2.doubleUp("foobar")} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/import_lib.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/import_lib.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/import_lib.ftl new file mode 100644 index 0000000..3329af9 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/import_lib.ftl @@ -0,0 +1,31 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#macro test foo> + Test ${foo}. + Email: ${mail} + <#if .main.mail?exists> + Email in the root: ${.main.mail} + </#if> +</#macro> + +<#function doubleUp foo> + <#return foo+foo> +</#function> + +<#assign mail = "[email protected]"> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include.ftl new file mode 100644 index 0000000..3e997e7 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include.ftl @@ -0,0 +1,47 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: Include Instruction Test</title> +</head> +<body> + +<p>A simple test follows:</p> + +${message} + +<#if message?exists> + <p>Message exists! +</#if> + +<p>Test normal includes:</p> +<#include "included.ftl"> + +${foo} +${nestedMessage} + +<@twice> +Kilroy +</@twice> + +<p>Test subdir includes:</p> +<#include "subdir/include-subdir.ftl"> +</body> +</html> + http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2-included.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2-included.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2-included.ftl new file mode 100644 index 0000000..db9dfc1 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2-included.ftl @@ -0,0 +1,19 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +${'A'} próba http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2.ftl new file mode 100644 index 0000000..5f3ccc3 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/include2.ftl @@ -0,0 +1,32 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#include "include2" + "-included.ftl"> +<#assign s = "de"> +<#include "inclu" + s + "2-included.ftl"> + +<#assign bTrue=true> +<#assign bFalse=false> +<#include "include2-included.ftl" ignore_missing=true> +<#include "include2-included.ftl" ignore_missing=bTrue> +<#include "include2-included.ftl" ignore_missing=false> +<#include "include2-included.ftl" ignore_missing=bFalse> + +<@assertFails message="not found"><#include "missing.ftl"></@> +[<#include "missing.ftl" ignore_missing=true>] +[<#include "missing.ftl" ignore_missing=bTrue>] http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/included.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/included.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/included.ftl new file mode 100644 index 0000000..f711a67 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/included.ftl @@ -0,0 +1,30 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<p>A test of included files:</p> + +<#if .globals.message?exists> + <p>Message exists!:<br /> + ${.globals.message}</p> +<#else> + <p>No message :(</p> +</#if> + +<#assign foo="assigning from included template", bar=" Can you see me? "> +<#macro twice><#nested/>${bar}<#nested/></#macro> +<#include "nestedinclude.ftl"> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/interpret.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/interpret.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/interpret.ftl new file mode 100644 index 0000000..41f8425 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/interpret.ftl @@ -0,0 +1,25 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#global x=["a", "b", "c"]> +<#global templateSource = r"<#list x as y>${y}</#list>"> +<@templateSource?interpret>def</@> +<@[templateSource]?interpret>def</@> +<@[templateSource,"id"]?interpret>def</@> + +<#assign t = '<#macro m>M</#macro>'?interpret><@t /><@m/> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/iterators.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/iterators.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/iterators.ftl new file mode 100644 index 0000000..389abf3 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/iterators.ftl @@ -0,0 +1,71 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: List Iterator Test</title> +</head> +<body> +<#assign list= ["one", "two", "three", "four", "five"]> +<#assign hash = {"key", list}> +<#assign hash2 = {"value", hash}> + +<p>A simple test follows:</p> + +<p>${message}</p> + +<p>Now iterate over a list:</p> + +<#list list as item> +<p>${item}</p> +</#list> + +<p>Now iterate again:</p> + +<#list list as item> +<p>${item_index}. ${item}</p> +</#list> + +<p>Iterate over a list in a hash:</p> + +<#list hash.key as item> +<p>${item}</p> +</#list> + +<#list hash.key as item> +<p>${item}</p> +</#list> + +<#list hash[ "key" ] as item> +<p>${item}</p> +</#list> + +<#list hash["key"] as item> +<p>${item}</p> +</#list> + +<#list hash2["value"].key as key> +<p>${key}</p> +</#list> + +<#list hash2.value.key as az> +<p>${az}</p> +</#list> + +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/lastcharacter.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/lastcharacter.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/lastcharacter.ftl new file mode 100644 index 0000000..e762356 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/lastcharacter.ftl @@ -0,0 +1,31 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: Last Character Test</title> +</head> +<body> + +<p>A simple test follows:</p> + + #{message?capitalize?length} + + ${message [1..] ? upper_case} + + message: ${message ?capitalize[0..10]} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list-bis.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list-bis.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list-bis.ftl new file mode 100644 index 0000000..e52307f --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list-bis.ftl @@ -0,0 +1,48 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#list ['a', 'b', 'c'] as x> + ${x?index}: ${x} [<#list ['A', 'B', 'C'] as x>${x?index}:${x}<#sep>, </#list>] +</#list> + +<#list ['a', 'b', 'c'] as i> + ${i?index}: ${i} <#list ['A', 'B', 'C'] as j>${i?index}${i}/${j?index}${j}<#sep>, </#list> +</#list> + +<#list ['a', 'b', 'c']><#items as x>${x?index}:${x}<#sep>, </#items></#list> +<#list ['a', 'b', 'c']><#items as x>${x?counter}. ${x};<#sep> </#items></#list> + +<#list ['a', 'b', 'c'] as x>${x}<#if x?hasNext>, </#if></#list> +<#list ['a', 'b', 'c'] as x\-y>${x\-y}<#if x\-y?hasNext>, </#if></#list> + +<#list ['a', 'b', 'c'] as x><#if x?isFirst>${x?capFirst}<#else>${x}</#if><#sep>, </#sep><#if x?isLast>.</#if></#list> + +<#list ['a', 'b', 'c'] as x>${x?isOddItem?c}/${x?isEvenItem?c}<#sep> </#list> + +<#list ['a', 'b', 'c'] as x> + <td class="${x?itemParity}Row">${x}</td> +</#list> + +<#list ['a', 'b', 'c'] as x> + <td class="row${x?itemParityCap}">${x}</td> +</#list> + +<#list ['a', 'b', 'c', 'd', 'e', 'f', 'g'] as x> + <td class="${x?itemCycle('R', 'G', 'B')}">${x}</td> +</#list> +<@assertFails message="expects 1"><#list 1..1 as x>${x?itemCycle()}</#list></@> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list.ftl new file mode 100644 index 0000000..280491c --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list.ftl @@ -0,0 +1,44 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<@testList ["aardvark", "bear", "cat", "dog"] /> + +<@testList ["aardvark"] /> + +<@testList [] /> + +<@testList listables.list /> + +<@testList listables.linkedList /> + +<@testList listables.set /> + +<@testList listables.iterator /> + +<@testList listables.emptyList /> + +<@testList listables.emptyLinkedList /> + +<@testList listables.emptySet /> + +<@testList listables.emptyIterator /> + +<#macro testList seq> +Size: <#attempt>${seq?size}<#recover>failed</#attempt> +Items: <#list seq as i>@${i_index} ${i}<#if i_has_next>, <#else>.</#if></#list> +</#macro> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list2.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list2.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list2.ftl new file mode 100644 index 0000000..db64a4b --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list2.ftl @@ -0,0 +1,90 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<@testList ["aardvark", "bear", "cat", "dog"] /> + +<@testList ["aardvark"] /> + +<@testList [] /> + +<@testList listables.list /> + +<@testList listables.set /> + +<@testList listables.getIterator /> + +<@testList listables.emptyList /> + +<@testList listables.emptySet /> + +<@testList listables.getEmptyIterator /> + +<#macro testList xs> +=== [${resolve(xs)?join(", ")}] === +<#assign resolveCallCnt = 0> + +-- List+sep: +<#list resolve(xs) as x> + ${x}<#sep>,</#sep> +</#list> +-- List+else: +<#list resolve(xs) as x> + ${x} +<#else> + Empty! +</#list> +-- List+items: +<#list resolve(xs)> + [ + <#items as x> + ${x!'U'} + </#items> + ] +</#list> +-- List+items+else: +<#list resolve(xs)> + [ + <#items as x> + ${x!'U'} + </#items> + ] +<#else> + Empty! +</#list> +-- List+items+sep+else: +<#list resolve(xs)> + [ + <#items as x> + ${x!'U'}<#sep>,</#sep> + </#items> + ] +<#else> + Empty! +</#list> +<@assertEquals expected=5 actual=resolveCallCnt /> +-- +</#macro> + +<#function resolve xs> + <#assign resolveCallCnt = (resolveCallCnt!0) + 1> + <#if xs?isMethod> + <#return xs()> + <#else> + <#return xs> + </#if> +</#function> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list3.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list3.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list3.ftl new file mode 100644 index 0000000..d2fcf71 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/list3.ftl @@ -0,0 +1,70 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +[ +<#list listables.list as i> + [<#list listables.list as j>(${i}@${i_index}, ${j}@${j_index})<#sep>, </#sep></#list>]<#sep>,</#sep> +</#list> +] + +<#macro hits xs style=""> + <#list xs> + <p>${xs?size} hits: + <div class="hits"> + <#switch style> + <#case "hidden"> + ... + <#break> + <#case "other"> + <#items as x> + <div class="hitOther">${x}</div> + </#items> + <#break> + <#case "none"> + <#default> + <#items as x> + <div class="hit">${x}</div> + </#items> + <#break> + </#switch> + </div> + <#else> + <p>Nothing. + </#list> +</#macro> + +<@hits ['a', 'b'] /> + +<@hits ['a', 'b'], "other" /> + +<@hits ['a', 'b'], "hidden" /> + +<@hits [] /> + +<#list listables.list as i><#if i_index gt 1>...<#break></#if>${i}<#sep>, </#sep></#list> +<#list listables.list>[<#items as i><#if i_index gt 1>...<#break></#if>${i}<#sep>, </#sep></#items>]</#list> + +<@testAutoClosedSep 1..3 /> +<@testAutoClosedSep [1] /> +<@testAutoClosedSep [] /> + +<#macro testAutoClosedSep xs> +<#list xs as x>${x}<#sep>, <#else>Empty</#list> +<#list xs as x>${x}<#sep><#if x_index == 0> /*first*/, <#else>, </#if><#else>Empty</#list> +<#list xs>[<#items as x>${x}<#sep>, </#items>]<#else>Empty</#list> +</#macro> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/listhash.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/listhash.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/listhash.ftl new file mode 100644 index 0000000..6f22b43 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/listhash.ftl @@ -0,0 +1,70 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#setting booleanFormat='Y,N'> + +<#macro listings maps> + <#list maps as m> + Map: + + [ + <#list m as k, v> + ${k!'null'} = ${v!'null'} + </#list> + ] + + [ + <#list m as k, v> + ${k!'null'} = ${v!'null'}<#sep>;</#sep> // @${k?index}=@${v?index}; ${k?itemParity}=${v?itemParity}; ${k?hasNext}=${v?hasNext} + <#else> + Empty + </#list> + ] + + { + <#list m> + [ + <#items as k, v> + ${k!'null'} = ${v!'null'}<#sep>;</#sep> // @${k?index}=@${v?index}; ${k?itemParity}=${v?itemParity}; ${k?hasNext}=${v?hasNext} + </#items> + ] + <#else> + Empty + </#list> + } + + </#list> +</#macro> + +Non-empty maps: + +<@listings listables.hashEx2s /> +<@listings [ listables.hashNonEx2 ] /> + +Empty maps: + +<@listings listables.emptyHashes /> + +<#list { 'a': { 'aa': 11 }, 'b': { 'ba': 21, 'bb': 22 }, 'c': {} } as k1, v1> + ${k1} @ ${k1?index}, ${v1?size} + <#list v1 as k2, v2> + ${k2} = ${v2} @ ${k2?index} // inside ${k1} @ ${k1?index}, ${v1?size} + </#list> + ${k1} @ ${k1?index}, ${v1?size} + -- +</#list> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/listhashliteral.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/listhashliteral.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/listhashliteral.ftl new file mode 100644 index 0000000..06694c9 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/listhashliteral.ftl @@ -0,0 +1,35 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#list [ { "a": 1, "b": 2, "a": 3 }, { } ] as h> + KVPs: + <#list h as k, v> + ${k} = ${v} + </#list> + + Keys: + <#list h?keys as k> + ${k} + </#list> + + Values: + <#list h?values as v> + ${v} + </#list> + +</#list> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/listliteral.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/listliteral.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/listliteral.ftl new file mode 100644 index 0000000..d48578c --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/listliteral.ftl @@ -0,0 +1,84 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: List Literal Test</title> +</head> +<body> + +<p>A simple test follows:</p> + +<p>${message}</p> + +<p>Now perform a list assignment:</p> + +<#assign hash = {"temp", "Temporary"}> +<#assign mymessage = "hello"> +<#assign test = [ "test1", "test23", "test45", message, mymessage]> + +The list contains #{test?size} items. + +<#list test as item> +<p>${item}</p> +</#list> + +<p>Now update the assignment and repeat:</p> + +<#assign mymessage = "world"> + +<#list test as item> +<p>${item}</p> +</#list> + +<p>Now reassign the list and repeat:</p> + +<#assign test = [ hash.temp, "test1", "test23", "test45", mymessage, "hash", hash["temp"]]> +<#assign test = [ "foo", "bar" ] + test> + +<#list test[1..4] as item> +<p>${item}</p> +</#list> + +<p>Silly, but necessary tests, for one and zero element lists:</p> + +<#assign test = [ "Hello, world" ]> + +<#list test as item> +<p>${item}</p> +</#list> + +<p>Zero item test:</p> + +<#assign test = []> + +<#list test as item> +<p>${item}</p> +</#list> + +<p>Dumb test for number literals -- these weren't working as expected:</p> + +<#assign test = [] + [1, 2,3, 5, 7]> + +<#list test as item> +<p>${item}</p> +<#if item == 5><#break></#if> +</#list> + +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/localization.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/localization.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/localization.ftl new file mode 100644 index 0000000..cf46fbf --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/localization.ftl @@ -0,0 +1,32 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: Localization Test</title> +</head> +<body> + +<p>A simple test follows:</p> + +<p>${message}</p> + +<p>Hello, in the default language.</p> + +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/localization_en.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/localization_en.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/localization_en.ftl new file mode 100644 index 0000000..f8292bc --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/localization_en.ftl @@ -0,0 +1,32 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: Localization Test</title> +</head> +<body> + +<p>A simple test follows:</p> + +<p>${message}</p> + +<p>Hello, in the English language.</p> + +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/localization_en_AU.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/localization_en_AU.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/localization_en_AU.ftl new file mode 100644 index 0000000..938f681 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/localization_en_AU.ftl @@ -0,0 +1,32 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: Localization Test</title> +</head> +<body> + +<p>A simple test follows:</p> + +<p>${message}</p> + +<p>G'day, mate!</p> + +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/logging.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/logging.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/logging.ftl new file mode 100644 index 0000000..c44d6b8 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/logging.ftl @@ -0,0 +1,42 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: Logging Test</title> +</head> +<body> + +A simple test follows: + +${message.test[ "me" ]} + +<if message> + <p>Message exists! + <transform message.sdf> + ...and even generates output! + </transform> + </p> +</if> + +<compress> +Try this for size. +</compress> + +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/loopvariable.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/loopvariable.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/loopvariable.ftl new file mode 100644 index 0000000..bc77b82 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/loopvariable.ftl @@ -0,0 +1,49 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#setting locale="en_US"> +--- +<#macro myLoop from to> + <#list from..to as x> + - <#nested x></#list>* +</#macro> +<#list 2..1 as i> + ${i} + <@myLoop from=1 to=3; i> + L1 ${i} + <@myLoop from=1 to=2; i> + L2 ${i}: <#list 1..3 as i>${i}; </#list> + </@> + </@> +</#list> +--- +<#macro repeat count> + <#list 1..count as x> + <#nested x, x/2, x==count> + </#list> +</#macro> +<#macro test2> +<#local c = 123> +<@repeat count=4 ; c, halfc, last> + <#local c = .locals.c + 0.1> + ${c} ${halfc}<#if last> Last!</#if> +</@repeat> +${c} +</#macro> +<@test2/> +--- \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/macros-return.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/macros-return.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/macros-return.ftl new file mode 100644 index 0000000..220fa2a --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/macros-return.ftl @@ -0,0 +1,34 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#macro m>m{<#return>}</#macro> +<@m/> + +<#macro m><#if true>m{<#return>}</#if></#macro> +<@m/> + +<#macro m><#if true>m{<#return></#if>}</#macro> +<@m/> + +<#macro b>b{<#nested>}</#macro> +<#macro m><@b><#return></@></#macro> +<@m/> + +<#macro b>b{<#nested>}</#macro> +<#macro m>m:<@b><#return></@></#macro> +<@m/> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/macros.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/macros.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/macros.ftl new file mode 100644 index 0000000..9d8f456 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/macros.ftl @@ -0,0 +1,101 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<html> +<head> +<title>FreeMarker: Function Test</title> +</head> +<body> + +<p>A simple test follows:</p> + +<p>${message}</p> + +<p>Now perform function tests:</p> + +<#assign urls = {"home" : "/home.html", "about" : "/about.html"}> +<#assign images = {"home" : "/images/home.png", "about" : "/image/about-us.jpeg"}> +<#assign preferences = {"showImages" : true}> +<#assign "español" = français><#macro français(url, image, alt)> + <#local var = "Kilroy"> + <a href="${url}"> + <#if preferences.showImages> + <img src="${image}" border="0" alt="${alt}"> + <#else> + ${alt} + </#if> + </a> + ${var} was here. +</#macro> + +<p>Function is defined, now let's call it:</p> + + <@español urls.home images.home "Home" /><#t> + +<p>Again, but with different parameters:</p> + +<@français + url=urls.about + image=images.about + alt="About Us" +/> + +<#if var?exists> + Something is wrong here. +<#else> + Good. +</#if> + +<p>A recursive function call:</p> + +<#macro recurse(dummy, a=3)> + <#if (a > 0)> + <@recurse dummy a - 1 /> + </#if> + ${a} +</#macro> + +<@recurse urls /> + +<p>Test "catch-all" macro parameter:</p> + +<#macro "catch-all" foo bar...> +foo=${foo} baz=[<#list bar?keys?sort as key>${key}=${bar[key]}<#if key_has_next>, </#if></#list>] +</#macro> +<#assign catchall = .namespace["catch-all"]> + +<@catchall foo="a"/> +<@catchall foo="a" bar="b"/> +<@catchall foo="a" bar="b" baz="c"/> + +<#macro fmt pattern args...> + <#list args as arg> + <#local pattern = pattern?replace("{" + arg_index + "}", arg)> + </#list> + ${pattern}<#lt> +</#macro> + +<#macro m a=1 b=2> +</#macro> +<@assertFails message='"c"'><@m c=3 /></@> +<@assertFails message='3'><@m 9 8 7 /></@> + +<@fmt "Hello {0}! Today is {1}.", "World", "Monday" /> + +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/macros2.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/macros2.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/macros2.ftl new file mode 100644 index 0000000..55ceefd --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/macros2.ftl @@ -0,0 +1,35 @@ +<#-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<#macro m1 a b=a> +${a} ${b} +</#macro> +<@m1 a="1"/> +<#macro m2 a=b b=""> +${a} ${b} +</#macro> +<@m2 b="2"/> +<#macro m3 d b=c[a] a=d c={"3":"4"}> +${b} +</#macro> +<@m3 d="3"/> +<#attempt> +<@m3 d="4"/> +<#recover> +m3 with d="4" Failed! +</#attempt> \ No newline at end of file
