Exemple #1
0
def test_badly_behaved_lists():
    p = parser("""1,2
3,4""")
    eq_(p.data, [[1, 2], [3, 4]])

    p = parser("""a:
               1, 2
               3""")
    eq_(p.data['a'], [[1, 2], 3])
Exemple #2
0
def test_badly_behaved_lists():
    p = parser("""1,2
3,4""")
    eq_(p.data, [[1, 2], [3, 4]])

    p = parser("""a:
               1, 2
               3""")
    eq_(p.data['a'], [[1, 2], 3])
Exemple #3
0
def test_comma_lists():
    p = parser('1, yes, no, 8, "5435", nil, 766')
    eq_(p.data, [1, True, False, 8, "5435", None, 766])

    p = parser('1, 2, 3')
    eq_(p.data, [1, 2, 3])

    p = parser("a: 1, 2, 3")
    eq_(p.data['a'], [1, 2, 3])

    p = parser("a: 1.1, 2.2, 3.3")
    eq_(p.data['a'], [1.1, 2.2, 3.3])
Exemple #4
0
def test_comma_lists():
    p = parser('1, yes, no, 8, "5435", nil, 766')
    eq_(p.data, [1, True, False, 8, "5435", None, 766])

    p = parser('1, 2, 3')
    eq_(p.data, [1, 2, 3])

    p = parser("a: 1, 2, 3")
    eq_(p.data['a'], [1, 2, 3])

    p = parser("a: 1.1, 2.2, 3.3")
    eq_(p.data['a'], [1.1, 2.2, 3.3])
Exemple #5
0
def test_object_list():
    p = parser("""a:
               -
               b: 1
               c: 2
               --
               b: 1.1
               c: 2.2
               --
               b: 'one'
               c: 'two'
               -
d: 3
""")

    eq_(p.data['a'], [{
        'b': 1,
        'c': 2
    }, {
        'b': 1.1,
        'c': 2.2
    }, {
        'b': 'one',
        'c': 'two'
    }])
    eq_(p.data['d'], 3)
Exemple #6
0
def test_empty_lists():
    p = parser("--")
    eq_(p.data, [])

    p = parser("1\n--\n3")
    eq_(p.data, [1, [], 3])

    p = parser("a: --")
    eq_(p.data['a'], [])

    p = parser(r"""a:
               1
               2,3
               --
               'hello'""")
    eq_(p.data['a'], [1, [2,3], [], "hello"])
Exemple #7
0
def test_init():
    p = parser('a: 1')

    eq_(p.num_tokens, 4)
    eq_(p._cur_position, 0)
    assert p._finished is False
    assert p._data is None
Exemple #8
0
def test_empty_lists():
    p = parser("--")
    eq_(p.data, [])

    p = parser("1\n--\n3")
    eq_(p.data, [1, [], 3])

    p = parser("a: --")
    eq_(p.data['a'], [])

    p = parser(r"""a:
               1
               2,3
               --
               'hello'""")
    eq_(p.data['a'], [1, [2, 3], [], "hello"])
Exemple #9
0
def test_init():
    p = parser('a: 1')

    eq_(p.num_tokens, 4)
    eq_(p._cur_position, 0)
    assert p._finished is False
    assert p._data is None
Exemple #10
0
def test_object_lists():
    p = parser('''-
               a: 2
               b:2
               --
               c:1
               t:7
               -''')
    eq_(p.data, [{'a':2, 'b':2}, {'c':1, 't':7}])
Exemple #11
0
def test_object_lists():
    p = parser('''-
               a: 2
               b:2
               --
               c:1
               t:7
               -''')
    eq_(p.data, [{'a': 2, 'b': 2}, {'c': 1, 't': 7}])
Exemple #12
0
def test_newline_lists():
    p = parser('''1
2
3''')
    eq_(p.data, [1, 2, 3])

    p = parser(r"""a:
"one"
"two"
"three"
               """)
    eq_(p.data['a'], ["one", "two", "three"])

    p = parser(r"""a:
"one"
2
3.3""")
    eq_(p.data['a'], ["one", 2, 3.3])
Exemple #13
0
def test_newline_lists():
    p = parser('''1
2
3''')
    eq_(p.data, [1, 2, 3])

    p = parser(r"""a:
"one"
"two"
"three"
               """)
    eq_(p.data['a'], ["one", "two", "three"])

    p = parser(r"""a:
"one"
2
3.3""")
    eq_(p.data['a'], ["one", 2, 3.3])
Exemple #14
0
def test_nested_lists():
    p = parser(r"""1
2
3
    4
    5
6""")
    eq_(p.data, [1, 2, 3, [4, 5], 6])

    p = parser(r"""a:
    1
    2
        3
        4
    5""")
    eq_(p.data['a'], [1, 2, [3, 4], 5])

    p = parser(r"""a:
    1
    2, 3, 4
    5""")
    eq_(p.data['a'], [1, [2, 3, 4], 5])
Exemple #15
0
def test_nested_lists():
    p = parser(r"""1
2
3
    4
    5
6""")
    eq_(p.data, [1, 2, 3, [4, 5], 6])

    p = parser(r"""a:
    1
    2
        3
        4
    5""")
    eq_(p.data['a'], [1, 2, [3, 4], 5])

    p = parser(r"""a:
    1
    2, 3, 4
    5""")
    eq_(p.data['a'], [1, [2, 3, 4], 5])
Exemple #16
0
def test_key_val():
    p = parser(r"""
# a comment
a: 1
b: -1.23e-9
c: yes
d: no
e: nil
f: "a 'string'"
g: 'a different "string"'
""")

    eq_(p.data, {
        'a': 1, 'b': -1.23e-9, 'c': True, 'd': False, 'e': None,
        'f': "a 'string'", 'g': 'a different "string"',
    })
Exemple #17
0
def test_object_list():
    p = parser("""a:
               -
               b: 1
               c: 2
               --
               b: 1.1
               c: 2.2
               --
               b: 'one'
               c: 'two'
               -
d: 3
""")

    eq_(p.data['a'], [{'b': 1, 'c': 2}, {'b': 1.1, 'c': 2.2}, {'b': 'one', 'c': 'two'}])
    eq_(p.data['d'], 3)
Exemple #18
0
def test_key_val():
    p = parser(r"""
# a comment
a: 1
b: -1.23e-9
c: yes
d: no
e: nil
f: "a 'string'"
g: 'a different "string"'
""")

    eq_(
        p.data, {
            'a': 1,
            'b': -1.23e-9,
            'c': True,
            'd': False,
            'e': None,
            'f': "a 'string'",
            'g': 'a different "string"',
        })
Exemple #19
0
def test_nested_obect():
    p = parser("""a:
    b:
        c: 1
        d:2
    e:
        f:3
        g: 4""")

    d = {
        'a': {
            'b': {
                'c': 1,
                'd': 2,
            },
            'e': {
                'f': 3,
                'g': 4,
            },
        },
    }

    eq_(p.data, d)
Exemple #20
0
def test_nested_obect():
    p = parser("""a:
    b:
        c: 1
        d:2
    e:
        f:3
        g: 4""")

    d = {
        'a': {
            'b': {
                'c': 1,
                'd': 2,
            },
            'e': {
                'f': 3,
                'g': 4,
            },
        },
    }

    eq_(p.data, d)
Exemple #21
0
def test_only_literals():
    p = parser('1')
    eq_(p.data, 1)

    p = parser('-4.76E-9')
    eq_(p.data, -4.76E-9)

    p = parser('yes')
    eq_(p.data, True)

    p = parser('no')
    eq_(p.data, False)

    p = parser('nil')
    eq_(p.data, None)

    p = parser(r'''"'a' \"string\""''')
    eq_(p.data, """'a' "string\"""")
Exemple #22
0
def test_only_literals():
    p = parser('1')
    eq_(p.data, 1)

    p = parser('-4.76E-9')
    eq_(p.data, -4.76E-9)

    p = parser('yes')
    eq_(p.data, True)

    p = parser('no')
    eq_(p.data, False)

    p = parser('nil')
    eq_(p.data, None)

    p = parser(r'''"'a' \"string\""''')
    eq_(p.data, """'a' "string\"""")
Exemple #23
0
def test_types():
    p = parser('a: -1')
    assert isinstance(p.data['a'], int)
    eq_(p.data['a'], -1)

    p = parser('a: -123.456e-9')
    assert isinstance(p.data['a'], float)
    eq_(p.data['a'], -123.456e-9)

    p = parser('a: yes')
    assert p.data['a'] is True

    p = parser('a: no')
    assert p.data['a'] is False

    p = parser('a: nil')
    assert p.data['a'] is None

    p = parser(r'''a: "one 'kind' \"of\" string"''')
    eq_(p.data['a'], r"""one 'kind' "of" string""")

    p = parser(r"""a: 'a different \'kind\' "of" string'""")
    eq_(p.data['a'], r"""a different 'kind' "of" string""")
Exemple #24
0
def test_types():
    p = parser('a: -1')
    assert isinstance(p.data['a'], int)
    eq_(p.data['a'], -1)

    p = parser('a: -123.456e-9')
    assert isinstance(p.data['a'], float)
    eq_(p.data['a'], -123.456e-9)

    p = parser('a: yes')
    assert p.data['a'] is True

    p = parser('a: no')
    assert p.data['a'] is False

    p = parser('a: nil')
    assert p.data['a'] is None

    p = parser(r'''a: "one 'kind' \"of\" string"''')
    eq_(p.data['a'], r"""one 'kind' "of" string""")

    p = parser(r"""a: 'a different \'kind\' "of" string'""")
    eq_(p.data['a'], r"""a different 'kind' "of" string""")
Exemple #25
0
def test_singlevalue_list():
    p = parser('a: 1,')
    eq_(p.data['a'], [1])
Exemple #26
0
def test_complex_structure():
    p = parser("""bands:
	# Some people hate them some love them
	-
	name: "La Dispute"
	active: yes
	genre: "Post-Hardcore", "Progressive-Rock"
	albumCount: 3
	members:
		-
		name: "Jordan Dreyer"
		role: "Vocalist"
		--
		name: "Brad Vander Lugt"
		role: "Drummer"
		--
		name: "Chad Sterenberg"
		role: "Guitarist"
		--
		name: "Adam Vass"
		role: "Bass Guitarist"
		-
	--

	# I saw them live in Berlin. It was an
	# amazing concert!
	name: "Muse"
	active: yes
	genre: "Alternative Rock", "New Prog"
	members:
		-
		name: "Matthew Bellamy"
		role:
			"Vocalist"
			"Guitarist"
			"Pianist"
		--
		name: "Dominic Howard"
		role: "Drummer"
		--
		name: "Christopher Wolstenholme"
		role: "Bass Guitarist"
		-
	-""")

    d = {
        'bands': [
            {
                'name':
                "La Dispute",
                'active':
                True,
                'genre': ["Post-Hardcore", "Progressive-Rock"],
                'albumCount':
                3,
                'members': [
                    {
                        'name': "Jordan Dreyer",
                        'role': "Vocalist",
                    },
                    {
                        'name': "Brad Vander Lugt",
                        'role': "Drummer",
                    },
                    {
                        'name': "Chad Sterenberg",
                        'role': "Guitarist",
                    },
                    {
                        'name': "Adam Vass",
                        'role': "Bass Guitarist",
                    },
                ],
            },
            {
                'name':
                "Muse",
                'active':
                True,
                'genre': ["Alternative Rock", "New Prog"],
                'members': [
                    {
                        'name': "Matthew Bellamy",
                        'role': ["Vocalist", "Guitarist", "Pianist"],
                    },
                    {
                        'name': "Dominic Howard",
                        'role': "Drummer",
                    },
                    {
                        'name': "Christopher Wolstenholme",
                        'role': "Bass Guitarist",
                    },
                ],
            },
        ],
    }

    eq_(p.data, d)
Exemple #27
0
def test_complex_structure():
    p = parser("""bands:
	# Some people hate them some love them
	-
	name: "La Dispute"
	active: yes
	genre: "Post-Hardcore", "Progressive-Rock"
	albumCount: 3
	members:
		-
		name: "Jordan Dreyer"
		role: "Vocalist"
		--
		name: "Brad Vander Lugt"
		role: "Drummer"
		--
		name: "Chad Sterenberg"
		role: "Guitarist"
		--
		name: "Adam Vass"
		role: "Bass Guitarist"
		-
	--

	# I saw them live in Berlin. It was an
	# amazing concert!
	name: "Muse"
	active: yes
	genre: "Alternative Rock", "New Prog"
	members:
		-
		name: "Matthew Bellamy"
		role:
			"Vocalist"
			"Guitarist"
			"Pianist"
		--
		name: "Dominic Howard"
		role: "Drummer"
		--
		name: "Christopher Wolstenholme"
		role: "Bass Guitarist"
		-
	-""")

    d = {
        'bands': [
            {
                'name': "La Dispute",
                'active': True,
                'genre': ["Post-Hardcore", "Progressive-Rock"],
                'albumCount': 3,
                'members': [
                    {
                        'name': "Jordan Dreyer",
                        'role': "Vocalist",
                    },
                    {
                        'name': "Brad Vander Lugt",
                        'role': "Drummer",
                    },
                    {
                        'name': "Chad Sterenberg",
                        'role': "Guitarist",
                    },
                    {
                        'name': "Adam Vass",
                        'role': "Bass Guitarist",
                    },
                ],
            },
            {
                'name': "Muse",
                'active': True,
                'genre': ["Alternative Rock", "New Prog"],
                'members': [
                    {
                        'name': "Matthew Bellamy",
                        'role': ["Vocalist", "Guitarist", "Pianist"],
                    },
                    {
                        'name': "Dominic Howard",
                        'role': "Drummer",
                    },
                    {
                        'name': "Christopher Wolstenholme",
                        'role': "Bass Guitarist",
                    },
                ],
            },
        ],
    }

    eq_(p.data, d)
Exemple #28
0
def test_singlevalue_list():
    p = parser('a: 1,')
    eq_(p.data['a'], [1])