def test_it_should_parse_a_nested_mapping_with_weirdly_nested_list(self): text = textwrap.dedent(""" foo: - bar blah: boo """) result = self.parser.parse(text) ensure(result.as_data()).equals( OrderedDict([ (get_text_source(text, 'foo'), get_text_source(text, '- bar')), (get_text_source(text, 'blah'), get_text_source(text, 'boo')), ]))
def test_it_should_parse_a_simple_mapping(self): text = textwrap.dedent(""" foo: bar baz: boo """) result = self.parser.parse(text) ensure(result.as_data()).equals( OrderedDict([ (get_text_source(text, 'foo'), get_text_source(text, 'bar')), (get_text_source(text, 'baz'), get_text_source(text, 'boo')), ]))
def test_it_should_parse_a_list_with_multiline_values(self): text = textwrap.dedent(""" - foo - bar baz """) result = self.parser.parse(text) ensure(result.as_data()).equals([ get_text_source(text, 'foo'), get_text_source(text, 'bar\n baz', 'bar\nbaz', 'bar\nbaz') ])
def test_it_should_parse_a_simple_list(self): text = textwrap.dedent(""" - foo - bar - baz """) result = self.parser.parse(text) ensure(result.as_data()).equals([ get_text_source(text, 'foo'), get_text_source(text, 'bar'), get_text_source(text, 'baz'), ])
def test_it_should_parse_mixed_boolean_values(self): text = textwrap.dedent(""" - foo - yes - false """) result = self.parser.parse(text) ensure(result.as_data()).equals([ get_text_source(text, 'foo'), get_text_source(text, 'yes', value=True), get_text_source(text, 'false', value=False), ])
def test_it_should_represent_itself_nicely(self): text = textwrap.dedent(""" - foo - bar - baz """) source = utils.get_text_source(text, 'foo', filename='foo.txt') (ensure(repr(source)) .equals("foo.txt, Line 2, Column 2 (index 3): 'foo' ('foo')"))
def test_it_should_parse_a_nested_list_with_mapping(self): text = textwrap.dedent(""" - foo: - bar - baz - blah: boo """) result = self.parser.parse(text) ensure(result.as_data()).equals([ OrderedDict([ (get_text_source(text, 'foo'), [ get_text_source(text, 'bar'), get_text_source(text, 'baz'), ]), ]), OrderedDict([ (get_text_source(text, 'blah'), get_text_source(text, 'boo')), ]), ])
def test_it_should_parse_comments_and_blanks(self): text = textwrap.dedent(""" # A comment - foo: - bar # Something else entirely - baz - blah: boo # not a comment! """) result = self.parser.parse(text) ensure(result.as_data()).equals([ OrderedDict([ (get_text_source(text, 'foo'), [ get_text_source(text, 'bar'), get_text_source(text, 'baz'), ]), ]), OrderedDict([(get_text_source(text, 'blah'), get_text_source(text, 'boo # not a comment!'))]), ])
def test_it_should_parse_a_list_with_embedded_mappings_values(self): text = textwrap.dedent(""" - foo: bar - baz: boo blah: baloon """) result = self.parser.parse(text) ensure(result.as_data()).equals([ { get_text_source(text, 'foo'): get_text_source(text, 'bar') }, { get_text_source(text, 'baz'): get_text_source(text, 'boo'), get_text_source(text, 'blah'): get_text_source(text, 'baloon') }, ])
def test_it_should_parse_a_simple_text_value(self): text = textwrap.dedent("yes") result = self.parser.parse(text) ensure(result.as_data()).equals(get_text_source(text, 'yes'), )
def source(text): return get_text_source(text, text)