http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/type-builtins.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/type-builtins.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/type-builtins.ftl new file mode 100644 index 0000000..cb0f576 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/undefined.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/undefined.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/undefined.ftl new file mode 100644 index 0000000..2ca96ac --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/url.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/url.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/url.ftl new file mode 100644 index 0000000..814de80 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/var-layers.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/var-layers.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/var-layers.ftl new file mode 100644 index 0000000..25333de --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/varargs.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/varargs.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/varargs.ftl new file mode 100644 index 0000000..5e79aa7 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/variables.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/variables.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/variables.ftl new file mode 100644 index 0000000..b927381 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/varlayers_lib.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/varlayers_lib.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/varlayers_lib.ftl new file mode 100644 index 0000000..9a1a471 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/whitespace-trim.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/whitespace-trim.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/whitespace-trim.ftl new file mode 100644 index 0000000..9c10dd9 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/wsstripinheader_inc.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/wsstripinheader_inc.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/wsstripinheader_inc.ftl new file mode 100644 index 0000000..03cbfbe --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/wstrip-in-header.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/wstrip-in-header.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xml-fragment.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xml-fragment.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xml-fragment.ftl new file mode 100644 index 0000000..226215b --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xml-ns_prefix-scope-lib.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xml-ns_prefix-scope-lib.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xml-ns_prefix-scope-main.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xml-ns_prefix-scope-main.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xml.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xml.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xml.ftl new file mode 100644 index 0000000..b85fc03 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns1.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns1.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns1.ftl new file mode 100644 index 0000000..8aa893e --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns3.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns3.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns3.ftl new file mode 100644 index 0000000..c84ec69 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/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 http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns4.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns4.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns4.ftl new file mode 100644 index 0000000..e97bfc0 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns4.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 http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns5.ftl ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns5.ftl b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns5.ftl new file mode 100644 index 0000000..edc3b4a --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/templates/xmlns5.ftl @@ -0,0 +1,28 @@ +<#ftl ns_prefixes = {"D": "http://y.com", "xx" : "http://x.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["N:root"]> +${r["N:t1"][0]?default('-')} = No NS +${r["xx:t2"][0]?default('-')} = x NS +${r["t3"][0]?default('-')} = y NS +${r["xx:t4"][0]?default('-')} = x NS +${r["//t1"][0]?default('-')} = No NS +${r["//t2"][0]?default('-')} = - +${r["//t3"][0]?default('-')} = - +${r["//t4"][0]?default('-')} = - http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/testcases.xml ---------------------------------------------------------------------- diff --git a/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/testcases.xml b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/testcases.xml new file mode 100644 index 0000000..2cfe290 --- /dev/null +++ b/freemarker-core-test/src/test/resources/org/apache/freemarker/test/templatesuite/testcases.xml @@ -0,0 +1,211 @@ +<?xml version="1.0" ?> +<!-- + 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. +--> + +<!DOCTYPE testCases [ + <!ELEMENT testCases (setting?, testCase*)> + <!ELEMENT testCase (setting?)> + <!ATTLIST testCase + name CDATA #REQUIRED + template CDATA #IMPLIED + expected CDATA #IMPLIED + noOutput CDATA #IMPLIED + > + <!-- The default of `template` is "${name?keep_before('[#endTN]')}.ftl" --> + <!-- The default of `expected` is "${name}.txt" --> + <!-- The default of `noOutput` is false --> + + <!ELEMENT setting EMPTY> + <!ATTLIST setting + auto_import CDATA #IMPLIED + source_encoding CDATA #IMPLIED + locale CDATA #IMPLIED + object_wrapper CDATA #IMPLIED + output_encoding CDATA #IMPLIED + output_dir CDATA #IMPLIED + new_builtin_class_resolver CDATA #IMPLIED + url_escaping_charset CDATA #IMPLIED + incompatible_improvements CDATA #IMPLIED + time_zone CDATA #IMPLIED + api_builtin_enabled CDATA #IMPLIED + > +]> +<!-- +Note that for the incompatible_improvements setting you can specify a list of versions, for example: +<setting incompatible_improvements="min, 3.0.5, max" /> +--> + +<testCases> + <setting source_encoding="UTF-8" output_encoding="UTF-8" /> + + <testCase name="api-builtins" noOutput="true"> + <setting api_builtin_enabled="true" /> + </testCase> + <testCase name="arithmetic" /> + <testCase name="assignments" noOutput="true" /> + <testCase name="boolean" /> + <testCase name="charset-in-header" /> + <testCase name="comment" /> + <testCase name="comparisons" /> + <testCase name="compress" /> + <testCase name="then-builtin" noOutput="true" /> + <testCase name="dateformat-java" /> + <testCase name="dateformat-iso-like" noOutput="true" /> + <testCase name="dateformat-iso-bi" noOutput="true" /> + <testCase name="dateparsing" noOutput="true" /> + <testCase name="default"/> + <testCase name="default-object-wrapper"> + <setting api_builtin_enabled="true" /> + </testCase> + <testCase name="default-xmlns" /> + <testCase name="encoding-builtins" /> + <testCase name="escapes" /> + <testCase name="hashliteral" /> + <testCase name="identifier-non-ascii" /> + <testCase name="identifier-escaping" /> + <testCase name="import"> + <setting auto_import="import_lib.ftl as my"/> + </testCase> + <testCase name="include" /> + <testCase name="include2"> + <setting source_encoding="utf-8" /> + </testCase> + <testCase name="interpret"/> + <testCase name="iterators"/> + <testCase name="lastcharacter"/> + <testCase name="list[#endTN]-simpleTemplateModels" expected="list.txt"> + <setting object_wrapper="org.apache.freemarker.test.templatesuite.models.SimpleMapAndCollectionObjectWrapper(3.0.0)" /> + </testCase> + <testCase name="list[#endTN]-collectionAdapter" expected="list.txt"> + <setting object_wrapper="DefaultObjectWrapper(3.0.0)" /> + </testCase> + <testCase name="list2[#endTN]-simpleTemplateModels" expected="list2.txt"> + <setting object_wrapper="org.apache.freemarker.test.templatesuite.models.SimpleMapAndCollectionObjectWrapper(3.0.0)" /> + </testCase> + <testCase name="list2[#endTN]-collectionAdapter" expected="list2.txt"> + <setting object_wrapper="DefaultObjectWrapper(3.0.0)" /> + </testCase> + <testCase name="list3[#endTN]-simpleTemplateModels" expected="list3.txt"> + <setting object_wrapper="org.apache.freemarker.test.templatesuite.models.SimpleMapAndCollectionObjectWrapper(3.0.0)" /> + </testCase> + <testCase name="list3[#endTN]-collectionAdapter" expected="list3.txt"> + <setting object_wrapper="DefaultObjectWrapper(3.0.0)" /> + </testCase> + <testCase name="list-bis" /> + <testCase name="list-bis[#endTN]-collectionAdapter" expected="list-bis.txt"> + <setting object_wrapper="DefaultObjectWrapper(3.0.0)" /> + </testCase> + <testCase name="listhash" /> + <testCase name="listhashliteral" /> + <testCase name="listliteral" /> + <testCase name="localization" > + <setting locale="en_AU"/> + </testCase> + <testCase name="loopvariable" /> + <testCase name="macros"/> + <testCase name="macros2"/> + <testCase name="macros-return"/> + <testCase name="multimodels"/> + <testCase name="nested" /> + <testCase name="newlines1" /> + <testCase name="newlines2" /> + <testCase name="noparse" /> + <testCase name="number-format" /> + <testCase name="number-literal" > + <setting locale="fr_FR"/> + </testCase> + <testCase name="numerical-cast" /> + <testCase name="output-encoding1"/> + <testCase name="output-encoding2"> + <setting output_encoding="UTF-16"/> + </testCase> + <testCase name="output-encoding3"> + <setting output_encoding="ISO-8859-1" url_escaping_charset="UTF-16" /> + </testCase> + <testCase name="precedence"/> + <testCase name="range" noOutput="true" /> + <testCase name="recover" /> + <testCase name="root" /> + <testCase name="setting" noOutput="true" /> + <testCase name="sequence-builtins[#endTN]-with-SimpleTemplateModel" expected="sequence-builtins.txt"> + <setting object_wrapper="org.apache.freemarker.test.templatesuite.models.SimpleMapAndCollectionObjectWrapper(3.0.0)" /> + </testCase> + <testCase name="sequence-builtins[#endTN]-with-DefaultObjectWrapper" expected="sequence-builtins.txt"> + <setting object_wrapper="default"/> + </testCase> + <testCase name="sequence-builtins[#endTN]-with-DefaultObjectWrapper-collAdapters" expected="sequence-builtins.txt"> + <setting object_wrapper="DefaultObjectWrapper(3.0.0)"/> + </testCase> + <testCase name="simplehash-char-key" noOutput="true" /> + <testCase name="existence-operators" noOutput="true" /> + <testCase name="string-builtins1" /> + <testCase name="string-builtins2" /> + <testCase name="string-builtins3" noOutput="true" /> + <testCase name="string-builtins-regexps" /> + <testCase name="string-builtins-regexps-matches" /> + <testCase name="stringbimethods" /> + <testCase name="stringliteral"/> + <testCase name="if" /> + <testCase name="switch" /> + <testCase name="switch-builtin" noOutput="true" /> + <testCase name="transforms"/> + <testCase name="type-builtins" /> + <testCase name="date-type-builtins" noOutput="true" /> + <testCase name="url" noOutput="true" /> + <testCase name="var-layers"/> + <testCase name="variables"/> + <testCase name="whitespace-trim"/> + <testCase name="wstrip-in-header"/> + <testCase name="xml-fragment" /> + <testCase name="xmlns1" /> + <testCase name="xmlns2" template="xmlns1.ftl" expected="xmlns1.txt" /> + <testCase name="xmlns3" /> + <testCase name="xmlns4" /> + <testCase name="xmlns5" /> + <testCase name="xml-ns_prefix-scope" template="xml-ns_prefix-scope-main.ftl" /> + <testCase name="hashconcat"/> + <testCase name="new-defaultresolver" /> + <testCase name="new-unrestricted" template="new-defaultresolver.ftl" expected="new-defaultresolver.txt"> + <setting new_builtin_class_resolver="unrestricted"/> + </testCase> + <testCase name="new-allowsnothing" template="new-defaultresolver.ftl"> + <setting new_builtin_class_resolver="allows_nothing"/> + </testCase> + <testCase name="new-optin"> + <setting new_builtin_class_resolver=" + allowed_classes: org.apache.freemarker.test.templatesuite.models.NewTestModel, + trusted_templates: subdir/new-optin.ftl, subdir/subsub/*" + /> + </testCase> + <testCase name="specialvars"> + <setting locale="en_US" output_encoding="utf-8" url_escaping_charset="iso-8859-1"/> + </testCase> + <testCase name="number-to-date" /> + <testCase name="varargs" /> + <testCase name="boolean-formatting" /> + <testCase name="number-math-builtins" noOutput="true" /> + <testCase name="string-builtin-coercion" noOutput="true" /> + + <testCase name="overloaded-methods[#endTN]-inc-dow" noOutput="true"> + <setting object_wrapper="org.apache.freemarker.core.model.impl.DefaultObjectWrapperInc"/> + </testCase> + <testCase name="overloaded-methods[#endTN]-desc-dow" noOutput="true"> + <setting object_wrapper="org.apache.freemarker.core.model.impl.DefaultObjectWrapperDesc"/> + </testCase> +</testCases> http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/README.txt ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/README.txt b/freemarker-core/src/test/README.txt new file mode 100644 index 0000000..fe68269 --- /dev/null +++ b/freemarker-core/src/test/README.txt @@ -0,0 +1,7 @@ +The tests were moved to the freemarker-core-test and freemarker-core-test-java8 projects. +(This was necessary to avoid dependency loops. Some utility classes that are useful for testing +the core are also useful for testing the other modules. This those classes had to be moved into +a separate module, freemarker-test-utils, which however depends on freemarker-core to provide +template testing facilities and such. Hence, freemarker-core can't depend on freemarker-test-utils, +yet the classes in it are needed for testing freemarker-core, thus, yet another project had to be +added.) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/core/ASTBasedErrorMessagesTest.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/core/ASTBasedErrorMessagesTest.java b/freemarker-core/src/test/java/org/apache/freemarker/core/ASTBasedErrorMessagesTest.java deleted file mode 100644 index 10d63b3..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/core/ASTBasedErrorMessagesTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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. - */ - -package org.apache.freemarker.core; - -import java.util.Map; - -import org.apache.freemarker.test.TemplateTest; -import org.junit.Test; - -public class ASTBasedErrorMessagesTest extends TemplateTest { - - @Test - public void testInvalidRefBasic() { - assertErrorContains("${foo}", "foo", "specify a default"); - assertErrorContains("${map[foo]}", "foo", "\\!map[", "specify a default"); - } - - @Test - public void testInvalidRefDollar() { - assertErrorContains("${$x}", "$x", "must not start with \"$\"", "specify a default"); - assertErrorContains("${map.$x}", "map.$x", "must not start with \"$\"", "specify a default"); - } - - @Test - public void testInvalidRefAfterDot() { - assertErrorContains("${map.foo.bar}", "map.foo", "\\!foo.bar", "after the last dot", "specify a default"); - } - - @Test - public void testInvalidRefInSquareBrackets() { - assertErrorContains("${map['foo']}", "map", "final [] step", "specify a default"); - } - - @Test - public void testInvalidRefSize() { - assertErrorContains("${map.size()}", "map.size", "?size", "specify a default"); - assertErrorContains("${map.length()}", "map.length", "?length", "specify a default"); - } - - @Override - protected Object createDataModel() { - Map<String, Object> dataModel = createCommonTestValuesDataModel(); - dataModel.put("overloads", new Overloads()); - return dataModel; - } - - public static class Overloads { - - @SuppressWarnings("unused") - public void m(String s) {} - - @SuppressWarnings("unused") - public void m(int i) {} - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/core/ASTPrinter.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/core/ASTPrinter.java b/freemarker-core/src/test/java/org/apache/freemarker/core/ASTPrinter.java deleted file mode 100644 index 3518b29..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/core/ASTPrinter.java +++ /dev/null @@ -1,438 +0,0 @@ -/* - * 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. - */ - -package org.apache.freemarker.core; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.StringReader; -import java.io.StringWriter; -import java.io.Writer; -import java.nio.ByteBuffer; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.Charset; -import java.nio.charset.CodingErrorAction; -import java.nio.charset.StandardCharsets; -import java.util.Enumeration; -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.util.FTLUtil; -import org.apache.freemarker.core.util._ClassUtil; -import org.apache.freemarker.core.util._StringUtil; -import org.apache.freemarker.test.TestConfigurationBuilder; - -/** - * Static methods and command-line tool for printing the AST of a template. - */ -public class ASTPrinter { - - private final Configuration cfg; - private int successfulCounter; - private int failedCounter; - - static public void main(String[] args) throws IOException { - if (args.length == 0) { - usage(); - System.exit(-1); - } - - ASTPrinter astp = new ASTPrinter(); - if (args[0].equalsIgnoreCase("-r")) { - astp.mainRecursive(args); - } else { - astp.mainSingleTemplate(args); - } - } - - private ASTPrinter() { - cfg = new TestConfigurationBuilder(Configuration.VERSION_3_0_0).build(); - } - - private void mainSingleTemplate(String[] args) throws IOException, FileNotFoundException { - final String templateFileName; - final String templateContent; - if (args[0].startsWith("ftl:")) { - templateFileName = null; - templateContent = args[0]; - } else { - templateFileName = args[0]; - templateContent = null; - } - - Template t = new Template( - templateFileName, - templateFileName == null ? new StringReader(templateContent) : new FileReader(templateFileName), - cfg); - - p(getASTAsString(t)); - } - - private void mainRecursive(String[] args) throws IOException { - if (args.length != 4) { - p("Number of arguments must be 4, but was: " + args.length); - usage(); - System.exit(-1); - } - - final String srcDirPath = args[1].trim(); - File srcDir = new File(srcDirPath); - if (!srcDir.isDirectory()) { - p("This should be an existing directory: " + srcDirPath); - System.exit(-1); - } - - Pattern fnPattern; - try { - fnPattern = Pattern.compile(args[2]); - } catch (PatternSyntaxException e) { - p(_StringUtil.jQuote(args[2]) + " is not a valid regular expression"); - System.exit(-1); - return; - } - - final String dstDirPath = args[3].trim(); - File dstDir = new File(dstDirPath); - if (!dstDir.isDirectory()) { - p("This should be an existing directory: " + dstDirPath); - System.exit(-1); - } - - long startTime = System.currentTimeMillis(); - recurse(srcDir, fnPattern, dstDir); - long endTime = System.currentTimeMillis(); - - p("Templates successfully processed " + successfulCounter + ", failed " + failedCounter - + ". Time taken: " + (endTime - startTime) / 1000.0 + " s"); - } - - private void recurse(File srcDir, Pattern fnPattern, File dstDir) throws IOException { - File[] files = srcDir.listFiles(); - if (files == null) { - throw new IOException("Failed to kust directory: " + srcDir); - } - for (File file : files) { - if (file.isDirectory()) { - recurse(file, fnPattern, new File(dstDir, file.getName())); - } else { - if (fnPattern.matcher(file.getName()).matches()) { - File dstFile = new File(dstDir, file.getName()); - String res; - try { - Template t = new Template(file.getPath().replace('\\', '/'), loadIntoString(file), cfg); - res = getASTAsString(t); - successfulCounter++; - } catch (ParseException e) { - res = "<<<FAILED>>>\n" + e.getMessage(); - failedCounter++; - p(""); - p("-------------------------failed-------------------------"); - p("Error message was saved into: " + dstFile.getAbsolutePath()); - p(""); - p(e.getMessage()); - } - save(res, dstFile); - } - } - } - } - - private String loadIntoString(File file) throws IOException { - long ln = file.length(); - if (ln < 0) { - throw new IOException("Failed to get the length of " + file); - } - byte[] buffer = new byte[(int) ln]; - InputStream in = new FileInputStream(file); - try { - int offset = 0; - int bytesRead; - while (offset < buffer.length) { - bytesRead = in.read(buffer, offset, buffer.length - offset); - if (bytesRead == -1) { - throw new IOException("Unexpected end of file: " + file); - } - offset += bytesRead; - } - } finally { - in.close(); - } - - try { - return decode(buffer, StandardCharsets.UTF_8); - } catch (CharacterCodingException e) { - return decode(buffer, StandardCharsets.ISO_8859_1); - } - } - - private String decode(byte[] buffer, Charset charset) throws CharacterCodingException { - return charset.newDecoder() - .onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT) - .decode(ByteBuffer.wrap(buffer)).toString(); - } - - private void save(String astStr, File file) throws IOException { - File parentDir = file.getParentFile(); - if (!parentDir.isDirectory() && !parentDir.mkdirs()) { - throw new IOException("Failed to invoke parent directory: " + parentDir); - } - - Writer w = new BufferedWriter(new FileWriter(file)); - try { - w.write(astStr); - } finally { - w.close(); - } - } - - private static void usage() { - p("Prints template Abstract Syntax Tree (AST) as plain text."); - p("Usage:"); - p(" java org.apache.freemarker.core.PrintAST <templateFile>"); - p(" java org.apache.freemarker.core.PrintAST ftl:<templateSource>"); - p(" java org.apache.freemarker.core.PrintAST -r <src-directory> <regexp> <dst-directory>"); - } - - private static final String INDENTATION = " "; - - public static String getASTAsString(String ftl) throws IOException { - return getASTAsString(ftl, (Options) null); - } - - public static String getASTAsString(String ftl, Options opts) throws IOException { - return getASTAsString(null, ftl, opts); - } - - public static String getASTAsString(String templateName, String ftl) throws IOException { - return getASTAsString(templateName, ftl, null); - } - - public static String getASTAsString(String templateName, String ftl, Options opts) throws IOException { - Template t = new Template(templateName, ftl, new TestConfigurationBuilder().build()); - return getASTAsString(t, opts); - } - - public static String getASTAsString(Template t) throws IOException { - return getASTAsString(t, null); - } - - public static String getASTAsString(Template t, Options opts) throws IOException { - validateAST(t); - - StringWriter out = new StringWriter(); - printNode(t.getRootASTNode(), "", null, opts != null ? opts : Options.DEFAULT_INSTANCE, out); - return out.toString(); - } - - public static void validateAST(Template t) throws InvalidASTException { - final ASTElement node = t.getRootASTNode(); - if (node.getParent() != null) { - throw new InvalidASTException("Root node parent must be null." - + "\nRoot node: " + node.dump(false) - + "\nParent" - + ": " + node.getParent().getClass() + ", " + node.getParent().dump(false)); - } - validateAST(node); - } - - private static void validateAST(ASTElement te) { - int childCount = te.getChildCount(); - for (int i = 0; i < childCount; i++) { - ASTElement child = te.getChild(i); - ASTElement parentElement = child.getParent(); - // As ASTImplicitParent.accept does nothing but returns its children, it's optimized out in the final - // AST tree. While it will be present as a child, the parent element also will have children - // that contains the children of the ASTImplicitParent directly. - if (parentElement instanceof ASTImplicitParent && parentElement.getParent() != null) { - parentElement = parentElement.getParent(); - } - if (parentElement != te) { - throw new InvalidASTException("Wrong parent node." - + "\nNode: " + child.dump(false) - + "\nExpected parent: " + te.dump(false) - + "\nActual parent: " + parentElement.dump(false)); - } - if (child.getIndex() != i) { - throw new InvalidASTException("Wrong node index." - + "\nNode: " + child.dump(false) - + "\nExpected index: " + i - + "\nActual index: " + child.getIndex()); - } - } - if (te instanceof ASTImplicitParent && te.getChildCount() < 2) { - throw new InvalidASTException("Mixed content with child count less than 2 should removed by optimizatoin, " - + "but found one with " + te.getChildCount() + " child(ren)."); - } - ASTElement[] children = te.getChildBuffer(); - if (children != null) { - if (childCount == 0) { - throw new InvalidASTException( - "Children must be null when childCount is 0." - + "\nNode: " + te.dump(false)); - } - for (int i = 0; i < te.getChildCount(); i++) { - if (children[i] == null) { - throw new InvalidASTException( - "Child can't be null at index " + i - + "\nNode: " + te.dump(false)); - } - } - for (int i = te.getChildCount(); i < children.length; i++) { - if (children[i] != null) { - throw new InvalidASTException( - "Children can't be non-null at index " + i - + "\nNode: " + te.dump(false)); - } - } - } else { - if (childCount != 0) { - throw new InvalidASTException( - "Children mustn't be null when child count isn't 0." - + "\nNode: " + te.dump(false)); - } - } - } - - private static void printNode(Object node, String ind, ParameterRole paramRole, Options opts, Writer out) throws IOException { - if (node instanceof ASTNode) { - ASTNode tObj = (ASTNode) node; - - printNodeLineStart(paramRole, ind, out); - out.write(tObj.getNodeTypeSymbol()); - printNodeLineEnd(node, out, opts); - - if (opts.getShowConstantValue() && node instanceof ASTExpression) { - TemplateModel tm = ((ASTExpression) node).constantValue; - if (tm != null) { - out.write(INDENTATION); - out.write(ind); - out.write("= const "); - out.write(FTLUtil.getTypeDescription(tm)); - out.write(' '); - out.write(tm.toString()); - out.write('\n'); - } - } - - int paramCnt = tObj.getParameterCount(); - for (int i = 0; i < paramCnt; i++) { - ParameterRole role = tObj.getParameterRole(i); - if (role == null) throw new NullPointerException("parameter role"); - Object value = tObj.getParameterValue(i); - printNode(value, ind + INDENTATION, role, opts, out); - } - if (tObj instanceof ASTElement) { - Enumeration enu = ((ASTElement) tObj).children(); - while (enu.hasMoreElements()) { - printNode(enu.nextElement(), INDENTATION + ind, null, opts, out); - } - } - } else { - printNodeLineStart(paramRole, ind, out); - out.write(_StringUtil.jQuote(node)); - printNodeLineEnd(node, out, opts); - } - } - - protected static void printNodeLineEnd(Object node, Writer out, Options opts) throws IOException { - boolean commentStared = false; - if (opts.getShowJavaClass()) { - out.write(" // "); - commentStared = true; - out.write(_ClassUtil.getShortClassNameOfObject(node, true)); - } - if (opts.getShowLocation() && node instanceof ASTNode) { - if (!commentStared) { - out.write(" // "); - commentStared = true; - } else { - out.write("; "); - } - ASTNode tObj = (ASTNode) node; - out.write("Location " + tObj.beginLine + ":" + tObj.beginColumn + "-" + tObj.endLine + ":" + tObj.endColumn); - } - out.write('\n'); - } - - private static void printNodeLineStart(ParameterRole paramRole, String ind, Writer out) throws IOException { - out.write(ind); - if (paramRole != null) { - out.write("- "); - out.write(paramRole.toString()); - out.write(": "); - } - } - - public static class Options { - - private final static Options DEFAULT_INSTANCE = new Options(); - - private boolean showJavaClass = true; - private boolean showConstantValue = false; - private boolean showLocation = false; - - public boolean getShowJavaClass() { - return showJavaClass; - } - - public void setShowJavaClass(boolean showJavaClass) { - this.showJavaClass = showJavaClass; - } - - public boolean getShowConstantValue() { - return showConstantValue; - } - - public void setShowConstantValue(boolean showConstantValue) { - this.showConstantValue = showConstantValue; - } - - public boolean getShowLocation() { - return showLocation; - } - - public void setShowLocation(boolean showLocation) { - this.showLocation = showLocation; - } - - } - - private static void p(Object obj) { - System.out.println(obj); - } - - public static class InvalidASTException extends RuntimeException { - - public InvalidASTException(String message, Throwable cause) { - super(message, cause); - } - - public InvalidASTException(String message) { - super(message); - } - - } -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/core/ASTTest.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/core/ASTTest.java b/freemarker-core/src/test/java/org/apache/freemarker/core/ASTTest.java deleted file mode 100644 index 96f173a..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/core/ASTTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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. - */ - -package org.apache.freemarker.core; - -import java.io.FileNotFoundException; -import java.io.IOException; - -import org.apache.freemarker.core.ASTPrinter.Options; -import org.apache.freemarker.core.util._StringUtil; -import org.apache.freemarker.test.util.FileTestCase; -import org.apache.freemarker.test.TestUtil; - -public class ASTTest extends FileTestCase { - - public ASTTest(String name) { - super(name); - } - - public void test1() throws Exception { - testAST("ast-1"); - } - - public void testRange() throws Exception { - testAST("ast-range"); - } - - public void testAssignments() throws Exception { - testAST("ast-assignments"); - } - - public void testBuiltins() throws Exception { - testAST("ast-builtins"); - } - - public void testStringLiteralInterpolation() throws Exception { - testAST("ast-strlitinterpolation"); - } - - public void testWhitespaceStripping() throws Exception { - testAST("ast-whitespacestripping"); - } - - public void testMixedContentSimplifications() throws Exception { - testAST("ast-mixedcontentsimplifications"); - } - - public void testMultipleIgnoredChildren() throws Exception { - testAST("ast-multipleignoredchildren"); - } - - public void testNestedIgnoredChildren() throws Exception { - testAST("ast-nestedignoredchildren"); - } - - public void testLocations() throws Exception { - testASTWithLocations("ast-locations"); - } - - private void testAST(String testName) throws FileNotFoundException, IOException { - testAST(testName, null); - } - - private void testASTWithLocations(String testName) throws FileNotFoundException, IOException { - Options options = new Options(); - options.setShowLocation(true); - testAST(testName, options); - } - - private void testAST(String testName, Options ops) throws FileNotFoundException, IOException { - final String templateName = testName + ".ftl"; - assertExpectedFileEqualsString( - testName + ".ast", - ASTPrinter.getASTAsString(templateName, - TestUtil.removeFTLCopyrightComment( - normalizeLineBreaks( - loadTestTextResource( - getTestFileURL( - getExpectedContentFileDirectoryResourcePath(), templateName))) - ), ops)); - } - - private String normalizeLineBreaks(final String s) throws FileNotFoundException, IOException { - return _StringUtil.replace(s, "\r\n", "\n").replace('\r', '\n'); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/core/ActualNamingConvetionTest.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/core/ActualNamingConvetionTest.java b/freemarker-core/src/test/java/org/apache/freemarker/core/ActualNamingConvetionTest.java deleted file mode 100644 index 57e40fa..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/core/ActualNamingConvetionTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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. - */ - -package org.apache.freemarker.core; - -import static org.junit.Assert.*; - -import java.io.IOException; - -import org.apache.freemarker.test.TestConfigurationBuilder; -import org.junit.Test; - -public class ActualNamingConvetionTest { - - @Test - public void testUndetectable() throws IOException { - final String ftl = "<#if true>${x?size}</#if>"; - assertEquals(getActualNamingConvention(ftl, - ParsingConfiguration.AUTO_DETECT_NAMING_CONVENTION), ParsingConfiguration.AUTO_DETECT_NAMING_CONVENTION); - assertEquals(getActualNamingConvention(ftl, - ParsingConfiguration.LEGACY_NAMING_CONVENTION), ParsingConfiguration.LEGACY_NAMING_CONVENTION); - assertEquals(getActualNamingConvention(ftl, - ParsingConfiguration.CAMEL_CASE_NAMING_CONVENTION), ParsingConfiguration.CAMEL_CASE_NAMING_CONVENTION); - } - - @Test - public void testLegacyDetected() throws IOException { - final String ftl = "${x?upper_case}"; - assertEquals(getActualNamingConvention(ftl, - ParsingConfiguration.AUTO_DETECT_NAMING_CONVENTION), ParsingConfiguration.LEGACY_NAMING_CONVENTION); - assertEquals(getActualNamingConvention(ftl, - ParsingConfiguration.LEGACY_NAMING_CONVENTION), ParsingConfiguration.LEGACY_NAMING_CONVENTION); - } - - @Test - public void testCamelCaseDetected() throws IOException { - final String ftl = "${x?upperCase}"; - assertEquals(getActualNamingConvention(ftl, - ParsingConfiguration.AUTO_DETECT_NAMING_CONVENTION), ParsingConfiguration.CAMEL_CASE_NAMING_CONVENTION); - assertEquals(getActualNamingConvention(ftl, - ParsingConfiguration.CAMEL_CASE_NAMING_CONVENTION), ParsingConfiguration.CAMEL_CASE_NAMING_CONVENTION); - } - - private int getActualNamingConvention(String ftl, int namingConvention) throws IOException { - return new Template(null, ftl, - new TestConfigurationBuilder().namingConvention(namingConvention).build()) - .getActualNamingConvention(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/core/ActualTagSyntaxTest.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/core/ActualTagSyntaxTest.java b/freemarker-core/src/test/java/org/apache/freemarker/core/ActualTagSyntaxTest.java deleted file mode 100644 index 88f0646..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/core/ActualTagSyntaxTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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. - */ - -package org.apache.freemarker.core; - -import static org.apache.freemarker.core.ParsingConfiguration.*; -import static org.junit.Assert.*; - -import java.io.IOException; - -import org.apache.freemarker.test.TestConfigurationBuilder; -import org.junit.Test; - -public class ActualTagSyntaxTest { - - @Test - public void testWithFtlHeader() throws IOException { - testWithFtlHeader(AUTO_DETECT_TAG_SYNTAX); - testWithFtlHeader(ANGLE_BRACKET_TAG_SYNTAX); - testWithFtlHeader(SQUARE_BRACKET_TAG_SYNTAX); - } - - private void testWithFtlHeader(int cfgTagSyntax) throws IOException { - assertEquals(getActualTagSyntax("[#ftl]foo", cfgTagSyntax), SQUARE_BRACKET_TAG_SYNTAX); - assertEquals(getActualTagSyntax("<#ftl>foo", cfgTagSyntax), ANGLE_BRACKET_TAG_SYNTAX); - } - - @Test - public void testUndecidable() throws IOException { - assertEquals(getActualTagSyntax("foo", AUTO_DETECT_TAG_SYNTAX), ANGLE_BRACKET_TAG_SYNTAX); - assertEquals(getActualTagSyntax("foo", ANGLE_BRACKET_TAG_SYNTAX), ANGLE_BRACKET_TAG_SYNTAX); - assertEquals(getActualTagSyntax("foo", SQUARE_BRACKET_TAG_SYNTAX), SQUARE_BRACKET_TAG_SYNTAX); - } - - @Test - public void testDecidableWithoutFtlHeader() throws IOException { - assertEquals(getActualTagSyntax("foo<#if true></#if>", AUTO_DETECT_TAG_SYNTAX), ANGLE_BRACKET_TAG_SYNTAX); - assertEquals(getActualTagSyntax("foo<#if true></#if>", ANGLE_BRACKET_TAG_SYNTAX), ANGLE_BRACKET_TAG_SYNTAX); - assertEquals(getActualTagSyntax("foo<#if true></#if>", SQUARE_BRACKET_TAG_SYNTAX), SQUARE_BRACKET_TAG_SYNTAX); - - assertEquals(getActualTagSyntax("foo[#if true][/#if]", AUTO_DETECT_TAG_SYNTAX), SQUARE_BRACKET_TAG_SYNTAX); - assertEquals(getActualTagSyntax("foo[#if true][/#if]", ANGLE_BRACKET_TAG_SYNTAX), ANGLE_BRACKET_TAG_SYNTAX); - assertEquals(getActualTagSyntax("foo[#if true][/#if]", SQUARE_BRACKET_TAG_SYNTAX), SQUARE_BRACKET_TAG_SYNTAX); - } - - private int getActualTagSyntax(String ftl, int cfgTagSyntax) throws IOException { - return new Template( - null, ftl, - new TestConfigurationBuilder().tagSyntax(cfgTagSyntax).build()).getActualTagSyntax(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/28a276c8/freemarker-core/src/test/java/org/apache/freemarker/core/BreakPlacementTest.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/test/java/org/apache/freemarker/core/BreakPlacementTest.java b/freemarker-core/src/test/java/org/apache/freemarker/core/BreakPlacementTest.java deleted file mode 100644 index 61ba02b..0000000 --- a/freemarker-core/src/test/java/org/apache/freemarker/core/BreakPlacementTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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. - */ - -package org.apache.freemarker.core; - -import java.io.IOException; - -import org.apache.freemarker.test.TemplateTest; -import org.junit.Test; - -public class BreakPlacementTest extends TemplateTest { - - private static final String BREAK_NESTING_ERROR_MESSAGE_PART = "<#break> must be nested"; - - @Test - public void testValidPlacements() throws IOException, TemplateException { - assertOutput("<#assign x = 1><#switch x><#case 1>one<#break><#case 2>two</#switch>", "one"); - assertOutput("<#list 1..2 as x>${x}<#break></#list>", "1"); - assertOutput("<#list 1..2>[<#items as x>${x}<#break></#items>]</#list>", "[1]"); - assertOutput("<#list 1..2 as x>${x}<#list 1..3>B<#break>E<#items as y></#items></#list>E</#list>.", "1B."); - assertOutput("<#list 1..2 as x>${x}<#list 3..4 as x>${x}<#break></#list>;</#list>", "13;23;"); - assertOutput("<#list [1..2, 3..4, [], 5..6] as xs>[<#list xs as x>${x}<#else><#break></#list>]</#list>.", - "[12][34][."); - assertOutput("<#list [1..2, 3..4, [], 5..6] as xs>" - + "<#list xs>[<#items as x>${x}</#items>]<#else><#break></#list>" - + "</#list>.", - "[12][34]."); - } - - @Test - public void testInvalidPlacements() throws IOException, TemplateException { - assertErrorContains("<#break>", BREAK_NESTING_ERROR_MESSAGE_PART); - assertErrorContains("<#list 1..2 as x>${x}</#list><#break>", BREAK_NESTING_ERROR_MESSAGE_PART); - assertErrorContains("<#if false><#break></#if>", BREAK_NESTING_ERROR_MESSAGE_PART); - assertErrorContains("<#list xs><#break></#list>", BREAK_NESTING_ERROR_MESSAGE_PART); - assertErrorContains("<#list 1..2 as x>${x}<#else><#break></#list>", BREAK_NESTING_ERROR_MESSAGE_PART); - assertErrorContains("<#list 1..2 as x>${x}<#macro m><#break></#macro></#list>", BREAK_NESTING_ERROR_MESSAGE_PART); - } - -}
