Skip to content

Commit

Permalink
Included Quick and Nimble test framework to easily test specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Hout committed Oct 19, 2015
1 parent e63becc commit a275604
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 145 deletions.
34 changes: 28 additions & 6 deletions SwiftDate.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
objects = {

/* Begin PBXBuildFile section */
1FF867191BD5333F006B0E02 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FF867171BD5333F006B0E02 /* Nimble.framework */; };
1FF8671A1BD5333F006B0E02 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FF867181BD5333F006B0E02 /* Quick.framework */; };
1FF8671D1BD5334B006B0E02 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FF8671B1BD5334B006B0E02 /* Nimble.framework */; };
1FF8671E1BD5334B006B0E02 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FF8671C1BD5334B006B0E02 /* Quick.framework */; };
1FF867201BD537EE006B0E02 /* SwiftDateSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FF8671F1BD537EE006B0E02 /* SwiftDateSpecs.swift */; settings = {ASSET_TAGS = (); }; };
1FF867211BD537EE006B0E02 /* SwiftDateSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FF8671F1BD537EE006B0E02 /* SwiftDateSpecs.swift */; settings = {ASSET_TAGS = (); }; };
CCCADC7C1BB8909B00B905DD /* SwiftDate.h in Headers */ = {isa = PBXBuildFile; fileRef = CCCADC7B1BB8909B00B905DD /* SwiftDate.h */; settings = {ATTRIBUTES = (Public, ); }; };
CCCADC831BB8909B00B905DD /* SwiftDate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CCCADC781BB8909B00B905DD /* SwiftDate.framework */; settings = {ASSET_TAGS = (); }; };
CCCADC881BB8909B00B905DD /* SwiftDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCCADC871BB8909B00B905DD /* SwiftDateTests.swift */; };
CCCADC931BB8937700B905DD /* SwiftDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCCADC921BB8937700B905DD /* SwiftDate.swift */; settings = {ASSET_TAGS = (); }; };
CCCADCC81BB89C7600B905DD /* SwiftDate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CCCADCB71BB89C1C00B905DD /* SwiftDate.framework */; settings = {ASSET_TAGS = (); }; };
CCCADCCE1BB89D8D00B905DD /* SwiftDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCCADC921BB8937700B905DD /* SwiftDate.swift */; settings = {ASSET_TAGS = (); }; };
CCCADCCF1BB89E0700B905DD /* SwiftDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCCADC871BB8909B00B905DD /* SwiftDateTests.swift */; settings = {ASSET_TAGS = (); }; };
CCCADCD01BB89E1800B905DD /* SwiftDate.h in Headers */ = {isa = PBXBuildFile; fileRef = CCCADC7B1BB8909B00B905DD /* SwiftDate.h */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */

Expand All @@ -35,11 +39,17 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
1FF867131BD5332E006B0E02 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = "../Nimble/build/Debug-iphoneos/Nimble.framework"; sourceTree = "<group>"; };
1FF867141BD5332E006B0E02 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = ../Quick/build/Debug/Quick.framework; sourceTree = "<group>"; };
1FF867171BD5333F006B0E02 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = "../Nimble/build/Debug-iphoneos/Nimble.framework"; sourceTree = "<group>"; };
1FF867181BD5333F006B0E02 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = "../Quick/build/Debug-iphoneos/Quick.framework"; sourceTree = "<group>"; };
1FF8671B1BD5334B006B0E02 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = ../Nimble/build/Debug/Nimble.framework; sourceTree = "<group>"; };
1FF8671C1BD5334B006B0E02 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = ../Quick/build/Debug/Quick.framework; sourceTree = "<group>"; };
1FF8671F1BD537EE006B0E02 /* SwiftDateSpecs.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftDateSpecs.swift; sourceTree = "<group>"; };
CCCADC781BB8909B00B905DD /* SwiftDate.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftDate.framework; sourceTree = BUILT_PRODUCTS_DIR; };
CCCADC7B1BB8909B00B905DD /* SwiftDate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftDate.h; sourceTree = "<group>"; };
CCCADC7D1BB8909B00B905DD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CCCADC821BB8909B00B905DD /* SwiftDateTests iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftDateTests iOS.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
CCCADC871BB8909B00B905DD /* SwiftDateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDateTests.swift; sourceTree = "<group>"; };
CCCADC891BB8909B00B905DD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
CCCADC921BB8937700B905DD /* SwiftDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftDate.swift; sourceTree = "<group>"; };
CCCADCB71BB89C1C00B905DD /* SwiftDate.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftDate.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -58,6 +68,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1FF867191BD5333F006B0E02 /* Nimble.framework in Frameworks */,
1FF8671A1BD5333F006B0E02 /* Quick.framework in Frameworks */,
CCCADC831BB8909B00B905DD /* SwiftDate.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -73,6 +85,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1FF8671D1BD5334B006B0E02 /* Nimble.framework in Frameworks */,
1FF8671E1BD5334B006B0E02 /* Quick.framework in Frameworks */,
CCCADCC81BB89C7600B905DD /* SwiftDate.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -83,6 +97,12 @@
CCCADC6E1BB8909B00B905DD = {
isa = PBXGroup;
children = (
1FF8671B1BD5334B006B0E02 /* Nimble.framework */,
1FF8671C1BD5334B006B0E02 /* Quick.framework */,
1FF867171BD5333F006B0E02 /* Nimble.framework */,
1FF867181BD5333F006B0E02 /* Quick.framework */,
1FF867131BD5332E006B0E02 /* Nimble.framework */,
1FF867141BD5332E006B0E02 /* Quick.framework */,
CCCADC7A1BB8909B00B905DD /* SwiftDate */,
CCCADC861BB8909B00B905DD /* SwiftDateTests */,
CCCADC791BB8909B00B905DD /* Products */,
Expand Down Expand Up @@ -113,7 +133,7 @@
CCCADC861BB8909B00B905DD /* SwiftDateTests */ = {
isa = PBXGroup;
children = (
CCCADC871BB8909B00B905DD /* SwiftDateTests.swift */,
1FF8671F1BD537EE006B0E02 /* SwiftDateSpecs.swift */,
CCCADC891BB8909B00B905DD /* Info.plist */,
);
path = SwiftDateTests;
Expand Down Expand Up @@ -301,7 +321,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CCCADC881BB8909B00B905DD /* SwiftDateTests.swift in Sources */,
1FF867201BD537EE006B0E02 /* SwiftDateSpecs.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -317,7 +337,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CCCADCCF1BB89E0700B905DD /* SwiftDateTests.swift in Sources */,
1FF867211BD537EE006B0E02 /* SwiftDateSpecs.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -586,6 +606,7 @@
CCCADCBD1BB89C1C00B905DD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
CCCADCCB1BB89C7600B905DD /* Build configuration list for PBXNativeTarget "SwiftDateTests Mac" */ = {
isa = XCConfigurationList;
Expand All @@ -594,6 +615,7 @@
CCCADCCD1BB89C7600B905DD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
13 changes: 13 additions & 0 deletions SwiftDate.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

160 changes: 160 additions & 0 deletions SwiftDateTests/SwiftDateSpecs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
//
// SwiftDateTests.swift
// SwiftDateTests
//
// Created by fhisa on 2015/09/28.
// Copyright (C) 2015 SwiftDate. All rights reserved.
//

import Quick
import Nimble
@testable import SwiftDate

class SwiftDateSpec: QuickSpec {

override func spec() {

describe("SwiftDate") {

context("Initialisaton") {

it("should initialise with ymd specified") {
let testDate = NSDate(year: 2015, month: 10, day: 23)

expect(testDate.year) == 2015
expect(testDate.month) == 10
expect(testDate.day) == 23
expect(testDate.hour) == 0
expect(testDate.minute) == 0
expect(testDate.second) == 0
}


it("should initialise on reference date with ymd specified") {
let refDate = NSDate()
let testDate = NSDate(refDate: refDate, year: 2015, month: 10, day: 23)
expect(testDate.year) == 2015
expect(testDate.month) == 10
expect(testDate.day) == 23
expect(testDate.hour) == refDate.hour
expect(testDate.minute) == refDate.minute
expect(testDate.second) == refDate.second
}
}

context("comparisons") {

var before: NSDate!
var now: NSDate!
var after: NSDate!

beforeEach {
now = NSDate()
before = now.dateByAddingTimeInterval(-60.0)
after = now.dateByAddingTimeInterval(60.0)
}

it("should compare less than properly") {
expect(before < now) == true
expect(now < after) == true
expect(after < now) == false
expect(now < before) == false
expect(now < now) == false
}

it("should compare less than or equal properly") {
expect(before <= now) == true
expect(now <= after) == true
expect(after <= now) == false
expect(now <= before) == false
expect(now <= now) == true
}

it("should compare greater than properly") {
expect(before > now) == false
expect(now > after) == false
expect(after > now) == true
expect(now > before) == true
expect(now > now) == false
}

it("should compare greater than or equal properly") {
expect(before >= now) == false
expect(now >= after) == false
expect(after >= now) == true
expect(now >= before) == true
expect(now >= now) == true
}

it("should compare equality properly") {
let bc2015 = NSDate.date(refDate: nil, year: -2014, month: 9, day: 29, hour: 0, minute: 0, second: 0, tz: "UTC")
let ac2015 = NSDate.date(refDate: nil, year: 2015, month: 9, day: 29, hour: 0, minute: 0, second: 0, tz: "UTC")

expect(bc2015.isEqualToDate(ac2015, ignoreTime: true)) == false
}

it("should compare same year properly") {
let endOfYear = NSDate.date(refDate: nil, year: 2015, month: 12, day: 31, hour: 23, minute: 59, second: 59, tz: nil)
let betweenTime = endOfYear.dateByAddingTimeInterval(0.5)
let beginOfYear = NSDate.date(refDate: nil, year: 2016, month: 1, day: 1, tz: nil)
expect(endOfYear.isSameYearOf(betweenTime)) == true
expect(betweenTime.isSameYearOf(endOfYear)) == true
expect(endOfYear.isSameYearOf(beginOfYear)) == false
expect(betweenTime.isSameYearOf(beginOfYear)) == false
}
}

context("calulations") {

var now: NSDate!
var after: NSDate!

beforeEach {
now = NSDate()
after = now.dateByAddingTimeInterval(60.0)
}

it("should subtract seconds properly") {
expect(after - now) == 60
expect(now - now) == 0
expect(now - after) == -60
}

it("should differ properly") {
let summerTimeDay = NSDate.date(refDate: nil, year: 2015, month: 3, day: 29, tz: nil)
let nextDay = NSDate.date(refDate: nil, year: 2015, month: 3, day: 30, tz: nil)

let singleDay = NSDateComponents()
singleDay.day = 1

expect(summerTimeDay.difference(nextDay, unitFlags: NSCalendarUnit.Day)) == singleDay
}
}

context("string operations") {

it("should convert to ISO8601 strings with HM and Zulu") {
let expectedDate = NSDate.date(refDate: nil, year: 2015, month: 9, day: 29, hour: 0, minute: 0, second: 0, tz: "UTC")
let parsedDate = NSDate.date(fromString: "2015-09-29T00:00Z", format: .ISO8601)

expect(parsedDate) == expectedDate
}

it("should convert to ISO8601 strings with HMS and Zulu") {
let expectedDate = NSDate.date(refDate: nil, year: 2015, month: 9, day: 29, hour: 0, minute: 0, second: 0, tz: "UTC")
let parsedDate = NSDate.date(fromString: "2015-09-29T00:00:00Z", format: .ISO8601)

expect(parsedDate) == expectedDate
}

it("should convert to ISO8601 strings with HMS & fraction and Zulu") {
let expectedDate = NSDate.date(refDate: nil, year: 2015, month: 9, day: 29, hour: 0, minute: 0, second: 0, tz: "UTC")
let parsedDate = NSDate.date(fromString: "2015-09-29T00:00:00.000Z", format: .ISO8601)

expect(parsedDate) == expectedDate
}
}
}
}

}
Loading

0 comments on commit a275604

Please sign in to comment.