1
0
Fork 0
mirror of https://github.com/rails/execjs synced 2023-03-27 23:21:20 -04:00
execjs/test/test_execjs.rb

32 lines
852 B
Ruby
Raw Normal View History

2011-02-06 20:10:05 -05:00
require "execjs"
require "test/unit"
class TestExecJS < Test::Unit::TestCase
def test_exec
assert_equal true, ExecJS.exec("return true")
end
def test_eval
assert_equal ["red", "yellow", "blue"], ExecJS.eval("'red yellow blue'.split(' ')")
end
2011-02-06 21:35:37 -05:00
def test_runtime_available
2011-02-06 21:57:51 -05:00
runtime = ExecJS::ExternalRuntime.new(:command => "nonexistent")
assert !runtime.available?
2011-02-06 21:35:37 -05:00
2011-02-06 21:57:51 -05:00
runtime = ExecJS::ExternalRuntime.new(:command => "ruby")
assert runtime.available?
2011-02-06 21:35:37 -05:00
end
2011-02-11 12:39:06 -05:00
def test_compile
context = ExecJS.compile("foo = function() { return \"bar\"; }")
assert_equal "bar", context.exec("return foo()")
assert_equal "bar", context.eval("foo()")
end
2011-02-11 12:51:59 -05:00
def test_pure_evaluation
context = ExecJS.compile("foo = function() { return \"bar\"; }")
assert_equal "bar", context.eval("foo()", :pure => true)
end
2011-02-06 20:10:05 -05:00
end