summaryrefslogtreecommitdiff
path: root/test/json
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-28 09:22:57 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-28 09:22:57 +0000
commit0cf0b824182fc643c4e295b7178b84e71fdded54 (patch)
treef8eb0bb1ca3effb41119a9e505395f6ba8003752 /test/json
parent6272cf8ecd8f4cd35af10aecf505f22b8244c56d (diff)
* ext/json, lib/json, test/json: Update to JSON 1.1.2.
(RubyForge#15447) * math.c: fix typo. -- M ChangeLog M math.c M ext/json/ext/generator/generator.c M ext/json/ext/parser/parser.rl M ext/json/ext/parser/parser.c M lib/json/version.rb M lib/json/editor.rb M lib/json/common.rb M lib/json/pure/parser.rb M test/json/test_json_unicode.rb M test/json/test_json_fixtures.rb M test/json/test_json_generate.rb M test/json/test_json_addition.rb M test/json/test_json.rb M test/json/runner.rb git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/json')
-rwxr-xr-xtest/json/runner.rb2
-rwxr-xr-xtest/json/test_json.rb1
-rwxr-xr-xtest/json/test_json_addition.rb57
-rwxr-xr-xtest/json/test_json_fixtures.rb1
-rw-r--r--test/json/test_json_generate.rb1
-rwxr-xr-xtest/json/test_json_unicode.rb1
6 files changed, 55 insertions, 8 deletions
diff --git a/test/json/runner.rb b/test/json/runner.rb
index 930fed7..91bc12a 100755
--- a/test/json/runner.rb
+++ b/test/json/runner.rb
@@ -8,6 +8,7 @@ require 'test_json'
require 'test_json_generate'
require 'test_json_unicode'
require 'test_json_addition'
+require 'test_json_rails'
require 'test_json_fixtures'
class TS_AllTests
@@ -17,6 +18,7 @@ class TS_AllTests
suite << TC_JSON.suite
suite << TC_JSONUnicode.suite
suite << TC_JSONAddition.suite
+ suite << TC_JSONRails.suite
suite << TC_JSONFixtures.suite
end
end
diff --git a/test/json/test_json.rb b/test/json/test_json.rb
index 2be7b4a..2325c10 100755
--- a/test/json/test_json.rb
+++ b/test/json/test_json.rb
@@ -7,7 +7,6 @@ class TC_JSON < Test::Unit::TestCase
include JSON
def setup
- $KCODE = 'UTF8'
@ary = [1, "foo", 3.14, 4711.0, 2.718, nil, [1,-2,3], false, true].map do
|x| [x]
end
diff --git a/test/json/test_json_addition.rb b/test/json/test_json_addition.rb
index e527f70..2ae0ce4 100755
--- a/test/json/test_json_addition.rb
+++ b/test/json/test_json_addition.rb
@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
require 'test/unit'
-require 'json'
+require 'json/add/core'
+require 'date'
class TC_JSONAddition < Test::Unit::TestCase
include JSON
@@ -23,7 +24,7 @@ class TC_JSONAddition < Test::Unit::TestCase
def to_json(*args)
{
- 'json_class' => self.class,
+ 'json_class' => self.class.name,
'args' => [ @a ],
}.to_json(*args)
end
@@ -32,12 +33,16 @@ class TC_JSONAddition < Test::Unit::TestCase
class B
def to_json(*args)
{
- 'json_class' => self.class,
+ 'json_class' => self.class.name,
}.to_json(*args)
end
end
class C
+ def self.json_creatable?
+ false
+ end
+
def to_json(*args)
{
'json_class' => 'TC_JSONAddition::Nix',
@@ -46,7 +51,6 @@ class TC_JSONAddition < Test::Unit::TestCase
end
def setup
- $KCODE = 'UTF8'
end
def test_extended_json
@@ -58,6 +62,21 @@ class TC_JSONAddition < Test::Unit::TestCase
assert_equal a, a_again
end
+ def test_extended_json_disabled
+ a = A.new(666)
+ assert A.json_creatable?
+ json = generate(a)
+ a_again = JSON.parse(json, :create_additions => true)
+ assert_kind_of a.class, a_again
+ assert_equal a, a_again
+ a_hash = JSON.parse(json, :create_additions => false)
+ assert_kind_of Hash, a_hash
+ assert_equal(
+ {"args"=>[666], "json_class"=>"TC_JSONAddition::A"}.sort_by { |k,| k },
+ a_hash.sort_by { |k,| k }
+ )
+ end
+
def test_extended_json_fail
b = B.new
assert !B.json_creatable?
@@ -91,4 +110,34 @@ EOT
raw_again = JSON.parse(json)
assert_equal raw, raw_again
end
+
+ def test_core
+ t = Time.now
+ assert_equal t, JSON(JSON(t))
+ d = Date.today
+ assert_equal d, JSON(JSON(d))
+ d = DateTime.civil(2007, 6, 14, 14, 57, 10, Rational(1, 12), 2299161)
+ assert_equal d, JSON(JSON(d))
+ assert_equal 1..10, JSON(JSON(1..10))
+ assert_equal 1...10, JSON(JSON(1...10))
+ assert_equal "a".."c", JSON(JSON("a".."c"))
+ assert_equal "a"..."c", JSON(JSON("a"..."c"))
+ struct = Struct.new 'MyStruct', :foo, :bar
+ s = struct.new 4711, 'foot'
+ assert_equal s, JSON(JSON(s))
+ struct = Struct.new :foo, :bar
+ s = struct.new 4711, 'foot'
+ assert_raises(JSONError) { JSON(s) }
+ begin
+ raise TypeError, "test me"
+ rescue TypeError => e
+ e_json = JSON.generate e
+ e_again = JSON e_json
+ assert_kind_of TypeError, e_again
+ assert_equal e.message, e_again.message
+ assert_equal e.backtrace, e_again.backtrace
+ end
+ assert_equal /foo/, JSON(JSON(/foo/))
+ assert_equal /foo/i, JSON(JSON(/foo/i))
+ end
end
diff --git a/test/json/test_json_fixtures.rb b/test/json/test_json_fixtures.rb
index 665dcbd..33573cd 100755
--- a/test/json/test_json_fixtures.rb
+++ b/test/json/test_json_fixtures.rb
@@ -5,7 +5,6 @@ require 'json'
class TC_JSONFixtures < Test::Unit::TestCase
def setup
- $KCODE = 'UTF8'
fixtures = File.join(File.dirname(__FILE__), 'fixtures/*.json')
passed, failed = Dir[fixtures].partition { |f| f['pass'] }
@passed = passed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
diff --git a/test/json/test_json_generate.rb b/test/json/test_json_generate.rb
index 82d8c3d..e720b2d 100644
--- a/test/json/test_json_generate.rb
+++ b/test/json/test_json_generate.rb
@@ -5,7 +5,6 @@ class TC_JSONGenerate < Test::Unit::TestCase
include JSON
def setup
- $KCODE = 'UTF8'
@hash = {
'a' => 2,
'b' => 3.141,
diff --git a/test/json/test_json_unicode.rb b/test/json/test_json_unicode.rb
index a91f4b5..9e0d762 100755
--- a/test/json/test_json_unicode.rb
+++ b/test/json/test_json_unicode.rb
@@ -7,7 +7,6 @@ class TC_JSONUnicode < Test::Unit::TestCase
include JSON
def setup
- $KCODE = 'UTF8'
end
def test_unicode