mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Merge branch 'fix_3303' into 'main'
mkenums: Allow , in a character literal Closes #3103 See merge request GNOME/glib!3676
This commit is contained in:
commit
74d786e8bf
@ -223,6 +223,8 @@ def parse_entries(file, file_name):
|
||||
(\w+)\s* # name
|
||||
(\s+[A-Z]+_(?:AVAILABLE|DEPRECATED)_ENUMERATOR_IN_[0-9_]+(?:_FOR\s*\(\s*\w+\s*\))?\s*)? # availability
|
||||
(?:=( # value
|
||||
\s*'[^']*'\s* # char
|
||||
| # OR
|
||||
\s*\w+\s*\(.*\)\s* # macro with multiple args
|
||||
| # OR
|
||||
(?:[^,/]|/(?!\*))* # anything but a comma or comment
|
||||
@ -728,6 +730,10 @@ def process_file(curfilename):
|
||||
# approximation to C constant folding
|
||||
inum = eval(num, {}, c_namespace)
|
||||
|
||||
# Support character literals
|
||||
if isinstance(inum, str) and len(inum) == 1:
|
||||
inum = ord(inum)
|
||||
|
||||
# make sure it parsed to an integer
|
||||
if not isinstance(inum, int):
|
||||
sys.exit("Unable to parse enum value '%s'" % num)
|
||||
|
@ -785,6 +785,32 @@ comment: {standard_bottom_comment}
|
||||
"7",
|
||||
)
|
||||
|
||||
def test_comma_in_enum_value(self):
|
||||
"""Test use of comma in enum value."""
|
||||
h_contents = """
|
||||
typedef enum {
|
||||
ENUM_VALUE_WITH_COMMA = ',',
|
||||
} TestCommaEnum;
|
||||
"""
|
||||
|
||||
result = self.runMkenumsWithHeader(h_contents)
|
||||
self.assertEqual("", result.err)
|
||||
self.assertSingleEnum(
|
||||
result,
|
||||
"TestCommaEnum",
|
||||
"test_comma_enum",
|
||||
"TEST_COMMA_ENUM",
|
||||
"COMMA_ENUM",
|
||||
"TEST",
|
||||
"",
|
||||
"enum",
|
||||
"Enum",
|
||||
"ENUM",
|
||||
"ENUM_VALUE_WITH_COMMA",
|
||||
"comma",
|
||||
44,
|
||||
)
|
||||
|
||||
|
||||
class TestRspMkenums(TestMkenums):
|
||||
"""Run all tests again in @rspfile mode"""
|
||||
|
Loading…
Reference in New Issue
Block a user