Files
swift-mirror/test/Interpreter/testability.swift
Dave Abrahams ac3f047496 [stdlib] Renaming fallout from Mirror API review
toString(x)      => String(x)
toDebugString(x) => String(reflecting: x)
Printable        => CustomStringConvertible
DebugPrintable   => CustomDebugStringConvertible

Also updated comments to clarify these protocols

Swift SVN r27090
2015-04-07 20:32:26 +00:00

29 lines
1.1 KiB
Swift

// RUN: rm -rf %t && mkdir %t
// RUN: %target-build-swift -emit-library -c %S/Inputs/testability_helper.swift -enable-testing -force-single-frontend-invocation -o %t/testability_helper.o -emit-module
// RUN: %target-build-swift %s -I %t -Xlinker %t/testability_helper.o -o %t/main
// RUN: %target-run %t/main | FileCheck %s
@testable import testability_helper
func log(value: Any, line: Int = __LINE__) {
println("\(line): \(value)")
}
log(Base(1)) // CHECK: {{^}}[[@LINE]]: instance 1{{$}}
log(Base(2).description) // CHECK: {{^}}[[@LINE]]: instance 2{{$}}
log((Base(3) as CustomStringConvertible).description) // CHECK: {{^}}[[@LINE]]: instance 3{{$}}
class Sub : Base {
override var description: String {
return "sub " + super.description
}
}
log(Sub(1)) // CHECK: {{^}}[[@LINE]]: sub instance 1{{$}}
log(Sub(2) as Any as? Base) // CHECK: {{^}}[[@LINE]]: Optional(sub instance 2){{$}}
log(Base(1).callPrivate()) // CHECK: {{^}}[[@LINE]]: private 1{{$}}
log(Sub(2).callPrivate()) // CHECK: {{^}}[[@LINE]]: private 2{{$}}
log(getPrivateInstance().callPrivate()) // CHECK: {{^}}[[@LINE]]: really private{{$}}