Skip to content

Commit 784e36b

Browse files
ahoppenhamishknight
authored andcommitted
Import regex parsing tests from test/StringProcessing/Parse
1 parent ced4443 commit 784e36b

9 files changed

+3680
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// This test file has been translated from swift/test/StringProcessing/Parse/forward-slash-regex-disabled.swift
2+
3+
import XCTest
4+
5+
final class ForwardSlashRegexDisabledTests: XCTestCase {
6+
func testForwardSlashRegexDisabled1() {
7+
AssertParse(
8+
"""
9+
prefix operator /
10+
prefix operator ^/
11+
prefix operator /^/
12+
"""
13+
)
14+
}
15+
16+
func testForwardSlashRegexDisabled2() {
17+
AssertParse(
18+
"""
19+
precedencegroup P {
20+
associativity: left
21+
}
22+
"""
23+
)
24+
}
25+
26+
func testForwardSlashRegexDisabled3() {
27+
AssertParse(
28+
"""
29+
// The divisions in the body of the below operators make sure we don't try and
30+
// consider them to be ending delimiters of a regex.
31+
infix operator /^/ : P
32+
func /^/ (lhs: Int, rhs: Int) -> Int { 1 / 2 }
33+
"""
34+
)
35+
}
36+
37+
func testForwardSlashRegexDisabled4() {
38+
AssertParse(
39+
"""
40+
infix operator /^ : P
41+
func /^ (lhs: Int, rhs: Int) -> Int { 1 / 2 }
42+
"""
43+
)
44+
}
45+
46+
func testForwardSlashRegexDisabled5() {
47+
AssertParse(
48+
"""
49+
infix operator ^^/ : P
50+
func ^^/ (lhs: Int, rhs: Int) -> Int { 1 / 2 }
51+
"""
52+
)
53+
}
54+
55+
func testForwardSlashRegexDisabled6() {
56+
AssertParse(
57+
"""
58+
_ = #/x/#
59+
"""
60+
)
61+
}
62+
63+
func testForwardSlashRegexDisabled7() {
64+
AssertParse(
65+
"""
66+
_ = /x/
67+
""",
68+
diagnostics: [
69+
// TODO: Old parser expected error on line 1: '/' is not a prefix unary operator
70+
// TODO: Old parser expected error on line 1: cannot find 'x' in scope
71+
// TODO: Old parser expected error on line 1: '/' is not a postfix unary operator
72+
]
73+
)
74+
}
75+
76+
func testForwardSlashRegexDisabled8() {
77+
AssertParse(
78+
"""
79+
func baz(_ x: (Int, Int) -> Int, _ y: (Int, Int) -> Int) {}
80+
"""
81+
)
82+
}
83+
84+
func testForwardSlashRegexDisabled9() {
85+
AssertParse(
86+
"""
87+
baz(/, /)
88+
baz(/^, /)
89+
baz(^^/, /)
90+
"""
91+
)
92+
}
93+
94+
}
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// This test file has been translated from swift/test/StringProcessing/Parse/forward-slash-regex-skipping-allowed.swift
2+
3+
import XCTest
4+
5+
final class ForwardSlashRegexSkippingAllowedTests: XCTestCase {
6+
func testForwardSlashRegexSkippingAllowed1() {
7+
AssertParse(
8+
"""
9+
// Make sure we can skip in all of the below cases.
10+
"""
11+
)
12+
}
13+
14+
func testForwardSlashRegexSkippingAllowed2() {
15+
AssertParse(
16+
#"""
17+
// The printing implementation differs in asserts and no-asserts builds, it will
18+
// either print `"Parse.NumFunctionsParsed" 0` or not print it at all. Make sure
19+
// we don't output any non-zero value.
20+
// CHECK-NOT: {{"Parse.NumFunctionsParsed" [^0]}}
21+
"""#
22+
)
23+
}
24+
25+
func testForwardSlashRegexSkippingAllowed3() {
26+
AssertParse(
27+
"""
28+
// Ensures there is a parse error
29+
var 1️⃣: Int
30+
""",
31+
diagnostics: [
32+
// TODO: Old parser expected error on line 2: expected pattern
33+
DiagnosticSpec(message: "expected pattern in variable"),
34+
]
35+
)
36+
}
37+
38+
func testForwardSlashRegexSkippingAllowed4() {
39+
AssertParse(
40+
"""
41+
// Balanced `{}`, so okay.
42+
func a() { 1️⃣/ {}/ }
43+
""",
44+
diagnostics: [
45+
DiagnosticSpec(message: "unexpected code '/ {}/' in function"),
46+
]
47+
)
48+
}
49+
50+
func testForwardSlashRegexSkippingAllowed5() {
51+
AssertParse(
52+
#"""
53+
func b() { 1️⃣/ \{}/ }
54+
"""#,
55+
diagnostics: [
56+
DiagnosticSpec(message: #"unexpected code '/ \{}/' in function"#),
57+
]
58+
)
59+
}
60+
61+
func testForwardSlashRegexSkippingAllowed6() {
62+
AssertParse(
63+
#"""
64+
func c() { 1️⃣/ {"{"}/ }
65+
"""#,
66+
diagnostics: [
67+
DiagnosticSpec(message: #"unexpected code '/ {"{"}/' in function"#),
68+
]
69+
)
70+
}
71+
72+
func testForwardSlashRegexSkippingAllowed7() {
73+
AssertParse(
74+
"""
75+
// Some cases of infix '/' that we should continue to skip.
76+
func d() {
77+
_ = 1 / 2 + 3 * 4
78+
_ = 1 / 2 / 3 / 4
79+
}
80+
"""
81+
)
82+
}
83+
84+
func testForwardSlashRegexSkippingAllowed8() {
85+
AssertParse(
86+
#"""
87+
func e() {
88+
let arr = [1, 2, 3]
89+
_ = arr.reduce(0, /) / 2
90+
func foo(_ i: Int, _ fn: () -> Void) {}
91+
foo(1 / 2 / 3, { print("}}}{{{") })
92+
}
93+
"""#
94+
)
95+
}
96+
97+
func testForwardSlashRegexSkippingAllowed9() {
98+
AssertParse(
99+
"""
100+
// Some cases of prefix '/' that we should continue to skip.
101+
prefix operator /
102+
prefix func / <T> (_ x: T) -> T { x }
103+
"""
104+
)
105+
}
106+
107+
func testForwardSlashRegexSkippingAllowed10() {
108+
AssertParse(
109+
"""
110+
enum E {
111+
case e
112+
func foo<T>(_ x: T) {}
113+
}
114+
"""
115+
)
116+
}
117+
118+
func testForwardSlashRegexSkippingAllowed11() {
119+
AssertParse(
120+
"""
121+
func f() {
122+
_ = /E.e
123+
(/E.e).foo(/0)
124+
func foo<T, U>(_ x: T, _ y: U) {}
125+
foo(/E.e, /E.e)
126+
foo((/E.e), /E.e)
127+
foo((/)(E.e), /E.e)
128+
func bar<T>(_ x: T) -> Int { 0 }
129+
_ = bar(/E.e) / 2
130+
}
131+
"""
132+
)
133+
}
134+
135+
func testForwardSlashRegexSkippingAllowed12() {
136+
AssertParse(
137+
"""
138+
postfix operator /
139+
prefix func / <T> (_ x: T) -> T { x }
140+
"""
141+
)
142+
}
143+
144+
func testForwardSlashRegexSkippingAllowed13() {
145+
AssertParse(
146+
"""
147+
// Some cases of postfix '/' that we should continue to skip.
148+
func g() {
149+
_ = 0/
150+
_ = 0/ / 1/
151+
_ = 1/ + 1/
152+
_ = 1 + 2/
153+
}
154+
"""
155+
)
156+
}
157+
158+
}

0 commit comments

Comments
 (0)