You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2014/09/15 09:02:12 UTC

ios commit: CB-7450 - Fix deprecations in cordova-ios unit tests

Repository: cordova-ios
Updated Branches:
  refs/heads/master efde32e4b -> d5f570efa


CB-7450 - Fix deprecations in cordova-ios unit tests


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/d5f570ef
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/d5f570ef
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/d5f570ef

Branch: refs/heads/master
Commit: d5f570efa1d209f965c29fcc89efdf16bf1e5187
Parents: efde32e
Author: Shazron Abdullah <sh...@apache.org>
Authored: Mon Sep 15 00:02:02 2014 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Mon Sep 15 00:02:02 2014 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVJSON.h                    |  1 +
 CordovaLib/Classes/CDVJSON.m                    | 14 +++++++++++++
 .../CDVPluginResultJSONSerializationTests.m     | 21 ++++++--------------
 3 files changed, 21 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/d5f570ef/CordovaLib/Classes/CDVJSON.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJSON.h b/CordovaLib/Classes/CDVJSON.h
index eaa895e..8ad85da 100644
--- a/CordovaLib/Classes/CDVJSON.h
+++ b/CordovaLib/Classes/CDVJSON.h
@@ -27,4 +27,5 @@
 
 @interface NSString (CDVJSONSerializing)
 - (id)JSONObject;
+- (id)JSONFragment;
 @end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/d5f570ef/CordovaLib/Classes/CDVJSON.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVJSON.m b/CordovaLib/Classes/CDVJSON.m
index f42dfae..4698bfe 100644
--- a/CordovaLib/Classes/CDVJSON.m
+++ b/CordovaLib/Classes/CDVJSON.m
@@ -74,4 +74,18 @@
     return object;
 }
 
+- (id)JSONFragment
+{
+    NSError* error = nil;
+    id object = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding]
+                                                options:NSJSONReadingAllowFragments
+                                                  error:&error];
+
+    if (error != nil) {
+        NSLog(@"NSString JSONObject error: %@", [error localizedDescription]);
+    }
+
+    return object;
+}
+
 @end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/d5f570ef/CordovaLibTests/CDVPluginResultJSONSerializationTests.m
----------------------------------------------------------------------
diff --git a/CordovaLibTests/CDVPluginResultJSONSerializationTests.m b/CordovaLibTests/CDVPluginResultJSONSerializationTests.m
index 4e18dd6..48eaa82 100644
--- a/CordovaLibTests/CDVPluginResultJSONSerializationTests.m
+++ b/CordovaLibTests/CDVPluginResultJSONSerializationTests.m
@@ -32,27 +32,24 @@
 {
     int val = 5;
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:val];
-    NSString* argJson = [[result argumentsAsJSON] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 
-    XCTAssertTrue([[NSNumber numberWithInt:val] isEqual:@([argJson intValue])]);
+    XCTAssertTrue([[NSNumber numberWithInt:val] isEqual:[[result argumentsAsJSON] JSONFragment]]);
 }
 
 - (void)testSerializingMessageAsDouble
 {
     double val = 5.5;
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:val];
-    NSString* argJson = [[result argumentsAsJSON] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 
-    XCTAssertTrue([[NSNumber numberWithDouble:val] isEqual:@([argJson doubleValue])]);
+    XCTAssertTrue([[NSNumber numberWithDouble:val] isEqual:[[result argumentsAsJSON] JSONFragment]]);
 }
 
 - (void)testSerializingMessageAsBool
 {
     BOOL val = YES;
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:val];
-    NSString* argJson = [[result argumentsAsJSON] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 
-    XCTAssertTrue([[NSNumber numberWithBool:val] isEqual:@([argJson boolValue])]);
+    XCTAssertTrue([[NSNumber numberWithBool:val] isEqual:[[result argumentsAsJSON] JSONFragment]]);
 }
 
 - (void)testSerializingMessageAsArray
@@ -124,30 +121,24 @@
         nil];
 
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageToErrorObject:1];
-    NSDictionary* dic = [[result argumentsAsJSON] JSONObject];
 
-    [self __testDictionary:testValues withDictionary:dic];
+    [self __testDictionary:testValues withDictionary:[[result argumentsAsJSON] JSONObject]];
 }
 
 - (void)testSerializingMessageAsStringContainingQuotes
 {
     NSString* quotedString = @"\"quoted\"";
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:quotedString];
-    NSString* argJson = [[result argumentsAsJSON] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
-
-    // argJson here will return this will "\"quoted\""
-    // TODO: obviously this is ok when passing to JavaScript, but will fail this test
 
-    XCTAssertTrue([quotedString isEqual:argJson]);
+    XCTAssertTrue([quotedString isEqualToString:[[result argumentsAsJSON] JSONFragment]]);
 }
 
 - (void)testSerializingMessageAsStringThatIsNil
 {
     NSString* nilString = nil;
     CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nilString];
-    NSString* argJson = [[result argumentsAsJSON] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
 
-    XCTAssertTrue([@"null" isEqual: argJson]);
+    XCTAssertTrue([[NSNull null] isEqual:[[result argumentsAsJSON] JSONFragment]]);
 }
 
 @end