Skip to content

Implement equality for NSNull #129

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 4 commits into from
Dec 13, 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 @@ -199,6 +199,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 */; };
612952F91C1B235900BE0FD9 /* TestNSNull.swift in Sources */ = {isa = PBXBuildFile; fileRef = 612952F81C1B235900BE0FD9 /* TestNSNull.swift */; };
61F8AE7D1C180FC600FB62F0 /* TestNSNotificationCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61F8AE7C1C180FC600FB62F0 /* TestNSNotificationCenter.swift */; };
6E203B8D1C1303BB003B2576 /* TestNSBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E203B8C1C1303BB003B2576 /* TestNSBundle.swift */; };
7A7D6FBB1C16439400957E2E /* TestNSURLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A7D6FBA1C16439400957E2E /* TestNSURLResponse.swift */; };
Expand Down Expand Up @@ -538,6 +539,7 @@
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>"; };
5EB6A15C1C188FC40037DCB8 /* TestNSJSONSerialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSJSONSerialization.swift; sourceTree = "<group>"; };
612952F81C1B235900BE0FD9 /* TestNSNull.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSNull.swift; sourceTree = "<group>"; };
61F8AE7C1C180FC600FB62F0 /* TestNSNotificationCenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSNotificationCenter.swift; sourceTree = "<group>"; };
6E203B8C1C1303BB003B2576 /* TestNSBundle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSBundle.swift; sourceTree = "<group>"; };
7A7D6FBA1C16439400957E2E /* TestNSURLResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSURLResponse.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1071,6 +1073,7 @@
83712C8D1C1684900049AD49 /* TestNSURLRequest.swift */,
7A7D6FBA1C16439400957E2E /* TestNSURLResponse.swift */,
A5A34B551C18C85D00FD972B /* TestNSByteCountFormatter.swift */,
612952F81C1B235900BE0FD9 /* TestNSNull.swift */,
);
name = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1770,6 +1773,7 @@
E876A73E1C1180E000F279EC /* TestNSRange.swift in Sources */,
C2A9D75C1C15C08B00993803 /* TestNSUUID.swift in Sources */,
A5A34B561C18C85D00FD972B /* TestNSByteCountFormatter.swift in Sources */,
612952F91C1B235900BE0FD9 /* TestNSNull.swift in Sources */,
EA66F6521BF1619600136161 /* TestNSPropertyList.swift in Sources */,
4AE109271C17CCBF007367B5 /* TestNSIndexPath.swift in Sources */,
4DC1D0801C12EEEF00B5948A /* TestNSPipe.swift in Sources */,
Expand Down
9 changes: 8 additions & 1 deletion Foundation/NSNull.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public class NSNull : NSObject, NSCopying, NSSecureCoding {
public static func supportsSecureCoding() -> Bool {
return true
}

public override func isEqual(object: AnyObject?) -> Bool {
return object is NSNull
}
}


public func ===(lhs: NSNull?, rhs: NSNull?) -> Bool {
guard let _ = lhs, let _ = rhs else { return false }
return true
}
49 changes: 49 additions & 0 deletions TestFoundation/TestNSNull.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 TestNSNull : XCTestCase {

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

func test_alwaysEqual() {
let null_1 = NSNull()
let null_2 = NSNull()

let null_3: NSNull? = NSNull()
let null_4: NSNull? = nil

//Check that any two NSNull's are ==
XCTAssertEqual(null_1, null_2)

//Check that any two NSNull's are ===, preserving the singleton behavior
XCTAssertTrue(null_1 === null_2)

//Check that NSNull() == .Some(NSNull)
XCTAssertEqual(null_1, null_3)

//Make sure that NSNull() != .None
XCTAssertNotEqual(null_1, null_4)
}
}
1 change: 1 addition & 0 deletions TestFoundation/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ XCTMain([
TestNSURLComponents(),
TestNSURLRequest(),
TestNSURLResponse(),
TestNSNull(),
TestNSUUID(),
TestNSXMLParser(),
])