Files
swift-mirror/test/stdlib/Optional.swift
Dave Abrahams 9e0ecddfb9 stdlib: add Optional<T>
Swift SVN r5020
2013-05-01 23:19:48 +00:00

35 lines
706 B
Swift

// RUN: %swift -i -constraint-checker %s
var x = Optional<Int>()
if x { assert(false, "x is supposed to be false") }
else { println("an empty optional is logically false") }
assert(x == None)
assert(None == x)
for y in x {
assert(false, "x is supposed to be empty")
}
x = Optional<Int>(0)
x = Some(1)
if x { println("an non-empty optional is logically true") }
else { assert(false, "x is supposed to be true") }
assert(x != None)
assert(None != x)
if !x { assert(false, "x is supposed to be true") }
else { println("logical negation works") }
var empty: Bool = true
for y in x {
assert(y == 1)
empty = false
println("destructuring bind works")
}
assert(!empty)
x = +None
assert(!x)