Files
swift-mirror/test/Interpreter/unicode_scalar_literal.swift
Andrew Bennett ca31338e49 Simplifying implementation of ExpressibleByStringLiteral (#7125)
* Simplify conforming to ExpressibleByStringLiteral with default implementations

* attributes on default implementations

* ExpressibleByUnicodeScalarLiteral validation test

* more generic default implementations

* clean up test

* remove unneeded implementations

* remove test verification

* indent

* revert @effects and affected methods

* fix test generics with _ protocols

* Add semantic tests

* clean up tests

* Fix redundant conformance requirements
2017-04-21 20:45:28 -07:00

55 lines
1.7 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// RUN: %target-run-simple-swift
// RUN: %target-build-swift -O %s -o %t/a.out.optimized
// RUN: %target-run %t/a.out.optimized
// REQUIRES: executable_test
import StdlibUnittest
private let testSuite = TestSuite("UnicodeScalar literals")
private struct Expressible<T: _ExpressibleByBuiltinUnicodeScalarLiteral>
: ExpressibleByUnicodeScalarLiteral {
var value: T
init(unicodeScalarLiteral value: T) {
self.value = value
}
}
private func string(_ characters: UInt32...) -> String {
return String(characters.map { Character(UnicodeScalar($0)!) })
}
private func expressible<T>(_ literal: Expressible<T>, as type: T.Type)
-> String where T: CustomStringConvertible {
return literal.value.description
}
let b = string(0x62)
let β = string(0x03_B2)
let 𝔹 = string(0x01_D5_39)
testSuite.test("String literal type") {
expectEqual(expressible("b", as: String.self), b)
expectEqual(expressible("β", as: String.self), β)
expectEqual(expressible("𝔹", as: String.self), 𝔹)
}
testSuite.test("StaticString literal type") {
expectEqual(expressible("b", as: StaticString.self), b)
expectEqual(expressible("β", as: StaticString.self), β)
expectEqual(expressible("𝔹", as: StaticString.self), 𝔹)
}
testSuite.test("Character literal type") {
expectEqual(expressible("b", as: Character.self), b)
expectEqual(expressible("β", as: Character.self), β)
expectEqual(expressible("𝔹", as: Character.self), 𝔹)
}
testSuite.test("UnicodeScalar literal type") {
expectEqual(expressible("b", as: UnicodeScalar.self), b)
expectEqual(expressible("β", as: UnicodeScalar.self), β)
expectEqual(expressible("𝔹", as: UnicodeScalar.self), 𝔹)
}
runAllTests()