Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4795

Show
Ignore:
Timestamp:
08/20/06 17:27:28 (2 years ago)
Author:
madrobby
Message:

Fix unit tests for JSON emitters

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/test/json.rb

    r4595 r4795  
    2020                   [ [1, 'a', :b, nil, false], %([1, \"a\", \"b\", null, false]) ]] 
    2121 
    22   HashTests     = [[ {:a => :b, :c => :d}, %({\"c\": \"d\", \"a\": \"b\"}) ]] 
    23  
    2422  SymbolTests   = [[ :a,     %("a")    ], 
    2523                   [ :this,  %("this") ], 
     
    3028  VariableTests = [[ ActiveSupport::JSON::Variable.new('foo'), 'foo'], 
    3129                   [ ActiveSupport::JSON::Variable.new('alert("foo")'), 'alert("foo")']] 
    32   RegexpTests   = [[ /^a/, '/^a/' ], /^\w{1,2}[a-z]+/ix, '/^\\w{1,2}[a-z]+/ix'
     30  RegexpTests   = [[ /^a/, '/^a/' ], [/^\w{1,2}[a-z]+/ix, '/^\\w{1,2}[a-z]+/ix']
    3331 
    3432  constants.grep(/Tests$/).each do |class_tests| 
     
    3836      end 
    3937    end 
     38  end 
     39   
     40  def test_hash_encoding 
     41    assert_equal %({\"a\": \"b\"}), { :a => :b }.to_json 
     42    assert_equal %({\"a\": 1}), { 'a' => 1  }.to_json 
     43    assert_equal %({\"a\": [1, 2]}), { 'a' => [1,2] }.to_json 
     44     
     45    sorted_json  =  
     46      '{' + {:a => :b, :c => :d}.to_json[1..-2].split(', ').sort.join(', ') + '}' 
     47    assert_equal %({\"a\": \"b\", \"c\": \"d\"}), sorted_json 
    4048  end 
    4149