Skip to content

Commit

Permalink
extra unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evermeer committed Mar 29, 2016
1 parent 289fdbb commit a18dd7c
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion EVReflection.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Pod::Spec.new do |s|
#

s.name = "EVReflection"
s.version = "2.22.0"
s.version = "2.22.1"
s.summary = "iOS: Swift helper library with reflection functions"
s.description = "Swift helper library with reflection functions including support for NSCoding, Printable, Hashable, Equatable and JSON"
s.homepage = "https://github.com/evermeer/EVReflection"
Expand Down
4 changes: 3 additions & 1 deletion EVReflection/EVReflection.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = evict;
TargetAttributes = {
2DC8AA3C1C24215500FA6B8E = {
Expand Down Expand Up @@ -935,6 +935,7 @@
7F3E318A1BB9095C001E6788 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = "EVReflectionTests/osx-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "nl.evict.EVReflection-OSX-Tests";
Expand All @@ -947,6 +948,7 @@
7F3E318B1BB9095C001E6788 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
COMBINE_HIDPI_IMAGES = YES;
INFOPLIST_FILE = "EVReflectionTests/osx-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "nl.evict.EVReflection-OSX-Tests";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
9 changes: 9 additions & 0 deletions EVReflection/EVReflectionTests/EVReflectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ class EVReflectionTests: XCTestCase {
print(a2.toJsonString())
}

func testStruct() {
let json = X().toJsonString()
print("json = \(json)")
}
}

class X: EVObject {
var y:String = "the y"
var c:CGPoint = CGPointMake(2,3)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ class EVRelfectionEnheritanceTests: XCTestCase {
// Deserialize a new object based on that JSON
let newObject = Quz(json: json)

XCTAssertEqual((newObject.fooBar as? Bar)?.justBar, "For bar only", "fooBar is not Bar?")
XCTAssertEqual((newObject.fooBaz as? Baz)?.justBaz, "For baz only", "fooBaz is not Baz?")
XCTAssertEqual(newObject.fooArray.count, 3, "array should contain 3 objects")
if newObject.fooArray.count == 3 {
XCTAssertEqual((newObject.fooArray[0] as? Bar)?.justBar, "For bar only", "fooBar is not Bar?")
XCTAssertEqual((newObject.fooArray[1] as? Baz)?.justBaz, "For baz only", "fooBaz is not Baz?")
XCTAssertEqual(newObject.fooArray[2].allFoo, "all Foo", "should just be a Foo?")
}

// The new object JSON
let newJson = newObject.toJsonString()
print("New JSON = \(newJson)")
Expand Down
12 changes: 7 additions & 5 deletions EVReflection/pod/EVReflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ final public class EVReflection {
if !skipKey {
let mapping = keyMapping[k as! String]
let original:NSObject? = getValue(anyObject, key: mapping ?? k as! String)
if let dictValue = dictionaryAndArrayConversion(anyObject, key: k as! String, fieldType: types[mapping ?? k as! String], original: original, dictValue: v) {
if let dictValue = dictionaryAndArrayConversion(anyObject, key: k as! String, fieldType: types[mapping ?? k as! String], original: original, theDictValue: v) {
if let key:String = keyMapping[k as! String] {
setObjectValue(anyObject, key: key, value: dictValue, typeInObject: types[key])
setObjectValue(anyObject, key: key, theValue: dictValue, typeInObject: types[key])
} else {
setObjectValue(anyObject, key: k as! String, value: dictValue, typeInObject: types[k as! String])
setObjectValue(anyObject, key: k as! String, theValue: dictValue, typeInObject: types[k as! String])
}
}
}
Expand Down Expand Up @@ -629,7 +629,8 @@ final public class EVReflection {

:returns: Nothing
*/
public static func setObjectValue<T where T:NSObject>(anyObject: T, key:String, var value:AnyObject?, typeInObject:String? = nil) {
public static func setObjectValue<T where T:NSObject>(anyObject: T, key:String, theValue:AnyObject?, typeInObject:String? = nil) {
var value = theValue
if value == nil || value as? NSNull != nil {
// do {
// var nilValue: AnyObject? = Optional.None
Expand Down Expand Up @@ -789,7 +790,8 @@ final public class EVReflection {

:returns: The converted value
*/
private static func dictionaryAndArrayConversion(anyObject:NSObject, key: String, fieldType:String?, original:NSObject?, var dictValue: AnyObject?) -> AnyObject? {
private static func dictionaryAndArrayConversion(anyObject:NSObject, key: String, fieldType:String?, original:NSObject?, theDictValue: AnyObject?) -> AnyObject? {
var dictValue = theDictValue
if let type = fieldType {
if type.hasPrefix("Array<") && dictValue as? NSDictionary != nil {
if (dictValue as! NSDictionary).count == 1 {
Expand Down

0 comments on commit a18dd7c

Please sign in to comment.