Class: TC_JSONUnicode
- Includes:
- JSON
- Defined in:
- lib/crazy_ivan/vendor/json-1.1.7/tests/test_json_unicode.rb
Constant Summary
Constants included from JSON
JSON::Infinity, JSON::JSON_LOADED, JSON::MAP, JSON::MinusInfinity, JSON::NaN, JSON::UnparserError, JSON::VERSION, JSON::VERSION_ARRAY, JSON::VERSION_BUILD, JSON::VERSION_MAJOR, JSON::VERSION_MINOR
Instance Method Summary collapse
Methods included from JSON
[], deep_const_get, dump, fast_generate, generate, load, parse, parse!, pretty_generate, recurse_proc, swap!, utf8_to_json
Instance Method Details
#test_chars ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/crazy_ivan/vendor/json-1.1.7/tests/test_json_unicode.rb', line 41 def test_chars (0..0x7f).each do |i| json = '["\u%04x"]' % i if RUBY_VERSION >= "1.9." i = i.chr end assert_equal i, JSON.parse(json).first[0] if i == ?\b generated = JSON.generate(["" << i]) assert '["\b"]' == generated || '["\10"]' == generated elsif [?\n, ?\r, ?\t, ?\f].include?(i) assert_equal '[' << ('' << i).dump << ']', JSON.generate(["" << i]) elsif i.chr < 0x20.chr assert_equal json, JSON.generate(["" << i]) end end assert_raise(JSON::GeneratorError) do JSON.generate(["\x80"]) end assert_equal "\302\200", JSON.parse('["\u0080"]').first end |
#test_unicode ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/crazy_ivan/vendor/json-1.1.7/tests/test_json_unicode.rb', line 14 def test_unicode assert_equal '""', ''.to_json assert_equal '"\\b"', "\b".to_json assert_equal '"\u0001"', 0x1.chr.to_json assert_equal '"\u001f"', 0x1f.chr.to_json assert_equal '" "', ' '.to_json assert_equal "\"#{0x7f.chr}\"", 0x7f.chr.to_json utf8 = [ "© ≠ €! \01" ] json = '["\u00a9 \u2260 \u20ac! \u0001"]' assert_equal json, utf8.to_json assert_equal utf8, parse(json) utf8 = ["\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"] json = "[\"\\u3042\\u3044\\u3046\\u3048\\u304a\"]" assert_equal json, utf8.to_json assert_equal utf8, parse(json) utf8 = ['საქართველო'] json = "[\"\\u10e1\\u10d0\\u10e5\\u10d0\\u10e0\\u10d7\\u10d5\\u10d4\\u10da\\u10dd\"]" assert_equal json, utf8.to_json assert_equal utf8, parse(json) assert_equal '["\\u00c3"]', JSON.generate(["Ã"]) assert_equal ["€"], JSON.parse('["\u20ac"]') utf8 = ["\xf0\xa0\x80\x81"] json = '["\ud840\udc01"]' assert_equal json, JSON.generate(utf8) assert_equal utf8, JSON.parse(json) end |