summaryrefslogtreecommitdiff
path: root/tests/test_cpp.py
blob: e847079d00343b7cc5179fcc2e6c8100edf516b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
"""
    CPP Tests
    ~~~~~~~~~

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

import pytest

from pygments.lexers import CppLexer, CLexer
from pygments.token import Token

from pygments.lexers import guess_lexer


@pytest.fixture(scope='module')
def lexer():
    yield CppLexer()


def test_good_comment(lexer):
    fragment = '/* foo */\n'
    tokens = [
        (Token.Comment.Multiline, '/* foo */'),
        (Token.Text, '\n'),
    ]
    assert list(lexer.get_tokens(fragment)) == tokens


def test_open_comment(lexer):
    fragment = '/* foo\n'
    tokens = [
        (Token.Comment.Multiline, '/* foo\n'),
    ]
    assert list(lexer.get_tokens(fragment)) == tokens

def test_guess_c_lexer():
    code = '''
    #include <stdio.h>
    #include <stdlib.h>

    int main(void);

    int main(void) {
        uint8_t x = 42;
        uint8_t y = x + 1;

        /* exit 1 for success! */
        return 1;
    }
    '''
    lexer = guess_lexer(code)
    assert isinstance(lexer, CLexer)