Skip to content
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

Spm update #911

Merged
merged 2 commits into from
Jun 25, 2020
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
8 changes: 0 additions & 8 deletions Analytics.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -589,16 +589,12 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-AnalyticsTests/Pods-AnalyticsTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Nimble-iOS/Nimble.framework",
"${BUILT_PRODUCTS_DIR}/Nocilla-iOS/Nocilla.framework",
"${BUILT_PRODUCTS_DIR}/Quick-iOS/Quick.framework",
"${BUILT_PRODUCTS_DIR}/SwiftTryCatch-iOS/SwiftTryCatch.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nocilla.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftTryCatch.framework",
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -657,16 +653,12 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-AnalyticsTestsTVOS/Pods-AnalyticsTestsTVOS-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Nimble-tvOS/Nimble.framework",
"${BUILT_PRODUCTS_DIR}/Nocilla-tvOS/Nocilla.framework",
"${BUILT_PRODUCTS_DIR}/Quick-tvOS/Quick.framework",
"${BUILT_PRODUCTS_DIR}/SwiftTryCatch-tvOS/SwiftTryCatch.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nocilla.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftTryCatch.framework",
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
373 changes: 179 additions & 194 deletions AnalyticsTests/AnalyticsTests.swift

Large diffs are not rendered by default.

197 changes: 95 additions & 102 deletions AnalyticsTests/AnalyticsUtilTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,134 +7,127 @@
//


import Quick
import Nimble
import Analytics
import XCTest

class AnalyticsUtilTests: QuickSpec {
override func spec() {

it("format NSDate objects to RFC 3339 complaint string") {
let date = Date(timeIntervalSince1970: 0)
let formattedString = iso8601FormattedString(date)
expect(formattedString) == "1970-01-01T00:00:00.000Z"

var components = DateComponents()
components.year = 1992
components.month = 8
components.day = 6
components.hour = 7
components.minute = 32
components.second = 4
components.nanosecond = 335000000
let calendar = NSCalendar(calendarIdentifier: .gregorian)!
calendar.timeZone = TimeZone(secondsFromGMT: -4 * 60 * 60)!
let date2 = calendar.date(from: components)!
let formattedString2 = iso8601FormattedString(date2)
expect(formattedString2) == "1992-08-06T11:32:04.335Z"
class AnalyticsUtilTests: XCTestCase {

let filters = [
"(foo)": "$1-bar"
]

func equals(a: Any, b: Any) -> Bool {
let aData = try! JSONSerialization.data(withJSONObject: a, options: .prettyPrinted) as NSData
let bData = try! JSONSerialization.data(withJSONObject: b, options: .prettyPrinted)

return aData.isEqual(to: bData)
}

it("format NSDate objects to RFC 3339 complaint string w/ nanoseconds") {
let date = Date(timeIntervalSince1970: 0)
let formattedString = iso8601NanoFormattedString(date)
expect(formattedString) == "1970-01-01T00:00:00.000000000Z"

var components = DateComponents()
components.year = 1992
components.month = 8
components.day = 6
components.hour = 7
components.minute = 32
components.second = 4
components.nanosecond = 335000008
let calendar = NSCalendar(calendarIdentifier: .gregorian)!
calendar.timeZone = TimeZone(secondsFromGMT: -4 * 60 * 60)!
let date2 = calendar.date(from: components)!
let formattedString2 = iso8601NanoFormattedString(date2)
expect(formattedString2) == "1992-08-06T11:32:04.335000008Z"
func testFormatNSDateObjects() {
let date = Date(timeIntervalSince1970: 0)
let formattedString = iso8601FormattedString(date)
XCTAssertEqual(formattedString, "1970-01-01T00:00:00.000Z")
var components = DateComponents()
components.year = 1992
components.month = 8
components.day = 6
components.hour = 7
components.minute = 32
components.second = 4
components.nanosecond = 335000000
let calendar = NSCalendar(calendarIdentifier: .gregorian)!
calendar.timeZone = TimeZone(secondsFromGMT: -4 * 60 * 60)!
let date2 = calendar.date(from: components)!
let formattedString2 = iso8601FormattedString(date2)
XCTAssertEqual(formattedString2, "1992-08-06T11:32:04.335Z")
}

describe("trimQueue", {
it("does nothing when count < max") {

func testFormatNSDateRFC3339() {
let date = Date(timeIntervalSince1970: 0)
let formattedString = iso8601NanoFormattedString(date)
XCTAssertEqual(formattedString, "1970-01-01T00:00:00.000000000Z")

var components = DateComponents()
components.year = 1992
components.month = 8
components.day = 6
components.hour = 7
components.minute = 32
components.second = 4
components.nanosecond = 335000008
let calendar = NSCalendar(calendarIdentifier: .gregorian)!
calendar.timeZone = TimeZone(secondsFromGMT: -4 * 60 * 60)!
let date2 = calendar.date(from: components)!
let formattedString2 = iso8601NanoFormattedString(date2)
XCTAssertEqual(formattedString2, "1992-08-06T11:32:04.335000008Z")
}

func testTrimQueueDoesNothingCountLessThan() {
let queue = NSMutableArray(array: [])
for i in 1...4 {
queue.add(i)
queue.add(i)
}
trimQueue(queue, 5)
expect(queue) == [1, 2, 3, 4]
}

it("trims when count > max") {
XCTAssertEqual(queue, [1, 2, 3, 4])
}
func testTrimQueueWhenCountGreaterThan() {
let queue = NSMutableArray(array: [])
for i in 1...10 {
queue.add(i)
queue.add(i)
}
trimQueue(queue, 5)
expect(queue) == [6, 7, 8, 9, 10]
}

it("does not trim when count == max") {
XCTAssertEqual(queue, [6, 7, 8, 9, 10])
}
func testTrimQueueWhenCountEqual() {
let queue = NSMutableArray(array: [])
for i in 1...5 {
queue.add(i)
queue.add(i)
}
trimQueue(queue, 5)
expect(queue) == [1, 2, 3, 4, 5]
}
})
XCTAssertEqual(queue, [1, 2, 3, 4, 5])
}

describe("JSON traverse", {
let filters = [
"(foo)": "$1-bar"
]

func equals(a: Any, b: Any) -> Bool {
let aData = try! JSONSerialization.data(withJSONObject: a, options: .prettyPrinted) as NSData
let bData = try! JSONSerialization.data(withJSONObject: b, options: .prettyPrinted)

return aData.isEqual(to: bData)
}

it("works with strings") {
expect(Utilities.traverseJSON("a b foo c", andReplaceWithFilters: filters) as? String) == "a b foo-bar c"
}

it("works recursively") {
expect(Utilities.traverseJSON("a b foo foo c", andReplaceWithFilters: filters) as? String) == "a b foo-bar foo-bar c"
}

it("works with nested dictionaries") {
func testJSONTraverseWithStrings() {
XCTAssertEqual(Utilities.traverseJSON("a b foo c", andReplaceWithFilters: filters) as? String, "a b foo-bar c")
}

func testJSONTraverseRecursively() {
XCTAssertEqual(Utilities.traverseJSON("a b foo foo c", andReplaceWithFilters: filters) as? String, "a b foo-bar foo-bar c")
}

func testJSONWorksNestedDictionaries() {
let data = [
"foo": [1, nil, "qfoob", ["baz": "foo"]],
"bar": "foo"
] as [String: Any]
"foo": [1, nil, "qfoob", ["baz": "foo"]],
"bar": "foo"
] as [String: Any]

guard let input = Utilities.traverseJSON(data, andReplaceWithFilters: filters) as? [String: Any] else {
XCTFail("Failed to create actual result from traversed JSON replace")
return
XCTFail("Failed to create actual result from traversed JSON replace")
return
}

let output = [
"foo": [1, nil, "qfoo-barb", ["baz": "foo-bar"]],
"bar": "foo-bar"
] as [String: Any]
"foo": [1, nil, "qfoo-barb", ["baz": "foo-bar"]],
"bar": "foo-bar"
] as [String: Any]

expect(NSDictionary(dictionary: output).isEqual(to: input)) == true
}
it("works with nested arrays") {
XCTAssertEqual(NSDictionary(dictionary: output).isEqual(to: input), true)
}

func testJSONWorksNestedArrays() {
let data = [
[1, nil, "qfoob", ["baz": "foo"]],
"foo"
] as [Any]
[1, nil, "qfoob", ["baz": "foo"]],
"foo"
] as [Any]
let input = Utilities.traverseJSON(data, andReplaceWithFilters: filters)
let output = [
[1, nil, "qfoo-barb", ["baz": "foo-bar"]],
"foo-bar"
] as [Any]
[1, nil, "qfoo-barb", ["baz": "foo-bar"]],
"foo-bar"
] as [Any]

expect(equals(a: input!, b: output)) == true
}
})
}
XCTAssertEqual(equals(a: input!, b: output), true)
}
}
Loading