http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins-regexps.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins-regexps.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins-regexps.ftl new file mode 100644 index 0000000..81c0b8f --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins-regexps.ftl @@ -0,0 +1,136 @@ +<#-- + 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. +--> +${"test"?matches('test')?string} == true +${"test"?matches('test', '')?string} == true + +${"TEST"?matches('test')?string} == false +${"TEST"?matches('test', 'i')?string} == true + +${"test\nfoo"?matches('.*^foo')?string} == false +${"test\nfoo"?matches(r'.*\n^foo', 'm')?string} == true + +${"test\nfoo"?matches('test.foo')?string} == false +${"test\nfoo"?matches('test.foo', 's')?string} == true + +${"test\nFoo"?matches('.*foo', 's')?string} == false +${"test\nFoo"?matches('.*foo', 'i')?string} == false +${"test\nFoo"?matches('.*foo', 'im')?string} == false +${"test\nFoo"?matches('.*foo', 'si')?string} == true +${"test\nFoo"?matches('.*foo', 'is')?string} == true +${"test\nFoo"?matches('.*foo', 'mis')?string} == true + +${"test\nFoo"?matches('.*\n^foo', 'm')?string} == false +${"test\nFoo"?matches('.*\n^foo', 'i')?string} == false +${"test\nFoo"?matches('.*\n^foo', 'im')?string} == true +${"test\nFoo"?matches('.*\n^foo', 'mi')?string} == true +${"test\nFoo"?matches('.*^foo', 'ism')?string} == true +${"test\nFoo"?matches('.*^foo', 'smi')?string} == true +<#setting boolean_format="True,False"> +<@assert test=false?matches('[eslaF]+') /> +<@assert test='False'?matches('[eslaF]+') /> + +<#assign s = "Code without test coverage\nis considered to be BROKEN"> + +Lower 'c'-words: +<#list s?matches('c[a-z]*') as m> +- ${m} +</#list> + +Any 'c'-words: +<#list s?matches('c[a-z]*', 'i') as m> +- ${m} +</#list> + +Lower line-last words: +<#list s?matches('[a-z]+$', 'm') as m> +- ${m} +</#list> + +Any line-last words: +<#list s?matches('[a-z]+$', 'mi') as m> +- ${m} +</#list> + +Any last words: +<#list s?matches('[a-z]+$', 'i') as m> +- ${m} +</#list> + +c-word with follower: +<#list s?matches('(c[a-z]*+).([a-z]++)', 'is') as m> +- "${m?j_string}" + Groups: <#list m?groups as g>"${g?j_string}"<#if g_has_next>, </#if></#list> +</#list> + +c-word with follower in the same line: +<#list s?matches('c[a-z]*+.[a-z]++', 'i') as m> +- ${m} +</#list> + +Lower c-word with follower in the same line: +<#list s?matches('c[a-z]*+.[a-z]++', '') as m> +- ${m} +</#list> + +<#attempt> + Ignored but logged in 2.3: ${s?matches('broken', 'I')?string} == False +<#recover> + Fails in 2.4 +</#attempt> +<#attempt> + Ignored but logged in 2.3: ${s?matches('broken', 'f')?string} == False +<#recover> + Fails in 2.4 +</#attempt> + +${"foobar"?replace("foo", "FOO")} == FOObar +${"Foobar"?replace("foo", "FOO", "")} == Foobar +${"Foobar"?replace("foo", "FOO", "i")} == FOObar +${"FoobarfOO"?replace("foo", "FOO", "i")} == FOObarFOO +${"FoobarfOO"?replace("foo", "FOO", "if")} == FOObarfOO +${"FoobarfOO"?replace("foo", "FOO", "fi")} == FOObarfOO +${"Foobar"?replace("foo", "FOO", "r")} == Foobar +${"Foobar"?replace("foo", "FOO", "ri")} == FOObar +${"FoobarfOO"?replace("foo", "FOO", "ri")} == FOObarFOO +${"FoobarfOO"?replace("foo", "FOO", "rif")} == FOObarfOO +${"FoobarfOO"?replace("foo", "FOO", "fri")} == FOObarfOO +${"foobar"?replace("fo+", "FOO")} == foobar +${"foobar"?replace("fo+", "FOO", "")} == foobar +${"foobar"?replace("fo+", "FOO", "r")} == FOObar +${"foobarfOo"?replace("fo+", "FOO", "ri")} == FOObarFOO +${"foobarfOo"?replace("fo+", "FOO", "rif")} == FOObarfOo +${false?replace('a', 'A')} == FAlse +${false?replace('[abc]', 'A', 'r')} == FAlse + +<#attempt> + Ignored but logged in 2.3: ${"foobar"?replace("foo", "FOO", "c")} +<#recover> + Fails in 2.4 +</#attempt> + +<#macro dumpList xs>[<#list xs as x>${x}<#if x_has_next>, </#if></#list>]</#macro> +<@dumpList "fooXbarxbaaz"?split("X") /> == [foo, barxbaaz] +<@dumpList "fooXbarxbaaz"?split("X", "") /> == [foo, barxbaaz] +<@dumpList "fooXbarxbaaz"?split("X", "i") /> == [foo, bar, baaz] +<@dumpList "fooXbarxbaaz"?split("X", "r") /> == [foo, barxbaaz] +<@dumpList "fooXbarxbaaz"?split("X", "ri") /> == [foo, bar, baaz] +<@dumpList "fooXXbarxxbaaz"?split("X+", "i") /> == [fooXXbarxxbaaz] +<@dumpList "fooXXbarxxbaaz"?split("X+", "ri") /> == [foo, bar, baaz] +<@dumpList false?split("[ae]", "r") /> == [F, ls] +<@dumpList false?split("e") /> == [Fals, ] \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins1.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins1.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins1.ftl new file mode 100644 index 0000000..cd7f061 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins1.ftl @@ -0,0 +1,129 @@ +<#-- + 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 string built-in tests + +<#assign x = r' dieBugsDie! * vazzZE 123456 --cdc-- --<<--@ x ${"kigyo"?upper_case} '> + +cap_first: ${x?cap_first} +uncap_first:${x?uncap_first} +uncap_first:${"Blah"?uncap_first} +capitalize: ${x?capitalize} +html: ${x?html} +length: ${x?length} +lower_case: ${x?lower_case} +rtf: ${x?rtf} +trim: ${x?trim} +trim2: ${"foo bar"?trim} +trim3: ${" foo bar"?trim} +trim4: ${"foo bar "?trim} +upper_case: ${x?upper_case} +xml: ${x?xml} +xhtml: ${"\"Blah's is > 1 & < 2\""?xhtml} +<@assertEquals actual="'"?html expected="'" /> +<@assertEquals actual="'"?xhtml expected="'" /> +<@assertEquals actual="'"?xml expected="'" /> +<#-- ?substring: --> +<@assertEquals actual="ab"?substring(0) expected="ab" /> +<@assertEquals actual="ab"?substring(1) expected="b" /> +<@assertEquals actual="ab"?substring(2) expected="" /> +<@assertFails message="at least 0">${"ab"?substring(-1)}</@><#t> +<@assertFails message="greater than the length of the string">${"ab"?substring(3)}</@><#t> +<@assertEquals actual="ab"?substring(0, 0) expected="" /> +<@assertEquals actual="ab"?substring(0, 1) expected="a" /> +<@assertEquals actual="ab"?substring(0, 2) expected="ab" /> +<@assertFails message="at least 0">${"ab"?substring(0, -1)}</@><#t> +<@assertFails message="greater than the length of the string">${"ab"?substring(0, 3)}</@><#t> +<@assertEquals actual="ab"?substring(1, 1) expected="" /> +<@assertEquals actual="ab"?substring(1, 2) expected="b" /> +<@assertFails message="at least 0">${"ab"?substring(1, -1)}</@><#t> +<@assertFails message="greater than the length of the string">${"ab"?substring(1, 3)}</@><#t> +<@assertFails message="shouldn't be greater than the end index">${"ab"?substring(1, 0)}</@><#t> + +word_list: +<#global words = x?word_list> +<#list words as w>- ${w} +</#list> + +<#global canufeelitbabe = x?interpret> +interpret: <@canufeelitbabe></@> +<#setting locale="es_ES">number: ${"-123.45"?number + 1.1} +${"1.5e3"?number?c} +${"0005"?number?c} +${"+0"?number?c} +${"-0"?number?c} +${"NaN"?number?is_nan?c} +${("INF"?number?is_infinite && "INF"?number > 0)?c} +${("-INF"?number?is_infinite && "-INF"?number < 0)?c} +${("Infinity"?number?is_infinite && "Infinity"?number > 0)?c} +${("-Infinity"?number?is_infinite && "-Infinity"?number < 0)?c} + +${"org.apache.freemarker.core.templatesuite.models.NewTestModel"?new()} +${"org.apache.freemarker.core.templatesuite.models.NewTestModel"?new(1)} +${"org.apache.freemarker.core.templatesuite.models.NewTestModel"?new("xxx")} +${"org.apache.freemarker.core.templatesuite.models.NewTestModel"?new("xxx", "yyy")} + +<#assign x = "In the beginning, God created the Heavens and The Earth."> + +${x?replace("the", "The Sacred, Holy", "i")} <#-- case insensitive replacement --> +${x?replace("the", "the very", "f")} <#-- replace only the first one --> +${x?replace("", "|")} <#-- replace empry string --> +${x?replace("", "|", "f")} <#-- replace first empty string --> + +${x?replace("the H[a-z]+", "the sky", "r")} <#-- regexp replacement --> + +<#if x?matches(".*Heav..s.*")>matches<#else>Really?</#if> + +<#list x?matches("(the) ([a-z]+)", "i") as match> + ${match} + ${match?groups[1]} sacred ${match?groups[2]} +</#list> + +<#assign matches = x?matches("In the ([a-z]+), God created (.*)")> +${matches?groups[0]} +${matches?groups[1]} +${matches?groups[2]} + +<#assign x="foo, bar;baz, foobar"> +<#list x?split("[,;] ?", "r") as word> + ${word} +</#list> + + +<#assign a = "foo", b="bar", c="(a+b)?upper_case"> +${c?eval} + +[${"a"?j_string}] = [a] +[${"a\\'x'\nb"?j_string}] = [a\\'x'\nb] +[${"\x1\x1A\x20"?j_string}] = [\u0001\u001a ] + +[${"a"?js_string}] = [a] +[${"a\\'x'\nb"?js_string}] = [a\\\'x\'\nb] +[${"\x1\x1A\x20"?js_string}] = [\x01\x1A ] +[${"<![CDATA["?js_string}] = [\x3C![CDATA[] +[${"]]>"?js_string}] = []]\>] + +[${"a"?json_string}] = [a] +[${"a\\'x'\nb"?json_string}] = [a\\'x'\nb] +[${"\x1\x1A\x20"?json_string}] = [\u0001\u001A ] +[${"\n\r\t\f\b\""?json_string}] = [\n\r\t\f\b\"] +[${"/"?json_string}] = [\/] +[${"a/b"?json_string}] = [a/b] +[${"</script>"?json_string}] = [<\/script>] +[${"<![CDATA["?json_string}] = [\u003C![CDATA[] +[${"]]>"?json_string}] = []]\u003E] http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins2.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins2.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins2.ftl new file mode 100644 index 0000000..c9294fa --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins2.ftl @@ -0,0 +1,135 @@ +<#-- + 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 s = "abbcdbb"> +${s?index_of("bb")} = 1 +${s?index_of("bb", 2)} = 5 +${s?index_of("")} = 0 +-- +${s?last_index_of("bb")} = 5 +${s?last_index_of("bb", 4)} = 1 +${s?last_index_of("")} = ${s?length} +-- +${s?starts_with("abb")?string} = true +${s?starts_with("bb")?string} = false +${s?starts_with("")?string} = true +-- +${s?ends_with("dbb")?string} = true +${s?ends_with("cbb")?string} = false +${s?ends_with("")?string} = true +-- +${s?contains("abb")?string} = true +${s?contains("bcd")?string} = true +${s?contains("dbb")?string} = true +${s?contains("bbx")?string} = false +${s?contains("")?string} = true +-- +[${s?chop_linebreak}] = [abbcdbb] +[${"qwe\n"?chop_linebreak}] = [qwe] +[${"qwe\r"?chop_linebreak}] = [qwe] +[${"qwe\r\n"?chop_linebreak}] = [qwe] +[${"qwe\r\n\r\n"?chop_linebreak}] = [qwe +] +[${"qwe\n\n"?chop_linebreak}] = [qwe +] +-- +[${s?replace("A", "-")}] = [abbcdbb] +[${s?replace("c", "-")}] = [abb-dbb] +[${s?replace("bb", "-=*")}] = [a-=*cd-=*] +-- +<#assign ls = s?split("b")> +<#list ls as i>[${i}]</#list> == [a][][cd][][] +<#list "--die--maggots--!"?split("--") as i>[${i}]</#list> == [][die][maggots][!] +<#list "Die maggots!"?split("--") as i>[${i}]</#list> == [Die maggots!] +-- +[${""?left_pad(5)}] +[${"a"?left_pad(5)}] +[${"ab"?left_pad(5)}] +[${"abc"?left_pad(5)}] +[${"abcd"?left_pad(5)}] +[${"abcde"?left_pad(5)}] +[${"abcdef"?left_pad(5)}] +[${"abcdefg"?left_pad(5)}] +[${"abcdefgh"?left_pad(5)}] +[${""?left_pad(5, "-")}] +[${"a"?left_pad(5, "-")}] +[${"ab"?left_pad(5, "-")}] +[${"abc"?left_pad(5, "-")}] +[${"abcd"?left_pad(5, "-")}] +[${"abcde"?left_pad(5, "-")}] +[${"abcdef"?left_pad(5, "-")}] +[${"abcdefg"?left_pad(5, "-")}] +[${"abcdefgh"?left_pad(5, "-")}] +[${""?left_pad(8, ".oO")}] +[${"a"?left_pad(8, ".oO")}] +[${"ab"?left_pad(8, ".oO")}] +[${"abc"?left_pad(8, ".oO")}] +[${"abcd"?left_pad(8, ".oO")}] +[${"abcde"?left_pad(8, ".oO")}] +[${"abcdef"?left_pad(8, ".oO")}] +[${"abcdefg"?left_pad(8, ".oO")}] +[${"abcdefgh"?left_pad(8, ".oO")}] +[${"abcdefghi"?left_pad(8, ".oO")}] +[${"abcdefghij"?left_pad(8, ".oO")}] +[${""?left_pad(0, r"/\_")}] +[${""?left_pad(1, r"/\_")}] +[${""?left_pad(2, r"/\_")}] +[${""?left_pad(3, r"/\_")}] +[${""?left_pad(4, r"/\_")}] +[${""?left_pad(5, r"/\_")}] +[${""?left_pad(6, r"/\_")}] +[${""?left_pad(7, r"/\_")}] +-- +[${""?right_pad(5)}] +[${"a"?right_pad(5)}] +[${"ab"?right_pad(5)}] +[${"abc"?right_pad(5)}] +[${"abcd"?right_pad(5)}] +[${"abcde"?right_pad(5)}] +[${"abcdef"?right_pad(5)}] +[${"abcdefg"?right_pad(5)}] +[${"abcdefgh"?right_pad(5)}] +[${""?right_pad(5, "-")}] +[${"a"?right_pad(5, "-")}] +[${"ab"?right_pad(5, "-")}] +[${"abc"?right_pad(5, "-")}] +[${"abcd"?right_pad(5, "-")}] +[${"abcde"?right_pad(5, "-")}] +[${"abcdef"?right_pad(5, "-")}] +[${"abcdefg"?right_pad(5, "-")}] +[${"abcdefgh"?right_pad(5, "-")}] +[${""?right_pad(8, ".oO")}] +[${"a"?right_pad(8, ".oO")}] +[${"ab"?right_pad(8, ".oO")}] +[${"abc"?right_pad(8, ".oO")}] +[${"abcd"?right_pad(8, ".oO")}] +[${"abcde"?right_pad(8, ".oO")}] +[${"abcdef"?right_pad(8, ".oO")}] +[${"abcdefg"?right_pad(8, ".oO")}] +[${"abcdefgh"?right_pad(8, ".oO")}] +[${"abcdefghi"?right_pad(8, ".oO")}] +[${"abcdefghij"?right_pad(8, ".oO")}] +[${""?right_pad(0, r"/\_")}] +[${""?right_pad(1, r"/\_")}] +[${""?right_pad(2, r"/\_")}] +[${""?right_pad(3, r"/\_")}] +[${""?right_pad(4, r"/\_")}] +[${""?right_pad(5, r"/\_")}] +[${""?right_pad(6, r"/\_")}] +[${""?right_pad(7, r"/\_")}] \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins3.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins3.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins3.ftl new file mode 100644 index 0000000..77389fa --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/string-builtins3.ftl @@ -0,0 +1,225 @@ +<#-- + 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. +--> +<@assertEquals expected='foo' actual='foo'?keep_before('x') /> +<@assertEquals expected='f' actual='foo'?keep_before('o') /> +<@assertEquals expected='' actual='foo'?keep_before('f') /> +<@assertEquals expected='fo' actual='foobar'?keep_before('ob') /> +<@assertEquals expected='foob' actual='foobar'?keep_before('ar') /> +<@assertEquals expected='' actual='foobar'?keep_before('foobar') /> +<@assertEquals expected='' actual='foobar'?keep_before('') /> +<@assertEquals expected='' actual='foobar'?keep_before('', 'r') /> +<@assertEquals expected='FOO' actual='FOO'?keep_before('o') /> +<@assertEquals expected='F' actual='FOO'?keep_before('o', 'i') /> +<@assertEquals expected='fo' actual='fo.o'?keep_before('.') /> +<@assertEquals expected='' actual='fo.o'?keep_before('.', 'r') /> +<@assertEquals expected='FOOb' actual='FOObaar'?keep_before(r'([a-z])\1', 'r') /> +<@assertEquals expected='F' actual='FOObaar'?keep_before(r'([a-z])\1', 'ri') /> +<@assertEquals expected='foo' actual="foo : bar"?keep_before(r"\s*:\s*", "r") /> +<@assertEquals expected='foo' actual="foo:bar"?keep_before(r"\s*:\s*", "r") /> +<@assertFails message='"m" flag'> + ${'x'?keep_before('x', 'm')} +</@assertFails> +<@assertFails message='3'> + ${'x'?keep_before('x', 'i', 'x')} +</@assertFails> +<@assertFails message='none'> + ${'x'?keep_before()} +</@assertFails> + +<@assertEquals expected='' actual=''?keep_before_last('f') /> +<@assertEquals expected='ff' actual='fff'?keep_before_last('f') /> +<@assertEquals expected='' actual='foo'?keep_before_last('f') /> +<@assertEquals expected='' actual='f'?keep_before_last('f') /> +<@assertEquals expected='a.b' actual='a.b.txt'?keep_before_last('.') /> +<@assertEquals expected='ab' actual='ab'?keep_before_last('.') /> +<@assertEquals expected='a' actual='ab'?keep_before_last('.', 'r') /> +<@assertEquals expected='ab' actual='ab'?keep_before_last(r'\.', 'r') /> +<@assertEquals expected='af' actual='afFf'?keep_before_last('F') /> +<@assertEquals expected='afF' actual='afFf'?keep_before_last('F', 'i') /> +<@assertEquals expected='1a2' actual='1a2b3'?keep_before_last('[ab]', 'r') /> +<@assertEquals expected='aa' actual='aaabb'?keep_before_last('[ab]{3}', 'r') /> +<@assertEquals expected='aaabbx' actual='aaabbxbabe'?keep_before_last('[ab]{3}', 'r') /> +<@assertEquals expected='xxxaa' actual='xxxaaayyy'?keep_before_last('a+', 'r') /> +<@assertEquals expected='foobar' actual='foobar'?keep_before_last('') /> +<@assertEquals expected='foobar' actual='foobar'?keep_before_last('', 'r') /> +<@assertFails message='"m" flag'> + ${'x'?keep_before_last('x', 'm')} +</@assertFails> +<@assertFails message='3'> + ${'x'?keep_before_last('x', 'i', 'x')} +</@assertFails> +<@assertFails message='none'> + ${'x'?keep_before_last()} +</@assertFails> + +<@assertEquals expected='' actual='foo'?keep_after('x') /> +<@assertEquals expected='o' actual='foo'?keep_after('o') /> +<@assertEquals expected='oo' actual='foo'?keep_after('f') /> +<@assertEquals expected='ar' actual='foobar'?keep_after('ob') /> +<@assertEquals expected='' actual='foobar'?keep_after('ar') /> +<@assertEquals expected='' actual='foobar'?keep_after('foobar') /> +<@assertEquals expected='foobar' actual='foobar'?keep_after('') /> +<@assertEquals expected='foobar' actual='foobar'?keep_after('', 'r') /> +<@assertEquals expected='' actual='FOO'?keep_after('o') /> +<@assertEquals expected='O' actual='FOO'?keep_after('o', 'i') /> +<@assertEquals expected='o' actual='fo.o'?keep_after('.') /> +<@assertEquals expected='o.o' actual='fo.o'?keep_after('.', 'r') /> +<@assertEquals expected='r' actual='FOObaar'?keep_after(r'([a-z])\1', 'r') /> +<@assertEquals expected='baar' actual='FOObaar'?keep_after(r'([a-z])\1', 'ri') /> +<@assertEquals expected='bar' actual="foo : bar"?keep_after(r"\s*:\s*", "r") /> +<@assertEquals expected='bar' actual="foo:bar"?keep_after(r"\s*:\s*", "r") /> +<@assertFails message='"m" flag'> + ${'x'?keep_after('x', 'm')} +</@assertFails> +<@assertFails message='3'> + ${'x'?keep_after('x', 'i', 'x')} +</@assertFails> +<@assertFails message='none'> + ${'x'?keep_after()} +</@assertFails> + +<@assertEquals expected='' actual=''?keep_after_last('f') /> +<@assertEquals expected='' actual='fff'?keep_after_last('f') /> +<@assertEquals expected='' actual='oof'?keep_after_last('f') /> +<@assertEquals expected='' actual='f'?keep_after_last('f') /> +<@assertEquals expected='txt' actual='a.b.txt'?keep_after_last('.') /> +<@assertEquals expected='' actual='ab'?keep_after_last('.') /> +<@assertEquals expected='' actual='ab'?keep_after_last('.', 'r') /> +<@assertEquals expected='' actual='ab'?keep_after_last(r'\.', 'r') /> +<@assertEquals expected='fa' actual='fFfa'?keep_after_last('F') /> +<@assertEquals expected='a' actual='fFfa'?keep_after_last('F', 'i') /> +<@assertEquals expected='3' actual='1a2b3'?keep_after_last('[ab]', 'r') /> +<@assertEquals expected='' actual='aaabb'?keep_after_last('[ab]{3}', 'r') /> +<@assertEquals expected='x' actual='aaabbx'?keep_after_last('[ab]{3}', 'r') /> +<@assertEquals expected='e' actual='aaabbxbabe'?keep_after_last('[ab]{3}', 'r') /> +<@assertEquals expected='12345' actual='aaabb12345'?keep_after_last('[ab]{3}', 'r') /> +<@assertEquals expected='yyy' actual='xxxaaayyy'?keep_after_last('a+', 'r') /> +<@assertEquals expected='' actual='foobar'?keep_after_last('') /> +<@assertEquals expected='' actual='foobar'?keep_after_last('', 'r') /> +<@assertFails message='"m" flag'> + ${'x'?keep_after_last('x', 'm')} +</@assertFails> +<@assertFails message='3'> + ${'x'?keep_after_last('x', 'i', 'x')} +</@assertFails> +<@assertFails message='none'> + ${'x'?keep_after_last()} +</@assertFails> + +<@assertEquals expected='foo' actual='foo'?remove_beginning('x') /> +<@assertEquals expected='foo' actual='foo'?remove_beginning('o') /> +<@assertEquals expected='foo' actual='foo'?remove_beginning('fooo') /> +<@assertEquals expected='oo' actual='foo'?remove_beginning('f') /> +<@assertEquals expected='o' actual='foo'?remove_beginning('fo') /> +<@assertEquals expected='' actual='foo'?remove_beginning('foo') /> +<@assertEquals expected='foo' actual='foo'?remove_beginning('') /> +<@assertFails message='2'> + ${'x'?remove_beginning('x', 'x')} +</@assertFails> +<@assertFails message='none'> + ${'x'?remove_beginning()} +</@assertFails> + +<@assertEquals expected='bar' actual='bar'?remove_ending('x') /> +<@assertEquals expected='bar' actual='bar'?remove_ending('a') /> +<@assertEquals expected='bar' actual='bar'?remove_ending('barr') /> +<@assertEquals expected='ba' actual='bar'?remove_ending('r') /> +<@assertEquals expected='b' actual='bar'?remove_ending('ar') /> +<@assertEquals expected='' actual='bar'?remove_ending('bar') /> +<@assertEquals expected='bar' actual='bar'?remove_ending('') /> +<@assertFails message='2'> + ${'x'?remove_ending('x', 'x')} +</@assertFails> +<@assertFails message='none'> + ${'x'?remove_ending()} +</@assertFails> + +<@assertEquals expected='xfoo' actual='foo'?ensure_starts_with('x') /> +<@assertEquals expected='foo' actual='foo'?ensure_starts_with('f') /> +<@assertEquals expected='foo' actual='foo'?ensure_starts_with('foo') /> +<@assertEquals expected='fooofoo' actual='foo'?ensure_starts_with('fooo') /> +<@assertEquals expected='foo' actual='foo'?ensure_starts_with('') /> +<@assertEquals expected='x' actual=''?ensure_starts_with('x') /> +<@assertEquals expected='' actual=''?ensure_starts_with('') /> +<@assertEquals expected='bacdef' actual="bacdef"?ensure_starts_with("[ab]{2}", "ab") /> +<@assertEquals expected='bacdef' actual="bacdef"?ensure_starts_with("^[ab]{2}", "ab") /> +<@assertEquals expected='abcacdef' actual="cacdef"?ensure_starts_with("[ab]{2}", "ab") /> +<@assertEquals expected='abcacdef' actual="cacdef"?ensure_starts_with("^[ab]{2}", "ab") /> +<@assertEquals expected='ab!cdef' actual="cdef"?ensure_starts_with("ab", "ab!") /> +<@assertEquals expected='ab!ABcdef' actual="ABcdef"?ensure_starts_with("ab", "ab!") /> +<@assertEquals expected='ABcdef' actual="ABcdef"?ensure_starts_with("ab", "ab!", 'i') /> +<@assertEquals expected='abABcdef' actual="ABcdef"?ensure_starts_with(".b", "ab", 'i') /> +<@assertEquals expected='ABcdef' actual="ABcdef"?ensure_starts_with(".b", "ab", 'ri') /> +<@assertEquals expected='http://example.com' actual="example.com"?ensure_starts_with("[a-z]+://", "http://") /> +<@assertEquals expected='http://example.com' actual="http://example.com"?ensure_starts_with("[a-z]+://", "http://") /> +<@assertEquals expected='https://example.com' actual="https://example.com"?ensure_starts_with("[a-z]+://", "http://") /> +<@assertEquals expected='http://HTTP://example.com' actual="HTTP://example.com"?ensure_starts_with("[a-z]+://", "http://") /> +<@assertEquals expected='HTTP://example.com' actual="HTTP://example.com"?ensure_starts_with("[a-z]+://", "http://", "ir") /> +<@assertFails message='4'> + ${'x'?ensure_starts_with('x', 'x', 'x', 'x')} +</@assertFails> +<@assertFails message='none'> + ${'x'?ensure_starts_with()} +</@assertFails> + +<@assertEquals expected='foox' actual='foo'?ensure_ends_with('x') /> +<@assertEquals expected='foo' actual='foo'?ensure_ends_with('o') /> +<@assertEquals expected='foo' actual='foo'?ensure_ends_with('foo') /> +<@assertEquals expected='foofooo' actual='foo'?ensure_ends_with('fooo') /> +<@assertEquals expected='foo' actual='foo'?ensure_ends_with('') /> +<@assertEquals expected='x' actual=''?ensure_ends_with('x') /> +<@assertEquals expected='' actual=''?ensure_ends_with('') /> +<@assertFails message='2'> + ${'x'?ensure_ends_with('x', 'x')} +</@assertFails> +<@assertFails message='none'> + ${'x'?ensure_ends_with()} +</@assertFails> + +<@assertEquals expected='a' actual=1?lower_abc /> +<@assertEquals expected='b' actual=2?lower_abc /> +<@assertEquals expected='z' actual=26?lower_abc /> +<@assertEquals expected='aa' actual=27?lower_abc /> +<@assertEquals expected='ab' actual=28?lower_abc /> +<@assertEquals expected='cv' actual=100?lower_abc /> +<@assertFails messageRegexp='0|at least 1']> + ${0?lower_abc} +</@assertFails> +<@assertFails messageRegexp='0|at least 1'> + ${-1?lower_abc} +</@assertFails> +<@assertFails messageRegexp='1.00001|integer'> + ${1.00001?lower_abc} +</@assertFails> + +<@assertEquals expected='A' actual=1?upper_abc /> +<@assertEquals expected='B' actual=2?upper_abc /> +<@assertEquals expected='Z' actual=26?upper_abc /> +<@assertEquals expected='AA' actual=27?upper_abc /> +<@assertEquals expected='AB' actual=28?upper_abc /> +<@assertEquals expected='CV' actual=100?upper_abc /> +<@assertFails messageRegexp='0|at least 1']> + ${0?upper_abc} +</@assertFails> +<@assertFails messageRegexp='0|at least 1'> + ${-1?upper_abc} +</@assertFails> +<@assertFails messageRegexp='1.00001|integer'> + ${1.00001?upper_abc} +</@assertFails> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/stringbimethods.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/stringbimethods.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/stringbimethods.ftl new file mode 100644 index 0000000..1d31c44 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/stringbimethods.ftl @@ -0,0 +1,36 @@ +<#-- + 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"> +<#assign x = 3> +${x?string["0.00"]} +${x?string("0.00")} +${'01:02:03'?time.iso?string["iso ms nz"]} +${'01:02:03'?time.iso?string("iso ms nz")} +--- +${multi} +<#assign a = true> +<#assign b = false> +${a?string} ${b?string} +${a?string("yes", "no")} ${b?string("yes", "no")} +<#setting boolean_format="igen,nem"/> +${a?string} ${b?string} +<#setting number_format="0.0"> +${a?string(0, 1)} ${b?string(0, 1)} +<#setting boolean_format="true,false"/> +${a?string(0, 1)?is_string?string} ${b?string(0, 1)?is_string?string} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/stringliteral.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/stringliteral.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/stringliteral.ftl new file mode 100644 index 0000000..436c632 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/stringliteral.ftl @@ -0,0 +1,69 @@ +<#-- + 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: String literal test</title> + <meta http-equiv="Content-type" content="text/html; charset=UTF-8"> +</head> +<body> + +<p>A simple test follows:</p> + +<#assign x = "Hello", y = "World"> +<#assign message = "${x}, ${y}!"> + +${message} + +<p> +[${""}] = []<br> +[${"a"}] = [a]<br> +[${"abcdef"}] = [abcdef]<br> +[${"\""}] = ["]<br> +[${"\"\"\""}] = ["""]<br> +[${"a\""}] = [a"]<br> +[${"\"a"}] = ["a]<br> +[${"a\"b"}] = [a"b]<br> +[${"a\nb"}] = [a +b]<br> +[${"'"}] = [']<br> +[${"a'a"}] = [a'a]<br> +[${"\"\'\n\r\f\b\t\l\a\g"}]<br> +[${"\xA\x0A\x00A\x000A\x0000A"}]<br> +[${"\x15Bz\x15b"}]<br> +[${"\x010Cz\x010c"}]<br> + +<p> +[${''}] = []<br> +[${'a'}] = [a]<br> +[${'abcdef'}] = [abcdef]<br> +[${'"'}] = ["]<br> +[${'"""'}] = ["""]<br> +[${'a"'}] = [a"]<br> +[${'"a'}] = ["a]<br> +[${'a"b'}] = [a"b]<br> +[${'a\nb'}] = [a +b]<br> +[${'\''}] = [']<br> +[${'a\'a'}] = [a'a]<br> +[${'\"\'\n\r\f\b\t\l\a\g'}]<br> +[${'\xA\x0A\x00A\x000A\x0000A'}]<br> +[${'\x15Bz\x15b'}]<br> +[${'\x010Cz\x010c'}]<br> +</body> +</html> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/include-subdir.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/include-subdir.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/include-subdir.ftl new file mode 100644 index 0000000..cd24873 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/include-subdir.ftl @@ -0,0 +1,27 @@ +<#-- + 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>This is include-subdir.ftl</p> +<p>Testing including from same directory</p> +<#include "include-subdir2.ftl"> +<p>Testing including from relative parent</p> +<#include "../included.ftl"> +<p>Testing including from loader root</p> +<#include "/included.ftl"> +<p>Testing including through acquisition</p> +<#include "*/subdir/include-subdir2.ftl"> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/include-subdir2.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/include-subdir2.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/include-subdir2.ftl new file mode 100644 index 0000000..356fcb2 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/include-subdir2.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. +--> +<p>This is include-subdir2.ftl</p> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/new-optin-2.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/new-optin-2.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/new-optin-2.ftl new file mode 100644 index 0000000..fafe593 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/new-optin-2.ftl @@ -0,0 +1,24 @@ +<#-- + 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. +--> +${"org.apache.freemarker.core.templatesuite.models.NewTestModel"?new("works")} +<#attempt> +${"org.apache.freemarker.core.templatesuite.models.NewTestModel2"?new("works")} +<#recover> +fails +</#attempt> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/new-optin.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/new-optin.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/new-optin.ftl new file mode 100644 index 0000000..cc37004 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/new-optin.ftl @@ -0,0 +1,26 @@ +<#-- + 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. +--> +${"org.apache.freemarker.core.templatesuite.models.NewTestModel"?new("works")} +<#attempt> +${"org.apache.freemarker.core.templatesuite.models.NewTestModel2"?new("works")} +<#recover> +fails +</#attempt> + +<#include "new-optin-2.ftl"> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/subsub/new-optin.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/subsub/new-optin.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/subsub/new-optin.ftl new file mode 100644 index 0000000..fafe593 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/subdir/subsub/new-optin.ftl @@ -0,0 +1,24 @@ +<#-- + 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. +--> +${"org.apache.freemarker.core.templatesuite.models.NewTestModel"?new("works")} +<#attempt> +${"org.apache.freemarker.core.templatesuite.models.NewTestModel2"?new("works")} +<#recover> +fails +</#attempt> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/switch-builtin.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/switch-builtin.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/switch-builtin.ftl new file mode 100644 index 0000000..7441733 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/switch-builtin.ftl @@ -0,0 +1,54 @@ +<#-- + 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. +--> +<@assertEquals expected="A" actual="a"?switch("a", "A") /> +<@assertFails message="didn't match">${"b"?switch("a", "A")}</@> +<@assertEquals expected="D" actual="b"?switch("a", "A", "D") /> +<@assertEquals expected="B" actual="b"?switch("a", "A", "b", "B") /> +<@assertFails message="didn't match">${"c"?switch("a", "A", "b", "B")}</@> +<@assertEquals expected="D" actual="c"?switch("a", "A", "b", "B", "D") /> + +<#assign out = ""> +<#assign fInvocationCnt = 0> +<#list 0..5 as x> + <#assign out += x?switch(1, f("one"), 2, f("two"), 3, f("three"), f("default")) + ";"> +</#list> +<@assertEquals expected="default;one;two;three;default;default;" actual=out /> +<@assertEquals expected=6 actual=fInvocationCnt /> + +<#assign out = ""> +<#list 0..5 as x> + <#assign out += true?switch(x <= 1, "low", x == 2 || x == 3, "medium", x >= 3, "high") + ";"> +</#list> +<@assertEquals expected="low;low;medium;medium;high;high;" actual=out /> + +<#function f x> + <#assign fInvocationCnt++> + <#return x> +</#function> + +<@assertFails message="noSuchVar1">${1?switch(noSuchVar1, noSuchVar2)}</@> +<@assertFails message="noSuchVar2">${1?switch(1, noSuchVar2)}</@> +<@assertFails message="noSuchVar3">${noSuchVar3?switch(1, 1)}</@> + +<@assertEquals expected="one" actual=1?switch(1, "one", "2", "two") /> +<@assertFails messageRegexp="Can't compare.+number.+string">${2?switch(1, "one", "2", "two")}</@> +<@assertFails messageRegexp="Can't compare.+number.+string">${2?switch(1, "one", "2", "two", "default")}</@> + +<#assign out><#escape x as x?switch(2 * x, "zero", 1, "one", x, x?string("0.0"))>${0} ${1} ${2}</#escape></#assign> +<@assertEquals expected="zero one 2.0" actual=out /> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/switch.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/switch.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/switch.ftl new file mode 100644 index 0000000..6bbab3c --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/switch.ftl @@ -0,0 +1,139 @@ +<#-- + 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: Switch-Case Test</title> +</head> +<body> + +<p>Here we iterate over a list of animals.</p> +<#assign animalList = [ "aardvark", "kiwi", "gecko", "cat", "dog", "elephant", + "squirrel", "zebra" ]> +<#assign favoriteAnimal = "kiwi"> + +<#list animalList as animal> +<p>Animal is: ${animal}.<br /> +<#switch animal> + <#case "zebra"> + This is the HTML for a large stripey animal. + <#case "elephant"> + <#case "rhinocerous"> + This is the HTML for large animals. + <#break> + <#case "squirrel"> + <#case "gecko"> + This is the HTML for small animals. + <#break> + <#case favoriteAnimal> + This is the HTML for the user's favorite animal. + <#break> + <#default> + This is the HTML for other animals. + <#break> +</#switch> +</p> +</#list> + +<#-- Nesting and no-match --> +<#list [ 1, 2, 3 ] as x> + <#switch x> + <#case 1> + 1 + <#switch x*2> + <#case 1> + i1 + <#break> + <#case 2> + i2 + <#break> + <#case 3> + i3 + <#break> + <#case 4> + i4 + <#break> + <#case 6> + i6 + <#break> + </#switch> + <#break> + <#case 2> + 2 + <#switch x*2> + <#case 1> + i1 + <#break> + <#case 2> + i2 + <#break> + <#case 3> + i3 + <#break> + <#case 4> + i4 + <#-- falls through --> + <#case 5> + ft + <#-- falls through --> + </#switch> + ft + <#-- falls through --> + <#case 3> + 3 + <#switch x*2> + <#case 1> + i1 + <#break> + <#case 2> + i2 + <#break> + <#case 3> + i3 + <#break> + <#case 4> + i4 + <#break> + <#case 6> + i6 + <#break> + </#switch> + <#break> + </#switch> +</#list> + +<#-- No match --> +[<#switch 213> + <#case 1>sadas +</#switch>] + +<#-- Fall-through --> +<#list [ 0, 1, 2, 3, 4 ] as x> + "<#switch x><#case 1>1<#case 2>2<#case 3>3<#case 4>4</#switch>" +</#list> + +<#-- Legacy parser bug: #default might not be the last, but it doesn't fall through if called directly --> +<#list [1, 2, 3, 4, 5] as x> + "<#switch x><#case 1>1<#case 2>2<#default>default<#case 4>4<#case 5>5</#switch>" +</#list> + +<#-- two #default-s are parsing error --> +<@assertFails message="can only have one default"><@"<#switch 1><#case 1><#default><#default></#switch>"?interpret /></@> + +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/then-builtin.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/then-builtin.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/then-builtin.ftl new file mode 100644 index 0000000..de809e1 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/then-builtin.ftl @@ -0,0 +1,53 @@ +<#-- + 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 f1InvocationCnt = 0> +<#assign f2InvocationCnt = 0> + +<@assertEquals expected="f1 1" actual=true?then(f1(), f2()) /> +<@assertEquals expected="f2 1" actual=false?then(f1(), f2()) /> +<@assertEquals expected="f1 2" actual=true?then(f1(), f2()) /> +<@assertEquals expected="f2 2" actual=false?then(f1(), f2()) /> +<@assertEquals expected=2 actual=f1InvocationCnt /> +<@assertEquals expected=2 actual=f2InvocationCnt /> + +<#function f1> + <#assign f1InvocationCnt++> + <#return "f1 " + f1InvocationCnt> +</#function> + +<#function f2> + <#assign f2InvocationCnt++> + <#return "f2 " + f2InvocationCnt> +</#function> + +<#assign x = 1> +<@assertEquals expected='Y' actual=(x < 2 * x)?then(-x < x, false)?then('Y', 'N') /> + +<@assertEquals expected=1 actual=true?then(x, noSuchVar) /> +<@assertEquals expected=1 actual=false?then(noSuchVar, x) /> + +<@assertFails message="noSuchVar1">${true?then(noSuchVar1, noSuchVar2)}</@> +<@assertFails message="noSuchVar2">${false?then(noSuchVar1, noSuchVar2)}</@> +<@assertFails message="noSuchVar3">${noSuchVar3?then(noSuchVar1, noSuchVar2)}</@> + +<#assign out><#escape x as x?then(1, 0)>${false} ${true}</#escape></#assign> +<@assertEquals expected="0 1" actual=out /> + +<#assign out><#escape x as (x < 0)?then(-x * 3, x * 2)>${-1} ${1}</#escape></#assign> +<@assertEquals expected="3 2" actual=out /> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/transforms.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/transforms.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/transforms.ftl new file mode 100644 index 0000000..9b1e55a --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/transforms.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. +--> +<#assign htmlEscape = "org.apache.freemarker.core.util.HtmlEscape"?new(), + utility = "org.apache.freemarker.core.templatesuite.models.TransformHashWrapper"?new()> +<html> +<head> +<title>FreeMarker: Transformation Test</title> +</head> +<body> + +<p>A simple test follows:</p> + +<p>${message}</p> + +<@htmlEscape> +<p>${message}</p> +</@htmlEscape> + +<P>Now try the Utility package:</p> +<p>${utility}</p> + +<@utility.htmlEscape> +<p>${utility}</p> +</@> + +<p>Now some nested transforms:</p> +<@utility.compress> +<p >This tests the compress transformation</p > +</@> +<@utility.compress> +<@utility.htmlEscape> +<p >This tests the compress transformation</p > +</@> +</@utility.compress> +<#assign html_transform = "org.apache.freemarker.core.util.HtmlEscape"?new() /> +<@html_transform><#--Using the transform via an instantiation --> +<@utility.compress> +<p >This tests the compress transformation</p > +</@> +</@> + +<p>Now try method and transform interactions:</p> +<@utility.escape("xml")> +<p>This isn't a valid XML string.</p> +</@> +<@utility.escape("html")> +<p>This isn't a valid HTML string.</p> +</@> + +<p>A more advanced interaction involves getting a TemplateMethodModel +to initialise a TemplateTransformModel, as follow:</p> + +<@utility.special("This is a comment")> +Comment: * + +A test string containing quotes: "This isn't a test". +A test string containing amps: Fish & Chips. +A test string containing tags: <p>Fish & Chips.</p> +</@> + +<@utility.special("This is a second comment", "quote")> +Comment: * + +A test string containing quotes: "This isn't a test". +A test string containing amps: Fish & Chips. +A test string containing tags: <p>Fish & Chips.</p> +</@> +<@utility.special("This is a third comment", "ampersand", "quote")> +Comment: * + +A test string containing quotes: "This isn't a test". +A test string containing amps: Fish & Chips. +A test string containing tags: <p>Fish & Chips.</p> +</@> +<@utility.special("tag", utility)> +Comment: * + +A test string containing quotes: "This isn't a test". +A test string containing amps: Fish & Chips. +A test string containing tags: <p>Fish & Chips.</p> +</@> + +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/type-builtins.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/type-builtins.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/type-builtins.ftl new file mode 100644 index 0000000..cb0f576 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/type-builtins.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. +--> +<#setting boolean_format="1,0"> +StNuBoMeTaMaHaHxSeCoCxEnInDiNo +<#list [ + "a", 1, false, + testmethod, testmacro, html_escape, + {"a":1}, [1], testcollection, testcollectionEx, + testnode, + bean, bean.m, bean.mOverloaded +] as x> + ${x?is_string} <#t> + ${x?is_number} <#t> + ${x?is_boolean} <#t> + ${x?is_method} <#t> + ${x?is_macro} <#t> + ${x?is_transform} <#t> + ${x?is_hash} <#t> + ${x?is_hash_ex} <#t> + ${x?is_sequence} <#t> + ${x?is_collection} <#t> + ${x?is_collection_ex} <#t> + ${x?is_enumerable} <#t> + ${x?is_indexable} <#t> + ${x?is_directive} <#t> + ${x?is_node}<#lt> +</#list> +<#macro testmacro></#macro> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/undefined.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/undefined.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/undefined.ftl new file mode 100644 index 0000000..2ca96ac --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/undefined.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. +--> +${undefined_variable} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/url.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/url.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/url.ftl new file mode 100644 index 0000000..814de80 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/url.ftl @@ -0,0 +1,24 @@ +<#-- + 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 url_escaping_charset="utf-8"> +<#assign s = 'a/báb?c/x;y=1' /> +<@assertEquals expected='a%2Fb%E1b%3Fc%2Fx%3By%3D1' actual=s?url('ISO-8859-1') /> +<@assertEquals expected='a%2Fb%C3%A1b%3Fc%2Fx%3By%3D1' actual=s?url /> +<@assertEquals expected='a/b%E1b%3Fc/x%3By%3D1' actual=s?url_path('ISO-8859-1') /> +<@assertEquals expected='a/b%C3%A1b%3Fc/x%3By%3D1' actual=s?url_path /> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/var-layers.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/var-layers.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/var-layers.ftl new file mode 100644 index 0000000..25333de --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/var-layers.ftl @@ -0,0 +1,39 @@ +<#-- + 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 "varlayers_lib.ftl" as lib> +<@foo 1/> +${x} = ${.data_model.x} = ${.globals.x} +<#assign x = 5> +${x} = ${.main.x} = ${.namespace.x} +<#global x = 6> +${.globals.x} but ${.data_model.x} = 4 +${y} = ${.globals.y} = ${.data_model.y?default("ERROR")} +Invisiblity test 1.: <#if .main.y?exists || .namespace.y?exists>failed<#else>passed</#if> +Invisiblity test 2.: <#if .main.z?exists || .namespace.z?exists>failed<#else>passed</#if> +Invisiblity test 3.: <#global q = 1><#if .main.q?exists || .namespace.q?exists || .data_model.q?exists>failed<#else>passed</#if> +-- +<@lib.foo/> +-- +<#macro foo x> + ${x} = ${.locals.x} + <#local x = 2> + ${x} = ${.locals.x} + <#local y = 3> + ${y} = ${.locals.y} +</#macro> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/varargs.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/varargs.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/varargs.ftl new file mode 100644 index 0000000..5e79aa7 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/varargs.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. +--> +<#setting number_format="#"> + +${m.bar()} == 0 +${m.bar([])} == 0 +${m.bar(11)} == 11 +${m.bar(null, 11)} == 11 +${m.bar(11, 22)} == 1122 +${m.bar(11.6, 22.4)} == 1122 +${m.bar(11, 22, 33)} == 112233 +${m.bar([11, 22, 33])} == 112233 + +${m.bar2(11, [22, 33, 44])} == -22334411 +${m.bar2(11, 22, 33)} == -223311 +${m.bar2(11, 22)} == -2211 +${m.bar2(11)} == -11 + +${m.overloaded()} == 0 +${m.overloaded(11)} == -11 +${m.overloaded(11, 22)} == 1122 +${m.overloaded(11, 22, 33)} == -112233 +${m.overloaded(11, 22, 33, 44)} == -11223344 +${m.overloaded([11, 22, 33, 44, 55])} == -1122334455 + +${m.overloaded(11, 22)} == 1122 +${m.overloaded([11, 22])} == -1122 + +${m.noVarArgs("string", true, 123, 1000000?number_to_date)} == string, true, 123, 1000000 http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/variables.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/variables.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/variables.ftl new file mode 100644 index 0000000..b927381 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/variables.ftl @@ -0,0 +1,70 @@ +[#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. +--] +<html> +<head> +<title>FreeMarker: Variable Test</title> +</head> +<body> +[#assign list = ["one", "two", "three", "four", "five"]] +[#assign hash = {"output" : "My message.", "key" : list}] +[#assign hash2 = {"value" : hash}] +[#assign items = {"mykey" : "key", "_test", "out"}] + +<p>A simple test follows:</p> + +<p>${message}</p> + +<p>Now get into variable nesting:</p> + +<p>${hash.output}</p> +<p>${hash["output"]}</p> +<p>${hash. output}</p> +<p>${hash .output}</p> +<p>${hash + .output}</p> +<p>${hash + . output}</p> +<p>${hash ["output"]}</p> +<p>${hash + [ "output" ]}</p> + +<p>More deep nesting...</p> + +<p>${hash2.value.output}</p> +<p>${hash2.value.key[0]}</p> +<p>${hash2["value"]["key"][0]}</p> + + +<p>Nesting inside nesting...</p> + +<p>${hash2.value[ items.mykey ][ 1 ]}</p> +<p>${hash2.value[ items[ "mykey" ]][ 1 ]}</p> +<p>${hash2.value[ items[ "my" + items.mykey ]][ 1 ]}</p> +<p>${hash2.value[ items[ "my" + items["mykey"] ]][ 1 ]}</p> + +<p>Test underscores...</p> + +<p>${items[ "_test" ]}</p> +<p>${items._test}</p> + +${"God save the queen."?word_list[1]?upper_case} + +</body> +</html> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/varlayers_lib.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/varlayers_lib.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/varlayers_lib.ftl new file mode 100644 index 0000000..9a1a471 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/varlayers_lib.ftl @@ -0,0 +1,28 @@ +<#-- + 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 x1 = .data_model.x> +<#assign x2 = x> +<#assign z2 = z> +<#macro foo> +<@.main.foo 1/> + ${z} = ${z2} = ${x1} = ${.data_model.x} + 5 + ${x} == ${.globals.x} + ${y} == ${.globals.y} == ${.data_model.y?default("ERROR")} +</#macro> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/whitespace-trim.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/whitespace-trim.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/whitespace-trim.ftl new file mode 100644 index 0000000..9c10dd9 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/whitespace-trim.ftl @@ -0,0 +1,102 @@ +<#-- + 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. +--> + LB<#lt> + LB<#lt> + LB<#lt> +LB<#lt> + IB + IC1<#rt> + IC2<#rt> +C1<#rt> +C2<#rt> + ICS <#rt> +CS1 <#rt> + CS2 <#t> + C3<#t> + C1<#t> +C2 +B +B + C1<#t> +CB +C1 + C2<#t> + ICB + IC<#rt> + ICB + IC<#rt> + CB<#lt> +-- +<#macro x t>${t}</#macro> + ${""}<@x t="LB"/><#lt> + <@x t="LB"/><#lt>${""} + <@x t="LB"/><#lt>${""} +<@x t="LB"/><#lt>${""} + <@x t="IB"/>${""} +${""} <@x t="IC1"/><#rt> + <@x t="IC2"/><#rt>${""} +${""}<@x t="C1"/><#rt> +<@x t="C2"/><#rt>${""} + <@x t="ICS"/> <#rt>${""} +<@x t="CS1"/> <#rt>${""} + <@x t="CS2"/> <#t>${""} + <@x t="C3"/><#t> + <@x t="C1"/><#t> +<@x t="C2"/>${""} +<#nt><@x t="B"/> +<@x t="B"/><#nt> + <@x t="C1"/><#t> +<@x t="CB"/>${""} +<@x t="C1"/>${""} + <@x t="C2"/><#t>${""} + <@x t="ICB"/>${""} + ${""}<@x t="IC"/><#rt> + <@x t="ICB"/>${""} +${""} <@x t="IC"/><#rt> + <@x t="CB"/>${""}<#lt> +-- + <#lt> IB + IC1<#rt> + <#assign x = 1> <#-- just a comment --> + C2<#t> + <#assign x = 1> + IB +1<#t> + <#assign x = 1> +2 +--- +<#t>1 + <#t> 2 + <#lt>3 + 4 + <#rt>5 + 6 +--- +a + <#assign x = 1><#t> +b<#t> +c +--- + <#if true> + <#t>foo + </#if> +--- + <#if true><#-- just a comment --> + foo<#t> + </#if> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/wsstripinheader_inc.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/wsstripinheader_inc.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/wsstripinheader_inc.ftl new file mode 100644 index 0000000..03cbfbe --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/wsstripinheader_inc.ftl @@ -0,0 +1,22 @@ +<#ftl strip_whitespace="yes"> +<#-- + 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 +<#assign x = 1> +b \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/wstrip-in-header.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/wstrip-in-header.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/wstrip-in-header.ftl new file mode 100644 index 0000000..0dce83c --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/wstrip-in-header.ftl @@ -0,0 +1,26 @@ + + + + <#ftl strip_whitespace="no"> +<#-- + 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 +<#assign x = 1> +b +<#include "wsstripinheader_inc.ftl"> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml-fragment.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml-fragment.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml-fragment.ftl new file mode 100644 index 0000000..226215b --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml-fragment.ftl @@ -0,0 +1,26 @@ +<#ftl ns_prefixes = {"n" : "http://x"}> +<#-- + 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. +--> +${node?node_name} = b +${node?root?node_name} = @document +${node['/']?node_name} = @document + +${node['n:c']} = C<>&"']]> + +${node?root.@@markup} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml-ns_prefix-scope-lib.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml-ns_prefix-scope-lib.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml-ns_prefix-scope-lib.ftl new file mode 100644 index 0000000..0f0bde2 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml-ns_prefix-scope-lib.ftl @@ -0,0 +1,23 @@ +<#ftl ns_prefixes={ "n": "http://freemarker.org/test/bar", "D": "http://freemarker.org/test/namespace-test" }> +<#-- + 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 libResult>//n:e: ${doc['//n:e']}, ${doc.root['n:e']}</#global> +<#macro m> +//n:e: ${doc['//n:e']}, ${doc.root['n:e']} +</#macro> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml-ns_prefix-scope-main.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml-ns_prefix-scope-main.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml-ns_prefix-scope-main.ftl new file mode 100644 index 0000000..5b7ce24 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml-ns_prefix-scope-main.ftl @@ -0,0 +1,36 @@ +<#ftl ns_prefixes={ + "D": "http://freemarker.org/test/namespace-test", + "n": "http://freemarker.org/test/foo", + "bar": "http://freemarker.org/test/bar" +}> +<#-- + 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. +--> +//e: ${doc['//D:e']}, ${doc.root.e} +//n:e: ${doc['//n:e']}, ${doc.root['n:e']} +//bar:e: ${doc['//bar:e']}, ${doc.root['bar:e']} + +Included: +<#include "xml-ns_prefix-scope-lib.ftl"> +${libResult} +<@m /> + +Imported: +<#import "xml-ns_prefix-scope-lib.ftl" as lib> +${libResult} +<@lib.m /> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml.ftl new file mode 100644 index 0000000..b85fc03 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xml.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. +--> +<#-- test processing instructions --> +<#global PIs = doc._content._ftype("p")> +<#list PIs as pi> + ${pi} + ${pi["@target"]._text} + ${pi["@data"]._text} +</#list> +${PIs?size} +<#global firstPi = PIs[0]> +${firstPi._type} +${firstPi["@customKey"]} +${doc._registerNamespace("ns", "http://www.foo.com/ns1/")} +${doc._descendant["ns:e11"]} +${doc._descendant["ns:e12"]} +<#global docRoot = doc["ns:root"]> +${docRoot["ns:e1"]} +${doc("//ns:e11")} +${docRoot["ns:e1"]["@a1"]._name} +${docRoot["ns:e1"]["@a2"]._text} +${docRoot._children._parent._name} +${docRoot._children._parent._unique._name} +<#list doc._descendant as d> + ${d._name} +</#list> +<#list doc._descendant._ancestorOrSelf as d> + ${d._name} +</#list> +${docRoot["ns:e2"]["ns:e12"]._text} +${docRoot["ns:e2"]["ns:e12"]._plaintext} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xmlns1.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xmlns1.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xmlns1.ftl new file mode 100644 index 0000000..8aa893e --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xmlns1.ftl @@ -0,0 +1,53 @@ +<#ftl ns_prefixes = {"D" : "http://example.com/eBook"}> +<#-- + 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. +--> + +${doc.@@markup} + +<#recurse doc > + +<#macro book> + <html> + <head> + <title><#recurse .node.title></title> + </head> + <body> + <h1><#recurse .node.title></h1> + <#recurse> + </body> + </html> +</#macro> + +<#macro chapter> + <h2><#recurse .node.title></h2> + <#recurse> +</#macro> + +<#macro para> + <p><#recurse> +</#macro> + +<#macro title> + <#-- + We have handled this element imperatively, + so we do nothing here. + --> +</#macro> + +<#macro @text>${.node?html}</#macro> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/4b75ea93/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xmlns3.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xmlns3.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xmlns3.ftl new file mode 100644 index 0000000..c84ec69 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/core/templatesuite/templates/xmlns3.ftl @@ -0,0 +1,70 @@ +<#ftl ns_prefixes = {"x" : "http://x", "y" : "http://y"}> +<#-- + 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. +--> +<#recurse doc > + +<#macro book> + <html> + <head> + <title><#recurse .node["x:title"]></title> + </head> + <body> + <h1><#recurse .node["x:title"]></h1> + <#recurse> + </body> + </html> +</#macro> + +<#macro chapter> + <h2><#recurse .node["y:title"]></h2> + <#recurse> +</#macro> + +<#macro "x:chapter"> + <h2><#recurse .node["y:title"]></h2> + <#recurse> +</#macro> + +<#macro para> + <p><#recurse> +</#macro> + +<#macro "x:para"> + <p><#recurse> +</#macro> + +<#macro "y:para"> + <p><#recurse> +</#macro> + +<#macro "x:title"> + <#-- + We have handled this element imperatively, + so we do nothing here. + --> +</#macro> + +<#macro "y:title"> + <#-- + We have handled this element imperatively, + so we do nothing here. + --> +</#macro> + +<#macro @text>${.node?html}</#macro> \ No newline at end of file
