Add some more tests, and properly handle errors across the boundary in tests

This commit is contained in:
wycats
2010-11-25 16:09:42 -08:00
parent 4624eddf0b
commit 7d0204bf9f
3 changed files with 35 additions and 8 deletions
+2 -2
View File
@@ -67,7 +67,7 @@ Handlebars.PrintVisitor.prototype.mustache = function(mustache) {
} }
var params = "[" + paramStrings.join(", ") + "]"; 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) { Handlebars.PrintVisitor.prototype.partial = function(partial) {
@@ -75,7 +75,7 @@ Handlebars.PrintVisitor.prototype.partial = function(partial) {
}; };
Handlebars.PrintVisitor.prototype.STRING = function(string) { Handlebars.PrintVisitor.prototype.STRING = function(string) {
return string.string; return '"' + string.string + '"';
}; };
Handlebars.PrintVisitor.prototype.ID = function(id) { Handlebars.PrintVisitor.prototype.ID = function(id) {
+27
View File
@@ -1,5 +1,32 @@
require "v8" 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| RSpec.configure do |config|
config.before(:all) do config.before(:all) do
@context = V8::Context.new @context = V8::Context.new
+5 -5
View File
@@ -117,11 +117,11 @@ describe "Tokenizer" do
result[2].should be_token("STRING", %{bar"baz}) result[2].should be_token("STRING", %{bar"baz})
end end
it "does not time out with broken input" do it "does not time out in a mustache with a single } followed by EOF" do
lambda do Timeout.timeout(1) { tokenize("{{foo}").should match_tokens(%w(OPEN ID)) }
Timeout.timeout(1) do
tokenize("{{foo}")
end end
end.should_not raise_error(Timeout::Error)
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
end end