| 1 |
import pytest |
| 2 |
|
| 3 |
from cxxheaderparser.lexer import PlyLexer, LexerTokenStream |
| 4 |
from cxxheaderparser.tokfmt import tokfmt |
| 5 |
from cxxheaderparser.types import Token |
| 6 |
|
| 7 |
|
| 8 |
@pytest.mark.parametrize( |
| 9 |
"instr", |
| 10 |
[ |
| 11 |
"int", |
| 12 |
"unsigned int", |
| 13 |
"::uint8_t", |
| 14 |
"void *", |
| 15 |
"void * *", |
| 16 |
"const char *", |
| 17 |
"const char[]", |
| 18 |
"void * (*)()", |
| 19 |
"void (*)(void * buf, int buflen)", |
| 20 |
"void (* fnType)(void * buf, int buflen)", |
| 21 |
"TypeName<int, void>& x", |
| 22 |
"vector<string>&", |
| 23 |
"std::vector<Pointer *> *", |
| 24 |
"Alpha::Omega", |
| 25 |
"Convoluted::Nested::Mixin", |
| 26 |
"std::function<void ()>", |
| 27 |
"std::shared_ptr<std::function<void (void)>>", |
| 28 |
"tr1::shared_ptr<SnailTemplateClass<SnailNamespace::SnailClass>>", |
| 29 |
"std::map<unsigned, std::pair<unsigned, SnailTemplateClass<SnailNamespace::SnailClass>>>", |
| 30 |
"std::is_base_of<std::random_access_iterator_tag, IteratorCategoryT>::value", |
| 31 |
"const char&&", |
| 32 |
"something<T, U>{1, 2, 3}", |
| 33 |
"operator-=", |
| 34 |
"operator[]", |
| 35 |
"operator*", |
| 36 |
"operator>=", |
| 37 |
], |
| 38 |
) |
| 39 |
def test_tokfmt(instr: str) -> None: |
| 40 |
""" |
| 41 |
Each input string is exactly what the output of tokfmt should be |
| 42 |
""" |
| 43 |
toks = [] |
| 44 |
lexer = PlyLexer("") |
| 45 |
lexer.input(instr) |
| 46 |
|
| 47 |
while True: |
| 48 |
tok = lexer.token() |
| 49 |
if not tok: |
| 50 |
break |
| 51 |
|
| 52 |
if tok.type not in LexerTokenStream._discard_types: |
| 53 |
toks.append(Token(tok.value, tok.type)) |
| 54 |
|
| 55 |
assert tokfmt(toks) == instr |