forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenum.swift
181 lines (142 loc) · 5.95 KB
/
enum.swift
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-sil %s -verify
// -- Check that we can successfully round-trip.
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -D IRGEN -emit-ir %s >/dev/null
// REQUIRES: objc_interop
import Foundation
import user_objc
// NS_ENUM
var mince = NSRuncingMode.Mince
var quince = NSRuncingMode.Quince
var rawMince: UInt = NSRuncingMode.Mince.rawValue
var rawFoo: CInt = NSUnderlyingType.Foo.rawValue
var rawNegativeOne: CUnsignedInt
= NSUnsignedUnderlyingTypeNegativeValue.NegativeOne.rawValue
var rawWordBreakA: Int = NSPrefixWordBreak.Banjo.rawValue
var rawWordBreakB: Int = NSPrefixWordBreak.Bandana.rawValue
var rawWordBreak2A: Int = NSPrefixWordBreak2.BreakBarBas.rawValue
var rawWordBreak2B: Int = NSPrefixWordBreak2.BreakBareBass.rawValue
var rawWordBreak3A: Int = NSPrefixWordBreak3.Break1Bob.rawValue
var rawWordBreak3B: Int = NSPrefixWordBreak3.Break1Ben.rawValue
var singleConstant = NSSingleConstantEnum.Value
var myCoolWaterMelon = MyCoolEnum.WaterMelon
var hashMince: Int = NSRuncingMode.Mince.hashValue
if NSRuncingMode.Mince != .Quince { }
var numberBehavior: NSNumberFormatterBehavior = .BehaviorDefault
numberBehavior = .Behavior10_4
var postingStyle: NSPostingStyle = .PostWhenIdle
postingStyle = .PostASAP
func handler(formatter: NSByteCountFormatter) {
// Ensure that the Equality protocol is properly added to an
// imported ObjC enum type before the type is referenced by name
if (formatter.countStyle == .File) {}
}
// Unfortunate consequence of treating runs of capitals as a single word.
// See <rdar://problem/16768954>.
var pathStyle: CFURLPathStyle = .CFURLPOSIXPathStyle
pathStyle = .CFURLWindowsPathStyle
var URLOrUTI: CFURLOrUTI = .CFURLKind
URLOrUTI = .CFUTIKind
let magnitude: Magnitude = .k2
let magnitude2: MagnitudeWords = .Two
let objcABI: objc_abi = .v2
let underscoreSuffix: ALL_CAPS_ENUM = .ENUM_CASE_ONE
let underscoreSuffix2: ALL_CAPS_ENUM2 = .CASE_TWO
var alias1 = NSAliasesEnum.BySameValue
var alias2 = NSAliasesEnum.ByEquivalentValue
var alias3 = NSAliasesEnum.ByName
var aliasOriginal = NSAliasesEnum.Original
switch aliasOriginal {
case .Original:
break
case .DifferentValue:
break
}
switch aliasOriginal {
case .Original:
break
default:
break
}
switch aliasOriginal {
case .BySameValue:
break
case .DifferentValue:
break
}
switch aliasOriginal {
case .BySameValue:
break
default:
break
}
switch aliasOriginal {
case NSAliasesEnum.BySameValue:
break
case NSAliasesEnum.DifferentValue:
break
}
extension NSAliasesEnum {
func test() {
switch aliasOriginal {
case BySameValue:
break
case DifferentValue:
break
}
}
}
// Test NS_SWIFT_NAME:
_ = NSXMLNodeKind.DTDKind == .InvalidKind
_ = NSPrefixWordBreakCustom.ProblemCase == .DeprecatedGoodCase // expected-warning {{deprecated}}
_ = NSPrefixWordBreak2Custom.ProblemCase == .GoodCase
_ = NSPrefixWordBreak2Custom.ProblemCase == .PrefixWordBreak2DeprecatedBadCase // expected-warning {{deprecated}}
_ = NSPrefixWordBreak2Custom.ProblemCase == .DeprecatedGoodCase // expected-warning {{deprecated}}
_ = NSPrefixWordBreakReversedCustom.ProblemCase == .DeprecatedGoodCase // expected-warning {{deprecated}}
_ = NSPrefixWordBreakReorderedCustom.ProblemCase == .GoodCase
_ = NSPrefixWordBreakReorderedCustom.ProblemCase == .PrefixWordBreakReorderedDeprecatedBadCase // expected-warning {{deprecated}}
_ = NSPrefixWordBreakReorderedCustom.ProblemCase == .DeprecatedGoodCase // expected-warning {{deprecated}}
_ = NSPrefixWordBreakReordered2Custom.ProblemCase == .GoodCase
_ = NSPrefixWordBreakReordered2Custom.ProblemCase == .PrefixWordBreakReordered2DeprecatedBadCase // expected-warning {{deprecated}}
_ = NSPrefixWordBreakReordered2Custom.ProblemCase == .DeprecatedGoodCase // expected-warning {{deprecated}}
_ = NSSwiftNameAllTheThings.Foo == .Bar
_ = NSSwiftNameBad.`class`
#if !IRGEN
var qualifiedName = NSRuncingMode.Mince
var topLevelCaseName = NSRuncingMince // expected-error{{}}
#endif
// NS_OPTIONS
var withMince: NSRuncingOptions = .EnableMince
var withQuince: NSRuncingOptions = .EnableQuince
// When there is a single enum constant, compare it against the type name to
// derive the namespaced name.
var singleValue: NSSingleOptions = .Value
// Check OptionSetType conformance.
var minceAndQuince: NSRuncingOptions = NSRuncingOptions.EnableMince.intersect(NSRuncingOptions.EnableQuince)
var minceOrQuince: NSRuncingOptions = [.EnableMince, .EnableQuince]
minceOrQuince.intersectInPlace(minceAndQuince)
minceOrQuince.unionInPlace(minceAndQuince)
var minceValue: UInt = minceAndQuince.rawValue
var minceFromMask: NSRuncingOptions = []
// Strip leading 'k' in "kConstant".
let calendarUnit: CFCalendarUnit = [.Year, .Weekday]
// ...unless the next character is a non-identifier.
let curve3D: AU3DMixerAttenuationCurve = .k3DMixerAttenuationCurve_Exponential
// Match various plurals.
let observingOpts: NSKeyValueObservingOptions = [.New, .Old]
let bluetoothProps: CBCharacteristicProperties = [.Write, .WriteWithoutResponse]
let buzzFilter: AlertBuzzes = [.Funk, .Sosumi]
// Match multi-capital acronym.
let bitmapFormat: NSBitmapFormat = [.NSAlphaFirstBitmapFormat, .NS32BitBigEndianBitmapFormat];
let bitmapFormatR: NSBitmapFormatReversed = [.NSAlphaFirstBitmapFormatR, .NS32BitBigEndianBitmapFormatR];
let bitmapFormat2: NSBitmapFormat2 = [.NSU16a , .NSU32a]
let bitmapFormat3: NSBitmapFormat3 = [.NSU16b , .NSS32b]
let bitmapFormat4: NSUBitmapFormat4 = [.NSU16c , .NSU32c]
let bitmapFormat5: NSABitmapFormat5 = [.NSAA16d , .NSAB32d]
// Drop trailing underscores when possible.
let timeFlags: CMTimeFlags = [.Valid , .HasBeenRounded]
let timeFlags2: CMTimeFlagsWithNumber = [._Valid, ._888]
let audioComponentOpts: AudioComponentInstantiationOptions = [.LoadOutOfProcess]
let audioComponentFlags: AudioComponentFlags = [.SandboxSafe]
let audioComponentFlags2: FakeAudioComponentFlags = [.LoadOutOfProcess]
let objcFlags: objc_flags = [.taggedPointer, .swiftRefcount]
let optionsWithSwiftName: NSOptionsAlsoGetSwiftName = .Case