Пример #1
0
    def test_multiline_comment(self):
        """Multi-line spans should close at the end of one line and reopen at
        the beginning of the next."""
        c = Region('c')
        c2 = Region('c')
        l = LINE
        tags = [(0, True, c),
                (79, False, c),
                (80, False, l),

                (80, True, c2),
                (151, False, l),

                (222, False, l),

                (284, False, c2),
                (285, False, l),

                (286, False, l)]
        text = u"""/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"""
        eq_(list(html_lines(balanced_tags(tags), text.__getslice__)),
            ['<span class="c">/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */</span>',
             '<span class="c">/* This Source Code Form is subject to the terms of the Mozilla Public</span>',
             '<span class="c"> * License, v. 2.0. If a copy of the MPL was not distributed with this</span>',
             '<span class="c"> * file, You can obtain one at http://mozilla.org/MPL/2.0/. */</span>',
             ''])
Пример #2
0
 def test_coincident(self):
     """We shouldn't emit pointless empty tags when tempted to."""
     tags = sorted(tags_from_text("a _____\n" "b _____\n" "c _____\n"), key=nesting_order)
     eq_(
         spaced_tags(balanced_tags(tags)),
         "<L>\n" "<a>\n" "<b>\n" "<c>\n" "    </c>\n" "    </b>\n" "    </a>\n" "    </L>",
     )
Пример #3
0
 def test_coincident_ends(self):
     """We shouldn't emit empty tags even when coincidently-ending tags
     don't start together."""
     # These Regions aren't in startpoint order. That makes tags_from_test()
     # instantiate them in a funny order, which makes them sort in the wrong
     # order, which is realistic.
     tags = sorted(tags_from_text('d      _______\n'
                                  'c    _________\n'
                                  'b  ___________\n'
                                  'a ____________\n'
                                  'e     ___________\n'), key=nesting_order)
     eq_(spaced_tags(balanced_tags(tags)),
         '<L>\n'
         '<a>\n'
         ' <b>\n'
         '   <c>\n'
         '    <e>\n'
         '     <d>\n'
         '           </d>\n'
         '           </e>\n'
         '           </c>\n'
         '           </b>\n'
         '           </a>\n'
         '           <e>\n'
         '              </e>\n'
         '              </L>')
Пример #4
0
 def test_coincident_ends(self):
     """We shouldn't emit empty tags even when coincidently-ending tags
     don't start together."""
     # These Regions aren't in startpoint order. That makes tags_from_test()
     # instantiate them in a funny order, which makes them sort in the wrong
     # order, which is realistic.
     tags = sorted(tags_from_text('d      _______\n'
                                  'c    _________\n'
                                  'b  ___________\n'
                                  'a ____________\n'
                                  'e     ___________\n'),
                   key=nesting_order)
     eq_(
         spaced_tags(balanced_tags(tags)), '<L>\n'
         '<a>\n'
         ' <b>\n'
         '   <c>\n'
         '    <e>\n'
         '     <d>\n'
         '           </d>\n'
         '           </e>\n'
         '           </c>\n'
         '           </b>\n'
         '           </a>\n'
         '           <e>\n'
         '              </e>\n'
         '              </L>')
Пример #5
0
 def test_coincident(self):
     """We shouldn't emit pointless empty tags when tempted to."""
     tags = sorted(tags_from_text('a _____\n'
                                  'b _____\n'
                                  'c _____\n'), key=nesting_order)
     eq_(spaced_tags(balanced_tags(tags)),
         '<L>\n'
         '<a>\n'
         '<b>\n'
         '<c>\n'
         '    </c>\n'
         '    </b>\n'
         '    </a>\n'
         '    </L>')
Пример #6
0
    def test_horrors(self):
        """Try a fairly horrific scenario::

            A _______________            (0, 7)
            B     _________              (2, 6)
            C           ____________     (5, 9)
            D                    _______ (8, 11)
            E                         __ (10, 11)
              0   2     5 6 7    8 9

        A contains B. B closes while C's still going on. D and E end at the
        same time. There's even a Region in there.

        """
        a, b, c, d, e = Ref("a"), Region("b"), Ref("c"), Ref("d"), Ref("e")
        tags = [
            (0, True, a),
            (2, True, b),
            (5, True, c),
            (6, False, b),
            (7, False, a),
            (8, True, d),
            (9, False, c),
            (10, True, e),
            (11, False, e),
            (11, False, d),
        ]

        eq_(
            spaced_tags(balanced_tags(tags)),
            "<L>\n"
            "<a>\n"
            "  <b>\n"
            "     <c>\n"
            "      </c>\n"
            "      </b>\n"
            "      <c>\n"
            "       </c>\n"
            "       </a>\n"
            "       <c>\n"
            "        <d>\n"
            "         </d>\n"
            "         </c>\n"
            "         <d>\n"
            "          <e>\n"
            "           </e>\n"
            "           </d>\n"
            "           </L>",
        )
Пример #7
0
 def test_coincident(self):
     """We shouldn't emit pointless empty tags when tempted to."""
     tags = sorted(tags_from_text('a _____\n'
                                  'b _____\n'
                                  'c _____\n'),
                   key=nesting_order)
     eq_(
         spaced_tags(balanced_tags(tags)), '<L>\n'
         '<a>\n'
         '<b>\n'
         '<c>\n'
         '    </c>\n'
         '    </b>\n'
         '    </a>\n'
         '    </L>')
Пример #8
0
    def test_multiline_comment(self):
        """Multi-line spans should close at the end of one line and reopen at
        the beginning of the next."""
        c = Region('c')
        c2 = Region('c')
        l = LINE
        tags = [(0, True, c), (79, False, c), (80, False, l), (80, True, c2),
                (151, False, l), (222, False, l), (284, False, c2),
                (285, False, l), (286, False, l)]
        text = u"""/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"""
        eq_(list(html_lines(balanced_tags(tags), text.__getslice__)), [
            '<span class="c">/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */</span>',
            '<span class="c">/* This Source Code Form is subject to the terms of the Mozilla Public</span>',
            '<span class="c"> * License, v. 2.0. If a copy of the MPL was not distributed with this</span>',
            '<span class="c"> * file, You can obtain one at http://mozilla.org/MPL/2.0/. */</span>',
            ''
        ])
Пример #9
0
    def test_horrors(self):
        """Try a fairly horrific scenario::

            A _______________            (0, 7)
            B     _________              (2, 6)
            C           ____________     (5, 9)
            D                    _______ (8, 11)
            E                         __ (10, 11)
              0   2     5 6 7    8 9

        A contains B. B closes while C's still going on. D and E end at the
        same time. There's even a Region in there.

        """
        a, b, c, d, e = Ref('a'), Region('b'), Ref('c'), Ref('d'), Ref('e')
        tags = [(0, True, a), (2, True, b), (5, True, c), (6, False, b),
                (7, False, a), (8, True, d), (9, False, c), (10, True, e),
                (11, False, e), (11, False, d)]

        eq_(
            spaced_tags(balanced_tags(tags)), '<L>\n'
            '<a>\n'
            '  <b>\n'
            '     <c>\n'
            '      </c>\n'
            '      </b>\n'
            '      <c>\n'
            '       </c>\n'
            '       </a>\n'
            '       <c>\n'
            '        <d>\n'
            '         </d>\n'
            '         </c>\n'
            '         <d>\n'
            '          <e>\n'
            '           </e>\n'
            '           </d>\n'
            '           </L>')
Пример #10
0
 def test_empty(self):
     """Some files are empty. Make sure they work."""
     eq_(list(balanced_tags([])), [])
Пример #11
0
 def test_empty(self):
     """Some files are empty. Make sure they work."""
     eq_(list(balanced_tags([])), [])