Exemplo n.º 1
0
 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')),
         ]))
Exemplo n.º 2
0
 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')),
         ]))
Exemplo n.º 3
0
 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')
     ])
Exemplo n.º 4
0
 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'),
     ])
Exemplo n.º 5
0
 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),
     ])
Exemplo n.º 6
0
 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')"))
Exemplo n.º 7
0
 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')),
         ]),
     ])
Exemplo n.º 8
0
    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!'))]),
        ])
Exemplo n.º 9
0
 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')
         },
     ])
Exemplo n.º 10
0
 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'), )
Exemplo n.º 11
0
def source(text):
    return get_text_source(text, text)