Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 57049200C67 for ; Mon, 15 May 2017 23:23:30 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 55809160BD1; Mon, 15 May 2017 21:23:30 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id F1B8C160BCE for ; Mon, 15 May 2017 23:23:27 +0200 (CEST) Received: (qmail 76209 invoked by uid 500); 15 May 2017 21:23:27 -0000 Mailing-List: contact notifications-help@freemarker.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@freemarker.incubator.apache.org Delivered-To: mailing list notifications@freemarker.incubator.apache.org Received: (qmail 76200 invoked by uid 99); 15 May 2017 21:23:27 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 May 2017 21:23:27 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id A775DC06D1 for ; Mon, 15 May 2017 21:23:26 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.222 X-Spam-Level: X-Spam-Status: No, score=-4.222 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id ICCkXeFVoDnx for ; Mon, 15 May 2017 21:23:21 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 7CC365FC16 for ; Mon, 15 May 2017 21:23:19 +0000 (UTC) Received: (qmail 75952 invoked by uid 99); 15 May 2017 21:23:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 15 May 2017 21:23:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 955BCDFD43; Mon, 15 May 2017 21:23:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: ddekany@apache.org To: notifications@freemarker.incubator.apache.org Date: Mon, 15 May 2017 21:23:43 -0000 Message-Id: <723a72649dd64dd1a62885c713c36ab8@git.apache.org> In-Reply-To: <4bfc87c4667d4f69a855365b7369a594@git.apache.org> References: <4bfc87c4667d4f69a855365b7369a594@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [27/51] [abbrv] [partial] incubator-freemarker git commit: Restructured project so that freemarker-test-utils depends on freemarker-core (and hence can provide common classes for testing templates, and can use utility classes defined in the core). As a c archived-at: Mon, 15 May 2017 21:23:30 -0000 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} + +${array?size} +${array[0]} +${array[1]} +<#list list as item> +${item} + +${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 obj.baz?exists>hasbaz<#else>nobaz +${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} + + +${UNDEFINED![]?size} + +<#if UNDEFINED??> + UNDEFINED is defined. +<#else> + UNDEFINED is undefined. + \ 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&aa\"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>${1} + +${1} +${2} +${3} + +<#escape x as x?html> +${"<&>"} +<#escape x as x?xml> +${"<&>"} + +${"<&>"} + +--- +<#assign x = ""> +${x} = +<#escape x as x?upper_case> + ${x} = + <#escape x as x?html> + ${x} = <MOOO> + <#noescape> + ${x} = + + ${x} = <MOOO> + + ${x} = + <#noescape> + ${x} = + <#escape x as x?html> + ${x} = <Mooo> + <#noescape> + ${x} = + + ${x} = <Mooo> + + ${x} = + + ${x} = + +<#escape az as ["red", "green", "blue"][az-1]> + ${1} ${2} ${3} + +--- +<#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} + + \ 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. +--> + + +FreeMarker: Exception Test + + + +

A simple test follows:

+ +

${message}
+${test}

+ + + \ 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. +--> + + +FreeMarker: Exception Test + + + +

A simple test follows:

+ +

${message}
+${test}

+ + + \ 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. +--> + + +FreeMarker: Exception Test + + + +

A simple test follows:

+ +

${message}
+${%@#$test}

+ + + \ 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 /> + +<@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'> + <@assertEquals actual=((x!'-') == '-') expected=(i < 3) /> + + +<#macro attemptTest> + <#attempt> + ${fails} + <#recover> + <@assert test=isNonFastIREMessage(.error) /> + + +<@attemptTest /> +${(callMacroFromExpression(attemptTest))!} + +<#macro interpretTest><@'$\{fails}'?interpret /> +<#attempt> + <@interpretTest /> +<#recover> + <@assert test=isNonFastIREMessage(.error) /> + +<#attempt> + ${(callMacroFromExpression(interpretTest))!} +<#recover> + <@assert test=isNonFastIREMessage(.error) /> + + +<@assertEquals actual='fails'?eval!'-' expected='-' /> +<@assertEquals actual=('fails')?eval!'-' expected='-' /> + +<#macro isIRE><@assertFails exception="InvalidReferenceException"><#nested> +<#macro isNonFastIRE><@assertFails exception="InvalidReferenceException" message="Tip:"><#nested> +<#function isNonFastIREMessage msg><#return msg?contains('Tip:') && msg?contains('null or missing')> +<#function callMacroFromExpression m> + <#local captured><@m /> + <#return captured> + 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. +--> + + +FreeMarker: Hash Literal Test + + + +

A simple test follows:

+ +

${message}

+ +

Now perform a hash assignment:

+ +<#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} + +

Now update the assignment and repeat:

+ +<#assign mymessage = "world"> + +${test.test1} +${test.test45} +${test.hello} + +${test.bar} + +

Now reassign the list and repeat:

+ +<#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} + +

Pathological case: zero item hash:

+ +<#assign test = {}> +${test.test1?if_exists} + +

Hash of number literals:

+<#assign test = {"1" : 2}> +${test["1"]} + +

Hash concatenation:

+<#assign cc = { "a" : 1, "b" : 2 } + { "b" : 3, "c" : 4 }> +<#list cc?keys?sort as key> +${key} => ${cc[key]} + + +

Empty hash concatenation:

+${({} + { "a" : "foo" }).a}, ${({ "a" : "bar" } + {}).a} + + + +<@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'] /> + + \ 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. +--> + + +FreeMarker: Exec Model Test + + + +

A simple test follows:

+ +

${exec( "java freemarker.test.HelloWorld" )}

+ + + 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> + ${data\-color}<#nested \.namespace><#t> + +<#macro "m-b2"> +<#macro "m/b2"> + +<@m\-a data\-color="red"; loop\-var>${loop\-var} + +<#function f\-a p\-a> + <#return p\-a + " works"> + +${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} + +<#assign sw\-a=1> +Switch: <#switch sw\-a> + <#case 1>OK<#break> + <#default>Fails + + +<#escape \-x as \-x?upper_case>${'escaped'} + +<#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> + + +<#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...> + ${k}=${attrs[k]} /> + +<@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>...<#lt> + + +<@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 טֶקסט>${טֶקסט} +<#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 x == 1>good +- <#if x == 1>goo${missing!'d'} +- <#if x == 0>wronggood + +- <#if x == 1>good<#else>wrong +- <#if x == 0>wrong<#else>good + +- <#if x == 1>good<#elseif x == 2>wrong<#else>wrong +- <#if x == 1>good<#elseif x == 1>wrong<#else>wrong +- <#if x == 0>wrong<#elseif x == 1>good<#else>wrong +- <#if x == 0>wrong<#elseif x == 2>wrong<#else>good + +- <#if x == 1>good<#elseif x == 1>wrong +- <#if x == 0>wrong<#elseif x == 1>good +- <#if x == 0>wrong<#elseif x == 2>wronggood +- <#if x == 0>wrong<#elseif x == 1><#else>wronggood + +<#-- Same with pre-calculable results, just in case later the dead code will be optimized out: --> +- <#if 1 == 1>good +- <#if 1 == 0>wronggood +- <#if 1 == 1>goo${missing!'d'} +- <#if 1 == 0>wronggood + +- <#if 1 == 1>good<#else>wrong +- <#if 1 == 0>wrong<#else>good + +- <#if 1 == 1>good<#elseif 1 == 2>wrong<#else>wrong +- <#if 1 == 1>good<#elseif 1 == 1>wrong<#else>wrong +- <#if 1 == 0>wrong<#elseif 1 == 1>good<#else>wrong +- <#if 1 == 0>wrong<#elseif 1 == 2>wrong<#else>good + +- <#if 1 == 1>good<#elseif 1 == 1>wrong +- <#if 1 == 0>wrong<#elseif 1 == 1>good +- <#if 1 == 0>wrong<#elseif 1 == 2>wronggood +- <#if 1 == 0>wrong<#elseif 1 == 1><#else>wronggood + +<#-- Varying branch choice of the same AST nodes: --> +<#list [1, 2, 3, 4] as x> +- <#if x == 1>1 +- <#if x == 2>2 +- <#if x == 3>3 +- <#if x == 1>is 1<#else>isn't 1 +- <#if x == 2>is 2<#else>isn't 2 +- <#if x == 3>is 3<#else>isn't 3 +- Finally, it's: <#if x == 1>1<#elseif x == 2>2<#elseif x == 3>3<#else>4 + + +<#-- 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} + + <#elseif x == 2> + 2: + <#if (x > y)> + > ${y} + <#elseif x == y> + == ${y} + <#else> + <= ${y} + + <#else> + 3: + <#if (x > y)> + > ${y} + <#elseif x == y> + == ${y} + <#else> + <= ${y} + + <#if x == 3 && y == 3> + End + + + + +<#-- parsing errors --> +<@assertFails message="valid #if-#elseif-#else"><@"<#if t><#else><#elseif t2>"?interpret /> +<@assertFails message="valid #if-#elseif-#else"><@"<#if t><#else><#else>"?interpret /> +<@assertFails message="valid #if-#elseif-#else"><@"<#else>"?interpret /> +<@assertFails message="valid #if-#elseif-#else"><@"<#elseif t>"?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"> + + +${my.mail} +<@my.test foo="bar"/> + +<#assign mail="jsmith@other1.com"> +${my.mail} +<@my.test foo="bar"/> + +<#assign mail in my> + jsmith@other2.com<#t> + +${my.mail} +<@my.test foo="bar"/> + +<#import "/import_lib.ftl" as my2> +${my2.mail} +<#assign mail="jsmith@other3.com" 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} + + + +<#function doubleUp foo> + <#return foo+foo> + + +<#assign mail = "jsmith@acme.com"> \ 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. +--> + + +FreeMarker: Include Instruction Test + + + +

A simple test follows:

+ +${message} + +<#if message?exists> +

Message exists! + + +

Test normal includes:

+<#include "included.ftl"> + +${foo} +${nestedMessage} + +<@twice> +Kilroy + + +

Test subdir includes:

+<#include "subdir/include-subdir.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/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. +--> +

A test of included files:

+ +<#if .globals.message?exists> +

Message exists!:
+ ${.globals.message}

+<#else> +

No message :(

+ + +<#assign foo="assigning from included template", bar=" Can you see me? "> +<#macro twice><#nested/>${bar}<#nested/> +<#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}"> +<@templateSource?interpret>def +<@[templateSource]?interpret>def +<@[templateSource,"id"]?interpret>def + +<#assign t = '<#macro m>M'?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. +--> + + +FreeMarker: List Iterator Test + + +<#assign list= ["one", "two", "three", "four", "five"]> +<#assign hash = {"key", list}> +<#assign hash2 = {"value", hash}> + +

A simple test follows:

+ +

${message}

+ +

Now iterate over a list:

+ +<#list list as item> +

${item}

+ + +

Now iterate again:

+ +<#list list as item> +

${item_index}. ${item}

+ + +

Iterate over a list in a hash:

+ +<#list hash.key as item> +

${item}

+ + +<#list hash.key as item> +

${item}

+ + +<#list hash[ "key" ] as item> +

${item}

+ + +<#list hash["key"] as item> +

${item}

+ + +<#list hash2["value"].key as key> +

${key}

+ + +<#list hash2.value.key as az> +

${az}

+ + + + 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. +--> + + +FreeMarker: Last Character Test + + + +

A simple test follows:

+ + #{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 ['a', 'b', 'c'] as i> + ${i?index}: ${i} <#list ['A', 'B', 'C'] as j>${i?index}${i}/${j?index}${j}<#sep>, + + +<#list ['a', 'b', 'c']><#items as x>${x?index}:${x}<#sep>, +<#list ['a', 'b', 'c']><#items as x>${x?counter}. ${x};<#sep> + +<#list ['a', 'b', 'c'] as x>${x}<#if x?hasNext>, +<#list ['a', 'b', 'c'] as x\-y>${x\-y}<#if x\-y?hasNext>, + +<#list ['a', 'b', 'c'] as x><#if x?isFirst>${x?capFirst}<#else>${x}<#sep>, <#if x?isLast>. + +<#list ['a', 'b', 'c'] as x>${x?isOddItem?c}/${x?isEvenItem?c}<#sep> + +<#list ['a', 'b', 'c'] as x> + ${x} + + +<#list ['a', 'b', 'c'] as x> + ${x} + + +<#list ['a', 'b', 'c', 'd', 'e', 'f', 'g'] as x> + ${x} + +<@assertFails message="expects 1"><#list 1..1 as x>${x?itemCycle()} \ 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 +Items: <#list seq as i>@${i_index} ${i}<#if i_has_next>, <#else>. + \ 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>, + +-- List+else: +<#list resolve(xs) as x> + ${x} +<#else> + Empty! + +-- List+items: +<#list resolve(xs)> + [ + <#items as x> + ${x!'U'} + + ] + +-- List+items+else: +<#list resolve(xs)> + [ + <#items as x> + ${x!'U'} + + ] +<#else> + Empty! + +-- List+items+sep+else: +<#list resolve(xs)> + [ + <#items as x> + ${x!'U'}<#sep>, + + ] +<#else> + Empty! + +<@assertEquals expected=5 actual=resolveCallCnt /> +-- + + +<#function resolve xs> + <#assign resolveCallCnt = (resolveCallCnt!0) + 1> + <#if xs?isMethod> + <#return xs()> + <#else> + <#return xs> + + \ 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>, + +] + +<#macro hits xs style=""> + <#list xs> +

${xs?size} hits: +

+ <#switch style> + <#case "hidden"> + ... + <#break> + <#case "other"> + <#items as x> +
${x}
+ + <#break> + <#case "none"> + <#default> + <#items as x> +
${x}
+ + <#break> + +
+ <#else> +

Nothing. + + + +<@hits ['a', 'b'] /> + +<@hits ['a', 'b'], "other" /> + +<@hits ['a', 'b'], "hidden" /> + +<@hits [] /> + +<#list listables.list as i><#if i_index gt 1>...<#break>${i}<#sep>, +<#list listables.list>[<#items as i><#if i_index gt 1>...<#break>${i}<#sep>, ] + +<@testAutoClosedSep 1..3 /> +<@testAutoClosedSep [1] /> +<@testAutoClosedSep [] /> + +<#macro testAutoClosedSep xs> +<#list xs as x>${x}<#sep>, <#else>Empty +<#list xs as x>${x}<#sep><#if x_index == 0> /*first*/, <#else>, <#else>Empty +<#list xs>[<#items as x>${x}<#sep>, ]<#else>Empty + \ 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 m as k, v> + ${k!'null'} = ${v!'null'}<#sep>; // @${k?index}=@${v?index}; ${k?itemParity}=${v?itemParity}; ${k?hasNext}=${v?hasNext} + <#else> + Empty + + ] + + { + <#list m> + [ + <#items as k, v> + ${k!'null'} = ${v!'null'}<#sep>; // @${k?index}=@${v?index}; ${k?itemParity}=${v?itemParity}; ${k?hasNext}=${v?hasNext} + + ] + <#else> + Empty + + } + + + + +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} + + ${k1} @ ${k1?index}, ${v1?size} + -- + 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} + + + Keys: + <#list h?keys as k> + ${k} + + + Values: + <#list h?values as v> + ${v} + + + \ 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. +--> + + +FreeMarker: List Literal Test + + + +

A simple test follows:

+ +

${message}

+ +

Now perform a list assignment:

+ +<#assign hash = {"temp", "Temporary"}> +<#assign mymessage = "hello"> +<#assign test = [ "test1", "test23", "test45", message, mymessage]> + +The list contains #{test?size} items. + +<#list test as item> +

${item}

+ + +

Now update the assignment and repeat:

+ +<#assign mymessage = "world"> + +<#list test as item> +

${item}

+ + +

Now reassign the list and repeat:

+ +<#assign test = [ hash.temp, "test1", "test23", "test45", mymessage, "hash", hash["temp"]]> +<#assign test = [ "foo", "bar" ] + test> + +<#list test[1..4] as item> +

${item}

+ + +

Silly, but necessary tests, for one and zero element lists:

+ +<#assign test = [ "Hello, world" ]> + +<#list test as item> +

${item}

+ + +

Zero item test:

+ +<#assign test = []> + +<#list test as item> +

${item}

+ + +

Dumb test for number literals -- these weren't working as expected:

+ +<#assign test = [] + [1, 2,3, 5, 7]> + +<#list test as item> +

${item}

+<#if item == 5><#break> + + + + 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. +--> + + +FreeMarker: Localization Test + + + +

A simple test follows:

+ +

${message}

+ +

Hello, in the default language.

+ + + \ 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. +--> + + +FreeMarker: Localization Test + + + +

A simple test follows:

+ +

${message}

+ +

Hello, in the English language.

+ + + \ 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. +--> + + +FreeMarker: Localization Test + + + +

A simple test follows:

+ +

${message}

+ +

G'day, mate!

+ + + \ 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. +--> + + +FreeMarker: Logging Test + + + +A simple test follows: + +${message.test[ "me" ]} + + +

Message exists! + + ...and even generates output! + +

+
+ + +Try this for size. + + + + 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 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}; + + + +--- +<#macro repeat count> + <#list 1..count as x> + <#nested x, x/2, x==count> + + +<#macro test2> +<#local c = 123> +<@repeat count=4 ; c, halfc, last> + <#local c = .locals.c + 0.1> + ${c} ${halfc}<#if last> Last! + +${c} + +<@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>} +<@m/> + +<#macro m><#if true>m{<#return>} +<@m/> + +<#macro m><#if true>m{<#return>} +<@m/> + +<#macro b>b{<#nested>} +<#macro m><@b><#return> +<@m/> + +<#macro b>b{<#nested>} +<#macro m>m:<@b><#return> +<@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. +--> + + +FreeMarker: Function Test + + + +

A simple test follows:

+ +

${message}

+ +

Now perform function tests:

+ +<#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"> +
+ <#if preferences.showImages> + ${alt} + <#else> + ${alt} + + + ${var} was here. + + +

Function is defined, now let's call it:

+ + <@español urls.home images.home "Home" /><#t> + +

Again, but with different parameters:

+ +<@français + url=urls.about + image=images.about + alt="About Us" +/> + +<#if var?exists> + Something is wrong here. +<#else> + Good. + + +

A recursive function call:

+ +<#macro recurse(dummy, a=3)> + <#if (a > 0)> + <@recurse dummy a - 1 /> + + ${a} + + +<@recurse urls /> + +

Test "catch-all" macro parameter:

+ +<#macro "catch-all" foo bar...> +foo=${foo} baz=[<#list bar?keys?sort as key>${key}=${bar[key]}<#if key_has_next>, ] + +<#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)> + + ${pattern}<#lt> + + +<#macro m a=1 b=2> + +<@assertFails message='"c"'><@m c=3 /> +<@assertFails message='3'><@m 9 8 7 /> + +<@fmt "Hello {0}! Today is {1}.", "World", "Monday" /> + + + 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} + +<@m1 a="1"/> +<#macro m2 a=b b=""> +${a} ${b} + +<@m2 b="2"/> +<#macro m3 d b=c[a] a=d c={"3":"4"}> +${b} + +<@m3 d="3"/> +<#attempt> +<@m3 d="4"/> +<#recover> +m3 with d="4" Failed! + \ No newline at end of file