-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from guineawheek/fix_cpp_int_literals
Allow int literals to be separated with single quotes
- Loading branch information
Showing
2 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Note: testcases generated via `python -m cxxheaderparser.gentest` | ||
|
||
from cxxheaderparser.types import ( | ||
FundamentalSpecifier, | ||
NameSpecifier, | ||
PQName, | ||
Token, | ||
Type, | ||
Value, | ||
Variable, | ||
) | ||
from cxxheaderparser.simple import ( | ||
Include, | ||
NamespaceScope, | ||
Pragma, | ||
parse_string, | ||
ParsedData, | ||
) | ||
|
||
|
||
def test_numeric_literals() -> None: | ||
content = """ | ||
#pragma once | ||
#include <cstdint> | ||
int test_binary = 0b01'10'01; | ||
int test_decimal = 123'456'789u; | ||
int test_octal = 012'42'11l; | ||
""" | ||
data = parse_string(content, cleandoc=True) | ||
|
||
assert data == ParsedData( | ||
namespace=NamespaceScope( | ||
variables=[ | ||
Variable( | ||
name=PQName(segments=[NameSpecifier(name="test_binary")]), | ||
type=Type( | ||
typename=PQName(segments=[FundamentalSpecifier(name="int")]) | ||
), | ||
value=Value(tokens=[Token(value="0b01'10'01")]), | ||
), | ||
Variable( | ||
name=PQName(segments=[NameSpecifier(name="test_decimal")]), | ||
type=Type( | ||
typename=PQName(segments=[FundamentalSpecifier(name="int")]) | ||
), | ||
value=Value(tokens=[Token(value="123'456'789u")]), | ||
), | ||
Variable( | ||
name=PQName(segments=[NameSpecifier(name="test_octal")]), | ||
type=Type( | ||
typename=PQName(segments=[FundamentalSpecifier(name="int")]) | ||
), | ||
value=Value(tokens=[Token(value="012'42'11l")]), | ||
), | ||
] | ||
), | ||
pragmas=[Pragma(content=Value(tokens=[Token(value="once")]))], | ||
includes=[Include(filename="<cstdint>")], | ||
) |