From 7d0204bf9f3aac1f38f012ae1e8156efe07fc40d Mon Sep 17 00:00:00 2001 From: wycats Date: Thu, 25 Nov 2010 16:09:42 -0800 Subject: [PATCH] Add some more tests, and properly handle errors across the boundary in tests --- lib/handlebars/printer.js | 4 ++-- spec/spec_helper.rb | 27 +++++++++++++++++++++++++++ spec/tokenizer_spec.rb | 12 ++++++------ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/lib/handlebars/printer.js b/lib/handlebars/printer.js index 5db2f814..b388a3a4 100644 --- a/lib/handlebars/printer.js +++ b/lib/handlebars/printer.js @@ -67,7 +67,7 @@ Handlebars.PrintVisitor.prototype.mustache = function(mustache) { } var params = "[" + paramStrings.join(", ") + "]"; - return this.pad("{{ " + this.accept(mustache.id) + " " + params + "}}"); + return this.pad("{{ " + this.accept(mustache.id) + " " + params + " }}"); }; Handlebars.PrintVisitor.prototype.partial = function(partial) { @@ -75,7 +75,7 @@ Handlebars.PrintVisitor.prototype.partial = function(partial) { }; Handlebars.PrintVisitor.prototype.STRING = function(string) { - return string.string; + return '"' + string.string + '"'; }; Handlebars.PrintVisitor.prototype.ID = function(id) { diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2028b883..9d8fe50b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,32 @@ require "v8" +# Monkey patches due to bugs in RubyRacer +class V8::JSError + def initialize(try, to) + @to = to + begin + super(initialize_unsafe(try)) + rescue Exception => e + # Original code does not make an Array here + @boundaries = [Boundary.new(:rbframes => e.backtrace)] + @value = e + super("BUG! please report. JSError#initialize failed!: #{e.message}") + end + end + + def parse_js_frames(try) + raw = @to.rb(try.StackTrace()) + if raw && !raw.empty? + raw.split("\n")[1..-1].tap do |frames| + # Original code uses strip!, and the frames are not guaranteed to be strippable + frames.each {|frame| frame.strip.chomp!(",")} + end + else + [] + end + end +end + RSpec.configure do |config| config.before(:all) do @context = V8::Context.new diff --git a/spec/tokenizer_spec.rb b/spec/tokenizer_spec.rb index bed81024..54063dba 100644 --- a/spec/tokenizer_spec.rb +++ b/spec/tokenizer_spec.rb @@ -117,11 +117,11 @@ describe "Tokenizer" do result[2].should be_token("STRING", %{bar"baz}) end - it "does not time out with broken input" do - lambda do - Timeout.timeout(1) do - tokenize("{{foo}") - end - end.should_not raise_error(Timeout::Error) + it "does not time out in a mustache with a single } followed by EOF" do + Timeout.timeout(1) { tokenize("{{foo}").should match_tokens(%w(OPEN ID)) } + end + + it "does not time out in a mustache when invalid ID characters are used" do + Timeout.timeout(1) { tokenize("{{foo & }}").should match_tokens(%w(OPEN ID)) } end end