Skip to content

Pulling latest changes #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
5BF7AEBF1BCD51F9008F214A /* NSURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F4A1BCC5DCB00ED97BB /* NSURL.swift */; };
5BF7AEC01BCD51F9008F214A /* NSUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F4B1BCC5DCB00ED97BB /* NSUUID.swift */; };
5BF7AEC11BCD51F9008F214A /* NSValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F4C1BCC5DCB00ED97BB /* NSValue.swift */; };
84BA558E1C16F90900F48C54 /* TestNSTimeZone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BA558D1C16F90900F48C54 /* TestNSTimeZone.swift */; };
C93559291C12C49F009FD6A9 /* TestNSAffineTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */; };
E876A73E1C1180E000F279EC /* TestNSRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = E876A73D1C1180E000F279EC /* TestNSRange.swift */; };
EA66F6361BEED03E00136161 /* TargetConditionals.h in Headers */ = {isa = PBXBuildFile; fileRef = EA66F6351BEED03E00136161 /* TargetConditionals.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -519,6 +520,7 @@
5BDC3FCF1BCF17E600ED97BB /* NSCFSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSCFSet.swift; sourceTree = "<group>"; };
5BDC405C1BD6D83B00ED97BB /* TestFoundation.app */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TestFoundation.app; sourceTree = BUILT_PRODUCTS_DIR; };
5BF7AEC21BCD568D008F214A /* ForSwiftFoundationOnly.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ForSwiftFoundationOnly.h; sourceTree = "<group>"; };
84BA558D1C16F90900F48C54 /* TestNSTimeZone.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSTimeZone.swift; sourceTree = "<group>"; };
C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSAffineTransform.swift; sourceTree = "<group>"; };
E876A73D1C1180E000F279EC /* TestNSRange.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSRange.swift; sourceTree = "<group>"; };
EA313DFC1BE7F2E90060A403 /* CFURLComponents_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFURLComponents_Internal.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1024,6 +1026,7 @@
525AECEB1BF2C96400D15BB0 /* TestNSFileManager.swift */,
5B40F9F11C125187000E72E3 /* TestNSXMLParser.swift */,
22B9C1E01C165D7A00DECFF9 /* TestNSDate.swift */,
84BA558D1C16F90900F48C54 /* TestNSTimeZone.swift */,
);
name = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1711,6 +1714,7 @@
E876A73E1C1180E000F279EC /* TestNSRange.swift in Sources */,
EA66F6521BF1619600136161 /* TestNSPropertyList.swift in Sources */,
4DC1D0801C12EEEF00B5948A /* TestNSPipe.swift in Sources */,
84BA558E1C16F90900F48C54 /* TestNSTimeZone.swift in Sources */,
52829AD71C160D64003BC4EF /* TestNSCalendar.swift in Sources */,
C93559291C12C49F009FD6A9 /* TestNSAffineTransform.swift in Sources */,
EA66F64E1BF1619600136161 /* TestNSIndexSet.swift in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions Foundation/NSObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ extension NSObject : Equatable, Hashable {
public func ==(lhs: NSObject, rhs: NSObject) -> Bool {
return lhs.isEqual(rhs)
}

extension NSObject : CustomDebugStringConvertible {
}

extension NSObject : CustomStringConvertible {
}
30 changes: 27 additions & 3 deletions Foundation/NSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,39 @@ extension NSString {
}

public func rangeOfCharacterFromSet(searchSet: NSCharacterSet) -> NSRange {
NSUnimplemented()
return rangeOfCharacterFromSet(searchSet, options: [])
}

public func rangeOfCharacterFromSet(searchSet: NSCharacterSet, options mask: NSStringCompareOptions) -> NSRange {
NSUnimplemented()
return rangeOfCharacterFromSet(searchSet, options: mask, range: NSMakeRange(0, length))
}

public func rangeOfCharacterFromSet(searchSet: NSCharacterSet, options mask: NSStringCompareOptions, range searchRange: NSRange) -> NSRange {
NSUnimplemented()
if mask.contains(.RegularExpressionSearch) {
NSUnimplemented()
}
if searchRange.length == 0 {
return NSMakeRange(NSNotFound, 0)
}

#if os(Linux)
var cfflags = CFStringCompareFlags(mask.rawValue)
if mask.contains(.LiteralSearch) {
cfflags |= UInt(kCFCompareNonliteral)
}
#else
var cfflags = CFStringCompareFlags(rawValue: mask.rawValue)
if mask.contains(.LiteralSearch) {
cfflags.unionInPlace(.CompareNonliteral)
}
#endif
var result = CFRangeMake(kCFNotFound, 0)

if CFStringFindCharacterFromSet(_cfObject, searchSet._cfObject, CFRangeMake(searchRange.location, searchRange.length), cfflags, &result) {
return NSMakeRange(result.location, result.length)
} else {
return NSMakeRange(NSNotFound, 0)
}
}

public func rangeOfComposedCharacterSequenceAtIndex(index: Int) -> NSRange {
Expand Down
10 changes: 9 additions & 1 deletion Foundation/NSTimeZone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,15 @@ extension NSTimeZone {
public class func timeZoneDataVersion() -> String { NSUnimplemented() }

public var secondsFromGMT: Int { NSUnimplemented() }
public var abbreviation: String? { NSUnimplemented() }

/// The abbreviation for the receiver, such as "EDT" (Eastern Daylight Time). (read-only)
///
/// This invokes `abbreviationForDate:` with the current date as the argument.
public var abbreviation: String? {
let currentDate = NSDate()
return abbreviationForDate(currentDate)
}

public var daylightSavingTime: Bool { NSUnimplemented() }
public var daylightSavingTimeOffset: NSTimeInterval { NSUnimplemented() }
/*@NSCopying*/ public var nextDaylightSavingTimeTransition: NSDate? { NSUnimplemented() }
Expand Down
13 changes: 12 additions & 1 deletion TestFoundation/TestNSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TestNSString : XCTestCase {
("test_FromNullTerminatedCStringInASCII", test_FromNullTerminatedCStringInASCII ),
("test_FromNullTerminatedCStringInUTF8", test_FromNullTerminatedCStringInUTF8 ),
("test_FromMalformedNullTerminatedCStringInUTF8", test_FromMalformedNullTerminatedCStringInUTF8 ),
("test_rangeOfCharacterFromSet", test_rangeOfCharacterFromSet ),
]
}

Expand Down Expand Up @@ -141,4 +142,14 @@ class TestNSString : XCTestCase {
let string = NSString(CString: bytes.map { Int8(bitPattern: $0) }, encoding: NSUTF8StringEncoding)
XCTAssertNil(string)
}
}

func test_rangeOfCharacterFromSet() {
let string: NSString = "0Az"
let letters = NSCharacterSet.letterCharacterSet()
let decimalDigits = NSCharacterSet.decimalDigitCharacterSet()
XCTAssertEqual(string.rangeOfCharacterFromSet(letters).location, 1)
XCTAssertEqual(string.rangeOfCharacterFromSet(decimalDigits).location, 0)
XCTAssertEqual(string.rangeOfCharacterFromSet(letters, options: [.BackwardsSearch]).location, 2)
XCTAssertEqual(string.rangeOfCharacterFromSet(letters, options: [], range: NSMakeRange(2, 1)).location, 2)
}
}
34 changes: 34 additions & 0 deletions TestFoundation/TestNSTimeZone.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//



#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif



class TestNSTimeZone: XCTestCase {

var allTests : [(String, () -> ())] {
return [
("test_abbreviation", test_abbreviation),
]
}

func test_abbreviation() {
let tz = NSTimeZone.systemTimeZone()
XCTAssertEqual(tz.abbreviation, tz.abbreviationForDate(NSDate()))
}
}
1 change: 1 addition & 0 deletions TestFoundation/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ XCTMain([
TestNSRange(),
TestNSXMLParser(),
TestNSDate(),
TestNSTimeZone(),
])