Skip to content

Commit 5b81cd2

Browse files
committed
More literal pattern testing
This adds another confirmation test, as part of the parse testing. When a parsing test is expected to succeed, and contains supported syntax, this checks that a round-tripped literal pattern maintains its identity.
1 parent 2d1ba4d commit 5b81cd2

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Tests/RegexTests/ParseTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ func parseTest(
118118
return
119119
}
120120
serializedCaptures.deallocate()
121+
122+
if !unsupported && expectedErrors.isEmpty,
123+
let pattern = Regex<AnyRegexOutput>(ast: ast)._literalPattern
124+
{
125+
let reparsedAST = parseWithRecovery(pattern, syntax)
126+
let roundtripPattern = Regex<AnyRegexOutput>(ast: ast)._literalPattern!
127+
XCTAssert(
128+
pattern == roundtripPattern,
129+
"""
130+
131+
Input: \(input)
132+
Pattern: \(pattern)
133+
Roundtrip: \(roundtripPattern)
134+
""",
135+
file: file, line: line)
136+
}
121137
}
122138

123139
/// Test delimiter lexing. Takes an input string that starts with a regex

0 commit comments

Comments
 (0)