Skip to content

Commit 6f252ec

Browse files
hamishknightmeg-gupta
authored andcommitted
[test] Split ASTGen tests
1 parent f0eadcb commit 6f252ec

File tree

3 files changed

+136
-88
lines changed

3 files changed

+136
-88
lines changed

test/ASTGen/verify-parse.swift renamed to test/ASTGen/decls.swift

Lines changed: 8 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -41,73 +41,31 @@ async
4141
throws
4242
->
4343
Int {
44-
let
45-
xx = fn(42)
46-
47-
let arlit = [0]
48-
let tuple = (0, 1)
49-
let diclit = [0: 1, 2: 3]
50-
51-
return fn(x)
52-
}
53-
54-
func testEmptyDictionary() -> [Int: Int] {
55-
return [:]
56-
}
57-
58-
func test2(e b: Bool) {
59-
if b
60-
{
61-
print(
62-
"TRUE"
63-
)
64-
}
65-
else
66-
{
67-
print("FALSE")
68-
}
69-
70-
let x =
71-
true
44+
return 0
7245
}
7346

74-
func test3(y: Int = 0, oi: Int? = nil) -> Int {
47+
func test2(y: Int = 0, oi: Int? = nil) -> Int {
7548
let x =
7649
y
7750
return x
7851
}
7952

80-
func test4(_ b: [Bool]) -> Int {
81-
if b.isEmpty { 0 } else {
82-
1
83-
}
84-
}
85-
86-
func test5(_ b: Swift.Bool) -> Int {
87-
return if b { 0 } else { 1 }
88-
}
89-
90-
func test6(_ b1: Bool, b2: Bool) -> Int {
91-
let x = if b1 { 0 } else if b2 { 1 } else { 2 }
92-
return x
93-
}
94-
95-
func test7(_ b: inout Bool) {
53+
func test3(_ b: inout Bool) {
9654
// b = true
9755
}
9856

99-
func test8(_ i: _const Int) {
57+
func test4(_ i: _const Int) {
10058
}
10159

102-
func test9(_ value: Any) { }
60+
func test5(_ value: Any) { }
10361

104-
func test10<T>(t: T) where T: Proto1 {}
62+
func test6<T>(t: T) where T: Proto1 {}
10563

106-
func test11() {
64+
func test7() {
10765
var binding1 = 0, binding2 = ""
10866
}
10967

110-
func test12(_: Int) {}
68+
func test8(_: Int) {}
11169

11270
func testVars() {
11371
var a = 0
@@ -305,7 +263,6 @@ operator
305263
postfix
306264
operator ⎩^-^⎩
307265

308-
309266
precedencegroup Precedence1 {
310267
}
311268

@@ -319,17 +276,6 @@ precedencegroup Precedence2 {
319276
struct TestStruct {
320277
func method(arg: Int, _ c: Int) {}
321278

322-
enum Ty {
323-
case `self`
324-
case `Self`
325-
}
326-
327-
func test() {
328-
_ = method(arg:_:)
329-
_ = self.method(arg:_:).self
330-
_ = Ty.`Self` == Ty.`self`
331-
}
332-
333279
// FIXME: Compute 'static' location
334280
// static var shared = TestStruct()
335281
// func testUnresolvedMember1() -> Self {
@@ -338,30 +284,4 @@ struct TestStruct {
338284
//
339285
// FIXME: Compute 'static' location
340286
// static func instance(arg: Int) -> TestStruct { return TestStruct() }
341-
// func testUnresolvedMember2() -> Self {
342-
// return .instance(arg:)(12)
343-
// }
344-
}
345-
346-
func testSequence(arg1: Int, arg2: () -> Int, arg3: Any) {
347-
_ = arg1 + arg2()
348-
_ = arg3 as? Int ?? 31 as Int
349-
_ = false ? arg2() : Int(1)
350-
_ = [() -> Int]()
351-
_ = [@Sendable () -> Int]().count + [any Collection]().count
352-
_ = arg3 is Double || !(arg3 is Int, 0).0
353-
}
354-
355-
func asyncFunc(_ arg: String) async throws -> Int {
356-
return 1
357-
}
358-
func testUnaryExprs() async throws {
359-
let str = String()
360-
let foo = try await asyncFunc(_borrow str)
361-
let bar = copy foo
362-
let baz = consume foo
363-
}
364-
365-
func testRepeatEach<each T>(_ t: repeat each T) -> (repeat each T) {
366-
return (repeat each t)
367287
}

test/ASTGen/exprs.swift

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
// RUN: %empty-directory(%t)
3+
// RUN: %target-swift-frontend %s -dump-parse -disable-availability-checking -enable-experimental-move-only -enable-experimental-feature ParserASTGen > %t/astgen.ast.raw
4+
// RUN: %target-swift-frontend %s -dump-parse -disable-availability-checking -enable-experimental-move-only > %t/cpp-parser.ast.raw
5+
6+
// Filter out any addresses in the dump, since they can differ.
7+
// RUN: sed -E 's#0x[0-9a-fA-F]+##g' %t/cpp-parser.ast.raw > %t/cpp-parser.ast
8+
// RUN: sed -E 's#0x[0-9a-fA-F]+##g' %t/astgen.ast.raw > %t/astgen.ast
9+
10+
// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast
11+
12+
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -enable-experimental-feature SwiftParser -enable-experimental-feature ParserASTGen)
13+
14+
// REQUIRES: executable_test
15+
// REQUIRES: swift_swift_parser
16+
17+
// -enable-experimental-feature requires an asserts build
18+
// REQUIRES: asserts
19+
// rdar://116686158
20+
// UNSUPPORTED: asan
21+
22+
// NB: Ridiculous formatting to test that we do not include leading trivia in locations.
23+
24+
func test1(x: Int, fn: (Int) -> Int) async throws -> Int {
25+
let
26+
xx = fn(42)
27+
28+
let y =
29+
true
30+
31+
let arlit = [0]
32+
let tuple = (0, 1)
33+
let diclit = [0: 1, 2: 3]
34+
35+
return fn(x)
36+
}
37+
38+
func test2(_ b: Swift.Bool) -> Int {
39+
return if b { 0 } else { 1 }
40+
}
41+
42+
func test3(_ b1: Bool, b2: Bool) -> Int {
43+
let x = if b1 { 0 } else if b2 { 1 } else { 2 }
44+
return x
45+
}
46+
47+
func test4(_ b: [Bool]) -> Int {
48+
if b.isEmpty { 0 } else {
49+
1
50+
}
51+
}
52+
53+
func testEmptyDictionary() -> [Int: Int] {
54+
return [:]
55+
}
56+
57+
enum Ty {
58+
case `self`
59+
case `Self`
60+
}
61+
62+
struct TestStruct {
63+
func method(arg: Int, _ c: Int) {}
64+
65+
func test() {
66+
_ = method(arg:_:)
67+
_ = self.method(arg:_:).self
68+
_ = Ty.`Self` == Ty.`self`
69+
}
70+
}
71+
72+
func testSequence(arg1: Int, arg2: () -> Int, arg3: Any) {
73+
_ = arg1 + arg2()
74+
_ = arg3 as? Int ?? 31 as Int
75+
_ = false ? arg2() : Int(1)
76+
_ = [() -> Int]()
77+
_ = [@Sendable () -> Int]().count + [any Collection]().count
78+
_ = arg3 is Double || !(arg3 is Int, 0).0
79+
}
80+
81+
func asyncFunc(_ arg: String) async throws -> Int {
82+
return 1
83+
}
84+
func testUnaryExprs() async throws {
85+
let str = String()
86+
let foo = try await asyncFunc(_borrow str)
87+
let bar = copy foo
88+
let baz = consume foo
89+
}
90+
91+
func testRepeatEach<each T>(_ t: repeat each T) -> (repeat each T) {
92+
return (repeat each t)
93+
}

test/ASTGen/stmts.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
// RUN: %empty-directory(%t)
3+
// RUN: %target-swift-frontend %s -dump-parse -disable-availability-checking -enable-experimental-move-only -enable-experimental-feature ParserASTGen > %t/astgen.ast.raw
4+
// RUN: %target-swift-frontend %s -dump-parse -disable-availability-checking -enable-experimental-move-only > %t/cpp-parser.ast.raw
5+
6+
// Filter out any addresses in the dump, since they can differ.
7+
// RUN: sed -E 's#0x[0-9a-fA-F]+##g' %t/cpp-parser.ast.raw > %t/cpp-parser.ast
8+
// RUN: sed -E 's#0x[0-9a-fA-F]+##g' %t/astgen.ast.raw > %t/astgen.ast
9+
10+
// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast
11+
12+
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking -enable-experimental-feature SwiftParser -enable-experimental-feature ParserASTGen)
13+
14+
// REQUIRES: executable_test
15+
// REQUIRES: swift_swift_parser
16+
17+
// -enable-experimental-feature requires an asserts build
18+
// REQUIRES: asserts
19+
// rdar://116686158
20+
// UNSUPPORTED: asan
21+
22+
// NB: Ridiculous formatting to test that we do not include leading trivia in locations.
23+
24+
func test1(e b: Bool) {
25+
if b
26+
{
27+
print(
28+
"TRUE"
29+
)
30+
}
31+
else
32+
{
33+
print("FALSE")
34+
}
35+
}

0 commit comments

Comments
 (0)