Files
swift-mirror/test/Interpreter/SDK/Foundation_printing.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

54 lines
1.2 KiB
Swift

// RUN: %target-run-simple-swift
// XFAIL: interpret
// REQUIRES: objc_interop
import Foundation
import StdlibUnittest
var FoundationPrinting = TestSuite("FoundationPrinting")
FoundationPrinting.test("OverlayTypesHaveDescription") {
func hasDescription(_: CustomStringConvertible) {}
var a: ObjCBool = true
hasDescription(a)
}
FoundationPrinting.test("ObjCBoolPrinting") {
var true_: ObjCBool = true
var false_: ObjCBool = false
expectPrinted("true", true_)
expectPrinted("false", false_)
}
FoundationPrinting.test("SelectorPrinting") {
expectPrinted("", Selector(""))
expectPrinted(":", Selector(":"))
expectPrinted("a", Selector("a"))
expectPrinted("abc", Selector("abc"))
expectPrinted("abc:", Selector("abc:"))
expectPrinted("abc:def:", Selector("abc:def:"))
}
// Pure Swift classes with and without a custom description
class PureSwiftDescription {
@objc var description: String = "awesome"
}
class PureSwiftNoDescription {
var x = 318
}
FoundationPrinting.test("NSArrayDescription") {
var array = NSArray(objects:PureSwiftDescription(), PureSwiftNoDescription())
var expected =
"(\n" +
" awesome,\n" +
" \"main.PureSwiftNoDescription\"\n" +
")"
expectPrinted(expected, array)
}
runAllTests()