Beispiel #1
0
    def test_simple1(self):
        self.maxDiff = None
        text = '''
fruits
  apple
  kiwi
'''
        expected = node(TDATA('root', 0))
        expected.ensure_path([TDATA('fruits', 2), TDATA('apple', 3)])
        expected.ensure_path([TDATA('fruits', 2), TDATA('kiwi', 4)])

        self.assertMultiLineEqual(
            expected.to_string(data_func=self._data_func), self._parse(text))
Beispiel #2
0
    def test_strip_quote_in_comments(self):
        self.maxDiff = None
        text = '''
fruits
  apple
  kiwi
###              fprintf(stderr, "Usage: cut.exe args\\n");
'''
        expected = node(TDATA('root', 0))
        expected.ensure_path([TDATA('fruits', 2), TDATA('apple', 3)])
        expected.ensure_path([TDATA('fruits', 2), TDATA('kiwi', 4)])

        self.assertMultiLineEqual(
            expected.to_string(data_func=self._data_func),
            self._parse(text, strip_comments=True))
Beispiel #3
0
    def test_strip_comments(self):
        self.maxDiff = None
        text = '''
# comment
fruits # comment
  # comment
  apple
  # comment
  kiwi
# comment
'''
        expected = node(TDATA('root', 0))
        expected.ensure_path([TDATA('fruits', 3), TDATA('apple', 5)])
        expected.ensure_path([TDATA('fruits', 3), TDATA('kiwi', 7)])

        self.assertMultiLineEqual(
            expected.to_string(data_func=self._data_func),
            self._parse(text, strip_comments=True))
Beispiel #4
0
    def test_indent_tabs(self):
        text = '''
fruits
\t\tapple
\t\tberries
\t\t\tblueberries
\t\t\tstrawberries
\t\tmelons
\t\t\twatermelon
cheeses
\t\tparmessan
\t\tasiago
'''
        expected = node(TDATA('root', 0))
        expected.ensure_path([TDATA('fruits', 2), TDATA('apple', 3)])
        expected.ensure_path(
            [TDATA('fruits', 2),
             TDATA('berries', 4),
             TDATA('blueberries', 5)])
        expected.ensure_path([
            TDATA('fruits', 2),
            TDATA('berries', 4),
            TDATA('strawberries', 6)
        ])
        expected.ensure_path(
            [TDATA('fruits', 2),
             TDATA('melons', 7),
             TDATA('watermelon', 8)])
        expected.ensure_path([TDATA('cheeses', 9), TDATA('parmessan', 10)])
        expected.ensure_path([TDATA('cheeses', 9), TDATA('asiago', 11)])

        self.assertMultiLineEqual(str(expected), self._parse(text))
Beispiel #5
0
    def test_simple2(self):
        self.maxDiff = None
        text = '''
fruits
  apple
  berries
    blueberries
    strawberries
  melons
    watermelon
cheeses
  parmessan
  asiago
'''
        expected = node(TDATA('root', 0))
        expected.ensure_path([TDATA('fruits', 2), TDATA('apple', 3)])
        expected.ensure_path(
            [TDATA('fruits', 2),
             TDATA('berries', 4),
             TDATA('blueberries', 5)])
        expected.ensure_path([
            TDATA('fruits', 2),
            TDATA('berries', 4),
            TDATA('strawberries', 6)
        ])
        expected.ensure_path(
            [TDATA('fruits', 2),
             TDATA('melons', 7),
             TDATA('watermelon', 8)])
        expected.ensure_path([TDATA('cheeses', 9), TDATA('parmessan', 10)])
        expected.ensure_path([TDATA('cheeses', 9), TDATA('asiago', 11)])

        self.assertMultiLineEqual(
            expected.to_string(data_func=self._data_func), self._parse(text))