Files
swift-mirror/test/stdlib/UnavailableStringAPIs.swift.gyb
Ben Cohen 9ee856f386 [stdlib][WIP] Eliminate (Closed)CountableRange using conditional conformance (#13342)
* Make Range conditionally a Collection

* Convert ClosedRange to conditionally a collection

* De-gyb Range/ClosedRange, refactoring some methods.

* Remove use of Countable{Closed}Range from stdlib

* Remove Countable use from Foundation

* Fix test errors and warnings resulting from Range/CountableRange collapse

* fix prespecialize test for new mangling

* Update CoreAudio use of CountableRange

* Update SwiftSyntax use of CountableRange

* Restore ClosedRange.Index: Hashable conformance

* Move fixed typechecker slowness test for array-of-ranges from slow to fast, yay

* Apply Doug's patch to loosen test to just check for error
2018-02-01 20:59:28 -08:00

54 lines
2.3 KiB
Plaintext

// RUN: %empty-directory(%t)
// RUN: %gyb -D_runtime=%target-runtime %s -o %t/main.swift
// RUN: %line-directive %t/main.swift -- %target-swift-frontend -typecheck -verify %t/main.swift
func test_StringSubscriptByInt(
x: String,
i: Int,
r1: Range<Int>,
r2: ClosedRange<Int>
) {
_ = x[i] // expected-error {{'subscript' is unavailable: cannot subscript String with an Int, see the documentation comment for discussion}} {{none}}
_ = x[r1] // expected-error {{'subscript' is unavailable: cannot subscript String with an integer range, see the documentation comment for discussion}} {{none}}
_ = x[r2] // expected-error {{'subscript' is unavailable: cannot subscript String with an integer range, see the documentation comment for discussion}} {{none}}
}
% if _runtime == 'objc':
func test_UTF16ViewSubscriptByInt(x: String.UTF16View, i: Int, r: Range<Int>) {
_ = x[i] // expected-error {{'subscript' is unavailable: Indexing a String's UTF16View requires a String.UTF16View.Index, which can be constructed from Int when Foundation is imported}} {{none}}
_ = x[r] // expected-error {{'subscript' is unavailable: Slicing a String's UTF16View requires a Range<String.UTF16View.Index>, String.UTF16View.Index can be constructed from Int when Foundation is imported}} {{none}}
}
% end
func test_UTF8View(s: String.UTF8View, i: String.UTF8View.Index, d: Int) {
_ = s.index(after: i) // OK
_ = s.index(before: i) // OK
_ = s.index(i, offsetBy: d) // OK
_ = s.index(i, offsetBy: d, limitedBy: i) // OK
_ = s.distance(from: i, to: i) // OK
}
func test_UTF16View(s: String.UTF16View, i: String.UTF16View.Index, d: Int) {
_ = s.index(after: i) // OK
_ = s.index(before: i) // OK
_ = s.index(i, offsetBy: d) // OK
_ = s.index(i, offsetBy: d, limitedBy: i) // OK
_ = s.distance(from: i, to: i) // OK
}
func test_UnicodeScalarView(s: String.UnicodeScalarView, i: String.UnicodeScalarView.Index, d: Int) {
_ = s.index(after: i) // OK
_ = s.index(before: i) // OK
_ = s.index(i, offsetBy: d) // OK
_ = s.index(i, offsetBy: d, limitedBy: i) // OK
_ = s.distance(from: i, to: i) // OK
}
func test_CharacterView(s: String, i: String.Index, d: Int) {
_ = s.index(after: i) // OK
_ = s.index(before: i) // OK
_ = s.index(i, offsetBy: d) // OK
_ = s.index(i, offsetBy: d, limitedBy: i) // OK
_ = s.distance(from: i, to: i) // OK
}