Files
swift-mirror/validation-test/stdlib/StdlibUnittestFoundationExtras.swift
Doug Gregor 06c5e9cd5b Enable "omit needless words" by default.
Most of this is in updating the standard library, SDK overlays, and
piles of test cases to use the new names. No surprises here, although
this shows us some potential heuristic tweaks.

There is one substantive compiler change that needs to be factored out
involving synthesizing calls to copyWithZone()/copy(zone:). Aside from
that, there are four failing tests:

    Swift :: ClangModules/objc_parse.swift
    Swift :: Interpreter/SDK/Foundation_test.swift
    Swift :: Interpreter/SDK/archiving_generic_swift_class.swift
    Swift :: Interpreter/SDK/objc_currying.swift

due to two independent remaining compiler bugs:
  * We're not getting partial ordering between NSCoder's
  encode(AnyObject, forKey: String) and NSKeyedArchiver's version of
  that method, and
  * Dynamic lookup (into AnyObject) doesn't know how to find the new
  names. We need the Swift name lookup tables enabled to address this.
2015-12-11 14:46:50 -08:00

105 lines
2.8 KiB
Swift

// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: objc_interop
import StdlibUnittest
import Foundation
import StdlibUnittestFoundationExtras
var FoundationExtrasTests = TestSuite("FoundationExtras")
FoundationExtrasTests.test("withOverriddenNSLocaleCurrentLocale(NSLocale)") {
// Check two locales to make sure the behavior is correct even if one of
// these locales happens to be the same as the actual current locale.
if true {
let result = withOverriddenNSLocaleCurrentLocale(
NSLocale(localeIdentifier: "en_US")) {
() -> Int in
expectEqual("en_US", NSLocale.current().localeIdentifier)
return 42
}
expectEqual(42, result)
}
if true {
let result = withOverriddenNSLocaleCurrentLocale(
NSLocale(localeIdentifier: "uk")) {
() -> Int in
expectEqual("uk", NSLocale.current().localeIdentifier)
return 42
}
expectEqual(42, result)
}
}
FoundationExtrasTests.test("withOverriddenNSLocaleCurrentLocale(NSLocale)/nested") {
withOverriddenNSLocaleCurrentLocale(
NSLocale(localeIdentifier: "uk")) {
() -> Void in
expectCrashLater()
withOverriddenNSLocaleCurrentLocale(
NSLocale(localeIdentifier: "uk")) {
() -> Void in
return ()
}
}
}
FoundationExtrasTests.test("withOverriddenNSLocaleCurrentLocale(String)") {
// Check two locales to make sure the behavior is correct even if one of
// these locales happens to be the same as the actual current locale.
if true {
let result = withOverriddenNSLocaleCurrentLocale("en_US") {
() -> Int in
expectEqual("en_US", NSLocale.current().localeIdentifier)
return 42
}
expectEqual(42, result)
}
if true {
let result = withOverriddenNSLocaleCurrentLocale("uk") {
() -> Int in
expectEqual("uk", NSLocale.current().localeIdentifier)
return 42
}
expectEqual(42, result)
}
}
@_silgen_name("objc_autorelease")
func objc_autorelease(ref: AnyObject)
FoundationExtrasTests.test("objc_autorelease()") {
autoreleasepool {
// Check that objc_autorelease indeed autoreleases.
objc_autorelease(LifetimeTracked(101))
expectEqual(1, LifetimeTracked.instances)
}
}
FoundationExtrasTests.test("autoreleasepoolIfUnoptimizedReturnAutoreleased()/autorelease") {
autoreleasepool {
autoreleasepoolIfUnoptimizedReturnAutoreleased {
objc_autorelease(LifetimeTracked(103))
expectEqual(1, LifetimeTracked.instances)
}
}
}
FoundationExtrasTests.test("autoreleasepoolIfUnoptimizedReturnAutoreleased()/return-autoreleased") {
autoreleasepool {
autoreleasepoolIfUnoptimizedReturnAutoreleased {
let nsa = [ LifetimeTracked(104) ] as NSArray
expectEqual(1, LifetimeTracked.instances)
_blackHole(nsa[0])
}
expectEqual(0, LifetimeTracked.instances)
}
}
runAllTests()