Files
swift-mirror/test/1_stdlib/LogicValue.swift
Jordan Rose e83c117c30 [test] Hack: run stdlib tests first to start long-running tests earlier.
This decreases total testing time by over a minute on my old Mac Pro.
It probably has much less effect on systems with fewer cores, but shouldn't
be any worse there.

Swift SVN r22745
2014-10-15 01:30:51 +00:00

50 lines
1.2 KiB
Swift

// RUN: %target-run-simple-swift | FileCheck %s
enum Bewl : BooleanType {
case False, True
var boolValue: Bool {
switch self {
case .False:
return false
case .True:
return true
}
}
}
func truthy() -> Bewl {
print("truthy ")
return .True
}
func falsy() -> Bewl {
print("falsy ")
return .False
}
func logicValueTests() {
// Logic values should convert to bool.
struct X : BooleanType {
var boolValue: Bool { return false }
}
var anX = X()
println("BooleanType Bool = \(Bool(anX))") // CHECK: BooleanType Bool = false
println("\(!Bewl.True)") // CHECK: false
println("\(!Bewl.False)") // CHECK: true
// Test short-circuiting operators
println("\(Bool(truthy() && truthy()))") // CHECK: truthy truthy true
println("\(Bool(truthy() && falsy()))") // CHECK: truthy falsy false
println("\(Bool(falsy() && truthy()))") // CHECK: falsy false
println("\(Bool(falsy() && falsy()))") // CHECK: falsy false
println("\(Bool(truthy() || truthy()))") // CHECK: truthy true
println("\(Bool(truthy() || falsy()))") // CHECK: truthy true
println("\(Bool(falsy() || truthy()))") // CHECK: falsy truthy true
println("\(Bool(falsy() || falsy()))") // CHECK: falsy falsy false
}
logicValueTests()