Пример #1
0
def test_empty_children():
    doc = parse('foo { }')
    assert len(doc[0].children) == 0
    assert str(doc) == 'foo'
    doc = parse('foo {}')
    assert len(doc[0].children) == 0
    assert str(doc) == 'foo'
Пример #2
0
def test_messy_identifiers():
    assert str(parse('struct :Mod')) == 'struct :Mod'
    assert str(
        parse('stringref<uint32>[:numFiles] :Files') ==
        'stringref<uint32>[:numFiles] :Files')
    assert str(
        parse('Placeable[:numPlaceables] :Placeables') ==
        'Placeable[:numPlaceables] :Placeables')
    assert str(
        parse('foo :obj:stringTable[:index...]') ==
        'foo :obj:stringTable[:index...]')
Пример #3
0
def test_bare_empty():
    doc = parse('bare')
    assert len(doc) == 1
    node = doc[0]
    assert node.name == 'bare'
    assert len(list(node)) == 0
    assert str(doc) == 'bare'
Пример #4
0
def test_bare_true_arg():
    doc = parse('bare true')
    assert len(doc) == 1
    node = doc[0]
    assert node.name == 'bare'
    assert len(list(node)) == 1
    assert node[0] == True
    assert str(doc) == 'bare true'
Пример #5
0
def test_bare_int_arg():
    doc = parse('bare 123')
    assert len(doc) == 1
    node = doc[0]
    assert node.name == 'bare'
    assert len(list(node)) == 1
    assert node[0] == 123
    assert str(doc) == 'bare 123'
Пример #6
0
def test_bare_hex_arg():
    doc = parse('bare 0xdeadbeef')
    assert len(doc) == 1
    node = doc[0]
    assert node.name == 'bare'
    assert len(list(node)) == 1
    assert node[0] == 0xdeadbeef
    assert str(doc) == 'bare 3735928559'
Пример #7
0
def test_bare_octal_arg():
    doc = parse('bare 0o1237')
    assert len(doc) == 1
    node = doc[0]
    assert node.name == 'bare'
    assert len(list(node)) == 1
    assert node[0] == 0o1237
    assert str(doc) == 'bare 671'
Пример #8
0
def test_bare_float_us_arg():
    doc = parse('bare 12_3.5')
    assert len(doc) == 1
    node = doc[0]
    assert node.name == 'bare'
    assert len(list(node)) == 1
    assert node[0] == 123.5
    assert str(doc) == 'bare 123.5'
Пример #9
0
def test_bare_null_arg():
    doc = parse('bare null')
    assert len(doc) == 1
    node = doc[0]
    assert node.name == 'bare'
    assert len(list(node)) == 1
    assert node[0] is None
    assert str(doc) == 'bare null'
Пример #10
0
def test_bare_false_arg():
    doc = parse('bare false')
    assert len(doc) == 1
    node = doc[0]
    assert node.name == 'bare'
    assert len(list(node)) == 1
    assert node[0] == False
    assert str(doc) == 'bare false'
Пример #11
0
def test_prop():
    doc = parse('bare foo="bar"')
    assert len(doc) == 1
    node = doc[0]
    assert node.name == 'bare'
    assert len(list(node)) == 1
    assert node['foo'] == 'bar'
    assert str(doc) == 'bare foo="bar"'
Пример #12
0
def test_bare_binary_us_arg():
    doc = parse('bare 0b1_010')
    assert len(doc) == 1
    node = doc[0]
    assert node.name == 'bare'
    assert len(list(node)) == 1
    assert node[0] == 0b1010
    assert str(doc) == 'bare 10'
Пример #13
0
def test_commented_child():
    doc = parse('bare { foo; /-bar; baz; }')
    assert len(doc) == 1
    node = doc[0]
    assert node.name == 'bare'
    assert len(list(node)) == 2
    assert node.children[0].name == 'foo'
    assert node.children[1].name == 'baz'
    assert str(doc) == '''bare {
Пример #14
0
def test_from_file():
	os.chdir(os.path.dirname(__file__))
	with open('complex.kdl', 'r') as fp:
		doc = parse(fp)
	if sys.version_info.major == 3:
		with open('complex_formatted.kdl', 'r', encoding='utf-8') as fp:
			assert fp.read() == str(doc)
	else:
		with open('complex_formatted.kdl', 'r') as fp:
			assert fp.read().decode('utf-8') == str(doc)
Пример #15
0
def test_deep_raw_string_name():
    doc = parse('r####"name\\goes\\here"####')
    assert len(doc) == 1
    assert doc[0].name == 'name\\goes\\here'
    assert str(doc) == 'r#"name\\goes\\here"#'
Пример #16
0
def test_bare_deep_raw_string_symbol():
    doc = parse('bare :r####"name\\goes\\here"####')
    assert len(doc) == 1
    assert doc[0][0] == Symbol('name\\goes\\here')
    assert str(doc) == 'bare :r#"name\\goes\\here"#'
Пример #17
0
def test_bare_string_symbol():
    doc = parse('bare :"name goes here"')
    assert len(doc) == 1
    assert doc[0][0] == Symbol('name goes here')
    assert str(doc) == 'bare :"name goes here"'
Пример #18
0
def test_symbol_comparison():
    assert parse('bare :foo')[0][0] == Symbol('foo')
    assert parse('bare :foo')[0][0] == 'foo'
    assert parse('bare :foo')[0][0] != Symbol('bar')
    assert parse('bare :foo')[0][0] != 'bar'
Пример #19
0
def test_bare_plain_symbol():
    assert str(parse('bare :foo') == 'bare :foo')
    assert str(parse('bare :"foo"') == 'bare :foo')
    assert str(parse('bare :r#"foo"#') == 'bare :foo')
Пример #20
0
def test_short_identifier():
    assert str(parse('T') == 'T')
Пример #21
0
def test_commented_empty():
    doc = parse('/-bare')
    assert len(doc) == 0
    assert str(doc) == ''
Пример #22
0
def test_unicode_string():
    assert unicode(parse(u'foo "☜(゚ヮ゚☜)"')) == u'foo "☜(゚ヮ゚☜)"'
Пример #23
0
def test_unicode():
    assert unicode(parse(u'ノード お名前="☜(゚ヮ゚☜)"')) == u'ノード お名前="☜(゚ヮ゚☜)"'
Пример #24
0
def test_unicode_ident():
    assert unicode(parse(u'ノード')) == u'ノード'
Пример #25
0
def test_unicode_prop_ident():
    assert unicode(parse(u'foo お名前=5')) == u'foo お名前=5'
Пример #26
0
def test_commented_args():
    doc = parse('/-bare 1234 "foo"')
    assert len(doc) == 0
    assert str(doc) == ''
Пример #27
0
def test_unicode_ws():
    assert str(parse(u'foo\u3000:bar')) == 'foo :bar'
    assert str(parse(u'foo :bar')) == 'foo :bar'
Пример #28
0
def test_plain_ident():
    assert str(parse('"foo"')) == 'foo'
    assert str(parse('r#"foo"#')) == 'foo'
Пример #29
0
def test_commented_with_children():
    doc = parse('/-bare { }')
    assert len(doc) == 0
    assert str(doc) == ''
Пример #30
0
def test_string_name():
    doc = parse('"name goes here"')
    assert len(doc) == 1
    assert doc[0].name == 'name goes here'
    assert str(doc) == '"name goes here"'