Skip to content

Commit 3dce46f

Browse files
committed
Merge pull request swiftlang#70 from syoutsey/tests/NSDate
Tests for NSDate
2 parents 58cfe37 + 8cb5530 commit 3dce46f

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

Foundation.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
22B9C1E11C165D7A00DECFF9 /* TestNSDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22B9C1E01C165D7A00DECFF9 /* TestNSDate.swift */; };
1011
4DC1D0801C12EEEF00B5948A /* TestNSPipe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DC1D07F1C12EEEF00B5948A /* TestNSPipe.swift */; };
1112
525AECED1BF2C9C500D15BB0 /* TestNSFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525AECEB1BF2C96400D15BB0 /* TestNSFileManager.swift */; };
1213
528776141BF2629700CB0090 /* FoundationErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 522C253A1BF16E1600804FC6 /* FoundationErrors.swift */; };
@@ -314,6 +315,7 @@
314315
/* End PBXCopyFilesBuildPhase section */
315316

316317
/* Begin PBXFileReference section */
318+
22B9C1E01C165D7A00DECFF9 /* TestNSDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSDate.swift; sourceTree = "<group>"; };
317319
4DC1D07F1C12EEEF00B5948A /* TestNSPipe.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSPipe.swift; sourceTree = "<group>"; };
318320
522C253A1BF16E1600804FC6 /* FoundationErrors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationErrors.swift; sourceTree = "<group>"; };
319321
525AECEB1BF2C96400D15BB0 /* TestNSFileManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSFileManager.swift; sourceTree = "<group>"; };
@@ -1015,6 +1017,7 @@
10151017
5BC1D8BC1BF3ADFE009D3973 /* TestNSCharacterSet.swift */,
10161018
525AECEB1BF2C96400D15BB0 /* TestNSFileManager.swift */,
10171019
5B40F9F11C125187000E72E3 /* TestNSXMLParser.swift */,
1020+
22B9C1E01C165D7A00DECFF9 /* TestNSDate.swift */,
10181021
);
10191022
name = Tests;
10201023
sourceTree = "<group>";
@@ -1703,6 +1706,7 @@
17031706
EA66F6521BF1619600136161 /* TestNSPropertyList.swift in Sources */,
17041707
4DC1D0801C12EEEF00B5948A /* TestNSPipe.swift in Sources */,
17051708
EA66F64E1BF1619600136161 /* TestNSIndexSet.swift in Sources */,
1709+
22B9C1E11C165D7A00DECFF9 /* TestNSDate.swift in Sources */,
17061710
EA66F6541BF1619600136161 /* TestNSSet.swift in Sources */,
17071711
EA66F64A1BF1619600136161 /* TestNSArray.swift in Sources */,
17081712
5BC1D8BE1BF3B09E009D3973 /* TestNSCharacterSet.swift in Sources */,

TestFoundation/TestNSDate.swift

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See http://swift.org/LICENSE.txt for license information
7+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
//
9+
10+
11+
12+
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
13+
import Foundation
14+
import XCTest
15+
#else
16+
import SwiftFoundation
17+
import SwiftXCTest
18+
#endif
19+
20+
21+
22+
class TestNSDate : XCTestCase {
23+
24+
var allTests : [(String, () -> ())] {
25+
return [
26+
("test_BasicConstruction", test_BasicConstruction),
27+
("test_InitTimeIntervalSince1970", test_InitTimeIntervalSince1970),
28+
("test_InitTimeIntervalSinceSinceDate", test_InitTimeIntervalSinceSinceDate),
29+
("test_TimeIntervalSinceSinceDate", test_TimeIntervalSinceSinceDate),
30+
("test_DistantFuture", test_DistantFuture),
31+
("test_DistantPast", test_DistantPast),
32+
("test_DateByAddingTimeInterval", test_DateByAddingTimeInterval),
33+
("test_EarlierDate", test_EarlierDate),
34+
("test_LaterDate", test_LaterDate),
35+
("test_Compare", test_Compare),
36+
("test_IsEqualToDate", test_IsEqualToDate),
37+
]
38+
}
39+
40+
func test_BasicConstruction() {
41+
let d = NSDate()
42+
XCTAssertNotNil(d)
43+
}
44+
45+
func test_InitTimeIntervalSince1970() {
46+
let ti: NSTimeInterval = 1
47+
let d = NSDate(timeIntervalSince1970: ti)
48+
XCTAssertNotNil(d)
49+
}
50+
51+
func test_InitTimeIntervalSinceSinceDate() {
52+
let ti: NSTimeInterval = 1
53+
let d1 = NSDate()
54+
let d2 = NSDate(timeInterval: ti, sinceDate: d1)
55+
XCTAssertNotNil(d2)
56+
}
57+
58+
func test_TimeIntervalSinceSinceDate() {
59+
let ti: NSTimeInterval = 1
60+
let d1 = NSDate()
61+
let d2 = NSDate(timeInterval: ti, sinceDate: d1)
62+
XCTAssertEqual(d2.timeIntervalSinceDate(d1), ti)
63+
}
64+
65+
func test_DistantFuture() {
66+
let d = NSDate.distantFuture()
67+
XCTAssertNotNil(d)
68+
}
69+
70+
func test_DistantPast() {
71+
let d = NSDate.distantPast()
72+
XCTAssertNotNil(d)
73+
}
74+
75+
func test_DateByAddingTimeInterval() {
76+
let ti: NSTimeInterval = 1
77+
let d1 = NSDate()
78+
let d2 = d1.dateByAddingTimeInterval(ti)
79+
XCTAssertNotNil(d2)
80+
}
81+
82+
func test_EarlierDate() {
83+
let ti: NSTimeInterval = 1
84+
let d1 = NSDate()
85+
let d2 = d1.dateByAddingTimeInterval(ti)
86+
XCTAssertEqual(d1.earlierDate(d2), d1)
87+
}
88+
89+
func test_LaterDate() {
90+
let ti: NSTimeInterval = 1
91+
let d1 = NSDate()
92+
let d2 = d1.dateByAddingTimeInterval(ti)
93+
XCTAssertEqual(d1.laterDate(d2), d2)
94+
}
95+
96+
func test_Compare() {
97+
let ti: NSTimeInterval = 1
98+
let d1 = NSDate()
99+
let d2 = d1.dateByAddingTimeInterval(ti)
100+
XCTAssertEqual(d1.compare(d2), NSComparisonResult.OrderedAscending)
101+
}
102+
103+
func test_IsEqualToDate() {
104+
let ti: NSTimeInterval = 1
105+
let d1 = NSDate()
106+
let d2 = d1.dateByAddingTimeInterval(ti)
107+
let d3 = d1.dateByAddingTimeInterval(ti)
108+
XCTAssertTrue(d2.isEqualToDate(d3))
109+
}
110+
}

TestFoundation/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ XCTMain([
3434
TestNSFileManger(),
3535
TestNSRange(),
3636
TestNSXMLParser(),
37+
TestNSDate(),
3738
])

0 commit comments

Comments
 (0)