Commits

dcutting  committed bd72a3e

URL type.

  • Participants
  • Parent commits 89b99ce

Comments (0)

Files changed (5)

File VeriJSON.xcodeproj/project.pbxproj

 		C8A0CCEC1691EBB60067B7CA /* ObjectWithNonObject.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A0CCEB1691EBB50067B7CA /* ObjectWithNonObject.json */; };
 		C8A0CCEE1691F0C40067B7CA /* RealisticObject.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A0CCED1691F0C30067B7CA /* RealisticObject.json */; };
 		C8A0CCF01691F13B0067B7CA /* RealisticObjectPattern.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A0CCEF1691F13B0067B7CA /* RealisticObjectPattern.json */; };
+		C8A2072C169584C8001CA314 /* ObjectWithURL.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A2072A169584C8001CA314 /* ObjectWithURL.json */; };
+		C8A2072D169584C8001CA314 /* ObjectWithURLPattern.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A2072B169584C8001CA314 /* ObjectWithURLPattern.json */; };
 		C8A64F6F1692647700D01705 /* SimpleArray.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A64F6E1692647700D01705 /* SimpleArray.json */; };
 		C8A64F721692648B00D01705 /* SimpleArrayPattern.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A64F711692648B00D01705 /* SimpleArrayPattern.json */; };
 		C8A64F761692654800D01705 /* ArrayOfStringsPattern.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A64F741692654800D01705 /* ArrayOfStringsPattern.json */; };
 		C8A0CCEB1691EBB50067B7CA /* ObjectWithNonObject.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ObjectWithNonObject.json; path = Data/ObjectWithNonObject.json; sourceTree = "<group>"; };
 		C8A0CCED1691F0C30067B7CA /* RealisticObject.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = RealisticObject.json; path = Data/RealisticObject.json; sourceTree = "<group>"; };
 		C8A0CCEF1691F13B0067B7CA /* RealisticObjectPattern.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = RealisticObjectPattern.json; path = Data/RealisticObjectPattern.json; sourceTree = "<group>"; };
+		C8A2072A169584C8001CA314 /* ObjectWithURL.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ObjectWithURL.json; path = Data/ObjectWithURL.json; sourceTree = "<group>"; };
+		C8A2072B169584C8001CA314 /* ObjectWithURLPattern.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ObjectWithURLPattern.json; path = Data/ObjectWithURLPattern.json; sourceTree = "<group>"; };
 		C8A64F6E1692647700D01705 /* SimpleArray.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = SimpleArray.json; path = Data/SimpleArray.json; sourceTree = "<group>"; };
 		C8A64F711692648B00D01705 /* SimpleArrayPattern.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = SimpleArrayPattern.json; path = Data/SimpleArrayPattern.json; sourceTree = "<group>"; };
 		C8A64F741692654800D01705 /* ArrayOfStringsPattern.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ArrayOfStringsPattern.json; path = Data/ArrayOfStringsPattern.json; sourceTree = "<group>"; };
 				C8A64FA21693494A00D01705 /* ObjectWithDateStringPattern.json */,
 				C8A64FA11693494A00D01705 /* ObjectWithDateString.json */,
 				C8A64FA51693499700D01705 /* ObjectWithDateStringInvalid.json */,
+				C8A2072B169584C8001CA314 /* ObjectWithURLPattern.json */,
+				C8A2072A169584C8001CA314 /* ObjectWithURL.json */,
 			);
 			name = Data;
 			sourceTree = "<group>";
 				C8A64FA31693494B00D01705 /* ObjectWithDateString.json in Resources */,
 				C8A64FA41693494B00D01705 /* ObjectWithDateStringPattern.json in Resources */,
 				C8A64FA61693499700D01705 /* ObjectWithDateStringInvalid.json in Resources */,
+				C8A2072C169584C8001CA314 /* ObjectWithURL.json in Resources */,
+				C8A2072D169584C8001CA314 /* ObjectWithURLPattern.json in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

File VeriJSON/VeriJSON/VeriJSON.m

     if ([@"bool" isEqualToString:pattern]) {
         valid = [value isKindOfClass:[NSNumber class]];
     }
+    if ([@"url" isEqualToString:pattern]) {
+        valid = [self verifyURL:value];
+    }
 
     if (valid) {
         [patternStack removeLastObject];
     return YES;
 }
 
+- (BOOL)verifyURL:(NSString *)value {
+    NSURL *url = [NSURL URLWithString:value];
+    return nil != url;
+}
+
 - (NSError *)buildErrorFromPatternStack:(NSArray *)patternStack {
     NSString *path = [self buildPathFromPatternStack:patternStack];
     NSString *localisedDescription = [NSString stringWithFormat:@"Invalid pattern %@", path];

File VeriJSONTests/Data/ObjectWithURL.json

+{
+    "self": "http://example.com/self?q=1"
+}

File VeriJSONTests/Data/ObjectWithURLPattern.json

+{
+    "self": "url"
+}

File VeriJSONTests/VeriJSONTests.m

         });
     });
     
+    context(@"url types", ^{
+        it(@"absolute URL", ^{
+            id pattern = [bundle jsonFromResource:@"ObjectWithURLPattern.json"];
+            id json = [bundle jsonFromResource:@"ObjectWithURL.json"];
+            BOOL valid = [veriJSON verifyJSON:json pattern:pattern];
+            [[@(valid) should] beYes];
+        });
+    });
+    
     it(@"hack to ensure tests finish", ^{
         sleep(1);
     });