예제 #1
0
def test_bool_deserialize():
    assert loads('true')
    assert loads('   true   ')
    assert loads(' # comment\n true # comment')
    assert not loads('false')
    assert not loads('   false   ')
    assert not loads(' # comment\n false # comment')
예제 #2
0
def test_string_with_unicode_symbols_deserialize():
    assert loads('"ΑΒΓΔ"') == 'ΑΒΓΔ'    # Greek
    assert loads('"АБВГ"') == 'АБВГ'    # Cyrillic
    assert loads('"אבגד"') == 'אבגד'    # Hebrew

    assert loads('"\\u0391\\u0392\\u0393\\u0394"') == '\u0391\u0392\u0393\u0394'    # Greek
    assert loads('"\\u0410\\u0411\\u0412\\u0413"') == '\u0410\u0411\u0412\u0413'    # Cyrillic
    # with lowercase hexadecimal symbols
    assert loads('"\\u05d0\\u05d1\\u05d2\\u05d3"') == '\u05d0\u05d1\u05d2\u05d3'    # Hebrew
    # with uppercase hexadecimal symbols
    assert loads('"\\u05D0\\u05D1\\u05D2\\u05D3"') == '\u05D0\u05D1\u05D2\u05D3'
예제 #3
0
def test_string_deserialize():
    assert loads('"Testing"') == 'Testing'
    assert loads('   "Testing"   ') == 'Testing'
    assert loads(' # comment\n "Testing" # comment') == 'Testing'
    # the following assert test escape symbols "\" \\ \/ \b \f \n \r \t"
    assert loads(' # comment\n "\\" \\\\ \\/ \\b \\f \\n \\r \\t" # comment') == '" \\ / \b \f \n \r \t'
예제 #4
0
def test_float_number_deserialize():
    assert loads('5.0') == 5.0
    assert loads('  5.0  ') == 5.0
    assert loads('5e1') == 50.0
    assert loads('  -0.5e1  ') == -5.0
    assert loads(' # comment\n  -0.5e1  # comment') == -5.0
예제 #5
0
def test_int_number_deserialize():
    assert loads('5') == 5
    assert loads(' 5 ') == 5
    assert loads('-17') == -17
    assert loads(' -17 ') == -17
    assert loads(' # comment\n  -17  # comment') == -17
예제 #6
0
def test_null_deserialize():
    assert loads('null') is None
    assert loads('   null   ') is None
    assert loads(' # comment\n null # comment') is None
예제 #7
0
def test_object_without_comma_separator_deserialize():
    obj = loads(' # comment\n{\n  "one": 1  # comment\n  "two": [1 2 3] "three": false  # comment\n} ')
    assert obj.get('one') == 1
    assert obj.get('two') == [1, 2, 3]
    assert not obj.get('three')
    assert len(obj.keys()) == 3
예제 #8
0
def test_object_with_comma_separator_deserialize():
    obj = loads(' # comment\n{\n  "one": 1, # comment\n  "two": { "inner": [1, 2, 3] } # comment\n} ')
    assert obj.get('one') == 1
    assert obj.get('two').get("inner") == [1, 2, 3]
    assert len(obj.keys()) == 2
예제 #9
0
def test_array_without_comma_separator_deserialize():
    assert loads(" [1 2 3] ") == [1, 2, 3]
    assert loads('["string" 17 null [true false]]') == ["string", 17, None, [True, False]]
    assert loads(' # comment\n [ # comment\n"string"\n17\n# comment\n'
                 'null\n[\ntrue\nfalse\n]\n ] ') == ["string", 17, None, [True, False]]
예제 #10
0
def test_array_with_comma_separator_deserialize():
    assert loads(" [1,2,3] ") == [1, 2, 3]
    assert loads("[[[[[[[[[[1, 2, 3]]]]]]]]]]") == [[[[[[[[[[1, 2, 3]]]]]]]]]]
    assert loads('["string", 17, null, [true, false]]') == ["string", 17, None, [True, False]]
    assert loads(' # comment\n [ # comment\n "string" , 17 , # comment\n'
                 'null , \n[\n true,\nfalse\n]\n]') == ["string", 17, None, [True, False]]