erlydtl_test_defs.erl 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003
  1. -module(erlydtl_test_defs).
  2. -export([tests/0]).
  3. -include("testrunner.hrl").
  4. -record(testrec, {foo, bar, baz}).
  5. %% {Name, DTL, Vars, Output}
  6. %% {Name, DTL, Vars, RenderOpts, Output}
  7. %% {Name, DTL, Vars, RenderOpts, CompilerOpts, Output}
  8. %% {Name, DTL, Vars, RenderOpts, CompilerOpts, Output, Warnings}
  9. tests() ->
  10. [def_to_test(G, D) || {G, Ds} <- all_test_defs(), D <- Ds].
  11. all_test_defs() ->
  12. [{"vars",
  13. [{"string",
  14. <<"String value is: {{ var1 }}">>,
  15. [{var1, "foo"}], <<"String value is: foo">>},
  16. {"int",
  17. <<"The magic number is: {{ var1 }}">>,
  18. [{var1, 42}], <<"The magic number is: 42">>},
  19. {"float",
  20. <<"The price of milk is: {{ var1 }}">>,
  21. [{var1, 0.42}], <<"The price of milk is: 0.42">>},
  22. {"No spaces",
  23. <<"{{var1}}">>,
  24. [{var1, "foo"}], <<"foo">>},
  25. {"Variable name is a tag name",
  26. <<"{{ comment }}">>,
  27. [{comment, "Nice work!"}], <<"Nice work!">>},
  28. #test{
  29. title = "reserved name ok as variable name",
  30. source = <<"{{ from }}">>,
  31. render_vars = [{from, "test"}],
  32. output = <<"test">>
  33. }
  34. ]},
  35. {"comment",
  36. [{"comment block is excised",
  37. <<"bob {% comment %}(moron){% endcomment %} loblaw">>,
  38. [], <<"bob loblaw">>},
  39. {"inline comment is excised",
  40. <<"you're {# not #} a very nice person">>,
  41. [], <<"you're a very nice person">>}
  42. ]},
  43. {"autoescape",
  44. [{"Autoescape works",
  45. <<"{% autoescape on %}{{ var1 }}{% endautoescape %}">>,
  46. [{var1, "<b>bold</b>"}], <<"&lt;b&gt;bold&lt;/b&gt;">>},
  47. {"Nested autoescape",
  48. <<"{% autoescape on %}{{ var1 }}{% autoescape off %}{{ var1 }}{% endautoescape %}{% endautoescape %}">>,
  49. [{var1, "<b>"}], <<"&lt;b&gt;<b>">>},
  50. {"default auto escape",
  51. <<"{{ var1 }}">>, [{var1, "&"}], [], [auto_escape],
  52. <<"&amp;">>},
  53. {"intermixed autoescape",
  54. <<"{% autoescape on %}1:{{ var1 }}{% endautoescape %} 2:{{ var1 }}{% autoescape on %} 3:{{ var1 }}{% endautoescape %}">>,
  55. [{var1, "&"}],
  56. <<"1:&amp; 2:& 3:&amp;">>}
  57. ]},
  58. {"string literal",
  59. [{"Render literal",
  60. <<"{{ \"foo\" }} is my name">>, [], <<"foo is my name">>},
  61. {"Newlines are escaped",
  62. <<"{{ \"foo\\n\" }}">>, [], <<"foo\n">>},
  63. {"strip quotes",
  64. <<"{{ \"foo\"|add:\"\\\"\" }}">>, [], <<"foo\"">>}
  65. ]},
  66. {"cycle",
  67. [#test{
  68. title = "deprecated cycle syntax",
  69. source = <<"{% for i in test %}{% cycle a,b %}{{ i }},{% endfor %}">>,
  70. render_vars = [{test, [0,1,2,3,4]}],
  71. output = <<"a0,b1,a2,b3,a4,">>
  72. },
  73. {"Cycling through quoted strings",
  74. <<"{% for i in test %}{% cycle 'a' 'b' %}{{ i }},{% endfor %}">>,
  75. [{test, ["0", "1", "2", "3", "4"]}], <<"a0,b1,a2,b3,a4,">>},
  76. {"Cycling through normal variables",
  77. <<"{% for i in test %}{% cycle aye bee %}{{ i }},{% endfor %}">>,
  78. [{test, ["0", "1", "2", "3", "4"]}, {aye, "a"}, {bee, "b"}],
  79. <<"a0,b1,a2,b3,a4,">>},
  80. #test{
  81. title = "mix strings and variables",
  82. source = <<"{% for i in test %}{% cycle 'a' b 'c' %}{{ i }},{% endfor %}">>,
  83. render_vars = [{test, [0,1,2,3,4]}, {b, 'B'}],
  84. output = <<"a0,B1,c2,a3,B4,">>
  85. },
  86. #test{
  87. title = "keep current value in local variable",
  88. source = <<"{% for i in test %}{% cycle 'a' 'b' as c %}{{ i }}{{ c }},{% endfor %}">>,
  89. render_vars = [{test, [0,1,2,3,4]}],
  90. output = <<"a0a,b1b,a2a,b3b,a4a,">>
  91. }
  92. ]},
  93. {"number literal",
  94. [{"Render integer",
  95. <<"{{ 5 }}">>, [], <<"5">>}
  96. ]},
  97. {"variable",
  98. [{"Render variable",
  99. <<"{{ var1 }} is my game">>, [{var1, "bar"}], <<"bar is my game">>},
  100. {"Render variable with attribute",
  101. <<"I enjoy {{ var1.game }}">>, [{var1, [{game, "Othello"}]}], <<"I enjoy Othello">>},
  102. {"Render variable with string-key attribute",
  103. <<"I also enjoy {{ var1.game }}">>, [{var1, [{"game", "Parcheesi"}]}], <<"I also enjoy Parcheesi">>},
  104. {"Render variable with binary-key attribute",
  105. <<"I also enjoy {{ var1.game }}">>, [{var1, [{<<"game">>, "Parcheesi"}]}], <<"I also enjoy Parcheesi">>},
  106. {"Render variable in dict",
  107. <<"{{ var1 }}">>, dict:store(var1, "bar", dict:new()), <<"bar">>},
  108. {"Render variable with missing attribute in dict",
  109. <<"{{ var1.foo }}">>, [{var1, dict:store(bar, "Othello", dict:new())}], <<"">>},
  110. {"Render variable in gb_tree",
  111. <<"{{ var1 }}">>, gb_trees:insert(var1, "bar", gb_trees:empty()), <<"bar">>},
  112. {"Render variable in arity-1 func",
  113. <<"I enjoy {{ var1 }}">>, fun (var1) -> "Othello" end, <<"I enjoy Othello">>},
  114. {"Render variable with attribute in dict",
  115. <<"{{ var1.attr }}">>, [{var1, dict:store(attr, "Othello", dict:new())}], <<"Othello">>},
  116. {"Render variable with attribute in gb_tree",
  117. <<"{{ var1.attr }}">>, [{var1, gb_trees:insert(attr, "Othello", gb_trees:empty())}], <<"Othello">>},
  118. {"Render variable with attribute in arity-1 func",
  119. <<"I enjoy {{ var1.game }}">>, [{var1, fun (game) -> "Othello" end}], <<"I enjoy Othello">>},
  120. %% {"Render variable in parameterized module",
  121. %% <<"{{ var1.some_var }}">>, [{var1, erlydtl_example_variable_storage:new("foo")}], <<"foo">>},
  122. {"Nested attributes",
  123. <<"{{ person.city.state.country }}">>, [{person, [{city, [{state, [{country, "Italy"}]}]}]}],
  124. <<"Italy">>},
  125. {"Index list variable",
  126. <<"{{ var1.2 }}">>, [{var1, [a, b, c]}],
  127. <<"b">>},
  128. {"Index tuple variable",
  129. <<"{{ var1.2 }}">>, [{var1, {a, b, c}}],
  130. <<"b">>},
  131. {"Index all elements of list (default, 1-based)",
  132. <<"{{ var1.1 }},{{ var1.2 }},{{ var1.3 }}.">>,
  133. [{var1, [a, b, c]}],
  134. <<"a,b,c.">>},
  135. {"Index all list elements 0-based (selected at compile time)",
  136. <<"{{ var1.0 }},{{ var1.1 }},{{ var1.2 }}.">>,
  137. [{var1, [a, b, c]}], [], [lists_0_based],
  138. <<"a,b,c.">>},
  139. {"Index all list elements 0-based (selected at render time)",
  140. <<"{{ var1.0 }},{{ var1.1 }},{{ var1.2 }}.">>,
  141. [{var1, [a, b, c]}], [lists_0_based], [{lists_0_based, defer}],
  142. <<"a,b,c.">>},
  143. {"Index all list elements 1-based (selected at render time)",
  144. <<"{{ var1.1 }},{{ var1.2 }},{{ var1.3 }}.">>,
  145. [{var1, [a, b, c]}], [], [{lists_0_based, defer}],
  146. <<"a,b,c.">>},
  147. {"Index all elements of tuple (default, 1-based)",
  148. <<"{{ var1.1 }},{{ var1.2 }},{{ var1.3 }}.">>,
  149. [{var1, {a, b, c}}],
  150. <<"a,b,c.">>},
  151. {"Index all tuple elements 0-based (selected at compile time)",
  152. <<"{{ var1.0 }},{{ var1.1 }},{{ var1.2 }}.">>,
  153. [{var1, {a, b, c}}], [], [tuples_0_based],
  154. <<"a,b,c.">>},
  155. {"Index all tuple elements 0-based (selected at render time)",
  156. <<"{{ var1.0 }},{{ var1.1 }},{{ var1.2 }}.">>,
  157. [{var1, {a, b, c}}], [tuples_0_based], [{tuples_0_based, defer}],
  158. <<"a,b,c.">>},
  159. {"Index all tuple elements 1-based (selected at render time)",
  160. <<"{{ var1.1 }},{{ var1.2 }},{{ var1.3 }}.">>,
  161. [{var1, {a, b, c}}], [], [{tuples_0_based, defer}],
  162. <<"a,b,c.">>},
  163. {"Index tuple using a \"reserved\" keyword",
  164. <<"{{ list.count }}">>,
  165. [{list, [{count, 123}]}],
  166. <<"123">>},
  167. {"Index list value",
  168. <<"{{ content.description }}">>,
  169. [{content, "test"}], <<"">>},
  170. {"Index binary value",
  171. <<"{{ content.description }}">>,
  172. [{content, <<"test">>}], <<"">>}
  173. ]},
  174. {"now",
  175. [{"now functional",
  176. <<"It is the {% now \"jS \\o\\f F Y\" %}.">>, [{var1, ""}], generate_test_date()}
  177. ]},
  178. {"if",
  179. [{"If/else",
  180. <<"{% if var1 %}boo{% else %}yay{% endif %}">>, [{var1, ""}], <<"yay">>},
  181. {"If elif",
  182. <<"{% if var1 %}boo{% elif var2 %}yay{% endif %}">>, [{var1, ""}, {var2, "happy"}], <<"yay">>},
  183. {"If elif/else",
  184. <<"{% if var1 %}boo{% elif var2 %}sad{% else %}yay{% endif %}">>, [{var1, ""}, {var2, ""}], <<"yay">>},
  185. {"If elif/elif/else",
  186. <<"{% if var1 %}boo{% elif var2 %}yay{% elif var3 %}sad{% else %}noo{% endif %}">>,
  187. [{var1, ""}, {var2, "happy"}, {var3, "not_taken"}],
  188. <<"yay">>},
  189. {"If",
  190. <<"{% if var1 %}boo{% endif %}">>, [{var1, ""}], <<>>},
  191. {"If not",
  192. <<"{% if not var1 %}yay{% endif %}">>, [{var1, ""}], <<"yay">>},
  193. {"If \"0\"",
  194. <<"{% if var1 %}boo{% endif %}">>, [{var1, "0"}], <<>>},
  195. {"If 0",
  196. <<"{% if var1 %}boo{% endif %}">>, [{var1, 0}], <<>>},
  197. {"If false",
  198. <<"{% if var1 %}boo{% endif %}">>, [{var1, false}], <<>>},
  199. {"If false string",
  200. <<"{% if var1 %}boo{% endif %}">>, [{var1, "false"}], <<"boo">>},
  201. {"If undefined",
  202. <<"{% if var1 %}boo{% endif %}">>, [{var1, undefined}], <<>>},
  203. {"If other atom",
  204. <<"{% if var1 %}yay{% endif %}">>, [{var1, foobar}], <<"yay">>},
  205. {"If non-empty string",
  206. <<"{% if var1 %}yay{% endif %}">>, [{var1, "hello"}], <<"yay">>},
  207. {"If proplist",
  208. <<"{% if var1 %}yay{% endif %}">>, [{var1, [{foo, "bar"}]}], <<"yay">>},
  209. {"If complex",
  210. <<"{% if foo.bar.baz %}omgwtfbbq{% endif %}">>, [], <<"">>}
  211. ]},
  212. {"if .. in ..",
  213. [{"If substring in string",
  214. <<"{% if var1 in var2 %}yay{% endif %}">>, [{var1, "rook"}, {var2, "Crooks"}], <<"yay">>},
  215. {"If substring in string (false)",
  216. <<"{% if var1 in var2 %}boo{% endif %}">>, [{var1, "Cook"}, {var2, "Crooks"}], <<>>},
  217. {"If substring not in string",
  218. <<"{% if var1 not in var2 %}yay{% endif %}">>, [{var1, "Cook"}, {var2, "Crooks"}], <<"yay">>},
  219. {"If substring not in string (false)",
  220. <<"{% if var1 not in var2 %}boo{% endif %}">>, [{var1, "rook"}, {var2, "Crooks"}], <<>>},
  221. {"If literal substring in string",
  222. <<"{% if \"man\" in \"Ottoman\" %}yay{% endif %}">>, [], <<"yay">>},
  223. {"If literal substring in string (false)",
  224. <<"{% if \"woman\" in \"Ottoman\" %}boo{% endif %}">>, [], <<>>},
  225. {"If element in list",
  226. <<"{% if var1 in var2 %}yay{% endif %}">>, [{var1, "foo"}, {var2, ["bar", "foo", "baz"]}], <<"yay">>},
  227. {"If element in list (false)",
  228. <<"{% if var1 in var2 %}boo{% endif %}">>, [{var1, "FOO"}, {var2, ["bar", "foo", "baz"]}], <<>>}
  229. ]},
  230. {"if .. and ..",
  231. [{"If true and true",
  232. <<"{% if var1 and var2 %}yay{% endif %}">>, [{var1, true}, {var2, true}], <<"yay">>},
  233. {"If true and false",
  234. <<"{% if var1 and var2 %}yay{% endif %}">>, [{var1, true}, {var2, false}], <<"">>},
  235. {"If false and true",
  236. <<"{% if var1 and var2 %}yay{% endif %}">>, [{var1, false}, {var2, true}], <<"">>},
  237. {"If false and false ",
  238. <<"{% if var1 and var2 %}yay{% endif %}">>, [{var1, false}, {var2, false}], <<"">>}
  239. ]},
  240. {"if .. or ..",
  241. [{"If true or true",
  242. <<"{% if var1 or var2 %}yay{% endif %}">>, [{var1, true}, {var2, true}], <<"yay">>},
  243. {"If true or false",
  244. <<"{% if var1 or var2 %}yay{% endif %}">>, [{var1, true}, {var2, false}], <<"yay">>},
  245. {"If false or true",
  246. <<"{% if var1 or var2 %}yay{% endif %}">>, [{var1, false}, {var2, true}], <<"yay">>},
  247. {"If false or false ",
  248. <<"{% if var1 or var2 %}yay{% endif %}">>, [{var1, false}, {var2, false}], <<"">>}
  249. ]},
  250. {"if equality",
  251. [{"If int equals number literal",
  252. <<"{% if var1 == 2 %}yay{% endif %}">>, [{var1, 2}], <<"yay">>},
  253. {"If int equals number literal (false)",
  254. <<"{% if var1 == 2 %}yay{% endif %}">>, [{var1, 3}], <<"">>},
  255. {"If string equals string literal",
  256. <<"{% if var1 == \"2\" %}yay{% endif %}">>, [{var1, "2"}], <<"yay">>},
  257. {"If string equals string literal (false)",
  258. <<"{% if var1 == \"2\" %}yay{% endif %}">>, [{var1, "3"}], <<"">>},
  259. {"If int not equals number literal",
  260. <<"{% if var1 != 2 %}yay{% endif %}">>, [{var1, 3}], <<"yay">>},
  261. {"If string not equals string literal",
  262. <<"{% if var1 != \"2\" %}yay{% endif %}">>, [{var1, "3"}], <<"yay">>},
  263. {"If filter result equals number literal",
  264. <<"{% if var1|length == 2 %}yay{% endif %}">>, [{var1, ["fo", "bo"]}], <<"yay">>},
  265. {"If filter result equals string literal",
  266. <<"{% if var1|capfirst == \"Foo\" %}yay{% endif %}">>, [{var1, "foo"}], <<"yay">>}
  267. ]},
  268. {"if size comparison",
  269. [{"If int greater than number literal",
  270. <<"{% if var1 > 2 %}yay{% endif %}">>, [{var1, 3}], <<"yay">>},
  271. {"If int greater than negative number literal",
  272. <<"{% if var1 > -2 %}yay{% endif %}">>, [{var1, -1}], <<"yay">>},
  273. {"If int greater than number literal (false)",
  274. <<"{% if var1 > 2 %}yay{% endif %}">>, [{var1, 2}], <<"">>},
  275. {"If int greater than or equal to number literal",
  276. <<"{% if var1 >= 2 %}yay{% endif %}">>, [{var1, 3}], <<"yay">>},
  277. {"If int greater than or equal to number literal (2)",
  278. <<"{% if var1 >= 2 %}yay{% endif %}">>, [{var1, 2}], <<"yay">>},
  279. {"If int greater than or equal to number literal (false)",
  280. <<"{% if var1 >= 2 %}yay{% endif %}">>, [{var1, 1}], <<"">>},
  281. {"If int less than number literal",
  282. <<"{% if var1 < 2 %}yay{% endif %}">>, [{var1, 1}], <<"yay">>},
  283. {"If int less than number literal (false)",
  284. <<"{% if var1 < 2 %}yay{% endif %}">>, [{var1, 2}], <<"">>},
  285. {"If int less than or equal to number literal",
  286. <<"{% if var1 <= 2 %}yay{% endif %}">>, [{var1, 1}], <<"yay">>},
  287. {"If int less than or equal to number literal",
  288. <<"{% if var1 <= 2 %}yay{% endif %}">>, [{var1, 2}], <<"yay">>},
  289. {"If int less than or equal to number literal (false)",
  290. <<"{% if var1 <= 2 %}yay{% endif %}">>, [{var1, 3}], <<"">>}
  291. ]},
  292. {"if complex bool",
  293. [{"If (true or false) and true",
  294. <<"{% if (var1 or var2) and var3 %}yay{% endif %}">>,
  295. [{var1, true}, {var2, false}, {var3, true}], <<"yay">>},
  296. {"If true or (false and true)",
  297. <<"{% if var1 or (var2 and var3) %}yay{% endif %}">>,
  298. [{var1, true}, {var2, false}, {var3, true}], <<"yay">>}
  299. ]},
  300. {"for",
  301. [{"Simple loop",
  302. <<"{% for x in list %}{{ x }}{% endfor %}">>, [{'list', ["1", "2", "3"]}],
  303. <<"123">>},
  304. {"Reversed loop",
  305. <<"{% for x in list reversed %}{{ x }}{% endfor %}">>, [{'list', ["1", "2", "3"]}],
  306. <<"321">>},
  307. {"Expand list",
  308. <<"{% for x, y in list %}{{ x }},{{ y }}\n{% endfor %}">>, [{'list', [["X", "1"], ["X", "2"]]}],
  309. <<"X,1\nX,2\n">>},
  310. {"Expand tuple",
  311. <<"{% for x, y in list %}{{ x }},{{ y }}\n{% endfor %}">>, [{'list', [{"X", "1"}, {"X", "2"}]}],
  312. <<"X,1\nX,2\n">>},
  313. {"Resolve variable attribute",
  314. <<"{% for number in person.numbers %}{{ number }}\n{% endfor %}">>, [{person, [{numbers, ["411", "911"]}]}],
  315. <<"411\n911\n">>},
  316. {"Resolve nested variable attribute",
  317. <<"{% for number in person.home.numbers %}{{ number }}\n{% endfor %}">>, [{person, [{home, [{numbers, ["411", "911"]}]}]}],
  318. <<"411\n911\n">>},
  319. {"Counter0",
  320. <<"{% for number in numbers %}{{ forloop.counter0 }}. {{ number }}\n{% endfor %}">>,
  321. [{numbers, ["Zero", "One", "Two"]}], <<"0. Zero\n1. One\n2. Two\n">>},
  322. {"Counter",
  323. <<"{% for number in numbers %}{{ forloop.counter }}. {{ number }}\n{% endfor %}">>,
  324. [{numbers, ["One", "Two", "Three"]}], <<"1. One\n2. Two\n3. Three\n">>},
  325. {"Reverse Counter0",
  326. <<"{% for number in numbers %}{{ forloop.revcounter0 }}. {{ number }}\n{% endfor %}">>,
  327. [{numbers, ["Two", "One", "Zero"]}], <<"2. Two\n1. One\n0. Zero\n">>},
  328. {"Reverse Counter",
  329. <<"{% for number in numbers %}{{ forloop.revcounter }}. {{ number }}\n{% endfor %}">>,
  330. [{numbers, ["Three", "Two", "One"]}], <<"3. Three\n2. Two\n1. One\n">>},
  331. {"Counter \"first\"",
  332. <<"{% for number in numbers %}{% if forloop.first %}{{ number }}{% endif %}{% endfor %}">>,
  333. [{numbers, ["One", "Two", "Three"]}], <<"One">>},
  334. {"Counter \"last\"",
  335. <<"{% for number in numbers %}{% if forloop.last %}{{ number }}{% endif %}{% endfor %}">>,
  336. [{numbers, ["One", "Two", "Three"]}], <<"Three">>},
  337. {"Nested for loop",
  338. <<"{% for outer in list %}{% for inner in outer %}{{ inner }}\n{% endfor %}{% endfor %}">>,
  339. [{'list', [["Al", "Albert"], ["Jo", "Joseph"]]}],
  340. <<"Al\nAlbert\nJo\nJoseph\n">>},
  341. {"Unused variable in foreach proplist",
  342. <<"{% for k,v in plist %}{{v}}{% endfor %}">>,
  343. [{'plist',[{1,"one"},{2,"two"}]}], [], [], <<"onetwo">>,
  344. [error_info([{0, erl_lint, {unused_var, 'Var_k/1_1:8'}}])]},
  345. {"Unused variable in foreach proplist, prefixed with underscore",
  346. <<"{% for _k,v in plist %}{{v}}{% endfor %}">>,
  347. [{'plist',[{1,"one"},{2,"two"}]}], [], [], <<"onetwo">>},
  348. {"Access parent loop counters",
  349. <<"{% for outer in list %}{% for inner in outer %}({{ forloop.parentloop.counter0 }}, {{ forloop.counter0 }})\n{% endfor %}{% endfor %}">>,
  350. [{'list', [["One", "two"], ["One", "two"]]}], [], [], <<"(0, 0)\n(0, 1)\n(1, 0)\n(1, 1)\n">>,
  351. %% the warnings we get from the erlang compiler still needs some care..
  352. [error_info([{0, erl_lint, {unused_var, 'Var_inner/3_1:31'}}])]},
  353. {"If changed",
  354. <<"{% for x in list %}{% ifchanged %}{{ x }}\n{% endifchanged %}{% endfor %}">>,
  355. [{'list', ["one", "two", "two", "three", "three", "three"]}], <<"one\ntwo\nthree\n">>},
  356. {"If changed/2",
  357. <<"{% for x, y in list %}{% ifchanged %}{{ x|upper }}{% endifchanged %}{% ifchanged %}{{ y|lower }}{% endifchanged %}\n{% endfor %}">>,
  358. [{'list', [["one", "a"], ["two", "A"], ["two", "B"], ["three", "b"], ["three", "c"], ["Three", "b"]]}], <<"ONEa\nTWO\nb\nTHREE\nc\nb\n">>},
  359. {"If changed/else",
  360. <<"{% for x in list %}{% ifchanged %}{{ x }}\n{% else %}foo\n{% endifchanged %}{% endfor %}">>,
  361. [{'list', ["one", "two", "two", "three", "three", "three"]}], <<"one\ntwo\nfoo\nthree\nfoo\nfoo\n">>},
  362. {"If changed/param",
  363. <<"{% for date in list %}{% ifchanged date.month %} {{ date.month }}:{{ date.day }}{% else %},{{ date.day }}{% endifchanged %}{% endfor %}\n">>,
  364. [{'list', [[{month,"Jan"},{day,1}],[{month,"Jan"},{day,2}],[{month,"Apr"},{day,10}],
  365. [{month,"Apr"},{day,11}],[{month,"May"},{day,4}]]}],
  366. <<" Jan:1,2 Apr:10,11 May:4\n">>},
  367. {"If changed/param2",
  368. <<"{% for x, y in list %}{% ifchanged y|upper %}{{ x|upper }}{% endifchanged %}\n{% endfor %}">>,
  369. [{'list', [["one", "a"], ["two", "A"], ["two", "B"], ["three", "b"], ["three", "c"], ["Three", "b"]]}], <<"ONE\n\nTWO\n\nTHREE\nTHREE\n">>},
  370. {"If changed/param2 combined",
  371. <<"{% for x, y in list %}{% ifchanged x y|upper %}{{ x }}{% endifchanged %}\n{% endfor %}">>,
  372. [{'list', [["one", "a"], ["two", "A"], ["two", "B"], ["three", "b"], ["three", "B"], ["three", "c"]]}], <<"one\ntwo\ntwo\nthree\n\nthree\n">>},
  373. {"If changed/resolve",
  374. <<"{% for x in list %}{% ifchanged x.name|first %}{{ x.value }}{% endifchanged %}\n{% endfor %}">>,
  375. [{'list', [[{"name", ["nA","nB"]},{"value","1"}],[{"name", ["nA","nC"]},{"value","2"}],
  376. [{"name", ["nB","nC"]},{"value","3"}],[{"name", ["nB","nA"]},{"value","4"}]]}],
  377. <<"1\n\n3\n\n">>},
  378. {"Loop undefined var",
  379. <<"{% for i in undef %}i = {{ i }}.\n{% endfor %}">>,
  380. [],
  381. <<"">>},
  382. {"Loop filtered value rather than variable",
  383. <<"{% for x in 123|make_list %}{% if not forloop.first %}, {% endif %}{{ x }}{% endfor %}">>,
  384. [],
  385. <<"1, 2, 3">>}
  386. ]},
  387. {"for/empty",
  388. [{"Simple loop",
  389. <<"{% for x in list %}{{ x }}{% empty %}shucks{% endfor %}">>, [{'list', ["1", "2", "3"]}],
  390. <<"123">>},
  391. {"Simple loop (empty)",
  392. <<"{% for x in list %}{{ x }}{% empty %}shucks{% endfor %}">>, [{'list', []}],
  393. <<"shucks">>}
  394. ]},
  395. {"ifequal",
  396. [{"Compare variable to literal",
  397. <<"{% ifequal var1 \"foo\" %}yay{% endifequal %}">>,
  398. [{var1, "foo"}], <<"yay">>},
  399. {"Compare variable to unequal literal",
  400. <<"{% ifequal var1 \"foo\" %}boo{% endifequal %}">>,
  401. [{var1, "bar"}], <<>>},
  402. {"Compare literal to variable",
  403. <<"{% ifequal \"foo\" var1 %}yay{% endifequal %}">>,
  404. [{var1, "foo"}], <<"yay">>},
  405. {"Compare literal to unequal variable",
  406. <<"{% ifequal \"foo\" var1 %}boo{% endifequal %}">>,
  407. [{var1, "bar"}], <<>>},
  408. {"Compare variable to literal (int string)",
  409. <<"{% ifequal var1 \"2\" %}yay{% else %}boo{% endifequal %}">>,
  410. [{var1, "2"}], <<"yay">>},
  411. {"Compare variable to literal (int)",
  412. <<"{% ifequal var1 2 %}yay{% else %}boo{% endifequal %}">>,
  413. [{var1, 2}], <<"yay">>},
  414. {"Compare variable to unequal literal (int)",
  415. <<"{% ifequal var1 2 %}boo{% else %}yay{% endifequal %}">>,
  416. [{var1, 3}], <<"yay">>},
  417. {"Compare variable to equal literal (atom)",
  418. <<"{% ifequal var1 \"foo\"%}yay{% endifequal %}">>,
  419. [{var1, foo}], <<"yay">>},
  420. {"Compare variable to unequal literal (atom)",
  421. <<"{% ifequal var1 \"foo\"%}yay{% else %}boo{% endifequal %}">>,
  422. [{var1, bar}], <<"boo">>}
  423. ]},
  424. {"ifequal/else",
  425. [{"Compare variable to literal",
  426. <<"{% ifequal var1 \"foo\" %}yay{% else %}boo{% endifequal %}">>,
  427. [{var1, "foo"}], <<"yay">>},
  428. {"Compare variable to unequal literal",
  429. <<"{% ifequal var1 \"foo\" %}boo{% else %}yay{% endifequal %}">>,
  430. [{var1, "bar"}], <<"yay">>},
  431. {"Compare literal to variable",
  432. <<"{% ifequal \"foo\" var1 %}yay{% else %}boo{% endifequal %}">>,
  433. [{var1, "foo"}], <<"yay">>},
  434. {"Compare literal to unequal variable",
  435. <<"{% ifequal \"foo\" var1 %}boo{% else %}yay{% endifequal %}">>,
  436. [{var1, "bar"}], <<"yay">>}
  437. ]},
  438. {"ifnotequal",
  439. [{"Compare variable to literal",
  440. <<"{% ifnotequal var1 \"foo\" %}boo{% endifnotequal %}">>,
  441. [{var1, "foo"}], <<>>},
  442. {"Compare variable to unequal literal",
  443. <<"{% ifnotequal var1 \"foo\" %}yay{% endifnotequal %}">>,
  444. [{var1, "bar"}], <<"yay">>},
  445. {"Compare literal to variable",
  446. <<"{% ifnotequal \"foo\" var1 %}boo{% endifnotequal %}">>,
  447. [{var1, "foo"}], <<>>},
  448. {"Compare literal to unequal variable",
  449. <<"{% ifnotequal \"foo\" var1 %}yay{% endifnotequal %}">>,
  450. [{var1, "bar"}], <<"yay">>}
  451. ]},
  452. {"ifnotequal/else",
  453. [{"Compare variable to literal",
  454. <<"{% ifnotequal var1 \"foo\" %}boo{% else %}yay{% endifnotequal %}">>,
  455. [{var1, "foo"}], <<"yay">>},
  456. {"Compare variable to unequal literal",
  457. <<"{% ifnotequal var1 \"foo\" %}yay{% else %}boo{% endifnotequal %}">>,
  458. [{var1, "bar"}], <<"yay">>},
  459. {"Compare literal to variable",
  460. <<"{% ifnotequal \"foo\" var1 %}boo{% else %}yay{% endifnotequal %}">>,
  461. [{var1, "foo"}], <<"yay">>},
  462. {"Compare literal to unequal variable",
  463. <<"{% ifnotequal \"foo\" var1 %}yay{% else %}boo{% endifnotequal %}">>,
  464. [{var1, "bar"}], <<"yay">>}
  465. ]},
  466. {"filter tag",
  467. [{"Apply a filter",
  468. <<"{% filter escape %}&{% endfilter %}">>, [], <<"&amp;">>},
  469. {"Chained filters",
  470. <<"{% filter linebreaksbr|escape %}\n{% endfilter %}">>, [], <<"&lt;br /&gt;">>}
  471. ]},
  472. {"filters",
  473. [{"Filter a literal",
  474. <<"{{ \"pop\"|capfirst }}">>, [],
  475. <<"Pop">>},
  476. {"Filters applied in order",
  477. <<"{{ var1|force_escape|length }}">>, [{var1, <<"&">>}],
  478. <<"5">>},
  479. {"Escape is applied last",
  480. <<"{{ var1|escape|linebreaksbr }}">>, [{var1, <<"\n">>}],
  481. <<"&lt;br /&gt;">>},
  482. {"add; lhs number, rhs number",
  483. <<"{{ one|add:4}}">>, [{one, 1}],
  484. <<"5">>},
  485. {"add; lhs numeric string, rhs number",
  486. <<"{{ one|add:4}}">>, [{one, "1"}],
  487. <<"5">>},
  488. {"add; lhs number, rhs numeric string",
  489. <<"{{ one|add:'4'}}">>, [{one, 1}],
  490. <<"5">>},
  491. {"add; lhs non-numeric string, rhs number",
  492. <<"{{ one|add:4}}">>, [{one, "foo"}],
  493. <<"foo4">>},
  494. {"add; lhs number, rhs non-numeric string",
  495. <<"{{ one|add:'foo'}}">>, [{one, 1}],
  496. <<"1foo">>},
  497. {"add; lhs non-numeric string, rhs non-numeric string",
  498. <<"{{ one|add:'bar'}}">>, [{one, "foo"}],
  499. <<"foobar">>},
  500. {"add; lhs numeric string, rhs numeric string",
  501. <<"{{ one|add:'4'}}">>, [{one, "1"}],
  502. <<"5">>},
  503. {"|addslashes",
  504. <<"{{ var1|addslashes }}">>, [{var1, "Jimmy's \"great\" meats'n'things"}],
  505. <<"Jimmy\\'s \\\"great\\\" meats\\'n\\'things">>},
  506. {"|capfirst",
  507. <<"{{ var1|capfirst }}">>, [{var1, "dana boyd"}],
  508. <<"Dana boyd">>},
  509. {"|center:10",
  510. <<"{{ var1|center:10 }}">>, [{var1, "MB"}],
  511. <<" MB ">>},
  512. {"|center:1",
  513. <<"{{ var1|center:1 }}">>, [{var1, "KBR"}],
  514. <<"B">>},
  515. {"|cut:\" \"",
  516. <<"{{ var1|cut:\" \" }}">>, [{var1, "String with spaces"}],
  517. <<"Stringwithspaces">>},
  518. {"|date 1",
  519. <<"{{ var1|date:\"jS F Y H:i\" }}">>,
  520. [{var1, {1975,7,24}}],
  521. <<"24th July 1975 00:00">>},
  522. {"|date 2",
  523. <<"{{ var1|date:\"jS F Y H:i\" }}">>,
  524. [{var1, {{1975,7,24}, {7,13,1}}}],
  525. <<"24th July 1975 07:13">>},
  526. {"|date 3",
  527. <<"{{ var1|date }}">>,
  528. [{var1, {{1975,7,24}, {7,13,1}}}],
  529. <<"July 24, 1975">>},
  530. {"|default:\"foo\" 1",
  531. <<"{{ var1|default:\"foo\" }}">>, [], <<"foo">>},
  532. {"|default:\"foo\" 2",
  533. <<"{{ var1|default:\"foo\" }}">>, [{var1, "bar"}], <<"bar">>},
  534. {"|default:\"foo\" 3",
  535. <<"{{ var1|default:\"foo\" }}">>, [{var1, "0"}], <<"foo">>},
  536. {"|default_if_none:\"foo\"",
  537. <<"{{ var1|default_if_none:\"foo\" }}">>, [], <<"foo">>},
  538. {"|default_if_none:\"foo\" 2",
  539. <<"{{ var1|default_if_none:\"foo\" }}">>, [{var1, "bar"}], <<"bar">>},
  540. {"|dictsort 1",
  541. <<"{{ var1|dictsort:\"foo\" }}">>,
  542. [{var1,[[{foo,2}],[{foo,1}]]}], <<"{foo,1}{foo,2}">>},
  543. {"|dictsort 2",
  544. <<"{{ var1|dictsort:\"foo.bar\" }}">>,
  545. [{var1,[[{foo,[{bar,2}]}],[{foo,[{bar,1}]}]]}],
  546. <<"{foo,[{bar,1}]}{foo,[{bar,2}]}">>},
  547. {"|divisibleby:\"3\"",
  548. <<"{% if var1|divisibleby:\"3\" %}yay{% endif %}">>, [{var1, 21}], <<"yay">>},
  549. {"|divisibleby:\"3\"",
  550. <<"{% if var1|divisibleby:\"3\" %}yay{% endif %}">>, [{var1, 22}], <<"">>},
  551. {"|escape",
  552. <<"{% autoescape on %}{{ var1|escape|escape|escape }}{% endautoescape %}">>, [{var1, ">&1"}], <<"&gt;&amp;1">>},
  553. {"|escapejs",
  554. <<"{{ var1|escapejs }}">>, [{var1, "testing\r\njavascript 'string\" <b>escaping</b>"}],
  555. <<"testing\\u000D\\u000Ajavascript \\u0027string\\u0022 \\u003Cb\\u003Eescaping\\u003C/b\\u003E">>},
  556. {"|filesizeformat (bytes)",
  557. <<"{{ var1|filesizeformat }}">>, [{var1, 1023}], <<"1023 bytes">>},
  558. {"|filesizeformat (KB)",
  559. <<"{{ var1|filesizeformat }}">>, [{var1, 3487}], <<"3.4 KB">>},
  560. {"|filesizeformat (MB)",
  561. <<"{{ var1|filesizeformat }}">>, [{var1, 6277098}], <<"6.0 MB">>},
  562. {"|filesizeformat (GB)",
  563. <<"{{ var1|filesizeformat }}">>, [{var1, 1024 * 1024 * 1024}], <<"1.0 GB">>},
  564. {"|first",
  565. <<"{{ var1|first }}">>, [{var1, "James"}],
  566. <<"J">>},
  567. {"|fix_ampersands",
  568. <<"{{ var1|fix_ampersands }}">>, [{var1, "Ben & Jerry's"}],
  569. <<"Ben &amp; Jerry's">>},
  570. {"|floatformat:\"-1\"",
  571. <<"{{ var1|floatformat:\"-1\" }}">>, [{var1, 34.23234}],
  572. <<"34.2">>},
  573. {"int |floatformat",
  574. <<"{{ var1|floatformat:\"-1\" }}">>, [{var1, 123}],
  575. <<"123">>},
  576. {"string |floatformat",
  577. <<"{{ var1|floatformat:\"-1\" }}">>, [{var1, "123.321"}],
  578. <<"123.3">>},
  579. {"binary |floatformat",
  580. <<"{{ var1|floatformat:\"-1\" }}">>, [{var1, <<"123.321">>}],
  581. <<"123.3">>},
  582. %% from: https://docs.djangoproject.com/en/1.6/ref/templates/builtins/#floatformat
  583. {"1.a) |floatformat",
  584. <<"{{ var1|floatformat }}">>, [{var1, 34.23234}],
  585. <<"34.2">>},
  586. {"1.b) |floatformat",
  587. <<"{{ var1|floatformat }}">>, [{var1, 34.00000}],
  588. <<"34">>},
  589. {"1.c) |floatformat",
  590. <<"{{ var1|floatformat }}">>, [{var1, 34.26000}],
  591. <<"34.3">>},
  592. {"2.a) |floatformat:\"3\"",
  593. <<"{{ var1|floatformat:\"3\" }}">>, [{var1, 34.23234}],
  594. <<"34.232">>},
  595. {"2.b) |floatformat:\"3\"",
  596. <<"{{ var1|floatformat:\"3\" }}">>, [{var1, 34.00000}],
  597. <<"34.000">>},
  598. {"2.c) |floatformat:\"3\"",
  599. <<"{{ var1|floatformat:\"3\" }}">>, [{var1, 34.26000}],
  600. <<"34.260">>},
  601. {"3.a) |floatformat:\"0\"",
  602. <<"{{ var1|floatformat:\"0\" }}">>, [{var1, 34.23234}],
  603. <<"34">>},
  604. {"3.b) |floatformat:\"0\"",
  605. <<"{{ var1|floatformat:\"0\" }}">>, [{var1, 34.00000}],
  606. <<"34">>},
  607. {"3.c) |floatformat:\"0\"",
  608. <<"{{ var1|floatformat:\"0\" }}">>, [{var1, 39.56000}],
  609. <<"40">>},
  610. {"4.a) |floatformat:\"-3\"",
  611. <<"{{ var1|floatformat:\"-3\" }}">>, [{var1, 34.23234}],
  612. <<"34.232">>},
  613. {"4.b) |floatformat:\"-3\"",
  614. <<"{{ var1|floatformat:\"-3\" }}">>, [{var1, 34.00000}],
  615. <<"34">>},
  616. {"4.c) |floatformat:\"-3\"",
  617. <<"{{ var1|floatformat:\"-3\" }}">>, [{var1, 34.26000}],
  618. <<"34.260">>},
  619. {"|force_escape",
  620. <<"{{ var1|force_escape }}">>, [{var1, "Ben & Jerry's <=> \"The World's Best Ice Cream\""}],
  621. <<"Ben &amp; Jerry&#039;s &lt;=&gt; &quot;The World&#039;s Best Ice Cream&quot;">>},
  622. {"iolist |force_escape",
  623. <<"{{ var1|force_escape }}">>, [{var1, ["'a'"]}],
  624. <<"&#039;a&#039;">>},
  625. {"nested iolist |force_escape",
  626. <<"{{ var1|force_escape }}">>, [{var1, ["a'", <<"b">>, [<<"<c">>, "d", ["e>"]]]}],
  627. <<"a&#039;b&lt;cde&gt;">>},
  628. {"|format_integer",
  629. <<"{{ var1|format_integer }}">>, [{var1, 28}], <<"28">>},
  630. {"|format_number 1",
  631. <<"{{ var1|format_number }}">>, [{var1, 28}], <<"28">>},
  632. {"|format_number 2",
  633. <<"{{ var1|format_number }}">>, [{var1, 23.77}], <<"23.77">>},
  634. {"|format_number 3",
  635. <<"{{ var1|format_number }}">>, [{var1, "28.77"}], <<"28.77">>},
  636. {"|format_number 4",
  637. <<"{{ var1|format_number }}">>, [{var1, "23.77"}], <<"23.77">>},
  638. {"|format_number 5",
  639. <<"{{ var1|format_number }}">>, [{var1, fun() -> 29 end}], <<"29">>},
  640. {"|format_number 6",
  641. <<"{{ var1|format_number }}">>, [{var1, fun() -> fun() -> 31 end end}], <<"31">>},
  642. {"|get_digit:\"2\"",
  643. <<"{{ var1|get_digit:\"2\" }}">>, [{var1, 42}], <<"4">>},
  644. {"|iriencode",
  645. <<"{{ url|iriencode }}">>, [{url, "You #$*@!!"}], <<"You+#$*@!!">>},
  646. {"|join:\", \" (list)",
  647. <<"{{ var1|join:\", \" }}">>, [{var1, ["Liberte", "Egalite", "Fraternite"]}],
  648. <<"Liberte, Egalite, Fraternite">>},
  649. {"|join:\", \" (binary)",
  650. <<"{{ var1|join:\", \" }}">>, [{var1, [<<"Liberte">>, "Egalite", <<"Fraternite">>]}],
  651. <<"Liberte, Egalite, Fraternite">>},
  652. {"|last",
  653. <<"{{ var1|last }}">>, [{var1, "XYZ"}],
  654. <<"Z">>},
  655. {"|length",
  656. <<"{{ var1|length }}">>, [{var1, "antidisestablishmentarianism"}],
  657. <<"28">>},
  658. {"|linebreaks",
  659. <<"{{ var1|linebreaks }}">>, [{var1, "Joel\nis a slug"}],
  660. <<"<p>Joel<br />is a slug</p>">>},
  661. {"|linebreaks",
  662. <<"{{ var1|linebreaks }}">>, [{var1, "Joel\n\n\n\nis a slug"}],
  663. <<"<p>Joel</p><p>is a slug</p>">>},
  664. {"|linebreaks",
  665. <<"{{ var1|linebreaks }}">>, [{var1, "Joel\n\nis a \nslug"}],
  666. <<"<p>Joel</p><p>is a <br />slug</p>">>},
  667. {"|linebreaksbr",
  668. <<"{{ var1|linebreaksbr }}">>, [{var1, "One\nTwo\n\nThree\n\n\n"}],
  669. <<"One<br />Two<br /><br />Three<br /><br /><br />">>},
  670. {"|linebreaksbr",
  671. <<"{{ \"One\\nTwo\\n\\nThree\\n\\n\\n\"|linebreaksbr }}">>, [],
  672. <<"One<br />Two<br /><br />Three<br /><br /><br />">>},
  673. {"|linenumbers",
  674. <<"{{ var1|linenumbers }}">>, [{var1, "a\nb\nc"}],
  675. <<"1. a\n2. b\n3. c">>},
  676. {"|linenumbers",
  677. <<"{{ var1|linenumbers }}">>, [{var1, "a"}],
  678. <<"1. a">>},
  679. {"|linenumbers",
  680. <<"{{ var1|linenumbers }}">>, [{var1, "a\n"}],
  681. <<"1. a\n2. ">>},
  682. {"|ljust:10",
  683. <<"{{ var1|ljust:10 }}">>, [{var1, "Gore"}],
  684. <<"Gore ">>},
  685. {"|lower",
  686. <<"{{ var1|lower }}">>, [{var1, "E. E. Cummings"}],
  687. <<"e. e. cummings">>},
  688. {"|makelist",
  689. <<"{{ list|make_list }}">>, [{list, "Joel"}],
  690. <<"J","o","e","l">>},
  691. {"|pluralize",
  692. <<"{{ num|pluralize }}">>, [{num, 1}],
  693. <<"">>},
  694. {"|pluralize",
  695. <<"{{ num|pluralize }}">>, [{num, 2}],
  696. <<"s">>},
  697. {"|pluralize:\"s\"",
  698. <<"{{ num|pluralize }}">>, [{num, 1}],
  699. <<"">>},
  700. {"|pluralize:\"s\"",
  701. <<"{{ num|pluralize }}">>, [{num, 2}],
  702. <<"s">>},
  703. {"|pluralize:\"y,es\" (list)",
  704. <<"{{ num|pluralize:\"y,es\" }}">>, [{num, 1}],
  705. <<"y">>},
  706. {"|pluralize:\"y,es\" (list)",
  707. <<"{{ num|pluralize:\"y,es\" }}">>, [{num, 2}],
  708. <<"es">>},
  709. {"|length|pluralize",
  710. <<"{{ list|length|pluralize:\"plural\" }}">>, [{list, [foo, bar]}],
  711. <<"plural">>},
  712. {"|length|pluralize",
  713. <<"{{ list|length|pluralize:\"plural\" }}">>, [{list, [foo]}],
  714. <<"">>},
  715. {"|random",
  716. <<"{{ var1|random }}">>, [{var1, ["foo", "foo", "foo"]}],
  717. <<"foo">>},
  718. {"|removetags:\"b span\"",
  719. <<"{{ var1|removetags:\"b span\" }}">>, [{var1, "<B>Joel</B> <button>is</button> a <span>slug</span>"}],
  720. <<"<B>Joel</B> <button>is</button> a slug">>},
  721. {"|rjust:10",
  722. <<"{{ var1|rjust:10 }}">>, [{var1, "Bush"}],
  723. <<" Bush">>},
  724. {"|safe",
  725. <<"{% autoescape on %}{{ var1|safe|escape }}{% endautoescape %}">>, [{var1, "&"}],
  726. <<"&">>},
  727. {"|safe is local",
  728. <<"{{ var1 }}{{ var1|safe }}{{ var1 }}">>, [{var1, "&"}], [], [auto_escape],
  729. <<"&amp;&&amp;">>},
  730. %%python/django slice is zero based, erlang lists are 1 based
  731. %%first number included, second number not
  732. %%negative numbers are allowed
  733. %%regex to convert from erlydtl_filters_tests:
  734. % for slice: \?assert.*\( \[(.*)\], erlydtl_filters:(.*)\((.*),"(.*)"\)\),
  735. % {"|slice:\"$4\"", <<"{{ var|$2:\"$4\" }}">>, [{var, $3}],<<$1>>},
  736. % \t\t{"|slice:\"$4\"",\n\t\t\t\t\t <<"{{ var|$2:\"$4\" }}">>, [{var, $3}],\n\t\t\t\t\t<<$1>>},
  737. %
  738. % for stringformat:
  739. % \?assert.*\( (.*), erlydtl_filters:(.*)\((.*), "(.*)"\) \)
  740. % \t\t{"|stringformat:\"$4\"",\n\t\t\t\t\t <<"{{ var|$2:\"$4\" }}">>, [{var, $3}],\n\t\t\t\t\t<<$1>>}
  741. {"|slice:\":\"",
  742. <<"{{ var|slice:\":\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  743. <<1,2,3,4,5,6,7,8,9>>},
  744. {"|slice:\"1\"",
  745. <<"{{ var|slice:\"1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  746. <<"2">>},
  747. {"|slice:\"100\"",
  748. <<"{{ var|slice:\"100\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  749. <<"indexError">>},
  750. {"|slice:\"-1\"",
  751. <<"{{ var|slice:\"-1\" }}">>, [{var, ["a","b","c","d","e","f","g","h","i"]}],
  752. <<"i">>},
  753. {"|slice:\"-1\"",
  754. <<"{{ var|slice:\"-1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  755. <<"9">>},
  756. {"|slice:\"-100\"",
  757. <<"{{ var|slice:\"-100\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  758. <<"indexError">>},
  759. {"|slice:\"1:\"",
  760. <<"{{ var|slice:\"1:\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  761. <<2,3,4,5,6,7,8,9>>},
  762. {"|slice:\"100:\"",
  763. <<"{{ var|slice:\"100:\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  764. <<>>},
  765. {"|slice:\"-1:\"",
  766. <<"{{ var|slice:\"-1:\" }}">>, [{var, ["a","b","c","d","e","f","h","i","j"]}],
  767. <<"j">>},
  768. {"|slice:\"-1:\"",
  769. <<"{{ var|slice:\"-1:\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  770. <<9>>},
  771. {"|slice:\"-100:\"",
  772. <<"{{ var|slice:\"-100:\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  773. <<1,2,3,4,5,6,7,8,9>>},
  774. {"|slice:\":1\"",
  775. <<"{{ var|slice:\":1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  776. <<1>>},
  777. {"|slice:\":100\"",
  778. <<"{{ var|slice:\":100\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  779. <<1,2,3,4,5,6,7,8,9>>},
  780. {"|slice:\":-1\"",
  781. <<"{{ var|slice:\":-1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  782. <<1,2,3,4,5,6,7,8>>},
  783. {"|slice:\":-100\"",
  784. <<"{{ var|slice:\":-100\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  785. <<>>},
  786. {"|slice:\"-1:-1\"",
  787. <<"{{ var|slice:\"-1:-1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  788. <<>>},
  789. {"|slice:\"1:1\"",
  790. <<"{{ var|slice:\"1:1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  791. <<>>},
  792. {"|slice:\"1:-1\"",
  793. <<"{{ var|slice:\"1:-1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  794. <<2,3,4,5,6,7,8>>},
  795. {"|slice:\"-1:1\"",
  796. <<"{{ var|slice:\"-1:1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  797. <<>>},
  798. {"|slice:\"-100:-100\"",
  799. <<"{{ var|slice:\"-100:-100\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  800. <<>>},
  801. {"|slice:\"100:100\"",
  802. <<"{{ var|slice:\"100:100\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  803. <<>>},
  804. {"|slice:\"100:-100\"",
  805. <<"{{ var|slice:\"100:-100\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  806. <<>>},
  807. {"|slice:\"-100:100\"",
  808. <<"{{ var|slice:\"-100:100\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  809. <<1,2,3,4,5,6,7,8,9>>},
  810. {"|slice:\"1:3\"",
  811. <<"{{ var|slice:\"1:3\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  812. <<2,3>>},
  813. {"|slice:\"::\"",
  814. <<"{{ var|slice:\"::\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  815. <<1,2,3,4,5,6,7,8,9>>},
  816. {"|slice:\"1:9:1\"",
  817. <<"{{ var|slice:\"1:9:1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  818. <<2,3,4,5,6,7,8,9>>},
  819. {"|slice:\"10:1:-1\"",
  820. <<"{{ var|slice:\"10:1:-1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  821. <<9,8,7,6,5,4,3>>},
  822. {"|slice:\"-111:-1:1\"",
  823. <<"{{ var|slice:\"-111:-1:1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  824. <<1,2,3,4,5,6,7,8>>},
  825. {"|slice:\"-111:-111:1\"",
  826. <<"{{ var|slice:\"-111:-111:1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  827. <<>>},
  828. {"|slice:\"111:111:1\"",
  829. <<"{{ var|slice:\"111:111:1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  830. <<>>},
  831. {"|slice:\"-111:111:1\"",
  832. <<"{{ var|slice:\"-111:111:1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  833. <<1,2,3,4,5,6,7,8,9>>},
  834. {"|slice:\"111:-111:1\"",
  835. <<"{{ var|slice:\"111:-111:1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  836. <<>>},
  837. {"|slice:\"-111:-111:-1\"",
  838. <<"{{ var|slice:\"-111:-111:-1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  839. <<>>},
  840. {"|slice:\"111:111:-1\"",
  841. <<"{{ var|slice:\"111:111:-1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  842. <<>>},
  843. {"|slice:\"-111:111:-1\"",
  844. <<"{{ var|slice:\"-111:111:-1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  845. <<>>},
  846. {"|slice:\"111:-111:-1\"",
  847. <<"{{ var|slice:\"111:-111:-1\" }}">>, [{var, [1,2,3,4,5,6,7,8,9]}],
  848. <<9,8,7,6,5,4,3,2,1>>}, {"|phone2numeric",
  849. <<"{{ var1|phone2numeric }}">>, [{var1, "1-800-COLLECT"}],
  850. <<"1-800-2655328">>},
  851. {"|slugify",
  852. <<"{{ var1|slugify }}">>, [{var1, "What The $#_! Was He Thinking?"}],
  853. <<"what-the-_-was-he-thinking">>},
  854. {"|slice:\"s\"",
  855. <<"{{ var|stringformat:\"s\" }}">>, [{var, "test"}],
  856. <<"test">>},
  857. {"|stringformat:\"s\"",
  858. <<"{{ var|stringformat:\"s\" }}">>, [{var, "test"}],
  859. <<"test">>},
  860. {"|stringformat:\"s\"",
  861. <<"{{ var|stringformat:\"s\" }}">>, [{var, "1"}],
  862. <<"1">>},
  863. {"|stringformat:\"s\"",
  864. <<"{{ var|stringformat:\"s\" }}">>, [{var, "test"}],
  865. <<"test">>},
  866. {"|stringformat:\"10s\"",
  867. <<"{{ var|stringformat:\"10s\" }}">>, [{var, "test"}],
  868. <<" test">>},
  869. {"|stringformat:\"-10s\"",
  870. <<"{{ var|stringformat:\"-10s\" }}">>, [{var, "test"}],
  871. <<"test ">>},
  872. {"|stringformat:\"d\"",
  873. <<"{{ var|stringformat:\"d\" }}">>, [{var, "90"}],
  874. <<"90">>},
  875. {"|stringformat:\"10d\"",
  876. <<"{{ var|stringformat:\"10d\" }}">>, [{var, "90"}],
  877. <<" 90">>},
  878. {"|stringformat:\"-10d\"",
  879. <<"{{ var|stringformat:\"-10d\" }}">>, [{var, "90"}],
  880. <<"90 ">>},
  881. {"|stringformat:\"i\"",
  882. <<"{{ var|stringformat:\"i\" }}">>, [{var, "90"}],
  883. <<"90">>},
  884. {"|stringformat:\"10i\"",
  885. <<"{{ var|stringformat:\"10i\" }}">>, [{var, "90"}],
  886. <<" 90">>},
  887. {"|stringformat:\"-10i\"",
  888. <<"{{ var|stringformat:\"-10i\" }}">>, [{var, "90"}],
  889. <<"90 ">>},
  890. {"|stringformat:\"0.2d\"",
  891. <<"{{ var|stringformat:\"0.2d\" }}">>, [{var, "9"}],
  892. <<"09">>},
  893. {"|stringformat:\"10.4d\"",
  894. <<"{{ var|stringformat:\"10.4d\" }}">>, [{var, "9"}],
  895. <<" 0009">>},
  896. {"|stringformat:\"-10.4d\"",
  897. <<"{{ var|stringformat:\"-10.4d\" }}">>, [{var, "9"}],
  898. <<"0009 ">>},
  899. {"|stringformat:\"f\"",
  900. <<"{{ var|stringformat:\"f\" }}">>, [{var, "1"}],
  901. <<"1.000000">>},
  902. {"|stringformat:\".2f\"",
  903. <<"{{ var|stringformat:\".2f\" }}">>, [{var, "1"}],
  904. <<"1.00">>},
  905. {"|stringformat:\"0.2f\"",
  906. <<"{{ var|stringformat:\"0.2f\" }}">>, [{var, "1"}],
  907. <<"1.00">>},
  908. {"|stringformat:\"-0.2f\"",
  909. <<"{{ var|stringformat:\"-0.2f\" }}">>, [{var, "1"}],
  910. <<"1.00">>},
  911. {"|stringformat:\"10.2f\"",
  912. <<"{{ var|stringformat:\"10.2f\" }}">>, [{var, "1"}],
  913. <<" 1.00">>},
  914. {"|stringformat:\"-10.2f\"",
  915. <<"{{ var|stringformat:\"-10.2f\" }}">>, [{var, "1"}],
  916. <<"1.00 ">>},
  917. {"|stringformat:\".2f\"",
  918. <<"{{ var|stringformat:\".2f\" }}">>, [{var, "1"}],
  919. <<"1.00">>},
  920. {"|stringformat:\"x\"",
  921. <<"{{ var|stringformat:\"x\" }}">>, [{var, "90"}],
  922. <<"5a">>},
  923. {"|stringformat:\"X\"",
  924. <<"{{ var|stringformat:\"X\" }}">>, [{var, "90"}],
  925. <<"5A">>},
  926. {"|stringformat:\"o\"",
  927. <<"{{ var|stringformat:\"o\" }}">>, [{var, "90"}],
  928. <<"132">>},
  929. {"|stringformat:\"e\"",
  930. <<"{{ var|stringformat:\"e\" }}">>, [{var, "90"}],
  931. <<"9.000000e+01">>},
  932. {"|stringformat:\"e\"",
  933. <<"{{ var|stringformat:\"e\" }}">>, [{var, "90000000000"}],
  934. <<"9.000000e+10">>},
  935. {"|stringformat:\"E\"",
  936. <<"{{ var|stringformat:\"E\" }}">>, [{var, "90"}],
  937. <<"9.000000E+01">>},
  938. {"|striptags",
  939. <<"{{ var|striptags }}">>, [{var, "<b>Joel</b> <button>is</button> a <span>slug</span>"}],
  940. <<"Joel is a slug">>},
  941. {"|striptags",
  942. <<"{{ var|striptags }}">>, [{var, "<B>Joel</B> <button>is</button> a <span>slug</Span>"}],
  943. <<"Joel is a slug">>},
  944. {"|striptags",
  945. <<"{{ var|striptags }}">>, [{var, "Check out <a href=\"http://www.djangoproject.com\" rel=\"nofollow\">http://www.djangoproject.com</a>"}],
  946. <<"Check out http://www.djangoproject.com">>},
  947. {"|time:\"H:i\"",
  948. <<"{{ var|time:\"H:i\" }}">>, [{var, {{2010,12,1}, {10,11,12}} }],
  949. <<"10:11">>},
  950. {"|time",
  951. <<"{{ var|time }}">>, [{var, {{2010,12,1}, {10,11,12}} }],
  952. <<"10:11 a.m.">>},
  953. {"|timesince:from_date",
  954. <<"{{ from_date|timesince:conference_date }}">>, [{conference_date, {{2006,6,1},{8,0,0}} }, {from_date, {{2006,6,1},{0,0,0}} }],
  955. <<"8 hours">>},
  956. {"|timesince:from_date",
  957. <<"{{ from_date|timesince:conference_date }}">>, [{conference_date, {{2010,6,1},{8,0,0}} },{from_date, {{2006,6,1},{0,0,0}} }],
  958. <<"4 years, 1 day">>}, % leap year
  959. {"|timesince:from_date",
  960. <<"{{ from_date|timesince:conference_date }}">>, [{conference_date, {{2006,7,15},{8,0,0}} },{from_date, {{2006,6,1},{0,0,0}} }],
  961. <<"1 month, 2 weeks">>},
  962. {"|timeuntil:from_date",
  963. <<"{{ conference_date|timeuntil:from_date }}">>, [{conference_date, {{2006,6,1},{8,0,0}} }, {from_date, {{2006,6,1},{0,0,0}} }],
  964. <<"8 hours">>},
  965. {"|timeuntil:from_date",
  966. <<"{{ conference_date|timeuntil:from_date }}">>, [{conference_date, {{2010,6,1},{8,0,0}} },{from_date, {{2006,6,1},{0,0,0}} }],
  967. <<"4 years, 1 day">>},
  968. {"|timeuntil:from_date",
  969. <<"{{ conference_date|timeuntil:from_date }}">>, [{conference_date, {{2006,7,15},{8,0,0}} },{from_date, {{2006,6,1},{0,0,0}} }],
  970. <<"1 month, 2 weeks">>},
  971. {"|title",
  972. <<"{{ \"my title case\"|title }}">>, [],
  973. <<"My Title Case">>},
  974. {"|title (pre-formatted)",
  975. <<"{{ \"My Title Case\"|title }}">>, [],
  976. <<"My Title Case">>},
  977. {"|title (wacky separators)",
  978. <<"{{ \"my-title!case\"|title }}">>, [],
  979. <<"My-Title!Case">>},
  980. {"|title (numbers)",
  981. <<"{{ \"my-title123CaSe\"|title }}">>, [],
  982. <<"My-Title123case">>},
  983. {"|title (Irish names)",
  984. <<"{{ \"who's o'malley?\"|title }}">>, [],
  985. <<"Who's O'Malley?">>},
  986. {"|truncatechars:0",
  987. <<"{{ var1|truncatechars:0 }}">>, [{var1, "Empty Me"}],
  988. <<"...">>},
  989. {"|truncatechars:14",
  990. <<"{{ var1|truncatechars:14 }}">>, [{var1, "Truncate Me Please"}],
  991. <<"Truncate Me...">>},
  992. {"|truncatechars:17",
  993. <<"{{ var1|truncatechars:17 }}">>, [{var1, "Don't Truncate Me"}],
  994. <<"Don't Truncate Me">>},
  995. {"|truncatechars:4 (UTF-8)",
  996. <<"{{ var1|truncatechars:4 }}">>, [{var1, "\x{E2}\x{82}\x{AC}1.99"}],
  997. <<"\x{E2}\x{82}\x{AC}...">>},
  998. {"|truncatechars:5 (UTF-8)",
  999. <<"{{ var1|truncatechars:5 }}">>, [{var1, "\x{E2}\x{82}\x{AC} 1.99"}],
  1000. <<"\x{E2}\x{82}\x{AC} ...">>},
  1001. {"|truncatewords:0",
  1002. <<"{{ var1|truncatewords:0 }}">>, [{var1, "Empty Me"}],
  1003. <<" ...">>},
  1004. {"|truncatewords:2",
  1005. <<"{{ var1|truncatewords:2 }}">>, [{var1, "Truncate Me Please"}],
  1006. <<"Truncate Me ...">>},
  1007. {"|truncatewords:3",
  1008. <<"{{ var1|truncatewords:3 }}">>, [{var1, "Don't Truncate Me"}],
  1009. <<"Don't Truncate Me">>},
  1010. {"|truncatewords_html:4",
  1011. <<"{{ var1|truncatewords_html:4 }}">>, [{var1, "<p>The <strong>Long and <em>Winding</em> Road</strong> is too long</p>"}],
  1012. <<"<p>The <strong>Long and <em>Winding</em>...</strong></p>">>},
  1013. {"|unordered_list",
  1014. <<"{{ var1|unordered_list }}">>, [{var1, ["States", ["Kansas", ["Lawrence", "Topeka"], "Illinois"]]}],
  1015. <<"<li>States<ul><li>Kansas<ul><li>Lawrence</li><li>Topeka</li></ul></li><li>Illinois</li></ul></li>">>},
  1016. {"|upper",
  1017. <<"{{ message|upper }}">>, [{message, "That man has a gun."}],
  1018. <<"THAT MAN HAS A GUN.">>},
  1019. {"|urlencode",
  1020. <<"{{ url|urlencode }}">>, [{url, "You #$*@!!"}],
  1021. <<"You%20%23%24%2A%40%21%21">>},
  1022. {"|urlencode",
  1023. <<"{{ url|urlencode }}">>, [{url, "http://www.example.org/foo?a=b&c=d"}],
  1024. <<"http%3A//www.example.org/foo%3Fa%3Db%26c%3Dd">>},
  1025. {"|urlencode",
  1026. <<"{{ url|urlencode:\"\" }}">>, [{url, "http://www.example.org/foo?a=b&c=d"}],
  1027. <<"http%3A%2F%2Fwww.example.org%2Ffoo%3Fa%3Db%26c%3Dd">>},
  1028. {"|urlencode",
  1029. <<"{{ url|urlencode:\":/?=&\" }}">>, [{url, "http://www.example.org/foo?a=b&c=d"}],
  1030. <<"http://www.example.org/foo?a=b&c=d">>},
  1031. {"|urlize",
  1032. <<"{{ var|urlize }}">>, [{var, "Check out www.djangoproject.com"}],
  1033. <<"Check out <a href=\"http://www.djangoproject.com\" rel=\"nofollow\">www.djangoproject.com</a>">>},
  1034. {"|urlize",
  1035. <<"{{ var|urlize }}">>, [{var, "Check out http://www.djangoproject.com"}],
  1036. <<"Check out <a href=\"http://www.djangoproject.com\" rel=\"nofollow\">http://www.djangoproject.com</a>">>},
  1037. {"|urlize",
  1038. <<"{{ var|urlize }}">>, [{var, "Check out \"http://www.djangoproject.com\""}],
  1039. <<"Check out \"<a href=\"http://www.djangoproject.com\" rel=\"nofollow\">http://www.djangoproject.com</a>\"">>},
  1040. {"|urlizetrunc:15",
  1041. <<"{{ var|urlizetrunc:15 }}">>, [{var, "Check out www.djangoproject.com"}],
  1042. <<"Check out <a href=\"http://www.djangoproject.com\" rel=\"nofollow\">www.djangopr...</a>">>},
  1043. {"|wordcount",
  1044. <<"{{ words|wordcount }}">>, [{words, "Why Hello There!"}],
  1045. <<"3">>},
  1046. {"|wordwrap:2",
  1047. <<"{{ words|wordwrap:2 }}">>, [{words, "this is"}],
  1048. <<"this \nis">>},
  1049. {"|wordwrap:100",
  1050. <<"{{ words|wordwrap:100 }}">>, [{words, "testing testing"}],
  1051. <<"testing testing">>},
  1052. {"|wordwrap:10",
  1053. <<"{{ words|wordwrap:10 }}">>, [{words, ""}],
  1054. <<"">>},
  1055. {"|wordwrap:1",
  1056. <<"{{ words|wordwrap:1 }}">>, [{words, "two"}],
  1057. <<"two">>},
  1058. %% yesno match: \?assert.*\( (.*), erlydtl_filters:(.*)\((.*), "(.*)"\)\)
  1059. %% yesno replace: \t\t{"|$2:\"$4\"",\n\t\t\t\t\t <<"{{ var|$2:\"$4\" }}">>, [{var, $3}],\n\t\t\t\t\t<<$1>>}
  1060. {"|yesno:\"yeah,no,maybe\"",
  1061. <<"{{ var|yesno:\"yeah,no,maybe\" }}">>, [{var, true}],
  1062. <<"yeah">>},
  1063. {"|yesno:\"yeah,no,maybe\"",
  1064. <<"{{ var|yesno:\"yeah,no,maybe\" }}">>, [{var, false}],
  1065. <<"no">>},
  1066. {"|yesno:\"yeah,no\"",
  1067. <<"{{ var|yesno:\"yeah,no\" }}">>, [{var, undefined}],
  1068. <<"no">>},
  1069. {"|yesno:\"yeah,no,maybe\"",
  1070. <<"{{ var|yesno:\"yeah,no,maybe\" }}">>, [{var, undefined}],
  1071. <<"maybe">>},
  1072. {"string |yesno:\"yeah,no,maybe\"",
  1073. <<"{{ var|yesno:\"yeah,no,maybe\" }}">>, [{var, "non-empty string"}],
  1074. <<"yeah">>},
  1075. {"binary |yesno:\"yeah,no,maybe\"",
  1076. <<"{{ var|yesno:\"yeah,no,maybe\" }}">>, [{var, <<"non-empty binary">>}],
  1077. <<"yeah">>},
  1078. {"empty string |yesno:\"yeah,no,maybe\"",
  1079. <<"{{ var|yesno:\"yeah,no,maybe\" }}">>, [{var, ""}],
  1080. <<"no">>},
  1081. {"empty binary |yesno:\"yeah,no\"",
  1082. <<"{{ var|yesno:\",no\" }}">>, [{var, <<"">>}],
  1083. <<"no">>},
  1084. {"term |yesno:\"yeah,,maybe\"",
  1085. <<"{{ var|yesno:\"yeah,no,maybe\" }}">>, [{var, {my, [term, "test"]}}],
  1086. <<"yeah">>},
  1087. {"|yesno:\"yeah,\"",
  1088. <<"{{ var|yesno:\"yeah,\" }}">>, [{var, false}],
  1089. <<"">>},
  1090. {"|yesno:\"yeah,,maybe\"",
  1091. <<"{{ var|yesno:\"yeah,,maybe\" }}">>, [{var, false}],
  1092. <<"">>},
  1093. #test{
  1094. title = "|yesno:\"missing_false_choice\"",
  1095. source = <<"{{ var|yesno:\"missing_false_choice\" }}">>,
  1096. render_vars = [{var, true}],
  1097. output = {error, {yesno, choices}}
  1098. },
  1099. {"escape only once (#150) - no auto escape",
  1100. %% note that auto_escape is off by default in the test suite
  1101. %% due to how the tests have been written (and it's too much
  1102. %% work for me to rewrite them)
  1103. <<"{{ foo }}{{ foo|add:'bar' }}">>,
  1104. [{foo, "foo&"}],
  1105. <<"foo&foo&bar">>},
  1106. {"escape only once (#150) - auto escape block",
  1107. <<"{% autoescape on %}{{ foo }}{{ foo|add:'bar' }}{% endautoescape %}">>,
  1108. [{foo, "foo&"}],
  1109. <<"foo&amp;foo&amp;bar">>},
  1110. {"escape only once (#150) - auto escape",
  1111. <<"{{ foo }}{{ foo|add:'bar' }}">>,
  1112. [{foo, "foo&"}], [], [auto_escape],
  1113. <<"foo&amp;foo&amp;bar">>},
  1114. {"escape only once (#150) - auto escape, safe",
  1115. <<"{{ foo|safe }}{{ foo|add:'bar'|safe }}&{{ foo|safe|add:'bar' }}">>,
  1116. [{foo, "foo&"}], [], [auto_escape],
  1117. <<"foo&foo&bar&foo&bar">>},
  1118. {"escape only once (#150) - escape filter",
  1119. <<"{{ foo|escape }}{{ foo|add:'bar'|escape }}&{{ foo|escape|add:'bar' }}">>,
  1120. [{foo, "foo&"}],
  1121. <<"foo&amp;foo&amp;bar&foo&amp;bar">>},
  1122. {"escape only once (#150) - auto escape + escape filter",
  1123. <<"{{ foo|escape }}{{ foo|add:'bar'|escape }}&{{ foo|escape|add:'bar' }}">>,
  1124. [{foo, "foo&"}], [], [auto_escape],
  1125. <<"foo&amp;foo&amp;bar&foo&amp;bar">>}
  1126. ]},
  1127. {"filters_if",
  1128. [{"Filter if 1.1",
  1129. <<"{% if var1|length_is:0 %}Y{% else %}N{% endif %}">>,
  1130. [{var1, []}],
  1131. <<"Y">>},
  1132. {"Filter if 1.2",
  1133. <<"{% if var1|length_is:1 %}Y{% else %}N{% endif %}">>,
  1134. [{var1, []}],
  1135. <<"N">>},
  1136. {"Filter if 1.3",
  1137. <<"{% if var1|length_is:7 %}Y{% else %}N{% endif %}">>,
  1138. [{var1, []}],
  1139. <<"N">>},
  1140. {"Filter if 2.1",
  1141. <<"{% if var1|length_is:0 %}Y{% else %}N{% endif %}">>,
  1142. [{var1, ["foo"]}],
  1143. <<"N">>},
  1144. {"Filter if 2.2",
  1145. <<"{% if var1|length_is:1 %}Y{% else %}N{% endif %}">>,
  1146. [{var1, ["foo"]}],
  1147. <<"Y">>},
  1148. {"Filter if 2.3",
  1149. <<"{% if var1|length_is:7 %}Y{% else %}N{% endif %}">>,
  1150. [{var1, ["foo"]}],
  1151. <<"N">>},
  1152. {"Filter if 3.1",
  1153. <<"{% ifequal var1|length 0 %}Y{% else %}N{% endifequal %}">>,
  1154. [{var1, []}],
  1155. <<"Y">>},
  1156. {"Filter if 3.2",
  1157. <<"{% ifequal var1|length 1 %}Y{% else %}N{% endifequal %}">>,
  1158. [{var1, []}],
  1159. <<"N">>},
  1160. {"Filter if 4.1",
  1161. <<"{% ifequal var1|length 3 %}Y{% else %}N{% endifequal %}">>,
  1162. [{var1, ["foo", "bar", "baz"]}],
  1163. <<"Y">>},
  1164. {"Filter if 4.2",
  1165. <<"{% ifequal var1|length 0 %}Y{% else %}N{% endifequal %}">>,
  1166. [{var1, ["foo", "bar", "baz"]}],
  1167. <<"N">>},
  1168. {"Filter if 4.3",
  1169. <<"{% ifequal var1|length 1 %}Y{% else %}N{% endifequal %}">>,
  1170. [{var1, ["foo", "bar", "baz"]}],
  1171. <<"N">>}
  1172. ]},
  1173. {"firstof",
  1174. [{"Firstof first",
  1175. <<"{% firstof foo bar baz %}">>,
  1176. [{foo, "1"},{bar, "2"}],
  1177. <<"1">>},
  1178. {"Firstof second",
  1179. <<"{% firstof foo bar baz %}">>,
  1180. [{bar, "2"}],
  1181. <<"2">>},
  1182. {"Firstof none",
  1183. <<"{% firstof foo bar baz %}">>,
  1184. [],
  1185. <<"">>},
  1186. {"Firstof complex",
  1187. <<"{% firstof foo.bar.baz bar %}">>,
  1188. [{foo, [{bar, [{baz, "quux"}]}]}],
  1189. <<"quux">>},
  1190. {"Firstof undefined complex",
  1191. <<"{% firstof foo.bar.baz bar %}">>,
  1192. [{bar, "bar"}],
  1193. <<"bar">>},
  1194. {"Firstof literal",
  1195. <<"{% firstof foo bar \"baz\" %}">>,
  1196. [],
  1197. <<"baz">>}
  1198. ]},
  1199. {"regroup .. endregroup",
  1200. [{"Ordered",
  1201. <<"{% regroup people by gender as gender_list %}{% for gender in gender_list %}{{ gender.grouper }}\n{% for item in gender.list %}{{ item.first_name }}\n{% endfor %}{% endfor %}{% endregroup %}">>,
  1202. [{people, [[{first_name, "George"}, {gender, "Male"}], [{first_name, "Bill"}, {gender, "Male"}],
  1203. [{first_name, "Margaret"}, {gender, "Female"}], [{first_name, "Condi"}, {gender, "Female"}]]}],
  1204. <<"Male\nGeorge\nBill\nFemale\nMargaret\nCondi\n">>},
  1205. {"Unordered",
  1206. <<"{% regroup people by gender as gender_list %}{% for gender in gender_list %}{{ gender.grouper }}\n{% for item in gender.list %}{{ item.first_name }}\n{% endfor %}{% endfor %}{% endregroup %}">>,
  1207. [{people, [[{first_name, "George"}, {gender, "Male"}],
  1208. [{first_name, "Margaret"}, {gender, "Female"}],
  1209. [{first_name, "Condi"}, {gender, "Female"}],
  1210. [{first_name, "Bill"}, {gender, "Male"}]
  1211. ]}],
  1212. <<"Male\nGeorge\nFemale\nMargaret\nCondi\nMale\nBill\n">>},
  1213. {"NestedOrdered",
  1214. <<"{% regroup people by name.last as lastname_list %}{% for lastname in lastname_list %}{{ lastname.grouper }}\n{% for item in lastname.list %}{{ item.name.first }}\n{% endfor %}{% endfor %}{% endregroup %}">>,
  1215. [{people, [[{name, [{first,"George"},{last,"Costanza"}]}],
  1216. [{name, [{first,"Margaret"},{last,"Costanza"}]}],
  1217. [{name, [{first,"Bill"},{last,"Buffalo"}]}],
  1218. [{name, [{first,"Condi"},{last,"Buffalo"}]}]]}],
  1219. <<"Costanza\nGeorge\nMargaret\nBuffalo\nBill\nCondi\n">>},
  1220. {"NestedUnordered",
  1221. <<"{% regroup people by name.last as lastname_list %}{% for lastname in lastname_list %}{{ lastname.grouper }}\n{% for item in lastname.list %}{{ item.name.first }}\n{% endfor %}{% endfor %}{% endregroup %}">>,
  1222. [{people, [[{name, [{first,"George"},{last,"Costanza"}]}],
  1223. [{name, [{first,"Bill"},{last,"Buffalo"}]}],
  1224. [{name, [{first,"Margaret"},{last,"Costanza"}]}],
  1225. [{name, [{first,"Condi"},{last,"Buffalo"}]}]]}],
  1226. <<"Costanza\nGeorge\nBuffalo\nBill\nCostanza\nMargaret\nBuffalo\nCondi\n">>},
  1227. {"Filter",
  1228. <<"{% regroup people|dictsort:\"name.last\" by name.last as lastname_list %}{% for lastname in lastname_list %}{{ lastname.grouper }}\n{% for item in lastname.list %}{{ item.name.first }}\n{% endfor %}{% endfor %}{% endregroup %}">>,
  1229. [{people, [[{name, [{first,"George"},{last,"Costanza"}]}],
  1230. [{name, [{first,"Bill"},{last,"Buffalo"}]}],
  1231. [{name, [{first,"Margaret"},{last,"Costanza"}]}],
  1232. [{name, [{first,"Condi"},{last,"Buffalo"}]}]]}],
  1233. <<"Buffalo\nBill\nCondi\nCostanza\nGeorge\nMargaret\n">>}
  1234. ]},
  1235. {"regroup",
  1236. [{"Ordered",
  1237. <<"{% regroup people by gender as gender_list %}{% for gender in gender_list %}{{ gender.grouper }}\n{% for item in gender.list %}{{ item.first_name }}\n{% endfor %}{% endfor %}">>,
  1238. [{people, [[{first_name, "George"}, {gender, "Male"}], [{first_name, "Bill"}, {gender, "Male"}],
  1239. [{first_name, "Margaret"}, {gender, "Female"}], [{first_name, "Condi"}, {gender, "Female"}]]}],
  1240. <<"Male\nGeorge\nBill\nFemale\nMargaret\nCondi\n">>},
  1241. {"Unordered",
  1242. <<"{% regroup people by gender as gender_list %}{% for gender in gender_list %}{{ gender.grouper }}\n{% for item in gender.list %}{{ item.first_name }}\n{% endfor %}{% endfor %}">>,
  1243. [{people, [[{first_name, "George"}, {gender, "Male"}],
  1244. [{first_name, "Margaret"}, {gender, "Female"}],
  1245. [{first_name, "Condi"}, {gender, "Female"}],
  1246. [{first_name, "Bill"}, {gender, "Male"}]
  1247. ]}],
  1248. <<"Male\nGeorge\nFemale\nMargaret\nCondi\nMale\nBill\n">>},
  1249. {"NestedOrdered",
  1250. <<"{% regroup people by name.last as lastname_list %}{% for lastname in lastname_list %}{{ lastname.grouper }}\n{% for item in lastname.list %}{{ item.name.first }}\n{% endfor %}{% endfor %}">>,
  1251. [{people, [[{name, [{first,"George"},{last,"Costanza"}]}],
  1252. [{name, [{first,"Margaret"},{last,"Costanza"}]}],
  1253. [{name, [{first,"Bill"},{last,"Buffalo"}]}],
  1254. [{name, [{first,"Condi"},{last,"Buffalo"}]}]]}],
  1255. <<"Costanza\nGeorge\nMargaret\nBuffalo\nBill\nCondi\n">>},
  1256. {"NestedUnordered",
  1257. <<"{% regroup people by name.last as lastname_list %}{% for lastname in lastname_list %}{{ lastname.grouper }}\n{% for item in lastname.list %}{{ item.name.first }}\n{% endfor %}{% endfor %}">>,
  1258. [{people, [[{name, [{first,"George"},{last,"Costanza"}]}],
  1259. [{name, [{first,"Bill"},{last,"Buffalo"}]}],
  1260. [{name, [{first,"Margaret"},{last,"Costanza"}]}],
  1261. [{name, [{first,"Condi"},{last,"Buffalo"}]}]]}],
  1262. <<"Costanza\nGeorge\nBuffalo\nBill\nCostanza\nMargaret\nBuffalo\nCondi\n">>},
  1263. {"Filter",
  1264. <<"{% regroup people|dictsort:\"name.last\" by name.last as lastname_list %}{% for lastname in lastname_list %}{{ lastname.grouper }}\n{% for item in lastname.list %}{{ item.name.first }}\n{% endfor %}{% endfor %}">>,
  1265. [{people, [[{name, [{first,"George"},{last,"Costanza"}]}],
  1266. [{name, [{first,"Bill"},{last,"Buffalo"}]}],
  1267. [{name, [{first,"Margaret"},{last,"Costanza"}]}],
  1268. [{name, [{first,"Condi"},{last,"Buffalo"}]}]]}],
  1269. <<"Buffalo\nBill\nCondi\nCostanza\nGeorge\nMargaret\n">>},
  1270. {"With surrounding context",
  1271. <<"People: {% regroup people by gender as gender_list %}{% for gender in gender_list %}{{ gender.grouper }}\n{% for item in gender.list %}{{ item.first_name }}\n{% endfor %}{% endfor %}Done.">>,
  1272. [{people, [[{first_name, "George"}, {gender, "Male"}], [{first_name, "Bill"}, {gender, "Male"}],
  1273. [{first_name, "Margaret"}, {gender, "Female"}], [{first_name, "Condi"}, {gender, "Female"}]]}],
  1274. <<"People: Male\nGeorge\nBill\nFemale\nMargaret\nCondi\nDone.">>}
  1275. ]},
  1276. {"spaceless",
  1277. [{"Beginning", <<"{% spaceless %} <b>foo</b>{% endspaceless %}">>, [], <<"<b>foo</b>">>},
  1278. {"Middle", <<"{% spaceless %}<b>foo</b> <b>bar</b>{% endspaceless %}">>, [], <<"<b>foo</b><b>bar</b>">>},
  1279. {"End", <<"{% spaceless %}<b>foo</b> {% endspaceless %}">>, [], <<"<b>foo</b>">>},
  1280. {"NewLine", <<"{% spaceless %}\n<div> \n <b>foo</b> \n </div>\n {% endspaceless %}">>, [], <<"<div><b>foo</b></div>">>}
  1281. ]},
  1282. {"templatetag",
  1283. [{"openblock", <<"{% templatetag openblock %}">>, [], <<"{%">>},
  1284. {"closeblock", <<"{% templatetag closeblock %}">>, [], <<"%}">>},
  1285. {"openvariable", <<"{% templatetag openvariable %}">>, [], <<"{{">>},
  1286. {"closevariable", <<"{% templatetag closevariable %}">>, [], <<"}}">>},
  1287. {"openbrace", <<"{% templatetag openbrace %}">>, [], <<"{">>},
  1288. {"closebrace", <<"{% templatetag closebrace %}">>, [], <<"}">>},
  1289. {"opencomment", <<"{% templatetag opencomment %}">>, [], <<"{#">>},
  1290. {"closecomment", <<"{% templatetag closecomment %}">>, [], <<"#}">>}
  1291. ]},
  1292. {"trans",
  1293. [{"trans functional default locale",
  1294. <<"Hello {% trans \"Hi\" %}">>, [], <<"Hello Hi">>
  1295. },
  1296. {"trans functional reverse locale",
  1297. <<"Hello {% trans \"Hi\" %}">>, [], [{locale, "reverse"}],
  1298. [{locales, ["reverse"]}, {translation_fun, fun("Hi"=Key, "reverse") -> list_to_binary(lists:reverse(Key)) end}],
  1299. <<"Hello iH">>
  1300. },
  1301. {"trans literal at run-time",
  1302. <<"Hello {% trans \"Hi\" %}">>, [], [{translation_fun, fun("Hi") -> "Konichiwa" end}], [],
  1303. <<"Hello Konichiwa">>},
  1304. {"trans variable at run-time",
  1305. <<"Hello {% trans var1 %}">>, [{var1, <<"Hi">>}], [{translation_fun, fun(<<"Hi">>) -> <<"Konichiwa">> end}], [],
  1306. <<"Hello Konichiwa">>},
  1307. {"trans literal at run-time: No-op",
  1308. <<"Hello {% trans \"Hi\" noop %}">>, [], [{translation_fun, fun("Hi") -> <<"Konichiwa">> end}], [],
  1309. <<"Hello Hi">>},
  1310. {"trans variable at run-time: No-op",
  1311. <<"Hello {% trans var1 noop %}">>, [{var1, <<"Hi">>}], [{translation_fun, fun(<<"Hi">>) -> <<"Konichiwa">> end}], [],
  1312. <<"Hello Hi">>},
  1313. {"trans as",
  1314. <<"{% trans 'Hans' as name %}Hello {{ name }}">>, [],
  1315. <<"Hello Hans">>},
  1316. {"trans value",
  1317. <<"{{ _('foo') }}">>, [], [], [{locale, default}, {translation_fun, fun ("foo") -> "bar" end}],
  1318. <<"bar">>}
  1319. ]},
  1320. {"blocktrans",
  1321. [{"blocktrans default locale",
  1322. <<"{% blocktrans %}Hello{% endblocktrans %}">>, [], <<"Hello">>},
  1323. {"blocktrans choose locale",
  1324. <<"{% blocktrans %}Hello, {{ name }}{% endblocktrans %}">>, [{name, "Mr. President"}], [{locale, "de"}],
  1325. [{locales, ["de"]}, {translation_fun, fun("Hello, {{ name }}", "de") -> <<"Guten tag, {{ name }}">> end}], <<"Guten tag, Mr. President">>},
  1326. {"blocktrans with args",
  1327. <<"{% blocktrans with var1=foo %}{{ var1 }}{% endblocktrans %}">>, [{foo, "Hello"}], <<"Hello">>},
  1328. #test{
  1329. title = "blocktrans blocks in content not allowed",
  1330. source = <<"{% blocktrans %}Hello{%if name%}, {{ name }}{%endif%}!{% endblocktrans %}">>,
  1331. errors = [error_info([{{1, 24}, erlydtl_parser, ["syntax error before: ",["\"if\""]]}])]
  1332. },
  1333. #test{
  1334. title = "blocktrans nested variables not allowed",
  1335. source = <<"{% blocktrans %}Hello, {{ user.name }}!{% endblocktrans %}">>,
  1336. errors = [error_info([{{1,31}, erlydtl_parser, ["syntax error before: ","'.'"]}])]
  1337. },
  1338. {"blocktrans runtime",
  1339. <<"{% blocktrans with v1=foo%}Hello, {{ name }}! See {{v1}}.{%endblocktrans%}">>,
  1340. [{name, "Mr. President"}, {foo, <<"rubber-duck">>}],
  1341. [{translation_fun, fun("Hello, {{ name }}! See {{ v1 }}.") -> <<"Guten tag, {{name}}! Sehen {{ v1 }}.">> end}],
  1342. [], <<"Guten tag, Mr. President! Sehen rubber-duck.">>}
  1343. ]},
  1344. {"extended translation features (#131)",
  1345. [{"trans default locale",
  1346. <<"test {% trans 'message' %}">>,
  1347. [], [{translation_fun, fun ("message", default) -> "ok" end}],
  1348. <<"test ok">>},
  1349. {"trans foo locale",
  1350. <<"test {% trans 'message' %}">>,
  1351. [], [{locale, "foo"}, {translation_fun, fun ("message", "foo") -> "ok" end}],
  1352. <<"test ok">>},
  1353. {"trans context (run-time)",
  1354. <<"test {% trans 'message' context 'foo' %}">>,
  1355. [], [{translation_fun, fun ("message", {default, "foo"}) -> "ok" end}],
  1356. <<"test ok">>},
  1357. {"trans context (compile-time)",
  1358. <<"test {% trans 'message' context 'foo' %}">>,
  1359. [], [{locale, "baz"}],
  1360. [{locales, ["bar", "baz"]},
  1361. {translation_fun, fun ("message", {L, "foo"}) ->
  1362. case L of
  1363. "bar" -> "rab";
  1364. "baz" -> "ok"
  1365. end
  1366. end}],
  1367. <<"test ok">>},
  1368. {"trans context noop",
  1369. <<"{% trans 'message' noop context 'foo' %}">>, [], [],
  1370. <<"message">>},
  1371. {"blocktrans context (run-time)",
  1372. <<"{% blocktrans context 'bar' %}translate this{% endblocktrans %}">>,
  1373. [], [{locale, "foo"}, {translation_fun,
  1374. fun ("translate this", {"foo", "bar"}) ->
  1375. "got it"
  1376. end}],
  1377. <<"got it">>},
  1378. {"blocktrans context (compile-time)",
  1379. <<"{% blocktrans context 'bar' %}translate this{% endblocktrans %}">>,
  1380. [], [{locale, "foo"}],
  1381. [{locale, "foo"}, {translation_fun,
  1382. fun ("translate this", {"foo", "bar"}) ->
  1383. "got it"
  1384. end}],
  1385. <<"got it">>},
  1386. {"blocktrans plural",
  1387. <<"{% blocktrans count foo=bar %}",
  1388. "There is just one foo..",
  1389. "{% plural %}",
  1390. "There are many foo's..",
  1391. "{% endblocktrans %}">>,
  1392. [{bar, 2}], [{locale, "baz"},
  1393. {translation_fun,
  1394. fun ({"There is just one foo..", {"There are many foo's..", 2}}, "baz") ->
  1395. "ok"
  1396. end}],
  1397. <<"ok">>},
  1398. {"blocktrans a lot of stuff",
  1399. <<"{% blocktrans with foo=a.b count c=a|length context 'quux' %}"
  1400. "foo={{ foo }};bar={{ bar }};c={{ c }}:"
  1401. "{% plural %}"
  1402. "FOO:{{ foo }},BAR:{{ bar }},C:{{ c }}."
  1403. "{% endblocktrans %}">>,
  1404. [{a, [{b, "B"}]}, {bar, "BAR"}],
  1405. [{locale, "rub"},
  1406. {translation_fun, fun ({Single, {Plural, "1"=_Count}}, {Locale, Context}) ->
  1407. [Single, Plural, Locale, Context]
  1408. end}],
  1409. <<"foo=B;bar=BAR;c=1:"
  1410. "FOO:B,BAR:BAR,C:1."
  1411. "rub" "quux">>},
  1412. {"new translation options",
  1413. <<"{% trans foo %}{% blocktrans %}abc{% endblocktrans %}">>,
  1414. [{foo, "1234"}], [{locale, "test"}, {translation_fun, fun (Msg) -> lists:reverse(Msg) end}],
  1415. [{locale, "foo"}, {locale, "test"}, {locales, ["bar", "baz"]},
  1416. {translation_fun, fun (Msg, _) -> [Msg, lists:reverse(Msg)] end}],
  1417. <<"4321" "abccba">>}
  1418. %% This does work, but always prints a warning to std err.. :/
  1419. %% Warning: template translation: variable not closed: "bar {{ 123"
  1420. %% {"variable error",
  1421. %% <<"{% blocktrans %}foo{{ bar }}{% endblocktrans %}">>,
  1422. %% [], [{translation_fun, fun (_) -> "bar {{ 123" end}],
  1423. %% <<"foo">>}
  1424. ]},
  1425. {"i18n",
  1426. [{"setup translation context, using fun, at render time",
  1427. <<"{% trans 'foo' %}">>, [],
  1428. [{translation_fun, fun () -> fun (Msg) -> string:to_upper(Msg) end end}],
  1429. <<"FOO">>},
  1430. {"setup translation context, using fun, at compile time",
  1431. <<"{% trans 'foo' %}">>, [], [],
  1432. [{locale, default}, {translation_fun, fun () -> fun lists:reverse/1 end}],
  1433. <<"oof">>}
  1434. ]},
  1435. {"verbatim",
  1436. [{"Plain verbatim",
  1437. <<"{% verbatim %}{{ oh no{% foobar %}{% endverbatim %}">>, [],
  1438. <<"{{ oh no{% foobar %}">>},
  1439. {"Named verbatim",
  1440. <<"{% verbatim foobar %}{% verbatim %}{% endverbatim foobar2 %}{% endverbatim foobar %}">>, [],
  1441. <<"{% verbatim %}{% endverbatim foobar2 %}">>}
  1442. ]},
  1443. {"widthratio",
  1444. [{"Literals", <<"{% widthratio 5 10 100 %}">>, [], <<"50">>},
  1445. {"Rounds up", <<"{% widthratio a b 100 %}">>, [{a, 175}, {b, 200}], <<"88">>}
  1446. ]},
  1447. {"with",
  1448. [{"Cache literal",
  1449. <<"{% with a=1 %}{{ a }}{% endwith %}">>, [], <<"1">>},
  1450. {"Cache variable",
  1451. <<"{% with a=b %}{{ a }}{% endwith %}">>, [{b, "foo"}], <<"foo">>},
  1452. {"Cache variable with attribute",
  1453. <<"I enjoy {% with a = var1 %}{{ a.game }}{% endwith %}">>, [{var1, [{game, "Othello"}]}], <<"I enjoy Othello">>},
  1454. {"Cache variable attribute",
  1455. <<"I enjoy {% with a = var1.game %}{{ a }}{% endwith %}">>, [{var1, [{game, "Othello"}]}], <<"I enjoy Othello">>},
  1456. {"Cache multiple",
  1457. <<"{% with alpha=1 beta=b %}{{ alpha }}/{{ beta }}{% endwith %}">>, [{b, 2}], <<"1/2">>}
  1458. ]},
  1459. {"unicode",
  1460. [{"(tm) somewhere",
  1461. <<"™">>, [], <<"™">>}
  1462. ]},
  1463. {"contrib_humanize",
  1464. [{"intcomma",
  1465. <<"{{ a|intcomma }} {{ b|intcomma }} {{ c|intcomma }} {{ d|intcomma }}">>,
  1466. [{a, 999}, {b, 123456789}, {c, 12345}, {d, 1234567890}], [],
  1467. [{custom_filters_modules, [erlydtl_contrib_humanize]}],
  1468. <<"999 123,456,789 12,345 1,234,567,890">>}
  1469. ]},
  1470. %% custom syntax stuff
  1471. {"extension_module",
  1472. [ %% the erlydtl_test_extension module replaces a foo identifier with bar when hitting a # following foo.
  1473. {"replace parsed token", <<"{{ foo # }}">>, [{bar, "ok"}], [],
  1474. [{extension_module, erlydtl_test_extension}], <<"ok">>},
  1475. #test{
  1476. title = "proper error message",
  1477. source = <<"{{ bar # }}">>,
  1478. render_vars = [{bar, "ok"}],
  1479. compile_opts = [{extension_module, erlydtl_test_extension},
  1480. report, return, force_recompile, {out_dir, false}],
  1481. errors = [error_info([{{1,8},erlydtl_scanner,{illegal_char, $#}}])]
  1482. },
  1483. %% accept identifiers as expressions (this is a dummy functionality to test the parser extensibility)
  1484. {"identifiers as expressions", <<"{{ foo.bar or baz }}">>, [{baz, "ok"}], [],
  1485. [{extension_module, erlydtl_test_extension}], <<"ok">>}
  1486. ]},
  1487. {"records",
  1488. [{"field access",
  1489. <<"{{ r.baz }}">>, [{r, #testrec{ foo="Foo", bar="Bar", baz="Baz" }}], [],
  1490. [{record_info, [{testrec, record_info(fields, testrec)}]}],
  1491. <<"Baz">>}
  1492. ]},
  1493. {"error reporting",
  1494. [#test{
  1495. title = "no out dir warning",
  1496. source = <<"foo bar">>,
  1497. compile_opts = [report, return, force_recompile],
  1498. output = <<"foo bar">>,
  1499. warnings = [error_info([no_out_dir])]
  1500. },
  1501. #test{
  1502. title = "warnings as errors",
  1503. source = <<"foo bar">>,
  1504. compile_opts = [report, return, warnings_as_errors, force_recompile],
  1505. errors = [error_info([no_out_dir])]
  1506. },
  1507. #test{
  1508. title = "illegal character",
  1509. source = <<"{{{">>,
  1510. errors = [error_info([{{1,3},erlydtl_scanner,{illegal_char, ${}}])]
  1511. },
  1512. #test{
  1513. title = "unexpected end of file - in code",
  1514. source = <<"{{">>,
  1515. errors = [error_info([{{1,3},erlydtl_scanner,{eof, in_code}}])]
  1516. },
  1517. #test{
  1518. title = "unexpected end of file - in comment",
  1519. source = <<"{#">>,
  1520. errors = [error_info([{{1,3},erlydtl_scanner,{eof, in_comment}}])]
  1521. },
  1522. {"unknown library",
  1523. <<"{% load foo %}">>, [], [], [],
  1524. <<>>,
  1525. [error_info(
  1526. [{{1,9},erlydtl_compiler_utils,{load_library,foo,foo,nofile}}
  1527. ])]
  1528. },
  1529. {"not a library",
  1530. <<"{% load foo %}">>, [], [],
  1531. [{libraries, [{foo, ?MODULE}]}],
  1532. <<>>,
  1533. [error_info(
  1534. [{{1,9},erlydtl_compiler_utils,{load_library,foo,?MODULE,behaviour}}
  1535. ])]
  1536. },
  1537. {"library version",
  1538. <<"{% load foo %}">>, [], [],
  1539. [{libraries, [{foo, erlydtl_lib_testversion}]}],
  1540. <<>>,
  1541. [error_info(
  1542. [{{1,9},erlydtl_compiler_utils,{load_library,foo,erlydtl_lib_testversion,{version,invalid}}}
  1543. ])]
  1544. },
  1545. {"not in library",
  1546. <<"{% load foo bar from test1 %}\n{{ \"w00t\"|reverse }}">>, [], [],
  1547. [{libraries, [{test1, erlydtl_lib_test1}]}],
  1548. <<"\n">>,
  1549. [error_info(
  1550. [{{2,11},erlydtl_beam_compiler,{unknown_filter,reverse,1}},
  1551. {{1,22},erlydtl_compiler_utils,{load_from,test1,erlydtl_lib_test1,foo}},
  1552. {{1,22},erlydtl_compiler_utils,{load_from,test1,erlydtl_lib_test1,bar}}
  1553. ])]
  1554. },
  1555. {"pre load unknown library",
  1556. <<"{{ '123'|reverse }}">>, [], [],
  1557. [{default_libraries, [test1]}],
  1558. <<"">>,
  1559. [error_info(
  1560. [{{1,10},erlydtl_beam_compiler,{unknown_filter,reverse,1}},
  1561. {none,erlydtl_compiler_utils,{load_library,test1,test1,nofile}}
  1562. ])]
  1563. },
  1564. {"pre load unknown legacy library",
  1565. <<"{% foo %}">>, [], [],
  1566. [{custom_tags_modules, [foo]}],
  1567. <<"">>,
  1568. [error_info([{none,erlydtl_compiler,{load_library,'(custom-legacy)',foo,nofile}}])]
  1569. },
  1570. {"unknown filter",
  1571. <<"{{ '123'|foo }}">>, [], [], [],
  1572. <<"">>,
  1573. [error_info([{{1,10},erlydtl_beam_compiler,{unknown_filter,foo,1}}])]
  1574. },
  1575. {"ssi file not found",
  1576. <<"{% ssi 'foo' %}">>, [],
  1577. {error, {read_file, <<"./foo">>, enoent}}
  1578. },
  1579. {"deprecated compile options",
  1580. <<"">>, [], [],
  1581. [{blocktrans_locales, []}, {blocktrans_fun, fun (_) -> [] end}],
  1582. <<"">>,
  1583. [error_info([{deprecated_option, O, N}
  1584. || {O, N} <- [{blocktrans_locales, locales},
  1585. {blocktrans_fun, translation_fun}]],
  1586. erlydtl_compiler)]
  1587. }
  1588. ]},
  1589. {"load",
  1590. [{"filter",
  1591. <<"{% load test1 %}{{ \"1234\"|reverse }}">>, [], [],
  1592. [{libraries, [{test1, erlydtl_lib_test1}]}],
  1593. <<"4321">>
  1594. },
  1595. {"named",
  1596. <<"{% load reverse from test1 %}{{ \"abcd\"|reverse }}">>, [], [],
  1597. [{libraries, [{test1, erlydtl_lib_test1}]}],
  1598. <<"dcba">>
  1599. },
  1600. {"pre loaded",
  1601. <<"{{ QWER|reverse }}">>, [{'QWER', "Qwerty"}], [],
  1602. [{default_libraries, [test1]},
  1603. {libraries, [{test1, erlydtl_lib_test1}]}],
  1604. <<"ytrewQ">>
  1605. }
  1606. ]},
  1607. {"compile time default vars/constants",
  1608. begin
  1609. Tpl = <<"Test {{ var1 }}:{{ var2 }}.">>,
  1610. Txt = <<"Test 123:abc.">>,
  1611. Fun = fun (F) ->
  1612. fun (#test{ module=M }) ->
  1613. M:F()
  1614. end
  1615. end,
  1616. [{"default vars",
  1617. Tpl, [], [],
  1618. [{default_vars, [{var1, 123}, {var2, abc}]}], Txt},
  1619. {"default vars (using fun)",
  1620. Tpl, [], [],
  1621. [{default_vars, [{var1, 123}, {var2, fun () -> abc end}]}], Txt},
  1622. {"override default vars",
  1623. Tpl, [{var2, abc}], [],
  1624. [{default_vars, [{var1, 123}, {var2, 456}]}], Txt},
  1625. {"constants",
  1626. Tpl, [], [],
  1627. [{constants, [{var1, 123}, {var2, abc}]}], Txt},
  1628. {"constants (using fun)",
  1629. Tpl, [], [],
  1630. [{constants, [{var1, 123}, {var2, fun () -> abc end}]}], Txt},
  1631. {"constants non-overridable",
  1632. Tpl, [{var1, ohno}, {var2, noway}], [],
  1633. [{constants, [{var1, 123}, {var2, "abc"}]}], Txt}
  1634. |[#test{ title = T,
  1635. source = Tpl,
  1636. compile_vars = undefined,
  1637. compile_opts = CO ++ (#test{})#test.compile_opts,
  1638. renderer = Fun(F),
  1639. output = O
  1640. }
  1641. || {T, F, O, CO} <-
  1642. [{"variables/0",
  1643. variables, [var1, var2], []},
  1644. {"variables/0 w. defaults",
  1645. variables, [var1, var2], [{default_vars, [{var1, aaa}]}]},
  1646. {"variables/0 w. constants",
  1647. variables, [var2], [{constants, [{var1, bbb}]}]},
  1648. {"default_variables/0",
  1649. default_variables, [], []},
  1650. {"default_variables/0 w. defaults",
  1651. default_variables, [var1], [{default_vars, [{var1, aaa}]}]},
  1652. {"default_variables/0 w. constants",
  1653. default_variables, [], [{constants, [{var1, bbb}]}]},
  1654. {"constants/0",
  1655. constants, [], []},
  1656. {"constants/0 w. defaults",
  1657. constants, [], [{default_vars, [{var1, aaa}]}]},
  1658. {"constants/0 w. constants",
  1659. constants, [var1], [{constants, [{var1, bbb}]}]}
  1660. ]
  1661. ]]
  1662. end},
  1663. {"functional",
  1664. [functional_test(F)
  1665. %% order is important for a few of these tests, unfortunately.
  1666. || F <- ["autoescape", "comment", "extends", "filters", "for", "for_list", "for_tuple",
  1667. "for_list_preset", "for_preset", "for_records", "for_records_preset", "include",
  1668. "if", "if_preset", "ifequal", "ifequal_preset", "ifnotequal", "ifnotequal_preset",
  1669. "now", "var", "var_preset", "cycle", "custom_tag", "custom_tag1", "custom_tag2",
  1670. "custom_tag3", "custom_tag4", "custom_call", "include_template", "include_path",
  1671. "ssi", "extends_path", "extends_path2", "trans", "extends_for", "extends2",
  1672. "extends3", "recursive_block", "extend_recursive_block", "missing", "block_super",
  1673. "wrapper", "extends4", "super_escaped", "extends_chain"]
  1674. ]},
  1675. {"compile_dir",
  1676. [setup_compile(T)
  1677. || T <- [#test{
  1678. title = "non-existing dir",
  1679. source = {dir, "non-existing-made-up-dir"},
  1680. renderer = fun(#test{ source={dir, Dir} }) -> Dir end,
  1681. output = "non-existing-made-up-dir"
  1682. },
  1683. #test{
  1684. title = "path1",
  1685. source = {dir, template_file(input, "path1")},
  1686. renderer = fun(#test{ module=M, render_vars=V, render_opts=O }) ->
  1687. M:render(base1, V, O)
  1688. end
  1689. }
  1690. ]
  1691. ]}
  1692. ].
  1693. %% {Name, DTL, Vars, Output}
  1694. %% {Name, DTL, Vars, RenderOpts, Output}
  1695. %% {Name, DTL, Vars, RenderOpts, CompilerOpts, Output}
  1696. %% {Name, DTL, Vars, RenderOpts, CompilerOpts, Output, Warnings}
  1697. def_to_test(Group, #test{ title=Name }=T) ->
  1698. T#test{ title = lists:concat([Group, ": ", Name]) };
  1699. def_to_test(Group, {Name, DTL, Vars, Output}) ->
  1700. def_to_test(Group, {Name, DTL, Vars, [], [], Output, default_warnings()});
  1701. def_to_test(Group, {Name, DTL, Vars, RenderOpts, Output}) ->
  1702. def_to_test(Group, {Name, DTL, Vars, RenderOpts, [], Output, default_warnings()});
  1703. def_to_test(Group, {Name, DTL, Vars, RenderOpts, CompilerOpts, Output}) ->
  1704. def_to_test(Group, {Name, DTL, Vars, RenderOpts, CompilerOpts, Output, default_warnings()});
  1705. def_to_test(Group, {Name, DTL, Vars, RenderOpts, CompilerOpts, Output, Warnings}) ->
  1706. #test{
  1707. title = lists:concat([Group, ": ", Name]),
  1708. source = {template, DTL},
  1709. render_vars = Vars,
  1710. render_opts = RenderOpts,
  1711. compile_vars = undefined,
  1712. compile_opts = CompilerOpts ++ (#test{})#test.compile_opts,
  1713. output = Output,
  1714. warnings = Warnings
  1715. }.
  1716. generate_test_date() ->
  1717. {{Y,M,D}, _} = erlang:localtime(),
  1718. MonthName = [
  1719. "January", "February", "March", "April",
  1720. "May", "June", "July", "August", "September",
  1721. "October", "November", "December"
  1722. ],
  1723. OrdinalSuffix = [
  1724. "st","nd","rd","th","th","th","th","th","th","th", % 1-10
  1725. "th","th","th","th","th","th","th","th","th","th", % 10-20
  1726. "st","nd","rd","th","th","th","th","th","th","th", % 20-30
  1727. "st"
  1728. ],
  1729. list_to_binary([
  1730. "It is the ",
  1731. integer_to_list(D),
  1732. lists:nth(D, OrdinalSuffix),
  1733. " of ", lists:nth(M, MonthName),
  1734. " ", integer_to_list(Y), "."
  1735. ]).
  1736. default_warnings() -> [].
  1737. error_info(File, Ws, Mod) ->
  1738. {File, [error_info(W, Mod) || W <- Ws]}.
  1739. error_info({Line, ErrorDesc}, Mod)
  1740. when is_integer(Line); Line =:= none ->
  1741. {Line, Mod, ErrorDesc};
  1742. error_info({Line, Module, _}=ErrorDesc, _Mod)
  1743. when is_integer(Line), is_atom(Module) ->
  1744. ErrorDesc;
  1745. error_info({none, Module, _}=ErrorDesc, _Mod)
  1746. when is_atom(Module) ->
  1747. ErrorDesc;
  1748. error_info({{Line, Col}, Module, _}=ErrorDesc, _Mod)
  1749. when is_integer(Line), is_integer(Col), is_atom(Module) ->
  1750. ErrorDesc;
  1751. error_info(Ws, Mod) when is_list(Ws) ->
  1752. error_info("erly_test", Ws, Mod);
  1753. error_info(ErrorDesc, Mod) ->
  1754. {none, Mod, ErrorDesc}.
  1755. error_info(Ei) ->
  1756. error_info(Ei, erlydtl_beam_compiler).
  1757. template_file(Dir, Name) -> filename:join(["../test/files", Dir, Name]).
  1758. functional_test(F) ->
  1759. setup_compile(#test{
  1760. title = F,
  1761. module = list_to_atom("functional_test_" ++ F),
  1762. source = {file, template_file(input, F)}
  1763. }).
  1764. setup_compile(#test{ title=F, compile_opts=Opts }=T) ->
  1765. CompileOpts = [{doc_root, "../test/files/input"}|Opts],
  1766. case setup_compile(F) of
  1767. {ok, [CV|Other]} ->
  1768. CO = proplists:get_value(compile_opts, Other, []),
  1769. Ws = proplists:get_value(warnings, Other, []),
  1770. setup(T#test{
  1771. compile_vars = CV,
  1772. compile_opts = CO ++ CompileOpts,
  1773. warnings = Ws
  1774. });
  1775. {error, Es, Ws} ->
  1776. T#test{
  1777. errors = Es,
  1778. warnings = Ws,
  1779. compile_opts = CompileOpts
  1780. }
  1781. end;
  1782. setup_compile("for_list_preset") ->
  1783. CompileVars = [{fruit_list, [["apple", "apples"], ["banana", "bananas"], ["coconut", "coconuts"]]}],
  1784. {ok, [CompileVars]};
  1785. setup_compile("for_preset") ->
  1786. CompileVars = [{fruit_list, ["preset-apple", "preset-banana", "preset-coconut"]}],
  1787. {ok, [CompileVars]};
  1788. setup_compile("for_records_preset") ->
  1789. Link1a = [{name, "Amazon (preset)"}, {url, "http://amazon.com"}],
  1790. Link2a = [{name, "Google (preset)"}, {url, "http://google.com"}],
  1791. Link3a = [{name, "Microsoft (preset)"}, {url, "http://microsoft.com"}],
  1792. CompileVars = [{software_links, [Link1a, Link2a, Link3a]}],
  1793. {ok, [CompileVars]};
  1794. setup_compile("if_preset") ->
  1795. CompileVars = [{var1, "something"}],
  1796. {ok, [CompileVars]};
  1797. setup_compile("ifequal_preset") ->
  1798. CompileVars = [{var1, "foo"}, {var2, "foo"}],
  1799. {ok, [CompileVars]};
  1800. setup_compile("ifnotequal_preset") ->
  1801. CompileVars = [{var1, "foo"}, {var2, "foo"}],
  1802. {ok, [CompileVars]};
  1803. setup_compile("var_preset") ->
  1804. CompileVars = [{preset_var1, "preset-var1"}, {preset_var2, "preset-var2"}],
  1805. {ok, [CompileVars]};
  1806. setup_compile("extends_for") ->
  1807. CompileVars = [{veggie_list, ["broccoli", "beans", "peas", "carrots"]}],
  1808. {ok, [CompileVars]};
  1809. setup_compile("extends2") ->
  1810. File = template_file(input, "extends2"),
  1811. Error = {none, erlydtl_beam_compiler, unexpected_extends_tag},
  1812. {error, [{File, [Error]}], []};
  1813. setup_compile("extends3") ->
  1814. File = template_file(input, "extends3"),
  1815. Include = template_file(input, "imaginary"),
  1816. Error = {none, erlydtl_beam_compiler, {read_file, Include, enoent}},
  1817. {error, [{File, [Error]}], []};
  1818. setup_compile("extends4") ->
  1819. File = template_file(input, "extends4"),
  1820. Warning = {{1,21}, erlydtl_beam_compiler, non_block_tag},
  1821. {ok, [[]|[{warnings, [{File, [Warning]}]}]]};
  1822. setup_compile("missing") ->
  1823. File = template_file(input, "missing"),
  1824. Error = {none, erlydtl_compiler, {read_file, File, enoent}},
  1825. {error, [{File, [Error]}], []};
  1826. setup_compile("custom_tag") ->
  1827. {ok, [[]|[{compile_opts, [{custom_tags_modules, [erlydtl_custom_tags]}]}]]};
  1828. setup_compile("custom_tag1") -> setup_compile("custom_tag");
  1829. setup_compile("custom_tag2") -> setup_compile("custom_tag");
  1830. setup_compile("custom_tag3") -> setup_compile("custom_tag");
  1831. setup_compile("custom_tag4") -> setup_compile("custom_tag");
  1832. setup_compile("super_escaped") ->
  1833. {ok, [[]|[{compile_opts, [auto_escape]}]]};
  1834. setup_compile(_) ->
  1835. {ok, [[]]}.
  1836. expected(File) ->
  1837. Filename = template_file(expect, File),
  1838. case file:read_file(Filename) of
  1839. {ok, Data} -> Data;
  1840. _ -> fun (Data) ->
  1841. ok = file:write_file(Filename, Data),
  1842. io:format(
  1843. user,
  1844. "## Saved expected output for test ~p to ~p.~n"
  1845. " Verify the contents, as it is used to pass the test on subsequent test runs.~n"
  1846. "~n",
  1847. [File, Filename]),
  1848. throw({verify_new_expected_output, Filename})
  1849. end
  1850. end.
  1851. setup(#test{ title = F, output=undefined }=T) ->
  1852. {Vars, Opts, Result} =
  1853. case setup(F) of
  1854. {ok, V} -> {V, [], expected(F)};
  1855. {ok, V, O} -> {V, O, expected(F)};
  1856. {ok, V, O, skip_check} -> {V, O, fun (_) -> ok end};
  1857. {ok, V, O, R} -> {V, O, R}
  1858. end,
  1859. T#test{
  1860. render_vars = Vars,
  1861. render_opts = Opts,
  1862. output = Result
  1863. };
  1864. setup(#test{}=T) -> T;
  1865. setup("autoescape") ->
  1866. RenderVars = [{var1, "<b>bold</b>"}],
  1867. {ok, RenderVars};
  1868. setup("extends") ->
  1869. RenderVars = [{base_var, "base-barstring"}, {test_var, "test-barstring"}],
  1870. {ok, RenderVars};
  1871. setup("include_template") -> setup("extends");
  1872. setup("include_path") -> setup("extends");
  1873. setup("extends_path") -> setup("extends");
  1874. setup("extends_path2") -> setup("extends");
  1875. setup("block_super") -> setup("extends");
  1876. setup("filters") ->
  1877. RenderVars = [
  1878. {date_var1, {1975,7,24}},
  1879. {datetime_var1, {{1975,7,24}, {7,13,1}}},
  1880. {'list', ["eins", "zwei", "drei"]}
  1881. ],
  1882. {ok, RenderVars};
  1883. setup("for") ->
  1884. RenderVars = [{fruit_list, ["apple", "banana", "coconut"]}],
  1885. {ok, RenderVars};
  1886. setup("for_list") ->
  1887. RenderVars = [{fruit_list, [["apple", "apples", "$1"], ["banana", "bananas", "$2"], ["coconut", "coconuts", "$500"]]}],
  1888. {ok, RenderVars};
  1889. setup("for_tuple") ->
  1890. RenderVars = [{fruit_list, [{"apple", "apples"}, {"banana", "bananas"}, {"coconut", "coconuts"}]}],
  1891. {ok, RenderVars};
  1892. setup("for_records") ->
  1893. Link1 = [{name, "Amazon"}, {url, "http://amazon.com"}],
  1894. Link2 = [{name, "Google"}, {url, "http://google.com"}],
  1895. Link3 = [{name, "Microsoft"}, {url, "http://microsoft.com"}],
  1896. RenderVars = [{link_list, [Link1, Link2, Link3]}],
  1897. {ok, RenderVars};
  1898. setup("for_records_preset") ->
  1899. Link1b = [{name, "Canon"}, {url, "http://canon.com"}],
  1900. Link2b = [{name, "Leica"}, {url, "http://leica.com"}],
  1901. Link3b = [{name, "Nikon"}, {url, "http://nikon.com"}],
  1902. RenderVars = [{photo_links, [Link1b, Link2b, Link3b]}],
  1903. {ok, RenderVars};
  1904. setup("include") ->
  1905. RenderVars = [{var1, "foostring1"}, {var2, "foostring2"}],
  1906. {ok, RenderVars};
  1907. setup("if") ->
  1908. RenderVars = [{var1, "something"}],
  1909. {ok, RenderVars};
  1910. setup("ifequal") ->
  1911. RenderVars = [{var1, "foo"}, {var2, "foo"}, {var3, "bar"}],
  1912. {ok, RenderVars};
  1913. setup("ifequal_preset") ->
  1914. RenderVars = [{var3, "bar"}],
  1915. {ok, RenderVars};
  1916. setup("ifnotequal") ->
  1917. RenderVars = [{var1, "foo"}, {var2, "foo"}, {var3, "bar"}],
  1918. {ok, RenderVars};
  1919. setup("now") ->
  1920. {ok, [], [], skip_check};
  1921. setup("var") ->
  1922. RenderVars = [{var1, "foostring1"}, {var2, "foostring2"}, {var_not_used, "foostring3"}],
  1923. {ok, RenderVars};
  1924. setup("var_preset") ->
  1925. RenderVars = [{var1, "foostring1"}, {var2, "foostring2"}],
  1926. {ok, RenderVars};
  1927. setup("cycle") ->
  1928. RenderVars = [{test, [integer_to_list(X) || X <- lists:seq(1, 20)]},
  1929. {a, "Apple"}, {b, "Banana"}, {c, "Cherry"}],
  1930. {ok, RenderVars};
  1931. setup("trans") ->
  1932. RenderVars = [{locale, "reverse"}],
  1933. {ok, RenderVars};
  1934. setup("locale") ->
  1935. {ok, _RenderVars = [{locale, "ru"}]};
  1936. setup("custom_tag1") ->
  1937. {ok, [{a, <<"a1">>}], [{locale, ru}], <<"b1\n">>};
  1938. setup("custom_tag2") ->
  1939. {ok, [{a, <<"a1">>}], [{locale, ru}, {foo, bar}], <<"b2\n">>};
  1940. setup("custom_tag3") ->
  1941. {ok, [{a, <<"a1">>}], [{locale, ru}], <<"b3\n">>};
  1942. setup("custom_tag4") ->
  1943. {ok, [], [], <<"a\n">>};
  1944. setup("ssi") ->
  1945. RenderVars = [{path, "ssi_include.html"}],
  1946. {ok, RenderVars};
  1947. setup("wrapper") ->
  1948. RenderVars = [{types, ["b", "a", "c"]}],
  1949. {ok, RenderVars};
  1950. %%--------------------------------------------------------------------
  1951. %% Custom tags
  1952. %%--------------------------------------------------------------------
  1953. setup("custom_call") ->
  1954. RenderVars = [{var1, "something"}],
  1955. {ok, RenderVars};
  1956. setup(_) ->
  1957. {ok, []}.