TeX and CSS tweaks.
Sync with latest Instiki Trunk (Updates Rails to 1.2.2)
This commit is contained in:
parent
0ac586ee25
commit
c358389f25
443 changed files with 24218 additions and 9823 deletions
50
vendor/rails/activesupport/test/json.rb
vendored
50
vendor/rails/activesupport/test/json.rb
vendored
|
@ -1,6 +1,4 @@
|
|||
$:.unshift File.dirname(__FILE__) + '/../lib'
|
||||
require 'active_support'
|
||||
require 'test/unit'
|
||||
require File.dirname(__FILE__) + '/abstract_unit'
|
||||
|
||||
class Foo
|
||||
def initialize(a, b)
|
||||
|
@ -14,15 +12,13 @@ class TestJSONEmitters < Test::Unit::TestCase
|
|||
NilTests = [[ nil, %(null) ]]
|
||||
NumericTests = [[ 1, %(1) ],
|
||||
[ 2.5, %(2.5) ]]
|
||||
|
||||
|
||||
StringTests = [[ 'this is the string', %("this is the string") ],
|
||||
[ 'a "string" with quotes', %("a \\"string\\" with quotes") ]]
|
||||
|
||||
|
||||
ArrayTests = [[ ['a', 'b', 'c'], %([\"a\", \"b\", \"c\"]) ],
|
||||
[ [1, 'a', :b, nil, false], %([1, \"a\", \"b\", null, false]) ]]
|
||||
|
||||
HashTests = [[ {:a => :b, :c => :d}, %({\"c\": \"d\", \"a\": \"b\"}) ]]
|
||||
|
||||
|
||||
SymbolTests = [[ :a, %("a") ],
|
||||
[ :this, %("this") ],
|
||||
[ :"a b", %("a b") ]]
|
||||
|
@ -31,7 +27,7 @@ class TestJSONEmitters < Test::Unit::TestCase
|
|||
|
||||
VariableTests = [[ ActiveSupport::JSON::Variable.new('foo'), 'foo'],
|
||||
[ ActiveSupport::JSON::Variable.new('alert("foo")'), 'alert("foo")']]
|
||||
RegexpTests = [[ /^a/, '/^a/' ], /^\w{1,2}[a-z]+/ix, '/^\\w{1,2}[a-z]+/ix']
|
||||
RegexpTests = [[ /^a/, '/^a/' ], [/^\w{1,2}[a-z]+/ix, '/^\\w{1,2}[a-z]+/ix']]
|
||||
|
||||
constants.grep(/Tests$/).each do |class_tests|
|
||||
define_method("test_#{class_tests[0..-6].downcase}") do
|
||||
|
@ -40,7 +36,25 @@ class TestJSONEmitters < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
unquote(false)
|
||||
end
|
||||
|
||||
def teardown
|
||||
unquote(true)
|
||||
end
|
||||
|
||||
def test_hash_encoding
|
||||
assert_equal %({\"a\": \"b\"}), { :a => :b }.to_json
|
||||
assert_equal %({\"a\": 1}), { 'a' => 1 }.to_json
|
||||
assert_equal %({\"a\": [1, 2]}), { 'a' => [1,2] }.to_json
|
||||
|
||||
sorted_json =
|
||||
'{' + {:a => :b, :c => :d}.to_json[1..-2].split(', ').sort.join(', ') + '}'
|
||||
assert_equal %({\"a\": \"b\", \"c\": \"d\"}), sorted_json
|
||||
end
|
||||
|
||||
def test_utf8_string_encoded_properly_when_kcode_is_utf8
|
||||
old_kcode, $KCODE = $KCODE, 'UTF8'
|
||||
assert_equal '"\\u20ac2.99"', '€2.99'.to_json
|
||||
|
@ -48,10 +62,26 @@ class TestJSONEmitters < Test::Unit::TestCase
|
|||
ensure
|
||||
$KCODE = old_kcode
|
||||
end
|
||||
|
||||
|
||||
def test_exception_raised_when_encoding_circular_reference
|
||||
a = [1]
|
||||
a << a
|
||||
assert_raises(ActiveSupport::JSON::CircularReferenceError) { a.to_json }
|
||||
end
|
||||
|
||||
def test_unquote_hash_key_identifiers
|
||||
values = {0 => 0, 1 => 1, :_ => :_, "$" => "$", "a" => "a", :A => :A, :A0 => :A0, "A0B" => "A0B"}
|
||||
assert_equal %({"a": "a", 0: 0, "_": "_", 1: 1, "$": "$", "A": "A", "A0B": "A0B", "A0": "A0"}), values.to_json
|
||||
unquote(true) { assert_equal %({a: "a", 0: 0, _: "_", 1: 1, $: "$", A: "A", A0B: "A0B", A0: "A0"}), values.to_json }
|
||||
end
|
||||
|
||||
protected
|
||||
def unquote(value)
|
||||
previous_value = ActiveSupport::JSON.unquote_hash_key_identifiers
|
||||
ActiveSupport::JSON.unquote_hash_key_identifiers = value
|
||||
yield if block_given?
|
||||
ensure
|
||||
ActiveSupport::JSON.unquote_hash_key_identifiers = previous_value if block_given?
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue