Sha256: 275a803038745e8c2c704109fb747981e5c561d96bf25688f951ca946cb27ff5

Contents?: true

Size: 1.06 KB

Versions: 13

Compression:

Stored size: 1.06 KB

Contents

# -*- coding: utf-8 -*-
"""
    Pygments tests for using()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~

    :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import unittest

from pygments.lexer import using, bygroups, this, RegexLexer
from pygments.token import String, Text, Keyword

class TestLexer(RegexLexer):
    tokens = {
        'root': [
            (r'#.*',
             using(this, state='invalid')),
            (r'(")(.+?)(")',
             bygroups(String, using(this, state='string'), String)),
            (r'[^"]+', Text),
        ],
        'string': [
            (r'.+', Keyword),
        ],
    }


class UsingStateTest(unittest.TestCase):
    def test_basic(self):
        expected = [(Text, 'a'), (String, '"'), (Keyword, 'bcd'),
                    (String, '"'), (Text, 'e\n')]
        t = list(TestLexer().get_tokens('a"bcd"e'))
        self.assertEqual(t, expected)

    def test_error(self):
        def gen():
            return list(TestLexer().get_tokens('#a'))
        self.assertRaises(KeyError, gen)

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
mortar-pygments.rb-0.5.7 vendor/pygments-main/tests/test_using_api.py
mortar-pygments.rb-0.5.6 vendor/pygments-main/tests/test_using_api.py
mortar-pygments.rb-0.5.5 vendor/pygments-main/tests/test_using_api.py
pygments.rb-jruby-0.5.4.2 vendor/pygments-main/tests/test_using_api.py
pygments.rb-jruby-0.5.4.1 vendor/pygments-main/tests/test_using_api.py
pygments.rb-jruby-0.5.4 vendor/pygments-main/tests/test_using_api.py
gitlab-pygments.rb-0.5.4 vendor/pygments-main/tests/test_using_api.py
pygments.rb-0.5.4 vendor/pygments-main/tests/test_using_api.py
pygments.rb-0.5.2 vendor/pygments-main/tests/test_using_api.py
pygments.rb-0.5.1 vendor/pygments-main/tests/test_using_api.py
pygments.rb-0.5.0 vendor/pygments-main/tests/test_using_api.py
pygments.rb-0.4.2 vendor/pygments-main/tests/test_using_api.py
pygments.rb-0.4.1 vendor/pygments-main/tests/test_using_api.py