Skip to content

Commit 56de714

Browse files
committed
[ASTGen] Add some test cases for expression generation
1 parent e7a2102 commit 56de714

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

test/ASTGen/exprs.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ func testTrailingClsure() {
104104
acceptClosures(x: {}, y: { 12 }) {}
105105
}
106106

107+
func testInOut() {
108+
func acceptInOut(arg: inout Int) { arg += 1 }
109+
var value = 42
110+
acceptInOut(arg: &value)
111+
}
112+
107113
func testStringLiteral(arg: Int) {
108114
_ = "test"
109115
_ = "foo\(arg)bar"
@@ -129,3 +135,46 @@ func testStringLiteral(arg: Int) {
129135
baz
130136
"""
131137
}
138+
139+
func testNumberLiteral() {
140+
_ = 12
141+
_ = 1_2
142+
_ = 0xab
143+
_ = 0xab_p2
144+
_ = 12.42
145+
_ = 0b0000_1100_1000
146+
_ = 1_
147+
_ = 1_000
148+
_ = 0b1111_0000_
149+
_ = 0b1111_0000
150+
_ = 0o127_777_
151+
_ = 0o127_777
152+
_ = 0x12FF_FFFF
153+
_ = 0x12FF_FFFF_
154+
_ = 1.0e42
155+
_ = 0x1.0p0
156+
_ = 0x1.fffffep+2
157+
_ = 1_000.200_001e1_000
158+
_ = 0x1_0000.0FFF_ABCDp10_001
159+
}
160+
161+
class BaseCls {
162+
init(base: Int) {}
163+
}
164+
class DerivedCls: BaseCls {
165+
init(testSuperRef arg: Int) { super.init(base: arg) }
166+
}
167+
168+
struct HasSubscript {
169+
subscript(label label: Int, args: Int) -> Int { return 1 }
170+
}
171+
func testSubscript(intArry: [Int], val: HasSubscript) {
172+
_ = intArry[12]
173+
_ = val[label: 42, 14]
174+
}
175+
176+
struct Generic<T: Comparable> {}
177+
func testSpecializeExpr() {
178+
_ = Generic<Int>.self
179+
_ = Generic<Int>()
180+
}

test/ASTGen/regex.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -dump-parse -enable-bare-slash-regex -enable-experimental-feature ParserASTGen > %t/astgen.ast.raw
3+
// RUN: %target-swift-frontend %s -dump-parse -enable-bare-slash-regex > %t/cpp-parser.ast.raw
4+
5+
// Filter out any addresses in the dump, since they can differ.
6+
// RUN: sed -E 's#0x[0-9a-fA-F]+##g' %t/cpp-parser.ast.raw > %t/cpp-parser.ast
7+
// RUN: sed -E 's#0x[0-9a-fA-F]+##g' %t/astgen.ast.raw > %t/astgen.ast
8+
9+
// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast
10+
11+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ParserASTGen -enable-bare-slash-regex
12+
13+
// REQUIRES: swift_swift_parser
14+
15+
// -enable-experimental-feature requires an asserts build
16+
// REQUIRES: asserts
17+
// rdar://116686158
18+
// UNSUPPORTED: asan
19+
20+
func testRegexLiteral() {
21+
_ = /abc/
22+
_ = #/abc/#
23+
_ = ##/abc/##
24+
25+
func foo<T>(_ x: T...) {}
26+
foo(/abc/, #/abc/#, ##/abc/##)
27+
28+
let _ = [/abc/, #/abc/#, ##/abc/##]
29+
30+
_ = /\w+/.self
31+
_ = #/\w+/#.self
32+
_ = ##/\w+/##.self
33+
34+
_ = /#\/\#\\/
35+
_ = #/#/\/\#\\/#
36+
_ = ##/#|\|\#\\/##
37+
}
38+
39+

0 commit comments

Comments
 (0)