You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 15 година
пре 15 година
пре 15 година
пре 16 година
пре 16 година
пре 15 година
пре 16 година
пре 15 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. test("Argument validation", function() {
  2. equals(Mustache.to_html(undefined), '', 'No parameters');
  3. equals(Mustache.to_html('{{hi}}'), '', ' No View or Partials');
  4. equals(Mustache.to_html('{{hi}}', {hi:'Hi.'}), 'Hi.', 'No Partials');
  5. equals(Mustache.to_html('{{>hi}}', undefined, {hi:'{{p}}'}), '', 'Partial but no view');
  6. });
  7. test("Parser", function() {
  8. // matches whitespace_partial.html
  9. equals(
  10. Mustache.to_html(
  11. '<h1>{{ greeting }}</h1>\n{{> partial }}\n<h3>{{ farewell }}</h3>',
  12. {
  13. greeting: function() {
  14. return "Welcome";
  15. },
  16. farewell: function() {
  17. return "Fair enough, right?";
  18. },
  19. partial: {
  20. name: "Chris",
  21. value: 10000,
  22. taxed_value: function() {
  23. return this.value - (this.value * 0.4);
  24. },
  25. in_ca: true
  26. }
  27. },
  28. {partial:'Hello {{ name}}\nYou have just won ${{value }}!\n{{# in_ca }}\nWell, ${{ taxed_value }}, after taxes.\n{{/ in_ca }}\n'}
  29. ),
  30. '<h1>Welcome</h1>\nHello Chris\nYou have just won $10000!\n\nWell, $6000, after taxes.\n\n\n<h3>Fair enough, right?</h3>',
  31. 'Whitespace in Tag names'
  32. );
  33. equals(
  34. Mustache.to_html(
  35. '{{tag1}}\n\n\n{{tag2}}\n',
  36. { tag1: 'Hello', tag2: 'World' },
  37. {}
  38. ),
  39. 'Hello\n\n\nWorld\n',
  40. 'Preservation of white space'
  41. );
  42. raises(
  43. function() {
  44. Mustache.to_html(
  45. '{{=tag1}}',
  46. { tag1: 'Hello' },
  47. {}
  48. );
  49. }, function(e) {
  50. return e instanceof Mustache.Error && e.message === '(1,1): Malformed change delimiter token "{{=tag1}}".';
  51. },
  52. 'Malformed tags should be handled correctly.'
  53. );
  54. raises(
  55. function() {
  56. Mustache.to_html(
  57. '{{tag blah}}'
  58. )
  59. }, function(e) {
  60. return e.message === '(1,1): Malformed variable name "tag blah".';
  61. },
  62. 'Malformed tags should be handled correctly.'
  63. );
  64. var partials = { 'partial' : '{{key}}' };
  65. Mustache.compile('{{>partial}}', partials );
  66. equals(partials['partial'], '{{key}}', 'Partials compiler must be non-destructive');
  67. });
  68. test("Basic Variables", function() {
  69. // matches escaped.html
  70. equals(
  71. Mustache.to_html(
  72. '<h1>{{title}}</h1>\nBut not {{entities}}.\n',
  73. {
  74. title: function() {
  75. return "Bear > Shark";
  76. },
  77. entities: "&quot;"
  78. },
  79. {}
  80. ),
  81. '<h1>Bear &gt; Shark</h1>\nBut not &amp;quot;.\n',
  82. 'HTML Escaping'
  83. );
  84. // matches apostrophe.html (except in this implementation, apostrophes are not escaped.
  85. equals(
  86. Mustache.to_html(
  87. '{{apos}}{{control}}',
  88. { apos: '\'', control: 'X' },
  89. {}
  90. ),
  91. '\'X',
  92. 'Apostrophe escaping'
  93. );
  94. // matches null_string.html
  95. equals(
  96. Mustache.to_html(
  97. 'Hello {{name}}\nglytch {{glytch}}\nbinary {{binary}}\nvalue {{value}}\nnumeric {{numeric}}',
  98. {
  99. name: "Elise",
  100. glytch: true,
  101. binary: false,
  102. value: null,
  103. numeric: function() {
  104. return NaN;
  105. }
  106. },
  107. {}
  108. ),
  109. 'Hello Elise\nglytch true\nbinary false\nvalue \nnumeric NaN',
  110. 'Different variable types'
  111. );
  112. // matches two_in_a_row.html
  113. equals(
  114. Mustache.to_html(
  115. '{{greeting}}, {{name}}!',
  116. {
  117. name: "Joe",
  118. greeting: "Welcome"
  119. },
  120. {}
  121. ),
  122. 'Welcome, Joe!'
  123. );
  124. });
  125. test("Dot Notation", function() {
  126. equals(
  127. Mustache.to_html(
  128. '{{a.b.c}}',
  129. { a: { b: { c: 0 } } },
  130. {}
  131. ),
  132. '0'
  133. );
  134. equals(
  135. Mustache.to_html(
  136. '{{a.b.c}}',
  137. { a: { b: {} } },
  138. {}
  139. ),
  140. ''
  141. );
  142. equals(
  143. Mustache.to_html(
  144. '{{a.b.c}}',
  145. { a: { b: 0 } },
  146. {}
  147. ),
  148. ''
  149. );
  150. equals(
  151. Mustache.to_html(
  152. '{{a.b.c}}',
  153. { a: { b: function() { return { c: 5 } } } },
  154. {}
  155. ),
  156. '5'
  157. );
  158. equals(
  159. Mustache.to_html(
  160. '{{#a.b.c}}{{d}}{{/a.b.c}}',
  161. { a: { b: function() { return { c: [ {d: 'a'}, {d: 'b'}, {d: 'c'} ] } } } },
  162. {}
  163. ),
  164. 'abc'
  165. );
  166. });
  167. test("'{' or '&' (Unescaped Variable)", function() {
  168. // matches unescaped.html
  169. equals(
  170. Mustache.to_html(
  171. '<h1>{{{title}}}</h1>',
  172. {
  173. title: function() {
  174. return "Bear > Shark";
  175. }
  176. },
  177. {}
  178. ),
  179. '<h1>Bear > Shark</h1>',
  180. '{ character'
  181. );
  182. equals(
  183. Mustache.to_html(
  184. '<h1>{{&title}}</h1>',
  185. {
  186. title: function() {
  187. return "Bear > Shark";
  188. }
  189. },
  190. {}
  191. ),
  192. '<h1>Bear > Shark</h1>',
  193. '& character'
  194. );
  195. equals(
  196. Mustache.to_html(
  197. '<h1>{{title}}}</h1>',
  198. { title: 'Bear > Shark' }
  199. , {}
  200. ),
  201. '<h1>Bear &gt; Shark}</h1>'
  202. , 'Potential false positive'
  203. );
  204. });
  205. test("'#' (Sections)", function() {
  206. // matches array_of_partials_implicit_partial.html
  207. equals(
  208. Mustache.to_html(
  209. 'Here is some stuff!\n{{#numbers}}\n{{>partial}}\n{{/numbers}}',
  210. { numbers: ['1', '2', '3', '4'] },
  211. { partial: '{{.}}' }
  212. ),
  213. 'Here is some stuff!\n\n1\n\n2\n\n3\n\n4\n',
  214. 'Array of Partials (Implicit)'
  215. );
  216. // matches array_of_partials_partial.html
  217. equals(
  218. Mustache.to_html(
  219. 'Here is some stuff!\n{{#numbers}}\n{{>partial}}\n{{/numbers}}',
  220. { numbers: [{i: '1'}, {i: '2'}, {i: '3'}, {i: '4'}] },
  221. { partial: '{{i}}' }
  222. ),
  223. 'Here is some stuff!\n\n1\n\n2\n\n3\n\n4\n',
  224. 'Array of Partials (Explicit)'
  225. );
  226. // matches array_of_strings.html
  227. equals(
  228. Mustache.to_html(
  229. '{{#array_of_strings}}{{.}} {{/array_of_strings}}',
  230. {array_of_strings: ['hello', 'world']},
  231. {}
  232. ),
  233. 'hello world ',
  234. 'Array of Strings'
  235. );
  236. // mathces higher_order_sections.html
  237. equals(
  238. Mustache.to_html(
  239. '{{#bolder}}Hi {{name}}.{{/bolder}}\n',
  240. {
  241. "name": "Tater",
  242. "helper": "To tinker?",
  243. "bolder": function() {
  244. return function(text, render) {
  245. return "<b>" + render(text) + '</b> ' + this.helper;
  246. }
  247. }
  248. },
  249. {}
  250. ),
  251. '<b>Hi Tater.</b> To tinker?\n'
  252. );
  253. // matches recursion_with_same_names.html
  254. equals(
  255. Mustache.to_html(
  256. '{{ name }}\n{{ description }}\n\n{{#terms}}\n {{name}}\n {{index}}\n{{/terms}}\n',
  257. {
  258. name: 'name',
  259. description: 'desc',
  260. terms: [
  261. {name: 't1', index: 0},
  262. {name: 't2', index: 1}
  263. ]
  264. },
  265. {}
  266. ),
  267. 'name\ndesc\n\n\n t1\n 0\n\n t2\n 1\n\n'
  268. );
  269. // matches reuse_of_enumerables.html
  270. equals(
  271. Mustache.to_html(
  272. '{{#terms}}\n {{name}}\n {{index}}\n{{/terms}}\n{{#terms}}\n {{name}}\n {{index}}\n{{/terms}}\n',
  273. {
  274. terms: [
  275. {name: 't1', index: 0},
  276. {name: 't2', index: 1}
  277. ]
  278. },
  279. {}
  280. ),
  281. '\n t1\n 0\n\n t2\n 1\n\n\n t1\n 0\n\n t2\n 1\n\n',
  282. 'Lazy match of Section and Inverted Section'
  283. );
  284. // matches section_as_context.html
  285. equals(
  286. Mustache.to_html(
  287. '{{#a_object}}\n <h1>{{title}}</h1>\n <p>{{description}}</p>\n <ul>\n {{#a_list}}\n <li>{{label}}</li>\n {{/a_list}}\n </ul>\n{{/a_object}}\n',
  288. {
  289. a_object: {
  290. title: 'this is an object',
  291. description: 'one of its attributes is a list',
  292. a_list: [{label: 'listitem1'}, {label: 'listitem2'}]
  293. }
  294. },
  295. {}
  296. ),
  297. '\n <h1>this is an object</h1>\n <p>one of its attributes is a list</p>\n <ul>\n \n <li>listitem1</li>\n \n <li>listitem2</li>\n \n </ul>\n\n',
  298. 'Lazy match of Section and Inverted Section'
  299. );
  300. // matches nesting.html
  301. equals(
  302. Mustache.to_html(
  303. '{{#foo}}\n {{#a}}\n {{b}}\n {{/a}}\n{{/foo}}',
  304. {
  305. foo: [
  306. {a: {b: 1}},
  307. {a: {b: 2}},
  308. {a: {b: 3}}
  309. ]
  310. },
  311. {}
  312. ),
  313. '\n \n 1\n \n\n \n 2\n \n\n \n 3\n \n',
  314. 'Context Nesting'
  315. );
  316. });
  317. test("'^' (Inverted Section)", function() {
  318. // matches inverted_section.html
  319. equals(
  320. Mustache.to_html(
  321. '{{#repo}}<b>{{name}}</b>{{/repo}}\n{{^repo}}No repos :({{/repo}}\n',
  322. {
  323. "repo": []
  324. },
  325. {}
  326. ),
  327. '\nNo repos :(\n'
  328. );
  329. });
  330. test("'>' (Partials)", function() {
  331. // matches view_partial.html
  332. equals(
  333. Mustache.to_html(
  334. '<h1>{{greeting}}</h1>\n{{>partial}}\n<h3>{{farewell}}</h3>',
  335. {
  336. greeting: function() {
  337. return "Welcome";
  338. },
  339. farewell: function() {
  340. return "Fair enough, right?";
  341. },
  342. partial: {
  343. name: "Chris",
  344. value: 10000,
  345. taxed_value: function() {
  346. return this.value - (this.value * 0.4);
  347. },
  348. in_ca: true
  349. }
  350. },
  351. {partial: 'Hello {{name}}\nYou have just won ${{value}}!\n{{#in_ca}}\nWell, ${{ taxed_value }}, after taxes.\n{{/in_ca}}\n'}
  352. ),
  353. '<h1>Welcome</h1>\nHello Chris\nYou have just won $10000!\n\nWell, $6000, after taxes.\n\n\n<h3>Fair enough, right?</h3>'
  354. );
  355. // matches array_partial.html
  356. equals(
  357. Mustache.to_html(
  358. '{{>partial}}',
  359. {
  360. partial: {
  361. array: ['1', '2', '3', '4']
  362. }
  363. },
  364. { partial: 'Here\'s a non-sense array of values\n{{#array}}\n {{.}}\n{{/array}}' }
  365. ),
  366. 'Here\'s a non-sense array of values\n\n 1\n\n 2\n\n 3\n\n 4\n'
  367. );
  368. // matches template_partial.html
  369. equals(
  370. Mustache.to_html(
  371. '<h1>{{title}}</h1>\n{{>partial}}',
  372. {
  373. title: function() {
  374. return "Welcome";
  375. },
  376. partial: {
  377. again: "Goodbye"
  378. }
  379. },
  380. {partial:'Again, {{again}}!'}
  381. ),
  382. '<h1>Welcome</h1>\nAgain, Goodbye!'
  383. );
  384. // matches partial_recursion.html
  385. equals(
  386. Mustache.to_html(
  387. '{{name}}\n{{#kids}}\n{{>partial}}\n{{/kids}}',
  388. {
  389. name: '1',
  390. kids: [
  391. {
  392. name: '1.1',
  393. children: [
  394. {name: '1.1.1'}
  395. ]
  396. }
  397. ]
  398. },
  399. {partial:'{{name}}\n{{#children}}\n{{>partial}}\n{{/children}}'}
  400. ),
  401. '1\n\n1.1\n\n1.1.1\n\n\n'
  402. );
  403. raises(
  404. function() {
  405. Mustache.to_html(
  406. '{{>partial}}',
  407. {},
  408. {partal: ''}
  409. );
  410. }, function(e) {
  411. return e.message === '(1,1): Unknown partial "partial".';
  412. },
  413. 'Missing partials should be handled correctly.'
  414. );
  415. });
  416. test("'=' (Set Delimiter)", function() {
  417. // matches delimiter.html
  418. equals(
  419. Mustache.to_html(
  420. '{{=<% %>=}}*\n<% first %>\n* <% second %>\n<%=| |=%>\n* | third |\n|={{ }}=|\n* {{ fourth }}',
  421. {
  422. first: "It worked the first time.",
  423. second: "And it worked the second time.",
  424. third: "Then, surprisingly, it worked the third time.",
  425. fourth: "Fourth time also fine!."
  426. },
  427. {}
  428. ),
  429. '*\nIt worked the first time.\n* And it worked the second time.\n\n* Then, surprisingly, it worked the third time.\n\n* Fourth time also fine!.',
  430. 'Simple Set Delimiter'
  431. );
  432. equals(
  433. Mustache.to_html(
  434. '{{#noData}}{{=~~ ~~=}}Set Change Delimiter ~~data~~ ~~={{ }}=~~{{/noData}}'
  435. , {
  436. noData: true
  437. , data: false
  438. }
  439. , {}
  440. )
  441. , 'Set Change Delimiter false '
  442. , 'Change Delimiter inside Section');
  443. });
  444. test("'!' (Comments)", function() {
  445. equals(
  446. Mustache.to_html('{{! this is a single line comment !}}'),
  447. '',
  448. 'Single Line Comments');
  449. equals(
  450. Mustache.to_html('{{!this is a multiline comment\ni said this is a multiline comment!}}'),
  451. '',
  452. 'Multiline Comments');
  453. equals(
  454. Mustache.to_html('{{!this {{is}} {{#a}} {{/multiline}} comment\ni {{^said}} ! hello !! bye!}}'),
  455. '',
  456. 'Correct tokenization');
  457. // matches comments.html
  458. equals(
  459. Mustache.to_html(
  460. '<h1>{{title}}{{! just something interesting... or not... !}}</h1>\n',
  461. {
  462. title: function() {
  463. return "A Comedy of Errors";
  464. }
  465. },
  466. {}
  467. ),
  468. '<h1>A Comedy of Errors</h1>\n'
  469. );
  470. });
  471. test("'%' (Pragmas)", function() {
  472. // matches array_of_strings_options.html
  473. equals(
  474. Mustache.to_html(
  475. '{{%IMPLICIT-ITERATOR iterator=rob}}\n{{#array_of_strings_options}}{{rob}} {{/array_of_strings_options}}',
  476. {array_of_strings_options: ['hello', 'world']},
  477. {}
  478. ),
  479. '\nhello world ',
  480. 'IMPLICIT-ITERATOR pragma'
  481. );
  482. // matches unknown_pragma.txt
  483. raises(
  484. function() {
  485. Mustache.to_html(
  486. '{{%I-HAVE-THE-GREATEST-MUSTACHE}}\n',
  487. {},
  488. {}
  489. );
  490. },
  491. function(e) {
  492. return e.message === 'This implementation of mustache does not implement the "I-HAVE-THE-GREATEST-MUSTACHE" pragma.';
  493. },
  494. 'Notification of unimplemented pragmas'
  495. );
  496. equals(
  497. Mustache.to_html(
  498. '{{%IMPLICIT-ITERATOR}}{{#dataSet}}{{.}}:{{/dataSet}}',
  499. { dataSet: [ 'Object 1', 'Object 2', 'Object 3' ] },
  500. {}
  501. ),
  502. "Object 1:Object 2:Object 3:",
  503. 'Default behaviour for IMPLICIT ITERATOR'
  504. );
  505. equals(
  506. Mustache.to_html(
  507. '{{%IMPLICIT-ITERATOR iterator=rob}}{{=<% %>=}}<%#dataSet%><%rob%>:<%/dataSet%>',
  508. { dataSet: [ 'Object 1', 'Object 2', 'Object 3' ] },
  509. {}
  510. ),
  511. "Object 1:Object 2:Object 3:",
  512. 'Change Delimiter and Pragma mixes'
  513. );
  514. raises(
  515. function() {
  516. Mustache.to_html(
  517. '{{%IMPLICIT-ITERATOR iterator=rob}}{{%I-HAVE-THE-GREATEST-MUSTACHE}}',
  518. {},
  519. {}
  520. );
  521. },
  522. function(e) {
  523. return e.message === 'This implementation of mustache does not implement the "I-HAVE-THE-GREATEST-MUSTACHE" pragma.';
  524. },
  525. 'Multiple Pragmas'
  526. );
  527. });
  528. test("Empty", function() {
  529. // matches empty_template.html
  530. equals(
  531. Mustache.to_html(
  532. '<html><head></head><body><h1>Test</h1></body></html>',
  533. {},
  534. {}
  535. ),
  536. '<html><head></head><body><h1>Test</h1></body></html>',
  537. 'Empty Template'
  538. );
  539. // matches empty_partial.html
  540. equals(
  541. Mustache.to_html(
  542. 'hey {{foo}}\n{{>partial}}\n',
  543. {
  544. foo: 1
  545. },
  546. {partial: 'yo'}
  547. ),
  548. 'hey 1\nyo\n',
  549. 'Empty Partial'
  550. );
  551. });
  552. test("Demo", function() {
  553. // matches simple.html
  554. equals(
  555. Mustache.to_html(
  556. 'Hello {{name}}\nYou have just won ${{value}}!\n{{#in_ca}}\nWell, ${{ taxed_value }}, after taxes.\n{{/in_ca}}',
  557. {
  558. name: "Chris",
  559. value: 10000,
  560. taxed_value: function() {
  561. return this.value - (this.value * 0.4);
  562. },
  563. in_ca: true
  564. },
  565. {}
  566. ),
  567. 'Hello Chris\nYou have just won $10000!\n\nWell, $6000, after taxes.\n',
  568. 'A simple template'
  569. );
  570. // matches complex.html
  571. var template = [
  572. '<h1>{{header}}</h1>',
  573. '{{#list}}',
  574. ' <ul>',
  575. ' {{#item}}',
  576. ' {{#current}}',
  577. ' <li><strong>{{name}}</strong></li>',
  578. ' {{/current}}',
  579. ' {{#link}}',
  580. ' <li><a href="{{url}}">{{name}}</a></li>',
  581. ' {{/link}}',
  582. ' {{/item}}',
  583. ' </ul>',
  584. '{{/list}}',
  585. '{{#empty}}',
  586. ' <p>The list is empty.</p>',
  587. '{{/empty}}'
  588. ].join('\n');
  589. var view = {
  590. header: function() {
  591. return "Colors";
  592. },
  593. item: [
  594. {name: "red", current: true, url: "#Red"},
  595. {name: "green", current: false, url: "#Green"},
  596. {name: "blue", current: false, url: "#Blue"}
  597. ],
  598. link: function() {
  599. return this["current"] !== true;
  600. },
  601. list: function() {
  602. return this.item.length !== 0;
  603. },
  604. empty: function() {
  605. return this.item.length === 0;
  606. }
  607. };
  608. var expected_result = '<h1>Colors</h1>\n\n <ul>\n \n \n <li><strong>red</strong></li>\n \n \n <li><a href=\"#Red\">red</a></li>\n \n \n \n \n <li><a href=\"#Green\">green</a></li>\n \n \n \n \n <li><a href=\"#Blue\">blue</a></li>\n \n \n </ul>\n\n';
  609. equals(
  610. Mustache.to_html(
  611. template,
  612. view,
  613. {}
  614. ),
  615. expected_result,
  616. 'A complex template'
  617. );
  618. });
  619. test("Error Handling", function() {
  620. raises(
  621. function() {
  622. Mustache.to_html(
  623. 'this is a partial\nyes it is. {{>partial}}',
  624. {},
  625. {partal: ''}
  626. );
  627. }, function(e) {
  628. return e.line === 2 && e.character === 12;
  629. },
  630. 'Missing partial line and character correctness.'
  631. );
  632. raises(
  633. function() {
  634. Mustache.to_html(
  635. 'this is a partial\nyes it is. {{>partial}}',
  636. {},
  637. {partial: 'error in {{#foobar}}'}
  638. );
  639. }, function(e) {
  640. return e.message === '[partial](1,21): Closing section tag "foobar" expected.'
  641. },
  642. 'Unbalanced section correctness (Part 1).'
  643. );
  644. raises(
  645. function() {
  646. Mustache.to_html(
  647. 'something something something {{/darkside}}.',
  648. {},
  649. {}
  650. );
  651. }, function(e) {
  652. return e.message === '(1,31): Unbalanced End Section tag "{{/darkside}}".'
  653. },
  654. 'Unbalanced section correctness (Part 2).'
  655. );
  656. raises(
  657. function() {
  658. Mustache.to_html(
  659. 'this is a partial\nyes it is. {{>maria}}',
  660. {},
  661. {maria: 'error in {{#foobar}}this is the most aw\ns\nme think {{#evar}}hello joe{{/foobar}}{{/evar}}'}
  662. );
  663. }, function(e) {
  664. return e.message === '[maria](3,28): Unexpected section end tag "foobar", expected "evar".'
  665. },
  666. 'Partials metric correctness.'
  667. );
  668. });
  669. test("Regression Suite", function() {
  670. // matches bug_11_eating_whitespace.html
  671. equals(
  672. Mustache.to_html(
  673. '{{tag}} foo',
  674. { tag: "yo" },
  675. {}
  676. ),
  677. 'yo foo',
  678. 'Issue 11'
  679. );
  680. // matches delimiters_partial.html
  681. equals(
  682. Mustache.to_html(
  683. '{{#enumerate}}\n{{>partial}}\n{{/enumerate}}',
  684. { enumerate: [ { text: 'A' }, { text: 'B' } ] },
  685. { partial: '{{=[[ ]]=}}\n{{text}}\n[[={{ }}=]]' }
  686. ),
  687. '\n\n{{text}}\n\n\n\n{{text}}\n\n',
  688. 'Issue 44'
  689. );
  690. // matches bug_46_set_delimiter.html
  691. equals(
  692. Mustache.to_html(
  693. '{{=[[ ]]=}}[[#IsMustacheAwesome]]mustache is awesome![[/IsMustacheAwesome]]',
  694. {IsMustacheAwesome: true},
  695. {}
  696. ),
  697. 'mustache is awesome!',
  698. 'Issue 46'
  699. );
  700. // matches Issue #79
  701. equals(
  702. Mustache.to_html(
  703. '{{#inner}}{{f}}{{#inner}}{{b}}{{/inner}}{{/inner}}'
  704. , {
  705. inner: [{
  706. f: 'foo'
  707. , inner: [{
  708. b: 'bar'
  709. }]
  710. }]
  711. }
  712. , {}
  713. )
  714. , 'foobar'
  715. , 'Nested Sections with the same name'
  716. );
  717. equals(
  718. Mustache.to_html(
  719. '{{=~~ ~~=}} ~~>staticInfoPanel~~ ~~={{ }}=~~'
  720. , {}
  721. , { staticInfoPanel: 'Hello' }
  722. )
  723. , ' Hello '
  724. , 'Change Delimiter + Partial');
  725. });