From 2bc2bf49a0eec9bc6d246ed75fd6f4e8fb5bf6f1 Mon Sep 17 00:00:00 2001 From: Ryunosuke SATO Date: Tue, 21 Oct 2014 00:30:44 +0900 Subject: [PATCH 1/3] Test against Ruby 2.1 / 2.2 on Travis CI --- .travis.yml | 2 ++ Gemfile | 1 + 2 files changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 222078e..9577abf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,3 +2,5 @@ language: ruby rvm: - 1.9.3 - 2.0.0 + - 2.1 + - 2.2 diff --git a/Gemfile b/Gemfile index 0d13b86..3f1a9ea 100644 --- a/Gemfile +++ b/Gemfile @@ -5,4 +5,5 @@ gemspec group :test do gem 'therubyracer', platform: :mri gem 'therubyrhino', ">=1.73.3", platform: :jruby + gem 'minitest', require: false end From e9d67ff49eb07c803ec0a7626d3afaf50db4fd4b Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 10 Dec 2014 22:14:01 -0800 Subject: [PATCH 2/3] Test more json values --- test/test_execjs.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/test_execjs.rb b/test/test_execjs.rb index 591caff..fa162d7 100644 --- a/test/test_execjs.rb +++ b/test/test_execjs.rb @@ -89,6 +89,40 @@ class TestExecJS < Test assert_equal "\\", ExecJS.eval('"\\\\"') end + def test_json_values + [ + nil, + true, + false, + 1, + 3.14, + "hello", + "\\", + "café", + "☃", + ["0ff98948"].pack("h*").force_encoding("UTF-8"), # Smiling emoji + [1, 2, 3], + [1, [2, 3]], + [1, [2, [3]]], + ["red", "yellow", "blue"], + { "a" => 1, "b" => 2}, + { "a" => 1, "b" => [2, 3]}, + { "a" => true } + ].each do |value| + json_value = JSON.generate(value, quirks_mode: true) + assert_equal value, JSON.parse(json_value, quirks_mode: true) + + assert_equal value, ExecJS.exec("return #{json_value}") + assert_equal value, ExecJS.eval("#{json_value}") + + context = ExecJS.compile("function json(obj) { return JSON.stringify(obj); }") + assert_equal json_value, context.call("json", value) + + context = ExecJS.compile("function id(obj) { return obj; }") + assert_equal value, context.call("id", value) + end + end + def test_encoding utf8 = Encoding.find('UTF-8') From 167c5e2e6403df4287ca858a05ddf71557ee0f9a Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 10 Dec 2014 22:16:36 -0800 Subject: [PATCH 3/3] Require json --- test/test_execjs.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_execjs.rb b/test/test_execjs.rb index fa162d7..fa4ef02 100644 --- a/test/test_execjs.rb +++ b/test/test_execjs.rb @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- require "minitest/autorun" require "execjs/module" +require "json" begin require "execjs"