From e2d919a21492acbd97c4c8f430cef7193a5919b6 Mon Sep 17 00:00:00 2001
From: Chad Weider Authors: A Book
Price: €200 Euro In Stock
-VAT: €40
+Price: $200 USD In Stock
+VAT: $40
Zero: 0
diff --git a/spec/_files/escaped.js b/spec/_files/escaped.js index 7a8baef..903e559 100644 --- a/spec/_files/escaped.js +++ b/spec/_files/escaped.js @@ -2,5 +2,5 @@ var escaped = { title: function() { return "Bear > Shark"; }, - entities: """ + entities: "" \"'<>/" }; diff --git a/spec/_files/escaped.txt b/spec/_files/escaped.txt index 73ac5ce..be2f2e9 100644 --- a/spec/_files/escaped.txt +++ b/spec/_files/escaped.txt @@ -1,2 +1,2 @@"
-};
diff --git a/spec/_files/apostrophe.js b/spec/_files/apostrophe.js
deleted file mode 100644
index df69cd2..0000000
--- a/spec/_files/apostrophe.js
+++ /dev/null
@@ -1 +0,0 @@
-var apostrophe = {'apos': "'", 'control':'X'};
diff --git a/spec/_files/array_of_strings.js b/spec/_files/array_of_strings.js
deleted file mode 100644
index 12c4992..0000000
--- a/spec/_files/array_of_strings.js
+++ /dev/null
@@ -1 +0,0 @@
-var array_of_strings = {array_of_strings: ['hello', 'world']};
diff --git a/spec/_files/backslashes.js b/spec/_files/backslashes.js
deleted file mode 100644
index 0b9765b..0000000
--- a/spec/_files/backslashes.js
+++ /dev/null
@@ -1,3 +0,0 @@
-var backslashes = {
- value: "\\abc"
-};
diff --git a/spec/_files/bug_11_eating_whitespace.js b/spec/_files/bug_11_eating_whitespace.js
deleted file mode 100644
index 78ce975..0000000
--- a/spec/_files/bug_11_eating_whitespace.js
+++ /dev/null
@@ -1,3 +0,0 @@
-var bug_11_eating_whitespace = {
- tag: "yo"
-};
diff --git a/spec/_files/changing_delimiters.js b/spec/_files/changing_delimiters.js
deleted file mode 100644
index 4fbe9f3..0000000
--- a/spec/_files/changing_delimiters.js
+++ /dev/null
@@ -1,4 +0,0 @@
-var changing_delimiters = {
- "foo": "foooooooooooooo",
- "bar":"bar!"
-};
diff --git a/spec/_files/comments.js b/spec/_files/comments.js
deleted file mode 100644
index f85f979..0000000
--- a/spec/_files/comments.js
+++ /dev/null
@@ -1,5 +0,0 @@
-var comments = {
- title: function() {
- return "A Comedy of Errors";
- }
-};
diff --git a/spec/_files/disappearing_whitespace.js b/spec/_files/disappearing_whitespace.js
deleted file mode 100644
index 3fe7121..0000000
--- a/spec/_files/disappearing_whitespace.js
+++ /dev/null
@@ -1,4 +0,0 @@
-var disappearing_whitespace = {
- bedrooms: true,
- total: 1
-};
diff --git a/spec/_files/empty_list.js b/spec/_files/empty_list.js
deleted file mode 100644
index 80555c0..0000000
--- a/spec/_files/empty_list.js
+++ /dev/null
@@ -1,3 +0,0 @@
-var empty_list = {
- jobs: []
-};
diff --git a/spec/_files/empty_sections.js b/spec/_files/empty_sections.js
deleted file mode 100644
index 6e50514..0000000
--- a/spec/_files/empty_sections.js
+++ /dev/null
@@ -1 +0,0 @@
-var empty_sections = {};
diff --git a/spec/_files/empty_template.js b/spec/_files/empty_template.js
deleted file mode 100644
index 564c9e2..0000000
--- a/spec/_files/empty_template.js
+++ /dev/null
@@ -1 +0,0 @@
-var empty_template = {};
diff --git a/spec/_files/error_not_found.js b/spec/_files/error_not_found.js
deleted file mode 100644
index 6cdbdb3..0000000
--- a/spec/_files/error_not_found.js
+++ /dev/null
@@ -1 +0,0 @@
-var error_not_found = {bar: 2};
\ No newline at end of file
diff --git a/spec/_files/higher_order_sections.js b/spec/_files/higher_order_sections.js
deleted file mode 100644
index c7e558e..0000000
--- a/spec/_files/higher_order_sections.js
+++ /dev/null
@@ -1,9 +0,0 @@
-var higher_order_sections = {
- "name": "Tater",
- "helper": "To tinker?",
- "bolder": function() {
- return function(text, render) {
- return "" + render(text) + ' ' + this.helper;
- }
- }
-}
\ No newline at end of file
diff --git a/spec/_files/inverted_section.js b/spec/_files/inverted_section.js
deleted file mode 100644
index 2e07fc3..0000000
--- a/spec/_files/inverted_section.js
+++ /dev/null
@@ -1,3 +0,0 @@
-var inverted_section = {
- "repos": []
-};
diff --git a/spec/_files/multiline_comment.js b/spec/_files/multiline_comment.js
deleted file mode 100644
index 24e7445..0000000
--- a/spec/_files/multiline_comment.js
+++ /dev/null
@@ -1 +0,0 @@
-var multiline_comment = {};
diff --git a/spec/_files/partial_array_of_partials.js b/spec/_files/partial_array_of_partials.js
deleted file mode 100644
index 706e7ed..0000000
--- a/spec/_files/partial_array_of_partials.js
+++ /dev/null
@@ -1,3 +0,0 @@
-var partial_array_of_partials = {
- numbers: [{i: '1'}, {i: '2'}, {i: '3'}, {i: '4'}]
-};
diff --git a/spec/_files/partial_array_of_partials_implicit.js b/spec/_files/partial_array_of_partials_implicit.js
deleted file mode 100644
index 864efa3..0000000
--- a/spec/_files/partial_array_of_partials_implicit.js
+++ /dev/null
@@ -1,3 +0,0 @@
-var partial_array_of_partials_implicit = {
- numbers: ['1', '2', '3', '4']
-};
diff --git a/spec/_files/partial_empty.js b/spec/_files/partial_empty.js
deleted file mode 100644
index 3f36df6..0000000
--- a/spec/_files/partial_empty.js
+++ /dev/null
@@ -1,3 +0,0 @@
-var partial_empty = {
- foo: 1
-};
diff --git a/spec/_files/partial_template.js b/spec/_files/partial_template.js
deleted file mode 100644
index 196f1e8..0000000
--- a/spec/_files/partial_template.js
+++ /dev/null
@@ -1,6 +0,0 @@
-var partial_template = {
- title: function() {
- return "Welcome";
- },
- again: "Goodbye"
-};
diff --git a/spec/_files/string_as_context.js b/spec/_files/string_as_context.js
deleted file mode 100644
index 784368b..0000000
--- a/spec/_files/string_as_context.js
+++ /dev/null
@@ -1,4 +0,0 @@
-var string_as_context = {
- a_string: 'aa',
- a_list: ['a','b','c']
-};
diff --git a/spec/_files/two_sections.js b/spec/_files/two_sections.js
deleted file mode 100644
index 8546f64..0000000
--- a/spec/_files/two_sections.js
+++ /dev/null
@@ -1 +0,0 @@
-var two_sections = {};
\ No newline at end of file
diff --git a/spec/_files/unescaped.js b/spec/_files/unescaped.js
deleted file mode 100644
index 0bd20b8..0000000
--- a/spec/_files/unescaped.js
+++ /dev/null
@@ -1,5 +0,0 @@
-var unescaped = {
- title: function() {
- return "Bear > Shark";
- }
-};
diff --git a/spec/mustache_spec.rb b/spec/mustache_spec.rb
deleted file mode 100644
index 3c27d80..0000000
--- a/spec/mustache_spec.rb
+++ /dev/null
@@ -1,218 +0,0 @@
-require 'rubygems'
-require 'json'
-
-ROOT = File.expand_path('../..', __FILE__)
-SPEC = File.join(ROOT, 'spec')
-FILES = File.join(SPEC, '_files')
-
-MUSTACHE = File.read(File.join(ROOT, "mustache.js"))
-
-TESTS = Dir.glob(File.join(FILES, '*.js')).map do |name|
- File.basename name, '.js'
-end
-
-NODE_PATH = `which node`.strip
-JS_PATH = `which js`.strip
-JSC_PATH = "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc"
-RHINO_JAR = "org.mozilla.javascript.tools.shell.Main"
-
-def load_test(name)
- template = File.read(File.join(FILES, "#{name}.mustache"))
- view = File.read(File.join(FILES, "#{name}.js"))
- partial_file = File.join(FILES, "#{name}.partial")
- partial = if File.exist?(partial_file)
- File.read(partial_file)
- end
- expect = File.read(File.join(FILES, "#{name}.txt"))
-
- [template, view, partial, expect]
-end
-
-def run_js(runner, js)
- cmd = case runner
- when :spidermonkey
- JS_PATH
- when :jsc
- JSC_PATH
- when :rhino
- "java #{RHINO_JAR}"
- when :v8
- NODE_PATH
- end
-
- runner_file = "runner.js"
- File.open(runner_file, 'w') {|file| file.write(js) }
- `#{cmd} #{runner_file}`
-ensure
- FileUtils.rm_r(runner_file)
-end
-
-$engines_run = 0
-
-describe "mustache" do
- shared_examples_for "mustache rendering" do
- before(:all) do
- $engines_run += 1
- end
-
- it "should return the same result when invoked multiple times" do
- js = <<-JS
- #{@boilerplate}
- Mustache.render("x")
- print(Mustache.render("x"));
- JS
-
- run_js(@runner, js).should == "x\n"
- end
-
- it "should clear the context after each run" do
- js = <<-JS
- #{@boilerplate}
- Mustache.render("{{#list}}{{x}}{{/list}}", {list: [{x: 1}]})
- try {
- print(Mustache.render("{{#list}}{{x}}{{/list}}", {list: [{}]}));
- } catch(e) {
- print('ERROR: ' + e.message);
- }
- JS
-
- run_js(@runner, js).should == "\n"
- end
-
- TESTS.each do |test|
- describe test do
- it "should render the correct output" do
- template, view, partial, expect = load_test(test)
-
- js = <<-JS
- try {
- #{@boilerplate}
- var template = #{template.to_json};
- #{view}
- var partials = {partial: #{partial ? partial.to_json : '""'}};
- print(Mustache.render(template, #{test}, partials));
- } catch(e) {
- print('ERROR: ' + e.message);
- }
- JS
-
- run_js(@runner, js).chomp.should == expect
- end
-
- # it "should send the correct output" do
- # template, view, partial, expect = load_test(test)
- #
- # js = <<-JS
- # try {
- # #{@boilerplate}
- # var template = #{template.to_json};
- # #{view}
- # var partials = {
- # "partial": #{(partial || '').to_json}
- # };
- # var buffer = [];
- # var send = function (chunk) {
- # buffer.push(chunk);
- # };
- # Mustache.render(template, #{test}, partials, send);
- # print(buffer.join(""));
- # } catch(e) {
- # print('ERROR: ' + e.message);
- # }
- # JS
- #
- # run_js(@runner, js).chomp.should == expect
- # end
- end
- end
- end
-
- context "running in V8 (Chrome, node)" do
- if File.exist?(NODE_PATH)
- before(:all) do
- $stdout.write "Testing in V8 "
- @runner = :v8
- @boilerplate = MUSTACHE.dup
- @boilerplate << <<-JS
- var print = console.log;
- JS
- end
-
- after(:all) do
- puts " Done!"
- end
-
- it_should_behave_like "mustache rendering"
- else
- puts "Skipping tests in V8 (node not found)"
- end
- end
-
- context "running in SpiderMonkey (Mozilla, Firefox)" do
- if File.exist?(JS_PATH)
- before(:all) do
- $stdout.write "Testing in SpiderMonkey "
- @runner = :spidermonkey
- @boilerplate = MUSTACHE.dup
- end
-
- after(:all) do
- puts " Done!"
- end
-
- it_should_behave_like "mustache rendering"
- else
- puts "Skipping tests in SpiderMonkey (js not found)"
- end
- end
-
- context "running in JavaScriptCore (WebKit, Safari)" do
- if File.exist?(JSC_PATH)
- before(:all) do
- $stdout.write "Testing in JavaScriptCore "
- @runner = :jsc
- @boilerplate = MUSTACHE.dup
- end
-
- after(:all) do
- puts " Done!"
- end
-
- it_should_behave_like "mustache rendering"
- else
- puts "Skipping tests in JavaScriptCore (jsc not found)"
- end
- end
-
- context "running in Rhino (Mozilla, Java)" do
- if `java #{RHINO_JAR} 'foo' 2>&1` !~ /ClassNotFoundException/
- before(:all) do
- $stdout.write "Testing in Rhino "
- @runner = :rhino
- @boilerplate = MUSTACHE.dup
- end
-
- after(:all) do
- puts " Done!"
- end
-
- it_should_behave_like "mustache rendering"
- else
- puts "Skipping tests in Rhino (JAR #{RHINO_JAR} was not found)"
- end
- end
-
- context "suite" do
- before(:each) do
- $stdout.write "Verifying that we ran the tests in at least one engine ... "
- end
-
- after(:each) do
- puts @exception.nil? ? "OK" : "ERROR"
- end
-
- it "should have run at least one time" do
- $engines_run.should > 0
- end
- end
-end
diff --git a/test/_files/ampersand_escape.js b/test/_files/ampersand_escape.js
new file mode 100644
index 0000000..df6409f
--- /dev/null
+++ b/test/_files/ampersand_escape.js
@@ -0,0 +1,3 @@
+({
+ message: "Some "
+})
diff --git a/spec/_files/ampersand_escape.mustache b/test/_files/ampersand_escape.mustache
similarity index 100%
rename from spec/_files/ampersand_escape.mustache
rename to test/_files/ampersand_escape.mustache
diff --git a/spec/_files/ampersand_escape.txt b/test/_files/ampersand_escape.txt
similarity index 100%
rename from spec/_files/ampersand_escape.txt
rename to test/_files/ampersand_escape.txt
diff --git a/test/_files/apostrophe.js b/test/_files/apostrophe.js
new file mode 100644
index 0000000..183c6d5
--- /dev/null
+++ b/test/_files/apostrophe.js
@@ -0,0 +1,4 @@
+({
+ 'apos': "'",
+ 'control': 'X'
+})
diff --git a/spec/_files/apostrophe.mustache b/test/_files/apostrophe.mustache
similarity index 100%
rename from spec/_files/apostrophe.mustache
rename to test/_files/apostrophe.mustache
diff --git a/spec/_files/apostrophe.txt b/test/_files/apostrophe.txt
similarity index 100%
rename from spec/_files/apostrophe.txt
rename to test/_files/apostrophe.txt
diff --git a/test/_files/array_of_strings.js b/test/_files/array_of_strings.js
new file mode 100644
index 0000000..6926612
--- /dev/null
+++ b/test/_files/array_of_strings.js
@@ -0,0 +1,3 @@
+({
+ array_of_strings: ['hello', 'world']
+})
diff --git a/spec/_files/array_of_strings.mustache b/test/_files/array_of_strings.mustache
similarity index 100%
rename from spec/_files/array_of_strings.mustache
rename to test/_files/array_of_strings.mustache
diff --git a/spec/_files/array_of_strings.txt b/test/_files/array_of_strings.txt
similarity index 100%
rename from spec/_files/array_of_strings.txt
rename to test/_files/array_of_strings.txt
diff --git a/test/_files/backslashes.js b/test/_files/backslashes.js
new file mode 100644
index 0000000..427acd9
--- /dev/null
+++ b/test/_files/backslashes.js
@@ -0,0 +1,3 @@
+({
+ value: "\\abc"
+})
diff --git a/spec/_files/backslashes.mustache b/test/_files/backslashes.mustache
similarity index 100%
rename from spec/_files/backslashes.mustache
rename to test/_files/backslashes.mustache
diff --git a/spec/_files/backslashes.txt b/test/_files/backslashes.txt
similarity index 100%
rename from spec/_files/backslashes.txt
rename to test/_files/backslashes.txt
diff --git a/test/_files/bug_11_eating_whitespace.js b/test/_files/bug_11_eating_whitespace.js
new file mode 100644
index 0000000..e41ccd1
--- /dev/null
+++ b/test/_files/bug_11_eating_whitespace.js
@@ -0,0 +1,3 @@
+({
+ tag: "yo"
+})
diff --git a/spec/_files/bug_11_eating_whitespace.mustache b/test/_files/bug_11_eating_whitespace.mustache
similarity index 100%
rename from spec/_files/bug_11_eating_whitespace.mustache
rename to test/_files/bug_11_eating_whitespace.mustache
diff --git a/spec/_files/bug_11_eating_whitespace.txt b/test/_files/bug_11_eating_whitespace.txt
similarity index 100%
rename from spec/_files/bug_11_eating_whitespace.txt
rename to test/_files/bug_11_eating_whitespace.txt
diff --git a/test/_files/changing_delimiters.js b/test/_files/changing_delimiters.js
new file mode 100644
index 0000000..b808f4c
--- /dev/null
+++ b/test/_files/changing_delimiters.js
@@ -0,0 +1,4 @@
+({
+ "foo": "foooooooooooooo",
+ "bar": "bar!"
+})
diff --git a/spec/_files/changing_delimiters.mustache b/test/_files/changing_delimiters.mustache
similarity index 100%
rename from spec/_files/changing_delimiters.mustache
rename to test/_files/changing_delimiters.mustache
diff --git a/spec/_files/changing_delimiters.txt b/test/_files/changing_delimiters.txt
similarity index 100%
rename from spec/_files/changing_delimiters.txt
rename to test/_files/changing_delimiters.txt
diff --git a/test/_files/comments.js b/test/_files/comments.js
new file mode 100644
index 0000000..f20b8b1
--- /dev/null
+++ b/test/_files/comments.js
@@ -0,0 +1,5 @@
+({
+ title: function () {
+ return "A Comedy of Errors";
+ }
+})
diff --git a/spec/_files/comments.mustache b/test/_files/comments.mustache
similarity index 100%
rename from spec/_files/comments.mustache
rename to test/_files/comments.mustache
diff --git a/spec/_files/comments.txt b/test/_files/comments.txt
similarity index 100%
rename from spec/_files/comments.txt
rename to test/_files/comments.txt
diff --git a/spec/_files/complex.js b/test/_files/complex.js
similarity index 74%
rename from spec/_files/complex.js
rename to test/_files/complex.js
index a0dfb63..68a4809 100644
--- a/spec/_files/complex.js
+++ b/test/_files/complex.js
@@ -1,5 +1,5 @@
-var complex = {
- header: function() {
+({
+ header: function () {
return "Colors";
},
item: [
@@ -7,13 +7,13 @@ var complex = {
{name: "green", current: false, url: "#Green"},
{name: "blue", current: false, url: "#Blue"}
],
- link: function() {
+ link: function () {
return this["current"] !== true;
},
- list: function() {
+ list: function () {
return this.item.length !== 0;
},
- empty: function() {
+ empty: function () {
return this.item.length === 0;
}
-};
+})
diff --git a/spec/_files/complex.mustache b/test/_files/complex.mustache
similarity index 100%
rename from spec/_files/complex.mustache
rename to test/_files/complex.mustache
diff --git a/spec/_files/complex.txt b/test/_files/complex.txt
similarity index 100%
rename from spec/_files/complex.txt
rename to test/_files/complex.txt
diff --git a/spec/_files/context_lookup.js b/test/_files/context_lookup.js
similarity index 73%
rename from spec/_files/context_lookup.js
rename to test/_files/context_lookup.js
index 49d4453..8ce6299 100644
--- a/spec/_files/context_lookup.js
+++ b/test/_files/context_lookup.js
@@ -1,8 +1,8 @@
-var context_lookup = {
+({
"outer": {
"id": 1,
"second": {
"nothing": 2
}
}
-};
+})
diff --git a/spec/_files/context_lookup.mustache b/test/_files/context_lookup.mustache
similarity index 100%
rename from spec/_files/context_lookup.mustache
rename to test/_files/context_lookup.mustache
diff --git a/spec/_files/context_lookup.txt b/test/_files/context_lookup.txt
similarity index 100%
rename from spec/_files/context_lookup.txt
rename to test/_files/context_lookup.txt
diff --git a/spec/_files/delimiters.js b/test/_files/delimiters.js
similarity index 89%
rename from spec/_files/delimiters.js
rename to test/_files/delimiters.js
index 220d0d2..365d01e 100644
--- a/spec/_files/delimiters.js
+++ b/test/_files/delimiters.js
@@ -1,6 +1,6 @@
-var delimiters = {
+({
first: "It worked the first time.",
second: "And it worked the second time.",
third: "Then, surprisingly, it worked the third time.",
fourth: "Fourth time also fine!."
-}
+})
diff --git a/spec/_files/delimiters.mustache b/test/_files/delimiters.mustache
similarity index 100%
rename from spec/_files/delimiters.mustache
rename to test/_files/delimiters.mustache
diff --git a/spec/_files/delimiters.txt b/test/_files/delimiters.txt
similarity index 100%
rename from spec/_files/delimiters.txt
rename to test/_files/delimiters.txt
diff --git a/test/_files/disappearing_whitespace.js b/test/_files/disappearing_whitespace.js
new file mode 100644
index 0000000..973dd1c
--- /dev/null
+++ b/test/_files/disappearing_whitespace.js
@@ -0,0 +1,4 @@
+({
+ bedrooms: true,
+ total: 1
+})
diff --git a/spec/_files/disappearing_whitespace.mustache b/test/_files/disappearing_whitespace.mustache
similarity index 100%
rename from spec/_files/disappearing_whitespace.mustache
rename to test/_files/disappearing_whitespace.mustache
diff --git a/spec/_files/disappearing_whitespace.txt b/test/_files/disappearing_whitespace.txt
similarity index 100%
rename from spec/_files/disappearing_whitespace.txt
rename to test/_files/disappearing_whitespace.txt
diff --git a/spec/_files/dot_notation.js b/test/_files/dot_notation.js
similarity index 81%
rename from spec/_files/dot_notation.js
rename to test/_files/dot_notation.js
index c1295f5..ca995f7 100644
--- a/spec/_files/dot_notation.js
+++ b/test/_files/dot_notation.js
@@ -1,9 +1,9 @@
-var dot_notation = {
+({
name: "A Book",
authors: ["John Power", "Jamie Walsh"],
- price:{
+ price: {
value: 200,
- vat: function() {
+ vat: function () {
return this.value * 0.2;
},
currency: {
@@ -11,7 +11,7 @@ var dot_notation = {
name: 'Euro'
}
},
- availability:{
+ availability: {
status: true,
text: "In Stock"
},
@@ -20,4 +20,4 @@ var dot_notation = {
zero: 0,
notTrue: false
}
-};
+})
diff --git a/spec/_files/dot_notation.mustache b/test/_files/dot_notation.mustache
similarity index 84%
rename from spec/_files/dot_notation.mustache
rename to test/_files/dot_notation.mustache
index da1bad7..138ddd0 100644
--- a/spec/_files/dot_notation.mustache
+++ b/test/_files/dot_notation.mustache
@@ -2,7 +2,7 @@
{{name}}
Authors:
{{#authors}}- {{.}}
{{/authors}}
Price: {{price.currency.symbol}}{{price.value}} {{#price.currency}}{{name}} {{availability.text}}{{/price.currency}}
-VAT: {{price.currency.symbol}}{{price.vat}}
+VAT: {{price.currency.symbol}}{{#price}}{{vat}}{{/price}}
Test truthy false values:
Zero: {{truthy.zero}}
diff --git a/spec/_files/dot_notation.txt b/test/_files/dot_notation.txt
similarity index 100%
rename from spec/_files/dot_notation.txt
rename to test/_files/dot_notation.txt
diff --git a/spec/_files/double_render.js b/test/_files/double_render.js
similarity index 65%
rename from spec/_files/double_render.js
rename to test/_files/double_render.js
index 24125dc..28acb2c 100644
--- a/spec/_files/double_render.js
+++ b/test/_files/double_render.js
@@ -1,5 +1,5 @@
-var double_render = {
+({
foo: true,
bar: "{{win}}",
win: "FAIL"
-};
\ No newline at end of file
+})
diff --git a/spec/_files/double_render.mustache b/test/_files/double_render.mustache
similarity index 100%
rename from spec/_files/double_render.mustache
rename to test/_files/double_render.mustache
diff --git a/spec/_files/double_render.txt b/test/_files/double_render.txt
similarity index 100%
rename from spec/_files/double_render.txt
rename to test/_files/double_render.txt
diff --git a/test/_files/empty_list.js b/test/_files/empty_list.js
new file mode 100644
index 0000000..c0e1159
--- /dev/null
+++ b/test/_files/empty_list.js
@@ -0,0 +1,3 @@
+({
+ jobs: []
+})
diff --git a/spec/_files/empty_list.mustache b/test/_files/empty_list.mustache
similarity index 100%
rename from spec/_files/empty_list.mustache
rename to test/_files/empty_list.mustache
diff --git a/spec/_files/empty_list.txt b/test/_files/empty_list.txt
similarity index 100%
rename from spec/_files/empty_list.txt
rename to test/_files/empty_list.txt
diff --git a/test/_files/empty_sections.js b/test/_files/empty_sections.js
new file mode 100644
index 0000000..b4100a5
--- /dev/null
+++ b/test/_files/empty_sections.js
@@ -0,0 +1 @@
+({})
diff --git a/spec/_files/empty_sections.mustache b/test/_files/empty_sections.mustache
similarity index 100%
rename from spec/_files/empty_sections.mustache
rename to test/_files/empty_sections.mustache
diff --git a/spec/_files/empty_sections.txt b/test/_files/empty_sections.txt
similarity index 100%
rename from spec/_files/empty_sections.txt
rename to test/_files/empty_sections.txt
diff --git a/spec/_files/empty_string.js b/test/_files/empty_string.js
similarity index 73%
rename from spec/_files/empty_string.js
rename to test/_files/empty_string.js
index 2151336..be6e058 100644
--- a/spec/_files/empty_string.js
+++ b/test/_files/empty_string.js
@@ -1,6 +1,6 @@
-var empty_string = {
+({
description: "That is all!",
child: {
description: ""
}
-};
+})
diff --git a/spec/_files/empty_string.mustache b/test/_files/empty_string.mustache
similarity index 100%
rename from spec/_files/empty_string.mustache
rename to test/_files/empty_string.mustache
diff --git a/spec/_files/empty_string.txt b/test/_files/empty_string.txt
similarity index 100%
rename from spec/_files/empty_string.txt
rename to test/_files/empty_string.txt
diff --git a/test/_files/empty_template.js b/test/_files/empty_template.js
new file mode 100644
index 0000000..b4100a5
--- /dev/null
+++ b/test/_files/empty_template.js
@@ -0,0 +1 @@
+({})
diff --git a/spec/_files/empty_template.mustache b/test/_files/empty_template.mustache
similarity index 100%
rename from spec/_files/empty_template.mustache
rename to test/_files/empty_template.mustache
diff --git a/spec/_files/empty_template.txt b/test/_files/empty_template.txt
similarity index 100%
rename from spec/_files/empty_template.txt
rename to test/_files/empty_template.txt
diff --git a/test/_files/error_not_found.js b/test/_files/error_not_found.js
new file mode 100644
index 0000000..10e4709
--- /dev/null
+++ b/test/_files/error_not_found.js
@@ -0,0 +1,3 @@
+({
+ bar: 2
+})
diff --git a/spec/_files/error_not_found.mustache b/test/_files/error_not_found.mustache
similarity index 100%
rename from spec/_files/error_not_found.mustache
rename to test/_files/error_not_found.mustache
diff --git a/spec/_files/error_not_found.txt b/test/_files/error_not_found.txt
similarity index 100%
rename from spec/_files/error_not_found.txt
rename to test/_files/error_not_found.txt
diff --git a/spec/_files/escaped.js b/test/_files/escaped.js
similarity index 56%
rename from spec/_files/escaped.js
rename to test/_files/escaped.js
index 7a8baef..7735877 100644
--- a/spec/_files/escaped.js
+++ b/test/_files/escaped.js
@@ -1,6 +1,6 @@
-var escaped = {
- title: function() {
+({
+ title: function () {
return "Bear > Shark";
},
entities: """
-};
+})
diff --git a/spec/_files/escaped.mustache b/test/_files/escaped.mustache
similarity index 100%
rename from spec/_files/escaped.mustache
rename to test/_files/escaped.mustache
diff --git a/spec/_files/escaped.txt b/test/_files/escaped.txt
similarity index 100%
rename from spec/_files/escaped.txt
rename to test/_files/escaped.txt
diff --git a/test/_files/higher_order_sections.js b/test/_files/higher_order_sections.js
new file mode 100644
index 0000000..7b52c0d
--- /dev/null
+++ b/test/_files/higher_order_sections.js
@@ -0,0 +1,9 @@
+({
+ name: "Tater",
+ helper: "To tinker?",
+ bolder: function () {
+ return function (text, render) {
+ return "" + render(text) + ' ' + this.helper;
+ }
+ }
+})
diff --git a/spec/_files/higher_order_sections.mustache b/test/_files/higher_order_sections.mustache
similarity index 100%
rename from spec/_files/higher_order_sections.mustache
rename to test/_files/higher_order_sections.mustache
diff --git a/spec/_files/higher_order_sections.txt b/test/_files/higher_order_sections.txt
similarity index 100%
rename from spec/_files/higher_order_sections.txt
rename to test/_files/higher_order_sections.txt
diff --git a/spec/_files/included_tag.js b/test/_files/included_tag.js
similarity index 55%
rename from spec/_files/included_tag.js
rename to test/_files/included_tag.js
index a63df27..eb032a4 100644
--- a/spec/_files/included_tag.js
+++ b/test/_files/included_tag.js
@@ -1,3 +1,3 @@
-var included_tag = {
+({
html: "I like {{mustache}}"
-};
+})
diff --git a/spec/_files/included_tag.mustache b/test/_files/included_tag.mustache
similarity index 100%
rename from spec/_files/included_tag.mustache
rename to test/_files/included_tag.mustache
diff --git a/spec/_files/included_tag.txt b/test/_files/included_tag.txt
similarity index 100%
rename from spec/_files/included_tag.txt
rename to test/_files/included_tag.txt
diff --git a/test/_files/inverted_section.js b/test/_files/inverted_section.js
new file mode 100644
index 0000000..f8f08fd
--- /dev/null
+++ b/test/_files/inverted_section.js
@@ -0,0 +1,3 @@
+({
+ "repos": []
+})
diff --git a/spec/_files/inverted_section.mustache b/test/_files/inverted_section.mustache
similarity index 100%
rename from spec/_files/inverted_section.mustache
rename to test/_files/inverted_section.mustache
diff --git a/spec/_files/inverted_section.txt b/test/_files/inverted_section.txt
similarity index 100%
rename from spec/_files/inverted_section.txt
rename to test/_files/inverted_section.txt
diff --git a/spec/_files/keys_with_questionmarks.js b/test/_files/keys_with_questionmarks.js
similarity index 50%
rename from spec/_files/keys_with_questionmarks.js
rename to test/_files/keys_with_questionmarks.js
index 55a220d..becd631 100644
--- a/spec/_files/keys_with_questionmarks.js
+++ b/test/_files/keys_with_questionmarks.js
@@ -1,5 +1,5 @@
-var keys_with_questionmarks = {
+({
"person?": {
name: "Jon"
}
-}
+})
diff --git a/spec/_files/keys_with_questionmarks.mustache b/test/_files/keys_with_questionmarks.mustache
similarity index 100%
rename from spec/_files/keys_with_questionmarks.mustache
rename to test/_files/keys_with_questionmarks.mustache
diff --git a/spec/_files/keys_with_questionmarks.txt b/test/_files/keys_with_questionmarks.txt
similarity index 100%
rename from spec/_files/keys_with_questionmarks.txt
rename to test/_files/keys_with_questionmarks.txt
diff --git a/test/_files/multiline_comment.js b/test/_files/multiline_comment.js
new file mode 100644
index 0000000..b4100a5
--- /dev/null
+++ b/test/_files/multiline_comment.js
@@ -0,0 +1 @@
+({})
diff --git a/spec/_files/multiline_comment.mustache b/test/_files/multiline_comment.mustache
similarity index 100%
rename from spec/_files/multiline_comment.mustache
rename to test/_files/multiline_comment.mustache
diff --git a/spec/_files/multiline_comment.txt b/test/_files/multiline_comment.txt
similarity index 100%
rename from spec/_files/multiline_comment.txt
rename to test/_files/multiline_comment.txt
diff --git a/spec/_files/nested_iterating.js b/test/_files/nested_iterating.js
similarity index 71%
rename from spec/_files/nested_iterating.js
rename to test/_files/nested_iterating.js
index a8275f9..2708b2d 100644
--- a/spec/_files/nested_iterating.js
+++ b/test/_files/nested_iterating.js
@@ -1,8 +1,8 @@
-var nested_iterating = {
+({
inner: [{
foo: 'foo',
inner: [{
bar: 'bar'
}]
}]
-};
+})
diff --git a/spec/_files/nested_iterating.mustache b/test/_files/nested_iterating.mustache
similarity index 100%
rename from spec/_files/nested_iterating.mustache
rename to test/_files/nested_iterating.mustache
diff --git a/spec/_files/nested_iterating.txt b/test/_files/nested_iterating.txt
similarity index 100%
rename from spec/_files/nested_iterating.txt
rename to test/_files/nested_iterating.txt
diff --git a/spec/_files/nesting.js b/test/_files/nesting.js
similarity index 76%
rename from spec/_files/nesting.js
rename to test/_files/nesting.js
index 1f76cd0..264cc2f 100644
--- a/spec/_files/nesting.js
+++ b/test/_files/nesting.js
@@ -1,7 +1,7 @@
-var nesting = {
+({
foo: [
{a: {b: 1}},
{a: {b: 2}},
{a: {b: 3}}
]
-};
+})
diff --git a/spec/_files/nesting.mustache b/test/_files/nesting.mustache
similarity index 100%
rename from spec/_files/nesting.mustache
rename to test/_files/nesting.mustache
diff --git a/spec/_files/nesting.txt b/test/_files/nesting.txt
similarity index 100%
rename from spec/_files/nesting.txt
rename to test/_files/nesting.txt
diff --git a/spec/_files/nesting_same_name.js b/test/_files/nesting_same_name.js
similarity index 71%
rename from spec/_files/nesting_same_name.js
rename to test/_files/nesting_same_name.js
index a5fb65b..10a0c14 100644
--- a/spec/_files/nesting_same_name.js
+++ b/test/_files/nesting_same_name.js
@@ -1,8 +1,8 @@
-var nesting_same_name = {
+({
items: [
{
name: 'name',
items: [1, 2, 3, 4]
}
]
-};
+})
diff --git a/spec/_files/nesting_same_name.mustache b/test/_files/nesting_same_name.mustache
similarity index 100%
rename from spec/_files/nesting_same_name.mustache
rename to test/_files/nesting_same_name.mustache
diff --git a/spec/_files/nesting_same_name.txt b/test/_files/nesting_same_name.txt
similarity index 100%
rename from spec/_files/nesting_same_name.txt
rename to test/_files/nesting_same_name.txt
diff --git a/spec/_files/null_string.js b/test/_files/null_string.js
similarity index 84%
rename from spec/_files/null_string.js
rename to test/_files/null_string.js
index ab5291f..984ee51 100644
--- a/spec/_files/null_string.js
+++ b/test/_files/null_string.js
@@ -1,4 +1,4 @@
-var null_string = {
+({
name: "Elise",
glytch: true,
binary: false,
@@ -7,4 +7,4 @@ var null_string = {
numeric: function() {
return NaN;
}
-};
+})
diff --git a/spec/_files/null_string.mustache b/test/_files/null_string.mustache
similarity index 100%
rename from spec/_files/null_string.mustache
rename to test/_files/null_string.mustache
diff --git a/spec/_files/null_string.txt b/test/_files/null_string.txt
similarity index 100%
rename from spec/_files/null_string.txt
rename to test/_files/null_string.txt
diff --git a/spec/_files/partial_array.js b/test/_files/partial_array.js
similarity index 55%
rename from spec/_files/partial_array.js
rename to test/_files/partial_array.js
index f16e9eb..2a6ddf1 100644
--- a/spec/_files/partial_array.js
+++ b/test/_files/partial_array.js
@@ -1,3 +1,3 @@
-var partial_array = {
+({
array: ['1', '2', '3', '4']
-};
\ No newline at end of file
+})
diff --git a/spec/_files/partial_array.mustache b/test/_files/partial_array.mustache
similarity index 100%
rename from spec/_files/partial_array.mustache
rename to test/_files/partial_array.mustache
diff --git a/spec/_files/partial_array.partial b/test/_files/partial_array.partial
similarity index 100%
rename from spec/_files/partial_array.partial
rename to test/_files/partial_array.partial
diff --git a/spec/_files/partial_array.txt b/test/_files/partial_array.txt
similarity index 100%
rename from spec/_files/partial_array.txt
rename to test/_files/partial_array.txt
diff --git a/test/_files/partial_array_of_partials.js b/test/_files/partial_array_of_partials.js
new file mode 100644
index 0000000..03f13c9
--- /dev/null
+++ b/test/_files/partial_array_of_partials.js
@@ -0,0 +1,8 @@
+({
+ numbers: [
+ {i: '1'},
+ {i: '2'},
+ {i: '3'},
+ {i: '4'}
+ ]
+})
diff --git a/spec/_files/partial_array_of_partials.mustache b/test/_files/partial_array_of_partials.mustache
similarity index 100%
rename from spec/_files/partial_array_of_partials.mustache
rename to test/_files/partial_array_of_partials.mustache
diff --git a/spec/_files/partial_array_of_partials.partial b/test/_files/partial_array_of_partials.partial
similarity index 100%
rename from spec/_files/partial_array_of_partials.partial
rename to test/_files/partial_array_of_partials.partial
diff --git a/spec/_files/partial_array_of_partials.txt b/test/_files/partial_array_of_partials.txt
similarity index 100%
rename from spec/_files/partial_array_of_partials.txt
rename to test/_files/partial_array_of_partials.txt
diff --git a/test/_files/partial_array_of_partials_implicit.js b/test/_files/partial_array_of_partials_implicit.js
new file mode 100644
index 0000000..9ec0c00
--- /dev/null
+++ b/test/_files/partial_array_of_partials_implicit.js
@@ -0,0 +1,3 @@
+({
+ numbers: ['1', '2', '3', '4']
+})
diff --git a/spec/_files/partial_array_of_partials_implicit.mustache b/test/_files/partial_array_of_partials_implicit.mustache
similarity index 100%
rename from spec/_files/partial_array_of_partials_implicit.mustache
rename to test/_files/partial_array_of_partials_implicit.mustache
diff --git a/spec/_files/partial_array_of_partials_implicit.partial b/test/_files/partial_array_of_partials_implicit.partial
similarity index 100%
rename from spec/_files/partial_array_of_partials_implicit.partial
rename to test/_files/partial_array_of_partials_implicit.partial
diff --git a/spec/_files/partial_array_of_partials_implicit.txt b/test/_files/partial_array_of_partials_implicit.txt
similarity index 100%
rename from spec/_files/partial_array_of_partials_implicit.txt
rename to test/_files/partial_array_of_partials_implicit.txt
diff --git a/test/_files/partial_empty.js b/test/_files/partial_empty.js
new file mode 100644
index 0000000..82b8c22
--- /dev/null
+++ b/test/_files/partial_empty.js
@@ -0,0 +1,3 @@
+({
+ foo: 1
+})
diff --git a/spec/_files/partial_empty.mustache b/test/_files/partial_empty.mustache
similarity index 100%
rename from spec/_files/partial_empty.mustache
rename to test/_files/partial_empty.mustache
diff --git a/spec/_files/partial_empty.partial b/test/_files/partial_empty.partial
similarity index 100%
rename from spec/_files/partial_empty.partial
rename to test/_files/partial_empty.partial
diff --git a/spec/_files/partial_empty.txt b/test/_files/partial_empty.txt
similarity index 100%
rename from spec/_files/partial_empty.txt
rename to test/_files/partial_empty.txt
diff --git a/spec/_files/partial_recursion.js b/test/_files/partial_recursion.js
similarity index 78%
rename from spec/_files/partial_recursion.js
rename to test/_files/partial_recursion.js
index 3094eba..e39d64d 100644
--- a/spec/_files/partial_recursion.js
+++ b/test/_files/partial_recursion.js
@@ -1,4 +1,4 @@
-var partial_recursion = {
+({
name: '1',
kids: [
{
@@ -8,4 +8,4 @@ var partial_recursion = {
]
}
]
-};
+})
diff --git a/spec/_files/partial_recursion.mustache b/test/_files/partial_recursion.mustache
similarity index 100%
rename from spec/_files/partial_recursion.mustache
rename to test/_files/partial_recursion.mustache
diff --git a/spec/_files/partial_recursion.partial b/test/_files/partial_recursion.partial
similarity index 72%
rename from spec/_files/partial_recursion.partial
rename to test/_files/partial_recursion.partial
index ba6f8fa..457d2a0 100644
--- a/spec/_files/partial_recursion.partial
+++ b/test/_files/partial_recursion.partial
@@ -1,4 +1,4 @@
{{name}}
{{#children}}
{{>partial}}
-{{/children}}
+{{/children}}
\ No newline at end of file
diff --git a/spec/_files/partial_recursion.txt b/test/_files/partial_recursion.txt
similarity index 100%
rename from spec/_files/partial_recursion.txt
rename to test/_files/partial_recursion.txt
diff --git a/test/_files/partial_template.js b/test/_files/partial_template.js
new file mode 100644
index 0000000..a913f87
--- /dev/null
+++ b/test/_files/partial_template.js
@@ -0,0 +1,6 @@
+({
+ title: function () {
+ return "Welcome";
+ },
+ again: "Goodbye"
+})
diff --git a/spec/_files/partial_template.mustache b/test/_files/partial_template.mustache
similarity index 100%
rename from spec/_files/partial_template.mustache
rename to test/_files/partial_template.mustache
diff --git a/spec/_files/partial_template.partial b/test/_files/partial_template.partial
similarity index 100%
rename from spec/_files/partial_template.partial
rename to test/_files/partial_template.partial
diff --git a/spec/_files/partial_template.txt b/test/_files/partial_template.txt
similarity index 100%
rename from spec/_files/partial_template.txt
rename to test/_files/partial_template.txt
diff --git a/spec/_files/partial_view.js b/test/_files/partial_view.js
similarity index 60%
rename from spec/_files/partial_view.js
rename to test/_files/partial_view.js
index 4ea8a12..3ad70d3 100644
--- a/spec/_files/partial_view.js
+++ b/test/_files/partial_view.js
@@ -1,16 +1,14 @@
-var partial_view = {
- greeting: function() {
+({
+ greeting: function () {
return "Welcome";
},
-
- farewell: function() {
+ farewell: function () {
return "Fair enough, right?";
},
-
name: "Chris",
value: 10000,
- taxed_value: function() {
+ taxed_value: function () {
return this.value - (this.value * 0.4);
},
in_ca: true
-};
+})
diff --git a/spec/_files/partial_view.mustache b/test/_files/partial_view.mustache
similarity index 100%
rename from spec/_files/partial_view.mustache
rename to test/_files/partial_view.mustache
diff --git a/spec/_files/partial_view.partial b/test/_files/partial_view.partial
similarity index 89%
rename from spec/_files/partial_view.partial
rename to test/_files/partial_view.partial
index 2fea632..03df206 100644
--- a/spec/_files/partial_view.partial
+++ b/test/_files/partial_view.partial
@@ -2,4 +2,4 @@ Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{ taxed_value }}, after taxes.
-{{/in_ca}}
+{{/in_ca}}
\ No newline at end of file
diff --git a/spec/_files/partial_view.txt b/test/_files/partial_view.txt
similarity index 100%
rename from spec/_files/partial_view.txt
rename to test/_files/partial_view.txt
diff --git a/spec/_files/partial_whitespace.js b/test/_files/partial_whitespace.js
similarity index 59%
rename from spec/_files/partial_whitespace.js
rename to test/_files/partial_whitespace.js
index f4b1ee5..3ad70d3 100644
--- a/spec/_files/partial_whitespace.js
+++ b/test/_files/partial_whitespace.js
@@ -1,17 +1,14 @@
-var partial_whitespace = {
- greeting: function() {
+({
+ greeting: function () {
return "Welcome";
},
-
- farewell: function() {
+ farewell: function () {
return "Fair enough, right?";
},
-
name: "Chris",
value: 10000,
- taxed_value: function() {
+ taxed_value: function () {
return this.value - (this.value * 0.4);
},
in_ca: true
-};
-
+})
diff --git a/spec/_files/partial_whitespace.mustache b/test/_files/partial_whitespace.mustache
similarity index 100%
rename from spec/_files/partial_whitespace.mustache
rename to test/_files/partial_whitespace.mustache
diff --git a/spec/_files/partial_whitespace.partial b/test/_files/partial_whitespace.partial
similarity index 87%
rename from spec/_files/partial_whitespace.partial
rename to test/_files/partial_whitespace.partial
index 9c46084..30de8f6 100644
--- a/spec/_files/partial_whitespace.partial
+++ b/test/_files/partial_whitespace.partial
@@ -2,4 +2,4 @@ Hello {{ name}}
You have just won ${{value }}!
{{# in_ca }}
Well, ${{ taxed_value }}, after taxes.
-{{/ in_ca }}
+{{/ in_ca }}
\ No newline at end of file
diff --git a/spec/_files/partial_whitespace.txt b/test/_files/partial_whitespace.txt
similarity index 100%
rename from spec/_files/partial_whitespace.txt
rename to test/_files/partial_whitespace.txt
diff --git a/spec/_files/recursion_with_same_names.js b/test/_files/recursion_with_same_names.js
similarity index 56%
rename from spec/_files/recursion_with_same_names.js
rename to test/_files/recursion_with_same_names.js
index 5cceb08..ce26502 100644
--- a/spec/_files/recursion_with_same_names.js
+++ b/test/_files/recursion_with_same_names.js
@@ -1,8 +1,8 @@
-var recursion_with_same_names = {
+({
name: 'name',
description: 'desc',
terms: [
{name: 't1', index: 0},
- {name: 't2', index: 1},
+ {name: 't2', index: 1}
]
-};
\ No newline at end of file
+})
diff --git a/spec/_files/recursion_with_same_names.mustache b/test/_files/recursion_with_same_names.mustache
similarity index 100%
rename from spec/_files/recursion_with_same_names.mustache
rename to test/_files/recursion_with_same_names.mustache
diff --git a/spec/_files/recursion_with_same_names.txt b/test/_files/recursion_with_same_names.txt
similarity index 100%
rename from spec/_files/recursion_with_same_names.txt
rename to test/_files/recursion_with_same_names.txt
diff --git a/spec/_files/reuse_of_enumerables.js b/test/_files/reuse_of_enumerables.js
similarity index 69%
rename from spec/_files/reuse_of_enumerables.js
rename to test/_files/reuse_of_enumerables.js
index a3168d3..4368b57 100644
--- a/spec/_files/reuse_of_enumerables.js
+++ b/test/_files/reuse_of_enumerables.js
@@ -1,6 +1,6 @@
-var reuse_of_enumerables = {
+({
terms: [
{name: 't1', index: 0},
{name: 't2', index: 1}
]
-};
\ No newline at end of file
+})
diff --git a/spec/_files/reuse_of_enumerables.mustache b/test/_files/reuse_of_enumerables.mustache
similarity index 100%
rename from spec/_files/reuse_of_enumerables.mustache
rename to test/_files/reuse_of_enumerables.mustache
diff --git a/spec/_files/reuse_of_enumerables.txt b/test/_files/reuse_of_enumerables.txt
similarity index 100%
rename from spec/_files/reuse_of_enumerables.txt
rename to test/_files/reuse_of_enumerables.txt
diff --git a/spec/_files/section_as_context.js b/test/_files/section_as_context.js
similarity index 53%
rename from spec/_files/section_as_context.js
rename to test/_files/section_as_context.js
index 81ca1be..425b29c 100644
--- a/spec/_files/section_as_context.js
+++ b/test/_files/section_as_context.js
@@ -1,7 +1,10 @@
-var section_as_context = {
+({
a_object: {
title: 'this is an object',
description: 'one of its attributes is a list',
- a_list: [{label: 'listitem1'}, {label: 'listitem2'}]
+ a_list: [
+ {label: 'listitem1'},
+ {label: 'listitem2'}
+ ]
}
-};
+})
diff --git a/spec/_files/section_as_context.mustache b/test/_files/section_as_context.mustache
similarity index 100%
rename from spec/_files/section_as_context.mustache
rename to test/_files/section_as_context.mustache
diff --git a/spec/_files/section_as_context.txt b/test/_files/section_as_context.txt
similarity index 100%
rename from spec/_files/section_as_context.txt
rename to test/_files/section_as_context.txt
diff --git a/spec/_files/simple.js b/test/_files/simple.js
similarity index 67%
rename from spec/_files/simple.js
rename to test/_files/simple.js
index 30f9834..1d8d6f4 100644
--- a/spec/_files/simple.js
+++ b/test/_files/simple.js
@@ -1,8 +1,8 @@
-var simple = {
+({
name: "Chris",
value: 10000,
- taxed_value: function() {
+ taxed_value: function () {
return this.value - (this.value * 0.4);
},
in_ca: true
-};
+})
diff --git a/spec/_files/simple.mustache b/test/_files/simple.mustache
similarity index 100%
rename from spec/_files/simple.mustache
rename to test/_files/simple.mustache
diff --git a/spec/_files/simple.txt b/test/_files/simple.txt
similarity index 100%
rename from spec/_files/simple.txt
rename to test/_files/simple.txt
diff --git a/test/_files/string_as_context.js b/test/_files/string_as_context.js
new file mode 100644
index 0000000..e8bb4da
--- /dev/null
+++ b/test/_files/string_as_context.js
@@ -0,0 +1,4 @@
+({
+ a_string: 'aa',
+ a_list: ['a','b','c']
+})
diff --git a/spec/_files/string_as_context.mustache b/test/_files/string_as_context.mustache
similarity index 100%
rename from spec/_files/string_as_context.mustache
rename to test/_files/string_as_context.mustache
diff --git a/spec/_files/string_as_context.txt b/test/_files/string_as_context.txt
similarity index 100%
rename from spec/_files/string_as_context.txt
rename to test/_files/string_as_context.txt
diff --git a/spec/_files/two_in_a_row.js b/test/_files/two_in_a_row.js
similarity index 60%
rename from spec/_files/two_in_a_row.js
rename to test/_files/two_in_a_row.js
index 09c1809..9c17c11 100644
--- a/spec/_files/two_in_a_row.js
+++ b/test/_files/two_in_a_row.js
@@ -1,4 +1,4 @@
-var two_in_a_row = {
+({
name: "Joe",
greeting: "Welcome"
-};
+})
diff --git a/spec/_files/two_in_a_row.mustache b/test/_files/two_in_a_row.mustache
similarity index 100%
rename from spec/_files/two_in_a_row.mustache
rename to test/_files/two_in_a_row.mustache
diff --git a/spec/_files/two_in_a_row.txt b/test/_files/two_in_a_row.txt
similarity index 100%
rename from spec/_files/two_in_a_row.txt
rename to test/_files/two_in_a_row.txt
diff --git a/test/_files/two_sections.js b/test/_files/two_sections.js
new file mode 100644
index 0000000..b4100a5
--- /dev/null
+++ b/test/_files/two_sections.js
@@ -0,0 +1 @@
+({})
diff --git a/spec/_files/two_sections.mustache b/test/_files/two_sections.mustache
similarity index 100%
rename from spec/_files/two_sections.mustache
rename to test/_files/two_sections.mustache
diff --git a/spec/_files/two_sections.txt b/test/_files/two_sections.txt
similarity index 100%
rename from spec/_files/two_sections.txt
rename to test/_files/two_sections.txt
diff --git a/test/_files/unescaped.js b/test/_files/unescaped.js
new file mode 100644
index 0000000..b6d064f
--- /dev/null
+++ b/test/_files/unescaped.js
@@ -0,0 +1,5 @@
+({
+ title: function () {
+ return "Bear > Shark";
+ }
+})
diff --git a/spec/_files/unescaped.mustache b/test/_files/unescaped.mustache
similarity index 100%
rename from spec/_files/unescaped.mustache
rename to test/_files/unescaped.mustache
diff --git a/spec/_files/unescaped.txt b/test/_files/unescaped.txt
similarity index 100%
rename from spec/_files/unescaped.txt
rename to test/_files/unescaped.txt
diff --git a/spec/_files/whitespace.js b/test/_files/whitespace.js
similarity index 60%
rename from spec/_files/whitespace.js
rename to test/_files/whitespace.js
index 97f53c1..f41cb56 100644
--- a/spec/_files/whitespace.js
+++ b/test/_files/whitespace.js
@@ -1,4 +1,4 @@
-var whitespace = {
+({
tag1: "Hello",
tag2: "World"
-};
+})
diff --git a/spec/_files/whitespace.mustache b/test/_files/whitespace.mustache
similarity index 100%
rename from spec/_files/whitespace.mustache
rename to test/_files/whitespace.mustache
diff --git a/spec/_files/whitespace.txt b/test/_files/whitespace.txt
similarity index 100%
rename from spec/_files/whitespace.txt
rename to test/_files/whitespace.txt
diff --git a/test/context_test.js b/test/context_test.js
new file mode 100644
index 0000000..71c5830
--- /dev/null
+++ b/test/context_test.js
@@ -0,0 +1,47 @@
+var assert = require("assert"),
+ vows = require("vows"),
+ Context = require("./../mustache").Context;
+
+vows.describe("Mustache.Context").addBatch({
+ "A Context": {
+ topic: function () {
+ var view = { name: 'parent', message: 'hi', a: { b: 'b' } };
+ var context = new Context(view);
+ return context;
+ },
+ "should be able to lookup properties of its own view": function (context) {
+ assert.equal(context.lookup("name"), "parent");
+ },
+ "should be able to lookup nested properties of its own view": function (context) {
+ assert.equal(context.lookup("a.b"), "b");
+ },
+ "when pushed": {
+ topic: function (context) {
+ var view = { name: 'child', c: { d: 'd' } };
+ return context.push(view);
+ },
+ "should return the child context": function (context) {
+ assert.equal(context.view.name, "child");
+ assert.equal(context.parent.view.name, "parent");
+ },
+ "should be able to lookup properties of its own view": function (context) {
+ assert.equal(context.lookup("name"), "child");
+ },
+ "should be able to lookup properties of the parent context's view": function (context) {
+ assert.equal(context.lookup("message"), "hi");
+ },
+ "should be able to lookup nested properties of its own view": function (context) {
+ assert.equal(context.lookup("c.d"), "d");
+ },
+ "should be able to lookup nested properties of its parent view": function (context) {
+ assert.equal(context.lookup("a.b"), "b");
+ }
+ } // when pushed
+ }, // A Context
+ "make": {
+ "should return the same object when given a Context": function () {
+ var context = new Context;
+ assert.strictEqual(Context.make(context), context);
+ }
+ }
+}).export(module);
diff --git a/test/helper.rb b/test/helper.rb
new file mode 100644
index 0000000..baadb94
--- /dev/null
+++ b/test/helper.rb
@@ -0,0 +1,48 @@
+require 'test/unit'
+
+module Mustache
+ extend self
+
+ ROOT = File.expand_path('../..', __FILE__)
+ TEST = File.join(ROOT, 'test')
+ TEST_FILES = File.join(TEST, '_files')
+
+ MUSTACHE_JS = File.read(File.join(ROOT, 'mustache.js'))
+
+ TESTS = Dir.glob(File.join(TEST_FILES, '*.js')).map do |name|
+ File.basename name, '.js'
+ end
+
+ NODE_PATH = `which node`.strip
+ JS_PATH = `which js`.strip
+ JSC_PATH = "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc"
+ RHINO_JAR = "org.mozilla.javascript.tools.shell.Main"
+
+ def javascript_engines
+ %w[v8 spidermonkey javascriptcore rhino]
+ end
+
+ def available_javascript_engines
+ javascript_engines.select {|engine| send("has_#{engine}?") }
+ end
+
+ def has_any_engines?
+ available_javascript_engines.any?
+ end
+
+ def has_v8?
+ File.exist?(NODE_PATH)
+ end
+
+ def has_spidermonkey?
+ File.exist?(JS_PATH)
+ end
+
+ def has_javascriptcore?
+ File.exist?(JSC_PATH)
+ end
+
+ def has_rhino?
+ `java #{RHINO_JAR} 'foo' 2>&1` !~ /ClassNotFoundException/
+ end
+end
diff --git a/test/integration.rb b/test/integration.rb
new file mode 100644
index 0000000..d3d482d
--- /dev/null
+++ b/test/integration.rb
@@ -0,0 +1,76 @@
+require File.expand_path('../helper', __FILE__)
+require 'fileutils'
+require 'json'
+
+module Mustache
+ class Test < Test::Unit::TestCase
+
+ def self.run_tests_for(engine)
+ TESTS.each do |test|
+ define_method("test_#{engine}_#{test}") do
+ template, view, partial, expect = load_test(test)
+
+ assert_equal expect, run_js(engine, <<-JS).chomp
+ try {
+ #{boilerplate_for(engine)}
+ var template = #{template.to_json};
+ var view = #{view};
+ var partials = {partial: #{partial.to_json}};
+ print(Mustache.render(template, view, partials));
+ } catch(e) {
+ print('ERROR: ' + e.message);
+ }
+ JS
+ end
+ end
+ end
+
+ unless Mustache.has_any_engines?
+ abort "ERROR: Please install node, SpiderMonkey, JavaScriptCore or Rhino"
+ end
+
+ run_tests_for :v8 if Mustache.has_v8?
+ run_tests_for :spidermonkey if Mustache.has_spidermonkey?
+ run_tests_for :javascriptcore if Mustache.has_javascriptcore?
+ run_tests_for :rhino if Mustache.has_rhino?
+
+ private
+
+ def load_test(name)
+ template_file = File.join(TEST_FILES, "#{name}.mustache")
+ view_file = File.join(TEST_FILES, "#{name}.js")
+ partial_file = File.join(TEST_FILES, "#{name}.partial")
+ expect_file = File.join(TEST_FILES, "#{name}.txt")
+
+ [template_file, view_file, partial_file, expect_file].map do |file|
+ File.exist?(file) ? File.read(file) : ""
+ end
+ end
+
+ def runner_file
+ "runner.js"
+ end
+
+ def run_js(engine, js)
+ cmd = case engine
+ when :v8 then NODE_PATH
+ when :spidermonkey then JS_PATH
+ when :javascriptcore then JSC_PATH
+ when :rhino then "java #{RHINO_JAR}"
+ end
+
+ File.open(runner_file, 'w') {|file| file.write(js) }
+
+ `#{cmd} #{runner_file}`
+ ensure
+ FileUtils.rm_r(runner_file)
+ end
+
+ def boilerplate_for(engine)
+ boilerplate = MUSTACHE_JS
+ boilerplate += "\nvar print = console.log;" if engine == :v8
+ boilerplate
+ end
+
+ end
+end
diff --git a/test/parse_test.js b/test/parse_test.js
new file mode 100644
index 0000000..8586a25
--- /dev/null
+++ b/test/parse_test.js
@@ -0,0 +1,67 @@
+var assert = require("assert"),
+ vows = require("vows"),
+ parse = require("./../mustache").parse;
+
+// A map of templates to their expected token output.
+var expectations = {
+ "{{hi}}" : [ { type: 'name', value: 'hi' } ],
+ "{{hi.world}}" : [ { type: 'name', value: 'hi.world' } ],
+ "{{hi . world}}" : [ { type: 'name', value: 'hi . world' } ],
+ "{{ hi}}" : [ { type: 'name', value: 'hi' } ],
+ "{{hi }}" : [ { type: 'name', value: 'hi' } ],
+ "{{ hi }}" : [ { type: 'name', value: 'hi' } ],
+ "{{{hi}}}" : [ { type: '{', value: 'hi' } ],
+ "{{!hi}}" : [ { type: '!', value: 'hi' } ],
+ "{{! hi}}" : [ { type: '!', value: 'hi' } ],
+ "{{! hi }}" : [ { type: '!', value: 'hi' } ],
+ "{{ !hi}}" : [ { type: '!', value: 'hi' } ],
+ "{{ ! hi}}" : [ { type: '!', value: 'hi' } ],
+ "{{ ! hi }}" : [ { type: '!', value: 'hi' } ],
+ "a{{hi}}" : [ { type: 'text', value: 'a' }, { type: 'name', value: 'hi' } ],
+ "a {{hi}}" : [ { type: 'text', value: 'a ' }, { type: 'name', value: 'hi' } ],
+ " a{{hi}}" : [ { type: 'text', value: ' a' }, { type: 'name', value: 'hi' } ],
+ " a {{hi}}" : [ { type: 'text', value: ' a ' }, { type: 'name', value: 'hi' } ],
+ "a{{hi}}b" : [ { type: 'text', value: 'a' }, { type: 'name', value: 'hi' }, { type: 'text', value: 'b' } ],
+ "a{{hi}} b" : [ { type: 'text', value: 'a' }, { type: 'name', value: 'hi' }, { type: 'text', value: ' b' } ],
+ "a{{hi}}b " : [ { type: 'text', value: 'a' }, { type: 'name', value: 'hi' }, { type: 'text', value: 'b ' } ],
+ "a\n{{hi}} b \n" : [ { type: 'text', value: 'a\n' }, { type: 'name', value: 'hi' }, { type: 'text', value: ' b \n' } ],
+ "a\n {{hi}} \nb" : [ { type: 'text', value: 'a\n ' }, { type: 'name', value: 'hi' }, { type: 'text', value: ' \nb' } ],
+ "a\n {{!hi}} \nb" : [ { type: 'text', value: 'a\n' }, { type: '!', value: 'hi' }, { type: 'text', value: 'b' } ],
+ "a\n{{#a}}{{/a}}\nb" : [ { type: 'text', value: 'a\n' }, { type: '#', value: 'a', tokens: [] }, { type: 'text', value: 'b' } ],
+ "a\n {{#a}}{{/a}}\nb" : [ { type: 'text', value: 'a\n' }, { type: '#', value: 'a', tokens: [] }, { type: 'text', value: 'b' } ],
+ "a\n {{#a}}{{/a}} \nb" : [ { type: 'text', value: 'a\n' }, { type: '#', value: 'a', tokens: [] }, { type: 'text', value: 'b' } ],
+ "a\n{{#a}}\n{{/a}}\nb" : [ { type: 'text', value: 'a\n' }, { type: '#', value: 'a', tokens: [] }, { type: 'text', value: 'b' } ],
+ "a\n {{#a}}\n{{/a}}\nb" : [ { type: 'text', value: 'a\n' }, { type: '#', value: 'a', tokens: [] }, { type: 'text', value: 'b' } ],
+ "a\n {{#a}}\n{{/a}} \nb" : [ { type: 'text', value: 'a\n' }, { type: '#', value: 'a', tokens: [] }, { type: 'text', value: 'b' } ],
+ "a\n{{#a}}\n{{/a}}\n{{#b}}\n{{/b}}\nb" : [ { type: 'text', value: 'a\n' }, { type: '#', value: 'a', tokens: [] }, { type: '#', value: 'b', tokens: [] }, { type: 'text', value: 'b' } ],
+ "a\n {{#a}}\n{{/a}}\n{{#b}}\n{{/b}}\nb" : [ { type: 'text', value: 'a\n' }, { type: '#', value: 'a', tokens: [] }, { type: '#', value: 'b', tokens: [] }, { type: 'text', value: 'b' } ],
+ "a\n {{#a}}\n{{/a}}\n{{#b}}\n{{/b}} \nb" : [ { type: 'text', value: 'a\n' }, { type: '#', value: 'a', tokens: [] }, { type: '#', value: 'b', tokens: [] }, { type: 'text', value: 'b' } ],
+ "a\n{{#a}}\n{{#b}}\n{{/b}}\n{{/a}}\nb" : [ { type: 'text', value: 'a\n' }, { type: '#', value: 'a', tokens: [ { type: '#', value: 'b', tokens: [] } ] }, { type: 'text', value: 'b' } ],
+ "a\n {{#a}}\n{{#b}}\n{{/b}}\n{{/a}}\nb" : [ { type: 'text', value: 'a\n' }, { type: '#', value: 'a', tokens: [ { type: '#', value: 'b', tokens: [] } ] }, { type: 'text', value: 'b' } ],
+ "a\n {{#a}}\n{{#b}}\n{{/b}}\n{{/a}} \nb" : [ { type: 'text', value: 'a\n' }, { type: '#', value: 'a', tokens: [ { type: '#', value: 'b', tokens: [] } ] }, { type: 'text', value: 'b' } ],
+ "{{>abc}}" : [ { type: '>', value: 'abc' } ],
+ "{{> abc }}" : [ { type: '>', value: 'abc' } ],
+ "{{ > abc }}" : [ { type: '>', value: 'abc' } ],
+ "{{=<% %>=}}" : [ { type: '=', value: '<% %>' } ],
+ "{{= <% %> =}}" : [ { type: '=', value: '<% %>' } ],
+ "{{=<% %>=}}<%={{ }}=%>" : [ { type: '=', value: '<% %>' }, { type: '=', value: '{{ }}' } ],
+ "{{=<% %>=}}<%hi%>" : [ { type: '=', value: '<% %>' }, { type: 'name', value: 'hi' } ],
+ "{{#a}}{{/a}}hi{{#b}}{{/b}}\n" : [ { type: '#', value: 'a', tokens: [] }, { type: 'text', value: 'hi' }, { type: '#', value: 'b', tokens: [] }, { type: 'text', value: '\n' } ],
+ "{{a}}\n{{b}}\n\n{{#c}}\n{{/c}}\n" : [ { type: 'name', value: 'a' }, { type: 'text', value: '\n' }, { type: 'name', value: 'b' }, { type: 'text', value: '\n\n' }, { type: '#', value: 'c', tokens: [] } ],
+ "{{#foo}}\n {{#a}}\n {{b}}\n {{/a}}\n{{/foo}}\n"
+ : [ { type: "#", value: "foo", tokens: [ { type: "#", value: "a", tokens: [ { type: "text", value: " " }, { type: "name", value: "b" }, { type: "text", value: "\n" } ] } ] } ]
+};
+
+var spec = {};
+
+for (var template in expectations) {
+ (function (template, tokens) {
+ spec["knows how to parse " + JSON.stringify(template)] = function () {
+ assert.deepEqual(parse(template), tokens);
+ };
+ })(template, expectations[template]);
+}
+
+vows.describe("Mustache.parse").addBatch({
+ "parse": spec
+}).export(module);
diff --git a/test/render_test.js b/test/render_test.js
new file mode 100644
index 0000000..9638638
--- /dev/null
+++ b/test/render_test.js
@@ -0,0 +1,63 @@
+var fs = require("fs"),
+ path = require("path"),
+ assert = require("assert"),
+ vows = require("vows");
+
+var Mustache = require(path.join(__dirname, "..", "mustache"));
+var _files = path.join(__dirname, "_files");
+
+function getContents(testName, ext) {
+ var file = path.join(_files, testName + "." + ext);
+ try {
+ return fs.readFileSync(file, "utf8");
+ } catch (e) {}
+}
+
+// You can put the name of a specific test to run in the TEST environment
+// variable (e.g. TEST=backslashes vows test/render_test.js)
+var testToRun = process.env["TEST"];
+
+var testNames;
+if (testToRun) {
+ testNames = [testToRun];
+} else {
+ testNames = fs.readdirSync(_files).filter(function (file) {
+ return (/\.js$/).test(file);
+ }).map(function (file) {
+ return path.basename(file).replace(/\.js$/, "");
+ });
+}
+
+var spec = {};
+
+testNames.forEach(function (testName) {
+ var view = getContents(testName, "js");
+
+ if (view) {
+ view = eval(view);
+ } else {
+ console.log("Cannot find view for test: " + testName);
+ process.exit();
+ }
+
+ var template = getContents(testName, "mustache");
+ var expect = getContents(testName, "txt");
+ var partial = getContents(testName, "partial");
+
+ spec["knows how to render " + testName] = function () {
+ Mustache.clearCache();
+
+ var output;
+ if (partial) {
+ output = Mustache.render(template, view, {partial: partial});
+ } else {
+ output = Mustache.render(template, view);
+ }
+
+ assert.equal(output, expect);
+ };
+});
+
+vows.describe("Mustache.render").addBatch({
+ "render": spec
+}).export(module);
diff --git a/test/scanner_test.js b/test/scanner_test.js
new file mode 100644
index 0000000..79def2f
--- /dev/null
+++ b/test/scanner_test.js
@@ -0,0 +1,117 @@
+var assert = require("assert"),
+ vows = require("vows"),
+ Scanner = require("./../mustache").Scanner;
+
+vows.describe("Mustache.Scanner").addBatch({
+ "A Scanner": {
+ "for an empty string": {
+ topic: new Scanner(""),
+ "should be at the end of the string": function () {
+ var scanner = new Scanner("");
+ assert(scanner.eos());
+ }
+ },
+ "for a non-empty string": {
+ topic: "a b c",
+ "when calling scan": {
+ "when the regexp matches the entire string": {
+ topic: function (string) {
+ var scanner = new Scanner(string);
+ var match = scanner.scan(/a b c/);
+ this.callback(scanner, match);
+ },
+ "it should return the entire string": function (scanner, match) {
+ assert.equal(match, scanner.string);
+ },
+ "it should be at the end of the string": function (scanner, match) {
+ assert(scanner.eos());
+ }
+ }, // when the regexp matches the entire string
+ "when the regexp matches": {
+ "at the 0th index": {
+ topic: function (string) {
+ var scanner = new Scanner(string);
+ var match = scanner.scan(/a/);
+ this.callback(scanner, match);
+ },
+ "it should return the portion of the string that was matched": function (scanner, match) {
+ assert.equal(match, "a");
+ },
+ "it should advance the internal pointer the length of the match": function (scanner, match) {
+ assert.equal(scanner.pos, 1);
+ }
+ }, // at the 0th index
+ "at some index other than 0": {
+ topic: function (string) {
+ var scanner = new Scanner(string);
+ var match = scanner.scan(/b/);
+ this.callback(scanner, match);
+ },
+ "it should return null": function (scanner, match) {
+ assert.equal(match, null);
+ },
+ "it should not advance the internal pointer": function (scanner, match) {
+ assert.equal(scanner.pos, 0);
+ }
+ } // at some index other than 0
+ }, // when the regexp matches
+ "when the regexp doesn't match": {
+ topic: function (string) {
+ var scanner = new Scanner(string);
+ var match = scanner.scan(/z/);
+ this.callback(scanner, match);
+ },
+ "it should return null": function (scanner, match) {
+ assert.equal(match, null);
+ },
+ "it should not advance the internal pointer": function (scanner, match) {
+ assert.equal(scanner.pos, 0);
+ }
+ }
+ }, // when calling scan
+ "when calling scanUntil": {
+ "when the regexp matches": {
+ "at the 0th index": {
+ topic: function (string) {
+ var scanner = new Scanner(string);
+ var match = scanner.scanUntil(/a/);
+ this.callback(scanner, match);
+ },
+ "it should return null": function (scanner, match) {
+ assert.equal(match, null)
+ },
+ "it should not advance the internal pointer": function (scanner, match) {
+ assert.equal(scanner.pos, 0);
+ }
+ },
+ "at index 2": {
+ topic: function (string) {
+ var scanner = new Scanner(string);
+ var match = scanner.scanUntil(/b/);
+ this.callback(scanner, match);
+ },
+ "it should return the portion of the string it scanned": function (scanner, match) {
+ assert.equal(match, "a ");
+ },
+ "it should advance the internal pointer the length of the match": function (scanner, match) {
+ assert.equal(scanner.pos, 2);
+ }
+ }
+ }, // when the regexp matches
+ "when the regexp doesn't match": {
+ topic: function (string) {
+ var scanner = new Scanner(string);
+ var match = scanner.scanUntil(/z/);
+ this.callback(scanner, match);
+ },
+ "it should return the entire string": function (scanner, match) {
+ assert.equal(match, scanner.string);
+ },
+ "it should be at the end of the string": function (scanner, match) {
+ assert(scanner.eos());
+ }
+ } // when the regexp doesn't match
+ } // when calling scanUntil
+ } // for a non-empty string
+ }
+}).export(module);
diff --git a/test/unit.rb b/test/unit.rb
new file mode 100644
index 0000000..eb473bd
--- /dev/null
+++ b/test/unit.rb
@@ -0,0 +1,7 @@
+require File.expand_path('../helper', __FILE__)
+
+if Mustache.has_v8?
+ exec "vows #{Mustache::TEST}/*_test.js"
+else
+ abort "ERROR: Please install node"
+end
From 8efd0538cf5a89fd7b373f13719f14b8fc5becda Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Mon, 4 Jun 2012 07:39:21 -0700
Subject: [PATCH 05/65] This test should not work
---
test/_files/partial_recursion.js | 11 -----------
test/_files/partial_recursion.mustache | 4 ----
test/_files/partial_recursion.partial | 4 ----
test/_files/partial_recursion.txt | 3 ---
4 files changed, 22 deletions(-)
delete mode 100644 test/_files/partial_recursion.js
delete mode 100644 test/_files/partial_recursion.mustache
delete mode 100644 test/_files/partial_recursion.partial
delete mode 100644 test/_files/partial_recursion.txt
diff --git a/test/_files/partial_recursion.js b/test/_files/partial_recursion.js
deleted file mode 100644
index e39d64d..0000000
--- a/test/_files/partial_recursion.js
+++ /dev/null
@@ -1,11 +0,0 @@
-({
- name: '1',
- kids: [
- {
- name: '1.1',
- children: [
- {name: '1.1.1'}
- ]
- }
- ]
-})
diff --git a/test/_files/partial_recursion.mustache b/test/_files/partial_recursion.mustache
deleted file mode 100644
index 3c3651a..0000000
--- a/test/_files/partial_recursion.mustache
+++ /dev/null
@@ -1,4 +0,0 @@
-{{name}}
-{{#kids}}
-{{>partial}}
-{{/kids}}
diff --git a/test/_files/partial_recursion.partial b/test/_files/partial_recursion.partial
deleted file mode 100644
index 457d2a0..0000000
--- a/test/_files/partial_recursion.partial
+++ /dev/null
@@ -1,4 +0,0 @@
-{{name}}
-{{#children}}
-{{>partial}}
-{{/children}}
\ No newline at end of file
diff --git a/test/_files/partial_recursion.txt b/test/_files/partial_recursion.txt
deleted file mode 100644
index 0f70515..0000000
--- a/test/_files/partial_recursion.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-1
-1.1
-1.1.1
From eda51730614df1a3a5d5abec5d629a37d81affec Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Sun, 3 Jun 2012 22:26:14 -0700
Subject: [PATCH 06/65] Remove Ruby dependency
---
Rakefile | 38 ++++++++++++-----------
test/helper.rb | 48 ----------------------------
test/integration.rb | 76 ---------------------------------------------
test/unit.rb | 7 -----
4 files changed, 20 insertions(+), 149 deletions(-)
delete mode 100644 test/helper.rb
delete mode 100644 test/integration.rb
delete mode 100644 test/unit.rb
diff --git a/Rakefile b/Rakefile
index 7240f8b..0a62cb4 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,18 +1,28 @@
require 'rake'
require 'rake/clean'
-task :default => 'test:integration'
+task :default => :test
-namespace :test do
- desc "Run all integration tests"
- task :integration do
- require File.expand_path('../test/integration', __FILE__)
- end
+ROOT = File.expand_path('..', __FILE__)
+MUSTACHE_JS = File.read(File.join(ROOT, 'mustache.js'))
- desc "Run all unit tests"
- task :unit do
- require File.expand_path('../test/unit', __FILE__)
- end
+def mustache_version
+ match = MUSTACHE_JS.match(/exports\.version = "([^"]+)";/)
+ match[1]
+end
+
+def minified_file
+ ENV['FILE'] || 'mustache.min.js'
+end
+
+desc "Run all tests, requires vows (see http://vowsjs.org)"
+task :test do
+ sh "vows test/*_test.js"
+end
+
+desc "Minify to #{minified_file}, requires UglifyJS (see http://marijnhaverbeke.nl/uglifyjs)"
+task :minify do
+ sh "uglifyjs mustache.js > #{minified_file}"
end
# Creates a task that uses the various template wrappers to make a wrapped
@@ -52,11 +62,3 @@ templated_build "Dojo", :location => "dojox/string"
templated_build "YUI3", :location => "yui3/mustache"
templated_build "RequireJS"
templated_build "qooxdoo"
-
-task :minify do
- # npm install uglify-js
- mmjs = "mustache.min.js"
- `echo "/*! Version: 0.5.1-dev */" > #{mmjs}`
- `uglifyjs mustache.js >> #{mmjs}`
- puts "Created #{mmjs}"
-end
diff --git a/test/helper.rb b/test/helper.rb
deleted file mode 100644
index baadb94..0000000
--- a/test/helper.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require 'test/unit'
-
-module Mustache
- extend self
-
- ROOT = File.expand_path('../..', __FILE__)
- TEST = File.join(ROOT, 'test')
- TEST_FILES = File.join(TEST, '_files')
-
- MUSTACHE_JS = File.read(File.join(ROOT, 'mustache.js'))
-
- TESTS = Dir.glob(File.join(TEST_FILES, '*.js')).map do |name|
- File.basename name, '.js'
- end
-
- NODE_PATH = `which node`.strip
- JS_PATH = `which js`.strip
- JSC_PATH = "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc"
- RHINO_JAR = "org.mozilla.javascript.tools.shell.Main"
-
- def javascript_engines
- %w[v8 spidermonkey javascriptcore rhino]
- end
-
- def available_javascript_engines
- javascript_engines.select {|engine| send("has_#{engine}?") }
- end
-
- def has_any_engines?
- available_javascript_engines.any?
- end
-
- def has_v8?
- File.exist?(NODE_PATH)
- end
-
- def has_spidermonkey?
- File.exist?(JS_PATH)
- end
-
- def has_javascriptcore?
- File.exist?(JSC_PATH)
- end
-
- def has_rhino?
- `java #{RHINO_JAR} 'foo' 2>&1` !~ /ClassNotFoundException/
- end
-end
diff --git a/test/integration.rb b/test/integration.rb
deleted file mode 100644
index d3d482d..0000000
--- a/test/integration.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-require File.expand_path('../helper', __FILE__)
-require 'fileutils'
-require 'json'
-
-module Mustache
- class Test < Test::Unit::TestCase
-
- def self.run_tests_for(engine)
- TESTS.each do |test|
- define_method("test_#{engine}_#{test}") do
- template, view, partial, expect = load_test(test)
-
- assert_equal expect, run_js(engine, <<-JS).chomp
- try {
- #{boilerplate_for(engine)}
- var template = #{template.to_json};
- var view = #{view};
- var partials = {partial: #{partial.to_json}};
- print(Mustache.render(template, view, partials));
- } catch(e) {
- print('ERROR: ' + e.message);
- }
- JS
- end
- end
- end
-
- unless Mustache.has_any_engines?
- abort "ERROR: Please install node, SpiderMonkey, JavaScriptCore or Rhino"
- end
-
- run_tests_for :v8 if Mustache.has_v8?
- run_tests_for :spidermonkey if Mustache.has_spidermonkey?
- run_tests_for :javascriptcore if Mustache.has_javascriptcore?
- run_tests_for :rhino if Mustache.has_rhino?
-
- private
-
- def load_test(name)
- template_file = File.join(TEST_FILES, "#{name}.mustache")
- view_file = File.join(TEST_FILES, "#{name}.js")
- partial_file = File.join(TEST_FILES, "#{name}.partial")
- expect_file = File.join(TEST_FILES, "#{name}.txt")
-
- [template_file, view_file, partial_file, expect_file].map do |file|
- File.exist?(file) ? File.read(file) : ""
- end
- end
-
- def runner_file
- "runner.js"
- end
-
- def run_js(engine, js)
- cmd = case engine
- when :v8 then NODE_PATH
- when :spidermonkey then JS_PATH
- when :javascriptcore then JSC_PATH
- when :rhino then "java #{RHINO_JAR}"
- end
-
- File.open(runner_file, 'w') {|file| file.write(js) }
-
- `#{cmd} #{runner_file}`
- ensure
- FileUtils.rm_r(runner_file)
- end
-
- def boilerplate_for(engine)
- boilerplate = MUSTACHE_JS
- boilerplate += "\nvar print = console.log;" if engine == :v8
- boilerplate
- end
-
- end
-end
diff --git a/test/unit.rb b/test/unit.rb
deleted file mode 100644
index eb473bd..0000000
--- a/test/unit.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require File.expand_path('../helper', __FILE__)
-
-if Mustache.has_v8?
- exec "vows #{Mustache::TEST}/*_test.js"
-else
- abort "ERROR: Please install node"
-end
From c6aef7ea1299273038a033ed96adc6dd8237d329 Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Sun, 3 Jun 2012 22:37:56 -0700
Subject: [PATCH 07/65] Update testing instructions
---
README.md | 41 ++++++++++++++++++++++++------------
TESTING.md | 62 ------------------------------------------------------
2 files changed, 28 insertions(+), 75 deletions(-)
delete mode 100644 TESTING.md
diff --git a/README.md b/README.md
index a04f667..20e2f77 100644
--- a/README.md
+++ b/README.md
@@ -357,21 +357,9 @@ text and are awkward to use for markup."
Custom delimiters may not contain whitespace or the equals sign.
-## Streaming
-
-To stream template results out of mustache.js, you can pass an optional callback
-to the call to `Mustache.render`:
-
- Mustache.render(template, view, partials, function (chunk) {
- print(chunk);
- });
-
-When the template is finished rendering, the callback will be called with `null`
-after which it won't be called anymore for that rendering.
-
## Plugins for JavaScript Libraries
-By default mustache.js may be used in a browser or any [CommonJS](http://www.commonjs.org/)
+By default mustache.js may be used in any browser or [CommonJS](http://www.commonjs.org/)
environment, including [node](http://nodejs.org/). Additionally, mustache.js may
be built specifically for several different client libraries and platforms,
including the following:
@@ -393,6 +381,33 @@ following commands:
$ rake requirejs
$ rake qooxdoo
+## Testing
+
+The mustache.js test suite uses the [vows](http://vowsjs.org/) testing
+framework. In order to run the tests you'll need to install [node](http://nodejs.org/)
+first. Once it's installed, you can install vows using [npm](http://npmjs.org/).
+
+ $ npm install -g vows
+
+Then, run the tests.
+
+ $ vows test/*_test.js
+
+The test suite consists of both unit and integration tests. If a template isn't
+rendering correctly for you, you can make a test for it by doing the following:
+
+ 1. Create a template file named `mytest.mustache` in the `test/_files`
+ directory. Replace `mytest` with the name of your test.
+ 2. Create a corresponding view file named `mytest.js` in the same directory.
+ This file should contain a JavaScript object literal enclosed in
+ parentheses. See any of the other view files for an example.
+ 3. Create a file with the expected output in `mytest.txt` in the same
+ directory.
+
+Then, you can run the test with:
+
+ $ TEST=mytest vows test/render_test.js
+
## Thanks
Mustache.js wouldn't kick ass if it weren't for these fine souls:
diff --git a/TESTING.md b/TESTING.md
deleted file mode 100644
index 47d15e4..0000000
--- a/TESTING.md
+++ /dev/null
@@ -1,62 +0,0 @@
-## Running the mustache.js test suite
-
-The mustache.js test suite uses the [RSpec](http://rspec.info/) testing
-framework. In order to run the tests you'll need to install [Ruby](http://ruby-lang.org/)
-as well as the `rake`, `rspec` (>=2), and `json` [RubyGems](http://rubygems.org/).
-
-### How to install Ruby and the required gems from source
-
-Make sure you have the required tools to compile it:
-
- $ apt-get install build-essential libssl-dev libreadline5-dev zlib1g-dev
-
-Download and extract the Ruby source, and install it:
-
- $ wget ftp://ftp.ruby-lang.org/pub/ruby/stable-snapshot.tar.gz
- $ tar xvzf stable-snapshot.tar.gz
- $ cd ruby
- $ ./configure && make && make install
-
-Download and extract RubyGems, and install it:
-
- $ wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.12.tgz
- $ tar xzvf rubygems-1.8.12.tgz
- $ cd rubygems-1.8.12
- $ ruby setup.rb
-
-If you want to update RubyGems:
-
- $ gem update --system
-
-Install the required gems:
-
- $ gem install rake rspec json
-
-That's it!
-
-### How to run the tests
-
-The mustache.js test suite currently uses 4 different JavaScript runtime engines
-to maximize portability across platforms and browsers. They are:
-
- * node
- * SpiderMonkey (Mozilla, Firefox)
- * JavaScriptCore (WebKit, Safari)
- * Rhino (Mozilla, Java)
-
-When the test suite runs it will automatically determine which platforms are
-available on your machine and run on all of them. The suite must run on at least
-one platform in order to succeed.
-
-Once you have at least one JavaScript platform installed, you can run the test
-suite with the following command:
-
- $ rake
-
-### How to create a test
-
-All test files live in the spec/_files directory. To create a new test:
-
- * Create a template file called `somename.mustache`
- * Create a JavaScript file containing the view called `somename.js`
- * Create a text file with the expected result called `somename.txt`
From 3355e1720d462266783d6eb2a126cd825f84d25f Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Mon, 4 Jun 2012 07:48:27 -0700
Subject: [PATCH 08/65] Version 0.5.1-dev
---
mustache.js | 2 +-
mustache.js.nuspec | 2 +-
package.json | 5 +++--
wrappers/qooxdoo/mustache.js.pre | 2 +-
4 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/mustache.js b/mustache.js
index 7b34bbb..c89711a 100644
--- a/mustache.js
+++ b/mustache.js
@@ -7,7 +7,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
(function (exports) {
exports.name = "mustache.js";
- exports.version = "0.5.0-dev";
+ exports.version = "0.5.1-dev";
exports.tags = ["{{", "}}"];
exports.parse = parse;
diff --git a/mustache.js.nuspec b/mustache.js.nuspec
index ec69150..7eb14ac 100644
--- a/mustache.js.nuspec
+++ b/mustache.js.nuspec
@@ -2,7 +2,7 @@
mustache.js
- 0.5.0-dev
+ 0.5.1-dev
mustache.js Authors
https://github.com/janl/mustache.js/blob/master/LICENSE
http://mustache.github.com/
diff --git a/package.json b/package.json
index 5f348de..d64cd27 100644
--- a/package.json
+++ b/package.json
@@ -1,11 +1,12 @@
{
"name": "mustache",
- "version": "0.5.0-dev",
+ "version": "0.5.1-dev",
"description": "Logic-less {{mustache}} templates with JavaScript",
"author": "mustache.js Authors ",
"keywords": ["mustache", "template", "templates", "ejs"],
"main": "./mustache",
"devDependencies": {
- "vows": "0.6.x"
+ "vows": "0.6.x",
+ "uglify-js": "1.3.0"
}
}
diff --git a/wrappers/qooxdoo/mustache.js.pre b/wrappers/qooxdoo/mustache.js.pre
index d10c0d5..f6b1c96 100644
--- a/wrappers/qooxdoo/mustache.js.pre
+++ b/wrappers/qooxdoo/mustache.js.pre
@@ -19,7 +19,7 @@
This class contains code based on the following work:
- * Mustache.js version 0.5.0-dev
+ * Mustache.js version 0.5.1-dev
Code:
https://github.com/janl/mustache.js
From 9cc8ef13fd77b1dd4640ee99c6458525fd8be1fa Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Mon, 4 Jun 2012 13:23:33 -0700
Subject: [PATCH 09/65] Remove extra slashes
---
mustache.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mustache.js b/mustache.js
index c89711a..7dee0e9 100644
--- a/mustache.js
+++ b/mustache.js
@@ -20,7 +20,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
exports.Context = Context;
exports.Renderer = Renderer;
- // // This is here for backwards compatibility with 0.4.x.
+ // This is here for backwards compatibility with 0.4.x.
exports.to_html = function (template, view, partials, send) {
var result = render(template, view, partials);
From cae4fd5abe21b5f3ba5694ee35ef5fe765843ad6 Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Tue, 12 Jun 2012 14:46:23 -0700
Subject: [PATCH 10/65] Declare stripSpace with var
---
mustache.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mustache.js b/mustache.js
index 7dee0e9..0fef360 100644
--- a/mustache.js
+++ b/mustache.js
@@ -448,7 +448,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
// Strips all whitespace tokens array for the current line
// if there was a {{#tag}} on it and otherwise only space.
- function stripSpace() {
+ var stripSpace = function () {
if (hasTag && !nonSpace) {
while (spaces.length) {
tokens.splice(spaces.pop(), 1);
@@ -459,7 +459,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
hasTag = false;
nonSpace = false;
- }
+ };
var type, value, chr;
From b8a14eafe9f260277ee03cc52c26901166045f81 Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Tue, 12 Jun 2012 14:51:43 -0700
Subject: [PATCH 11/65] Strict escaping of ampersands
---
mustache.js | 2 +-
test/_files/dot_notation.mustache | 4 ++--
test/_files/escaped.mustache | 2 +-
test/_files/escaped.txt | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/mustache.js b/mustache.js
index 0fef360..c5be0c9 100644
--- a/mustache.js
+++ b/mustache.js
@@ -63,7 +63,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
};
function escapeHtml(string) {
- return String(string).replace(/&(?!\w+;)|[<>"']/g, function (s) {
+ return String(string).replace(/[&<>"']/g, function (s) {
return entityMap[s];
});
}
diff --git a/test/_files/dot_notation.mustache b/test/_files/dot_notation.mustache
index 138ddd0..f89d70b 100644
--- a/test/_files/dot_notation.mustache
+++ b/test/_files/dot_notation.mustache
@@ -1,8 +1,8 @@
{{name}}
Authors:
{{#authors}}- {{.}}
{{/authors}}
-Price: {{price.currency.symbol}}{{price.value}} {{#price.currency}}{{name}} {{availability.text}}{{/price.currency}}
-VAT: {{price.currency.symbol}}{{#price}}{{vat}}{{/price}}
+Price: {{{price.currency.symbol}}}{{price.value}} {{#price.currency}}{{name}} {{availability.text}}{{/price.currency}}
+VAT: {{{price.currency.symbol}}}{{#price}}{{vat}}{{/price}}
Test truthy false values:
Zero: {{truthy.zero}}
diff --git a/test/_files/escaped.mustache b/test/_files/escaped.mustache
index ea25951..93e800b 100644
--- a/test/_files/escaped.mustache
+++ b/test/_files/escaped.mustache
@@ -1,2 +1,2 @@
{{title}}
-But not {{entities}}.
+And even {{entities}}, but not {{{entities}}}.
diff --git a/test/_files/escaped.txt b/test/_files/escaped.txt
index 73ac5ce..2c3ad1f 100644
--- a/test/_files/escaped.txt
+++ b/test/_files/escaped.txt
@@ -1,2 +1,2 @@
Bear > Shark
-But not ".
+And even ", but not ".
From e53ce34af442d4d4b8cc3074c569e1a56e1b66ac Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Tue, 12 Jun 2012 15:25:35 -0700
Subject: [PATCH 12/65] Fix quote implementation for environments without
JSON.stringify
---
mustache.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mustache.js b/mustache.js
index c5be0c9..3535e66 100644
--- a/mustache.js
+++ b/mustache.js
@@ -47,7 +47,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
};
var quote = (typeof JSON !== "undefined" && JSON.stringify) || function (string) {
- return '"' + String(string).replace(/(^|[^\\])"/g, '\\"') + '"';
+ return '"' + String(string).replace(/([\\"])/g, '\\$1') + '"';
};
function escapeRe(string) {
From 585bff401a46c4b0142356fa94ddabb79d4aef49 Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Wed, 13 Jun 2012 11:11:39 -0700
Subject: [PATCH 13/65] Run tests using node on Travis
---
.travis.yml | 11 ++++++-----
package.json | 3 +++
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index b52599e..ad74a3f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,6 @@
-rvm:
- - 1.9.2
-before_script:
- - sudo apt-get -y install xulrunner-2.0
- - gem install rspec
+language: node_js
+node_js:
+ - 0.4
+ - 0.6
+ - 0.7
+
diff --git a/package.json b/package.json
index d64cd27..a3ae822 100644
--- a/package.json
+++ b/package.json
@@ -8,5 +8,8 @@
"devDependencies": {
"vows": "0.6.x",
"uglify-js": "1.3.0"
+ },
+ "scripts": {
+ "test": "vows --spec"
}
}
From 72971b320cb72c6cc8dc8de80e18c2000d247ad7 Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Wed, 6 Jun 2012 07:37:48 -0700
Subject: [PATCH 14/65] Use var declaration for helper functions
---
mustache.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mustache.js b/mustache.js
index 3535e66..dcb848c 100644
--- a/mustache.js
+++ b/mustache.js
@@ -239,9 +239,9 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
break;
case "function":
var sectionText = callback(context, this), self = this;
- function scopedRender(template) {
+ var scopedRender = function (template) {
return self.render(template, context);
- }
+ };
return value.call(context.view, sectionText, scopedRender) || "";
break;
default:
From c316c973f64f52794c0c420bb0c2d753f2984808 Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Wed, 20 Jun 2012 20:47:24 -0700
Subject: [PATCH 15/65] Run tests on node 0.6
---
.travis.yml | 2 --
1 file changed, 2 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index ad74a3f..3d839b0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,4 @@
language: node_js
node_js:
- - 0.4
- 0.6
- - 0.7
From 144d8bef85eaac11308493897bb7271ef2f5b469 Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Wed, 20 Jun 2012 21:02:22 -0700
Subject: [PATCH 16/65] Workaround for old SpiderMonkey builds
Fixes #189
---
mustache.js | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/mustache.js b/mustache.js
index a242c1c..24b1c19 100644
--- a/mustache.js
+++ b/mustache.js
@@ -38,8 +38,14 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
var curlyRe = /\s*\}/;
var tagRe = /#|\^|\/|>|\{|&|=|!/;
+ // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
+ // See https://github.com/janl/mustache.js/issues/189
+ function testRe(re, string) {
+ return RegExp.prototype.test.call(re, string);
+ }
+
function isWhitespace(string) {
- return !nonSpaceRe.test(string);
+ return !testRe(nonSpaceRe, string);
}
var isArray = Array.isArray || function (obj) {
From bb58576ba5ef62bce90d79a51cbc1bd4cf8d25ae Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Wed, 20 Jun 2012 21:03:44 -0700
Subject: [PATCH 17/65] Update testing instructions
---
README.md | 2 +-
Rakefile | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 20e2f77..d117222 100644
--- a/README.md
+++ b/README.md
@@ -391,7 +391,7 @@ first. Once it's installed, you can install vows using [npm](http://npmjs.org/).
Then, run the tests.
- $ vows test/*_test.js
+ $ vows --spec
The test suite consists of both unit and integration tests. If a template isn't
rendering correctly for you, you can make a test for it by doing the following:
diff --git a/Rakefile b/Rakefile
index 0a62cb4..33eb805 100644
--- a/Rakefile
+++ b/Rakefile
@@ -17,7 +17,7 @@ end
desc "Run all tests, requires vows (see http://vowsjs.org)"
task :test do
- sh "vows test/*_test.js"
+ sh "vows --spec"
end
desc "Minify to #{minified_file}, requires UglifyJS (see http://marijnhaverbeke.nl/uglifyjs)"
From a7a6e742d18c1fdf049263948c4f72a820e35210 Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Wed, 20 Jun 2012 21:37:27 -0700
Subject: [PATCH 18/65] Use @cweider's quoting function
Also fixed a bug that occurs when using the triple-stache with a key
that contains a closing stache. Fixes #192.
---
mustache.js | 34 ++++++++++++++++---------
test/_files/malicious_template.js | 1 +
test/_files/malicious_template.mustache | 5 ++++
test/_files/malicious_template.txt | 2 ++
4 files changed, 30 insertions(+), 12 deletions(-)
create mode 100644 test/_files/malicious_template.js
create mode 100644 test/_files/malicious_template.mustache
create mode 100644 test/_files/malicious_template.txt
diff --git a/mustache.js b/mustache.js
index 24b1c19..42b0144 100644
--- a/mustache.js
+++ b/mustache.js
@@ -52,9 +52,16 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
return Object.prototype.toString.call(obj) === "[object Array]";
};
- var quote = (typeof JSON !== "undefined" && JSON.stringify) || function (string) {
- return '"' + String(string).replace(/([\\"])/g, '\\$1') + '"';
- };
+ // OSWASP Guidlines: escape all non alphanumeric characters in ASCII space.
+ var jsCharsRe = /[\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\xFF\u2028\u2029]/gm;
+
+ function quote(text) {
+ var escaped = text.replace(jsCharsRe, function (c) {
+ return "\\u" + ('0000' + c.charCodeAt(0).toString(16)).slice(-4);
+ });
+
+ return '"' + escaped + '"';
+ }
function escapeRe(string) {
return string.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
@@ -444,7 +451,8 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
* course, the default is to use mustaches (i.e. Mustache.tags).
*/
function parse(template, tags) {
- tags = escapeTags(tags || exports.tags);
+ tags = tags || exports.tags;
+ tagRes = escapeTags(tags);
var scanner = new Scanner(template);
@@ -471,7 +479,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
var type, value, chr;
while (!scanner.eos()) {
- value = scanner.scanUntil(tags[0]);
+ value = scanner.scanUntil(tagRes[0]);
if (value) {
for (var i = 0, len = value.length; i < len; ++i) {
@@ -492,7 +500,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
}
// Match the opening tag.
- if (!scanner.scan(tags[0])) {
+ if (!scanner.scan(tagRes[0])) {
break;
}
@@ -506,17 +514,18 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
if (type === "=") {
value = scanner.scanUntil(eqRe);
scanner.scan(eqRe);
- scanner.scanUntil(tags[1]);
+ scanner.scanUntil(tagRes[1]);
} else if (type === "{") {
- value = scanner.scanUntil(curlyRe);
+ var closeRe = new RegExp("\\s*" + escapeRe("}" + tags[1]));
+ value = scanner.scanUntil(closeRe);
scanner.scan(curlyRe);
- scanner.scanUntil(tags[1]);
+ scanner.scanUntil(tagRes[1]);
} else {
- value = scanner.scanUntil(tags[1]);
+ value = scanner.scanUntil(tagRes[1]);
}
// Match the closing tag.
- if (!scanner.scan(tags[1])) {
+ if (!scanner.scan(tagRes[1])) {
throw new Error("Unclosed tag at " + scanner.pos);
}
@@ -528,7 +537,8 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
// Set the tags for the next time around.
if (type === "=") {
- tags = escapeTags(value.split(spaceRe));
+ tags = value.split(spaceRe);
+ tagRes = escapeTags(tags);
}
}
diff --git a/test/_files/malicious_template.js b/test/_files/malicious_template.js
new file mode 100644
index 0000000..b4100a5
--- /dev/null
+++ b/test/_files/malicious_template.js
@@ -0,0 +1 @@
+({})
diff --git a/test/_files/malicious_template.mustache b/test/_files/malicious_template.mustache
new file mode 100644
index 0000000..b956867
--- /dev/null
+++ b/test/_files/malicious_template.mustache
@@ -0,0 +1,5 @@
+{{"+(function () {throw "evil"})()+"}}
+{{{"+(function () {throw "evil"})()+"}}}
+{{> "+(function () {throw "evil"})()+"}}
+{{# "+(function () {throw "evil"})()+"}}
+{{/ "+(function () {throw "evil"})()+"}}
diff --git a/test/_files/malicious_template.txt b/test/_files/malicious_template.txt
new file mode 100644
index 0000000..139597f
--- /dev/null
+++ b/test/_files/malicious_template.txt
@@ -0,0 +1,2 @@
+
+
From 118cf2fc9ed40dc46ab9ac9fbe9b7fb87d624542 Mon Sep 17 00:00:00 2001
From: feng
Date: Sat, 30 Jun 2012 22:50:34 +0800
Subject: [PATCH 19/65] fix global var leak
---
mustache.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mustache.js b/mustache.js
index 42b0144..085d60b 100644
--- a/mustache.js
+++ b/mustache.js
@@ -433,7 +433,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
var lastToken;
for (var i = 0; i < tokens.length; ++i) {
- token = tokens[i];
+ var token = tokens[i];
if (lastToken && lastToken.type === "text" && token.type === "text") {
lastToken.value += token.value;
@@ -452,7 +452,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
*/
function parse(template, tags) {
tags = tags || exports.tags;
- tagRes = escapeTags(tags);
+ var tagRes = escapeTags(tags);
var scanner = new Scanner(template);
From 74ac6ae1442799b3a57b338d44683f5431d29c36 Mon Sep 17 00:00:00 2001
From: TimZaripov
Date: Tue, 3 Jul 2012 01:03:51 +0400
Subject: [PATCH 20/65] fixed error in README.md -- in case of {"person": true}
text from template {{#person}} Never shown! {{/person}} WILL be shown
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index d117222..d657757 100644
--- a/README.md
+++ b/README.md
@@ -144,7 +144,7 @@ Template:
View:
{
- "person": true
+ "person": false
}
Output:
From 9079bd88f21e51f44f8de38d1322d6f86419956f Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Thu, 21 Jun 2012 17:29:39 -0700
Subject: [PATCH 21/65] Add lint task using JSHint
---
.jshintrc | 5 +++++
Rakefile | 5 +++++
mustache.js | 18 +++++++++++-------
3 files changed, 21 insertions(+), 7 deletions(-)
create mode 100644 .jshintrc
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..28dff71
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,5 @@
+{
+ "eqnull": true,
+ "evil": true
+}
+
diff --git a/Rakefile b/Rakefile
index 33eb805..a1c7920 100644
--- a/Rakefile
+++ b/Rakefile
@@ -25,6 +25,11 @@ task :minify do
sh "uglifyjs mustache.js > #{minified_file}"
end
+desc "Run JSHint, requires jshint (see http://www.jshint.com)"
+task :lint do
+ sh "jshint mustache.js"
+end
+
# Creates a task that uses the various template wrappers to make a wrapped
# output file. There is some extra complexity because Dojo and YUI use
# different final locations.
diff --git a/mustache.js b/mustache.js
index 085d60b..f45009a 100644
--- a/mustache.js
+++ b/mustache.js
@@ -64,7 +64,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
}
function escapeRe(string) {
- return string.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
+ return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
}
var entityMap = {
@@ -243,21 +243,25 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
case "object":
if (isArray(value)) {
var buffer = "";
+
for (var i = 0, len = value.length; i < len; ++i) {
buffer += callback(context.push(value[i]), this);
}
+
return buffer;
- } else {
- return callback(context.push(value), this);
}
- break;
+
+ return callback(context.push(value), this);
case "function":
- var sectionText = callback(context, this), self = this;
+ // TODO: The text should be passed to the callback plain, not rendered.
+ var sectionText = callback(context, this),
+ self = this;
+
var scopedRender = function (template) {
return self.render(template, context);
};
+
return value.call(context.view, sectionText, scopedRender) || "";
- break;
default:
if (value) {
return callback(context, this);
@@ -549,7 +553,7 @@ var Mustache = (typeof module !== "undefined" && module.exports) || {};
// The high-level clearCache, compile, compilePartial, and render functions
// use this default renderer.
- var _renderer = new Renderer;
+ var _renderer = new Renderer();
/**
* Clears all cached templates and partials.
From 33920ad674126483414b8e879c57558352a382ed Mon Sep 17 00:00:00 2001
From: Michael Jackson
Date: Fri, 13 Jul 2012 22:09:54 -0700
Subject: [PATCH 22/65] Add AMD module support
---
Rakefile | 1 -
mustache.js | 16 ++++++++++++++--
wrappers/requirejs/mustache.js.post | 3 ---
wrappers/requirejs/mustache.js.pre | 6 ------
4 files changed, 14 insertions(+), 12 deletions(-)
delete mode 100644 wrappers/requirejs/mustache.js.post
delete mode 100644 wrappers/requirejs/mustache.js.pre
diff --git a/Rakefile b/Rakefile
index a1c7920..bc32175 100644
--- a/Rakefile
+++ b/Rakefile
@@ -65,5 +65,4 @@ templated_build "jQuery"
templated_build "MooTools"
templated_build "Dojo", :location => "dojox/string"
templated_build "YUI3", :location => "yui3/mustache"
-templated_build "RequireJS"
templated_build "qooxdoo"
diff --git a/mustache.js b/mustache.js
index f45009a..c6b6c6b 100644
--- a/mustache.js
+++ b/mustache.js
@@ -2,9 +2,19 @@
* mustache.js - Logic-less {{mustache}} templates with JavaScript
* http://github.com/janl/mustache.js
*/
-var Mustache = (typeof module !== "undefined" && module.exports) || {};
+
+var Mustache;
(function (exports) {
+ if (typeof module !== "undefined") {
+ module.exports = exports; // CommonJS
+ } else if (typeof define === "function") {
+ define(exports); // AMD
+ } else {
+ Mustache = exports; //