summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtests/test_json.rb32
1 files changed, 20 insertions, 12 deletions
diff --git a/tests/test_json.rb b/tests/test_json.rb
index 5d71d61..736c57b 100755
--- a/tests/test_json.rb
+++ b/tests/test_json.rb
@@ -9,6 +9,20 @@ else require 'json'
end
require 'stringio'
+unless Array.method_defined?(:permutation)
+ begin
+ require 'enumerator'
+ require 'permutation'
+ class Array
+ def permutation
+ Permutation.for(self).to_enum.map { |x| x.project }
+ end
+ end
+ rescue LoadError
+ warn "Skipping permutation tests."
+ end
+end
+
class TC_JSON < Test::Unit::TestCase
include JSON
@@ -94,30 +108,24 @@ class TC_JSON < Test::Unit::TestCase
assert_equal({ "a" => 0.23 }, parse(' { "a" : 0.23 } '))
end
- begin
- require 'permutation'
+ if Array.method_defined?(:permutation)
def test_parse_more_complex_arrays
a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
- perms = Permutation.for a
- perms.each do |perm|
- orig_ary = perm.project
- json = pretty_generate(orig_ary)
- assert_equal orig_ary, parse(json)
+ a.permutation.each do |perm|
+ json = pretty_generate(perm)
+ assert_equal perm, parse(json)
end
end
def test_parse_complex_objects
a = [ nil, false, true, "foßbar", [ "n€st€d", true ], { "nested" => true, "n€ßt€ð2" => {} }]
- perms = Permutation.for a
- perms.each do |perm|
+ a.permutation.each do |perm|
s = "a"
- orig_obj = perm.project.inject({}) { |h, x| h[s.dup] = x; s = s.succ; h }
+ orig_obj = perm.inject({}) { |h, x| h[s.dup] = x; s = s.succ; h }
json = pretty_generate(orig_obj)
assert_equal orig_obj, parse(json)
end
end
- rescue LoadError
- warn "Skipping permutation tests."
end
def test_parse_arrays