File: complete_stdlib_optional.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (140 lines) | stat: -rw-r--r-- 6,249 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=OPT_NO_DOT_1 > %t.opt.txt
// RUN: %FileCheck %s -check-prefix=OPT_NO_DOT_FOOSTRUCT < %t.opt.txt

// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=OPT_NO_DOT_2 > %t.opt.txt
// RUN: %FileCheck %s -check-prefix=OPT_NO_DOT_FOOSTRUCT < %t.opt.txt

// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=OPT_DOT_1 > %t.opt.txt
// RUN: %FileCheck %s -check-prefix=OPT_DOT_FOOSTRUCT < %t.opt.txt

// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=OPT_DOT_1_SPACES > %t.opt.txt
// RUN: %FileCheck %s -check-prefix=OPT_DOT_FOOSTRUCT_SPACES < %t.opt.txt

// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=OPT_DOT_2 > %t.opt.txt
// RUN: %FileCheck %s -check-prefix=OPT_DOT_FOOSTRUCT < %t.opt.txt

// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=UN_OPT_NO_DOT_1 > %t.opt.txt
// RUN: %FileCheck %s -check-prefix=UN_OPT_NO_DOT_FOOSTRUCT < %t.opt.txt

// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=UN_OPT_DOT_1 > %t.opt.txt
// RUN: %FileCheck %s -check-prefix=UN_OPT_DOT_FOOSTRUCT < %t.opt.txt

// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=UN_OPT_DOT_2 > %t.opt.txt
// RUN: %FileCheck %s -check-prefix=UN_OPT_DOT_FOOSTRUCT < %t.opt.txt

// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=UN_OPT_NO_DOT_2 > %t.opt.txt
// RUN: %FileCheck %s -check-prefix=UN_OPT_NO_DOT_FOOSTRUCT < %t.opt.txt

// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=OPT_TUPLE_1 | %FileCheck %s -check-prefix=OPT_TUPLE_1
// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=OPT_TUPLE_2 | %FileCheck %s -check-prefix=OPT_TUPLE_2
// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=OPT_TUPLE_3 | %FileCheck %s -check-prefix=OPT_TUPLE_3
// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=OPT_TUPLE_4 | %FileCheck %s -check-prefix=OPT_TUPLE_4
// RUN: %target-swift-ide-test -code-completion -source-filename %s -disable-objc-attr-requires-foundation-module -code-completion-token=OPT_TUPLE_5 | %FileCheck %s -check-prefix=OPT_TUPLE_5

//===---
//===--- Test code completion for stdlib Optional<T> type.
//===---

//===---
//===--- Helper types and functions that are used in this test.
//===---

struct FooStruct {
  var instanceVar: Int = 0
  func instanceFunc() {}
}

func returnsOptional() -> FooStruct? {
  return FooStruct()
}

func returnsImplicitlyUnwrappedOptional() -> FooStruct! {
  return FooStruct()
}

// OPT_NO_DOT_FOOSTRUCT-DAG: Decl[InstanceVar]/CurrNominal:    ?.instanceVar[#Int#]{{; name=.+$}}
// OPT_NO_DOT_FOOSTRUCT-DAG: Decl[InstanceMethod]/CurrNominal: ?.instanceFunc()[#Void#]{{; name=.+$}}

// OPT_DOT_FOOSTRUCT-DAG: Decl[InstanceVar]/CurrNominal/Erase[1]:    ?.instanceVar[#Int#]{{; name=.+$}}
// OPT_DOT_FOOSTRUCT-DAG: Decl[InstanceMethod]/CurrNominal/Erase[1]: ?.instanceFunc()[#Void#]{{; name=.+$}}

// OPT_DOT_FOOSTRUCT_SPACES-DAG: Decl[InstanceVar]/CurrNominal/Erase[3]:    ?.instanceVar[#Int#]{{; name=.+$}}
// OPT_DOT_FOOSTRUCT_SPACES-DAG: Decl[InstanceMethod]/CurrNominal/Erase[3]: ?.instanceFunc()[#Void#]{{; name=.+$}}

// UN_OPT_DOT_FOOSTRUCT-DAG: Decl[InstanceVar]/CurrNominal:    instanceVar[#Int#]{{; name=.+$}}
// UN_OPT_DOT_FOOSTRUCT-DAG: Decl[InstanceMethod]/CurrNominal: instanceFunc()[#Void#]{{; name=.+$}}


//===---
//===--- Tests.
//===---

func testOptionalVar1(a: FooStruct?) {
  a#^OPT_NO_DOT_1^#
}

func testOptionalVar2(a: FooStruct?) {
  a.#^OPT_DOT_1^#
}

func testOptionalVar3(a: FooStruct?) {
  a.  #^OPT_DOT_1_SPACES^#
}

func testImplicitlyUnwrappedOptionalVar1(a: FooStruct!) {
  a#^UN_OPT_NO_DOT_1^#
}

func testImplicitlyUnwrappedOptionalVar2(a: FooStruct!) {
  a.#^UN_OPT_DOT_1^#
}

func testOptionalReturnValue1() {
  returnsOptional()#^OPT_NO_DOT_2^#
}

func testOptionalReturnValue2() {
  returnsOptional().#^OPT_DOT_2^#
}

func testImplicitlyUnwrappedOptionalReturnValue1() {
  returnsImplicitlyUnwrappedOptional()#^UN_OPT_NO_DOT_2^#
}

func testImplicitlyUnwrappedOptionalReturnValue2() {
  returnsImplicitlyUnwrappedOptional().#^UN_OPT_DOT_2^#
}

func testOptionalTuple1(a: (Int, String)?) {
  a#^OPT_TUPLE_1^#
}
// OPT_TUPLE_1: Pattern/CurrNominal:                ?.0[#Int#]
// OPT_TUPLE_1: Pattern/CurrNominal:                ?.1[#String#]

func testOptionalTuple2(a: (Int, String)?) {
  a.#^OPT_TUPLE_2^#
}
// OPT_TUPLE_2: Pattern/CurrNominal/Erase[1]:       ?.0[#Int#]
// OPT_TUPLE_2: Pattern/CurrNominal/Erase[1]:       ?.1[#String#]

func testOptionalTuple3(a: (Int, String)?) {
  a?#^OPT_TUPLE_3^#
}
// OPT_TUPLE_3: Pattern/CurrNominal:                .0[#Int#]
// OPT_TUPLE_3: Pattern/CurrNominal:                .1[#String#]

func testOptionalTuple4(a: (x: Int, y: String)?) {
  a#^OPT_TUPLE_4^#
}
// OPT_TUPLE_4: Pattern/CurrNominal:                ?.x[#Int#]
// OPT_TUPLE_4: Pattern/CurrNominal:                ?.y[#String#]

func testOptionalTuple5(a: (x: Int, y: String)?) {
  a.#^OPT_TUPLE_5^#
}
// OPT_TUPLE_5: Pattern/CurrNominal/Erase[1]:       ?.x[#Int#]
// OPT_TUPLE_5: Pattern/CurrNominal/Erase[1]:       ?.y[#String#]

// UN_OPT_NO_DOT_FOOSTRUCT-DAG: Decl[InstanceVar]/CurrNominal:    .instanceVar[#Int#]{{; name=.+$}}
// UN_OPT_NO_DOT_FOOSTRUCT-DAG: Decl[InstanceMethod]/CurrNominal: .instanceFunc()[#Void#]{{; name=.+$}}