Files
swift-mirror/test/1_stdlib/StringDiagnostics.swift
Maxwell Swadling 40884c7030 [stdlib] added tests for string operators flipped
Swift SVN r24575
2015-01-20 23:31:33 +00:00

30 lines
2.2 KiB
Swift

// RUN: %target-parse-verify-swift
import Foundation
// Common pitfall: trying to subscript a string with integers.
func testIntSubscripting(s: String, i: Int) {
let c1 = s[i] // expected-error{{'subscript' is unavailable: cannot subscript String with an Int}}
let c2 = s[17] // expected-error{{'subscript' is unavailable: cannot subscript String with an Int}}
let c3 = s[i...i] // expected-error{{subscript' is unavailable: cannot subscript String with a range of Int}}
let c4 = s[17..<20] // expected-error{{subscript' is unavailable: cannot subscript String with a range of Int}}
let c5 = s[17...20] // expected-error{{subscript' is unavailable: cannot subscript String with a range of Int}}
}
func testAmbiguousStringComparisons(s: String) {
let nsString = s as NSString
let a1 = s == nsString // expected-error{{'==' is unavailable: Comparing Swift.String and NSString is ambiguous}}
let a2 = s != nsString // expected-error{{'!=' is unavailable: Comparing Swift.String and NSString is ambiguous}}
let a3 = s < nsString // expected-error{{'<' is unavailable: Comparing Swift.String and NSString is ambiguous}}
let a4 = s <= nsString // expected-error{{'<=' is unavailable: Comparing Swift.String and NSString is ambiguous}}
let a5 = s >= nsString // expected-error{{'>=' is unavailable: Comparing Swift.String and NSString is ambiguous}}
let a6 = s > nsString // expected-error{{'>' is unavailable: Comparing Swift.String and NSString is ambiguous}}
// now the other way
let a7 = nsString == s // expected-error{{'==' is unavailable: Comparing Swift.String and NSString is ambiguous}}
let a8 = nsString != s // expected-error{{'!=' is unavailable: Comparing Swift.String and NSString is ambiguous}}
let a9 = nsString < s // expected-error{{'<' is unavailable: Comparing Swift.String and NSString is ambiguous}}
let a10 = nsString <= s // expected-error{{'<=' is unavailable: Comparing Swift.String and NSString is ambiguous}}
let a11 = nsString >= s // expected-error{{'>=' is unavailable: Comparing Swift.String and NSString is ambiguous}}
let a12 = nsString > s // expected-error{{'>' is unavailable: Comparing Swift.String and NSString is ambiguous}}
}