FreeMarker: Hash Literal Test

A simple test follows:

${message}

Now perform a hash assignment:

<#assign mymessage = "hello", foo="bar", one="1"> <#assign test = { "test1": "test23", "test45" : message, mymessage : "hello all", foo: one}> ${test.test1} ${test.test45} ${test.hello} ${test.bar}

Now update the assignment and repeat:

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

Now reassign the list and repeat:

<#assign hash= {"temp" : "Temporary"}> <#assign test = { "test1" : "test23", "test45" : message, mymessage : "hello all", foo : one, "hash" : hash[ "temp" ], "true" : hash.temp, "newhash" : hash}> ${test.test1} ${test.test45} ${test.hello?if_exists} ${test.bar} ${test.hash} ${test.true} ${test.newhash.temp}

Pathological case: zero item hash:

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

Hash of number literals:

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

Hash concatenation:

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

Empty hash concatenation:

${({} + { "a" : "foo" }).a}, ${({ "a" : "bar" } + {}).a}
<@noOutput> <#assign m = { 'a': 1, 'b', 2, 'a': 3 }> <#if iciIntValue gte 2003021> <@assertEquals expected="a, b" actual=m?keys?join(', ') /> <@assertEquals expected="3, 2" actual=m?values?join(', ') /> <@assertEquals expected=3 actual=m['a'] /> <@assertEquals expected=2 actual=m['b'] /> <#else> <@assertEquals expected="a, b, a" actual=m?keys?join(', ') /> <@assertEquals expected="1, 2, 3" actual=m?values?join(', ') /> <@assertEquals expected=3 actual=m['a'] /> <@assertEquals expected=2 actual=m['b'] />