Sha256: 011dd37885c5316159fd358f95049e9a4f2a3dc7ecfdcbd6c8b721e8a2911629

Contents?: true

Size: 1.56 KB

Versions: 6

Compression:

Stored size: 1.56 KB

Contents

require 'rubygems'
require 'spec'
dir = File.dirname(__FILE__)
require File.expand_path("#{dir}/spec_helper")
require File.expand_path("#{dir}/../lib/fjson")

context "String with UTF8 values when supporting unicode Json" do
  setup do
    JSON.support_unicode = true
    $KCODE = "UTF8"
  end

  specify "should format values between 0x00000080 and 0x000007ff" do
    val = [0x0080].pack("U")
    JSON.utf8_to_json(val).should_equal "\\u0080"

    val = [0x07ff].pack("U")
    JSON.utf8_to_json(val).should_equal "\\u07ff"
  end

  specify "should format values between 0x00001000 and 0x0000ffff" do
    val = [0x1000].pack("U")
    JSON.utf8_to_json(val).should_equal "\\u1000"

    val = [0xffff].pack("U")
    JSON.utf8_to_json(val).should_equal "\\uffff"
  end

  specify "should format values between 0x00010000 and 0x0010ffff" do
    val = [0x010000].pack("U")
    JSON.utf8_to_json(val).should_equal "\\ud800dc00"

    val = [0x10ffff].pack("U")
    JSON.utf8_to_json(val).should_equal "\\udbffdfff"
  end

  specify "should parse unicode values" do
    utf8 = '© ≠ €!'
    json = '"\u00a9 \u2260 \u20ac!"'
    utf8.to_json.should_equal json
    JSON.parse(json).should_equal utf8
    
    utf8 = "\343\201\202\343\201\204\343\201\206\343\201\210\343\201\212"
    json = '"\u3042\u3044\u3046\u3048\u304a"'
    utf8.to_json.should_equal json
    JSON.parse(json).should_equal utf8

    utf8 = 'საქართველო'
    json = '"\u10e1\u10d0\u10e5\u10d0\u10e0\u10d7\u10d5\u10d4\u10da\u10dd"'
    utf8.to_json.should_equal json
    JSON.parse(json).should_equal utf8
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fjson-0.0.3 spec/string_with_utf8_values_when_supporting_unicode_json_spec.rb
fjson-0.0.4 spec/string_with_utf8_values_when_supporting_unicode_json_spec.rb
fjson-0.0.5 spec/string_with_utf8_values_when_supporting_unicode_json_spec.rb
fjson-0.0.6 spec/string_with_utf8_values_when_supporting_unicode_json_spec.rb
fjson-0.0.7 spec/string_with_utf8_values_when_supporting_unicode_json_spec.rb
fjson-0.0.8 spec/string_with_utf8_values_when_supporting_unicode_json_spec.rb