From fbc66a81400418983c2d7ccf0457aeea7af0fb1a Mon Sep 17 00:00:00 2001
From: Michael Jackson Authors: "
-};
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}}
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}}
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