in Sources/SwiftSyntaxBuilder/gyb_helpers/SyntaxBuildableWrappers.py [0:0]
def generate_assert_stmt_text_choices(self, var_name):
"""
If this node is a token that can't contain arbitrary text, generate a Swift `assert` statement that verifies the variable with name var_name and of type `TokenSyntax` contains one of the supported text options.
Otherwise return `None`.
"""
if not self.type().is_token():
return None
if self.child.text_choices:
text_choices = self.child.text_choices
elif self.child.token_choices:
text_choices = [SYNTAX_TOKEN_MAP.get(token_choice.name + 'Token').text for token_choice in self.child.token_choices]
else:
return None
if None in text_choices:
# If None is in the text choices, one of the token options can contain arbitrary text.
# Don't generate an assert statement.
return None
assert_choices = []
if self.type().is_optional:
assert_choices.append('%s == nil' % var_name)
unwrap = '!' if self.type().is_optional else ''
for text_choice in text_choices:
assert_choices.append('%s%s.text == "%s"' % (var_name, unwrap, text_choice))
return 'assert(%s)' % ' || '.join(assert_choices)