Skip to content

Commit

Permalink
first test, of JSONUnarchiver
Browse files Browse the repository at this point in the history
  • Loading branch information
JimRoepcke committed Jan 3, 2017
1 parent 8800156 commit de110fc
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 54 deletions.
8 changes: 4 additions & 4 deletions Example/JSONCoding.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; };
607FACEC1AFB9204008FA782 /* JSONUnarchiver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* JSONUnarchiver.swift */; };
CEE38F439386755CBEFDE6EA /* Pods_JSONCoding_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A24C9DAB021CD503FC19C0E4 /* Pods_JSONCoding_Tests.framework */; };
/* End PBXBuildFile section */

Expand All @@ -17,7 +17,7 @@
36246745792588BD7FF76D1C /* Pods-JSONCoding_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-JSONCoding_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-JSONCoding_Tests/Pods-JSONCoding_Tests.release.xcconfig"; sourceTree = "<group>"; };
607FACE51AFB9204008FA782 /* JSONCoding_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JSONCoding_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
607FACEB1AFB9204008FA782 /* JSONUnarchiver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONUnarchiver.swift; sourceTree = "<group>"; };
7DACE38BDD5F45ED4EA47AC0 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
8C38B400C844F2C157922E56 /* JSONCoding.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = JSONCoding.podspec; path = ../JSONCoding.podspec; sourceTree = "<group>"; };
A24C9DAB021CD503FC19C0E4 /* Pods_JSONCoding_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_JSONCoding_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -57,7 +57,7 @@
607FACE81AFB9204008FA782 /* Tests */ = {
isa = PBXGroup;
children = (
607FACEB1AFB9204008FA782 /* Tests.swift */,
607FACEB1AFB9204008FA782 /* JSONUnarchiver.swift */,
607FACE91AFB9204008FA782 /* Supporting Files */,
);
path = Tests;
Expand Down Expand Up @@ -219,7 +219,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */,
607FACEC1AFB9204008FA782 /* JSONUnarchiver.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
64 changes: 64 additions & 0 deletions Example/Tests/JSONUnarchiver.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// JSONUnarchiverSpec.swift
// JSONCoding
//
// Created by Jim Roepcke on 2017-01-02.
// Copyright © 2016- Jim Roepcke.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
import Quick
import Nimble
import JSONCoding

class JSONUnarchiverSpec: QuickSpec {
override func spec() {
describe("JSONUnarchiver") {

context("unarchiving top level JSONCoding values") {

it("can unarchive a VerySimpleTestThing") {
let number = 42
let json: JSON = ["number": number]
do {
let thing: VerySimpleTestThing = try JSONUnarchiver.topLevelUnarchived(with: json) { _ in }
expect(thing.number) == number
} catch {
fail("\(error)")
}
}

}
}
}
}

private struct VerySimpleTestThing: JSONCoding {

let number: Int

enum Key: String, JSONKey {
case number
}

static func _unarchived(with json: Any, unarchiver: JSONUnarchiving) throws -> VerySimpleTestThing {
return VerySimpleTestThing(number: try Key.number.value(in: json))
}

}
50 changes: 0 additions & 50 deletions Example/Tests/Tests.swift

This file was deleted.

0 comments on commit de110fc

Please sign in to comment.