Add basic preprocessor test

This commit is contained in:
Dustin Spicuzza
2023-09-02 19:47:46 -04:00
parent 4ab7b3fd16
commit a60bb7fd18
3 changed files with 45 additions and 5 deletions

View File

@@ -0,0 +1,27 @@
from cxxheaderparser.options import ParserOptions
from cxxheaderparser.preprocessor import make_pcpp_preprocessor
from cxxheaderparser.simple import NamespaceScope, ParsedData, parse_string
from cxxheaderparser.types import FundamentalSpecifier, NameSpecifier, PQName, Token, Type, Value, Variable
def test_basic_preprocessor() -> None:
content = """
#define X 1
int x = X;
"""
options = ParserOptions(preprocessor=make_pcpp_preprocessor())
data = parse_string(content, cleandoc=True, options=options)
assert data == ParsedData(
namespace=NamespaceScope(
variables=[
Variable(
name=PQName(segments=[NameSpecifier(name="x")]),
type=Type(
typename=PQName(segments=[FundamentalSpecifier(name="int")])
),
value=Value(tokens=[Token(value="1")]),
)
]
)
)