From df7405b18403306ff70f8031301e43ca1f6814d1 Mon Sep 17 00:00:00 2001 From: thegrandpoobah Date: Wed, 1 Dec 2010 12:54:33 -0500 Subject: [PATCH] Update unit tests based on merge with janl's branch --- test/unit.compiler.js | 32 ++++++++++++++++++++++++++++++-- test/unit.interpreter.js | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/test/unit.compiler.js b/test/unit.compiler.js index 1d7a522..7f98d73 100644 --- a/test/unit.compiler.js +++ b/test/unit.compiler.js @@ -83,7 +83,7 @@ test("Parser", function() { }); test("Basic Variables", function() { - expect(3); + expect(4); // matches escaped.html equals( @@ -100,6 +100,17 @@ test("Basic Variables", function() { '

Bear > Shark

\nBut not ".\n', 'HTML Escaping' ); + + // matches apostrophe.html (except in this implementation, apostrophes are not escaped. + equals( + Mustache.to_html( + '{{apos}}{{control}}', + { apos: '\'', control: 'X' }, + {} + ), + '\'X', + 'Apostrophe escaping' + ); // matches null_string.html equals( @@ -169,7 +180,7 @@ test("'{' or '&' (Unescaped Variable)", function() { }); test("'#' (Sections)", function() { - expect(7); + expect(8); // matches array_of_partials_implicit_partial.html equals( @@ -271,6 +282,23 @@ test("'#' (Sections)", function() { '\n

this is an object

\n

one of its attributes is a list

\n \n\n', 'Lazy match of Section and Inverted Section' ); + + // matches nesting.html + equals( + Mustache.to_html( + '{{#foo}}\n {{#a}}\n {{b}}\n {{/a}}\n{{/foo}}', + { + foo: [ + {a: {b: 1}}, + {a: {b: 2}}, + {a: {b: 3}} + ] + }, + {} + ), + '\n \n 1\n \n\n \n 2\n \n\n \n 3\n \n', + 'Context Nesting' + ); }); test("'^' (Inverted Section)", function() { diff --git a/test/unit.interpreter.js b/test/unit.interpreter.js index c2046d0..4633c2d 100644 --- a/test/unit.interpreter.js +++ b/test/unit.interpreter.js @@ -65,7 +65,7 @@ test("Parser", function() { }); test("Basic Variables", function() { - expect(3); + expect(4); // matches escaped.html equals( @@ -83,6 +83,17 @@ test("Basic Variables", function() { 'HTML Escaping' ); + // matches apostrophe.html (except in this implementation, apostrophes are not escaped. + equals( + Mustache.to_html( + '{{apos}}{{control}}', + { apos: '\'', control: 'X' }, + {} + ), + '\'X', + 'Apostrophe escaping' + ); + // matches null_string.html equals( Mustache.to_html( @@ -151,7 +162,7 @@ test("'{' or '&' (Unescaped Variable)", function() { }); test("'#' (Sections)", function() { - expect(7); + expect(8); // matches array_of_partials_implicit_partial.html equals( @@ -253,6 +264,23 @@ test("'#' (Sections)", function() { '\n

this is an object

\n

one of its attributes is a list

\n \n\n', 'Lazy match of Section and Inverted Section' ); + + // matches nesting.html + equals( + Mustache.to_html( + '{{#foo}}\n {{#a}}\n {{b}}\n {{/a}}\n{{/foo}}', + { + foo: [ + {a: {b: 1}}, + {a: {b: 2}}, + {a: {b: 3}} + ] + }, + {} + ), + '\n \n 1\n \n\n \n 2\n \n\n \n 3\n \n', + 'Context Nesting' + ); }); test("'^' (Inverted Section)", function() {