Commits

Michael Tindal committed 70f88fb

Add tests for conditional expressions, readd CodeGenKit support (but not tests), move DynamicIvar module to ext.sv, make including it optional, and add #{:} string replacement mechanism to wrap strings in quotes.

Comments (0)

Files changed (8)

Classes/Core/SVFunction.m

     }
     
     if (!func) {
-        @throw([NSException exceptionWithName:@"SVUnknownFunctionException" reason:[NSString stringWithFormat:@"Unknown function %@",
-                                                                                    funcName] userInfo:nil]);
+        @throw([NSException exceptionWithName:@"SVUnknownFunctionException" reason:[NSString stringWithFormat:@"Unknown function %@ (original name %@)",
+                                                                                    funcName, self.name] userInfo:nil]);
     }
     if ([func isKindOfClass:[NSBlock class]]) {
         func = [[[SVMiscFunctions alloc] init] svFunctionFromBlock:func];

Classes/Extensions/SVObjcExtensions.m

 {
     NSMutableDictionary * _context = [NSMutableDictionary dictionaryWithDictionary:context];
     NSMutableString *result;
+    BOOL escapeString = NO;
     NSArray *components = [self componentsSeparatedByString:@"#{"];
     if ([components count] == 1) {
         result = [NSMutableString stringWithString:self];
         for (i = 1; i < [components count]; i++) {
             NSArray *parts = [[components objectAtIndex:i] componentsSeparatedByString:@"}"];
             NSString *expression = [parts objectAtIndex:0];
+            if ([expression characterAtIndex:0] == ':') {
+                escapeString = YES;
+                expression = [expression substringFromIndex:1];
+            }
             // evaluate each expression
             if (expression) {
                 expression = [NSString stringWithFormat:@"%@;",expression];
                 SVNode * body = [[SVParserContext parserWithString:expression] parse];
                 id value = [body evaluateWithContext:_context];
                 NSString *stringValue = [value stringValue];
+                if(escapeString) {
+                    if([value isKindOfClass:[NSString class]]) {
+                        stringValue = [NSString stringWithFormat:@"\"%@\"",stringValue];
+                    }
+                }
                 [result appendString:stringValue ? stringValue:@""];
             }
             if (parts.count > 1) {
             }
         }
     }
+    
     return [NSString stringWithString:result];
 }
 

Classes/Types/SVClass.m

         parentName_ = par;
         protocols_ = p;
         NSMutableArray * c = [NSMutableArray arrayWithArray:_contents];
-        [c insertObject:[SVIncludeStatement includeStatementWithArgument:@"SVDynamicIvarKeyValueSupport"] atIndex:0];
         contents_ = c;
     }
     return self;

Silver.xcodeproj/project.pbxproj

 		3A360F14133B7E2A00B85BE0 /* NSMutableArray+SVAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A360F0E133B7E2A00B85BE0 /* NSMutableArray+SVAdditions.m */; };
 		3A360F15133B7E2A00B85BE0 /* NSMutableDictionary+SVExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A360F0F133B7E2A00B85BE0 /* NSMutableDictionary+SVExtensions.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		3A360F16133B7E2A00B85BE0 /* NSMutableDictionary+SVExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A360F10133B7E2A00B85BE0 /* NSMutableDictionary+SVExtensions.m */; };
+		3A501C4114DF376400197403 /* CodeGenKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A501C4014DF376400197403 /* CodeGenKit.framework */; };
 		3A6E42531388789500138ABA /* SVSetCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A6E42511388789400138ABA /* SVSetCommand.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		3A6E42541388789500138ABA /* SVSetCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = 3A6E42521388789400138ABA /* SVSetCommand.m */; };
 		3A6E425613888D2100138ABA /* library.sv in Resources */ = {isa = PBXBuildFile; fileRef = 3A6E425513888D2100138ABA /* library.sv */; };
 		3A360F0E133B7E2A00B85BE0 /* NSMutableArray+SVAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableArray+SVAdditions.m"; sourceTree = "<group>"; };
 		3A360F0F133B7E2A00B85BE0 /* NSMutableDictionary+SVExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMutableDictionary+SVExtensions.h"; sourceTree = "<group>"; };
 		3A360F10133B7E2A00B85BE0 /* NSMutableDictionary+SVExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSMutableDictionary+SVExtensions.m"; sourceTree = "<group>"; };
+		3A501C4014DF376400197403 /* CodeGenKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CodeGenKit.framework; path = "../../../Library/Developer/Xcode/DerivedData/EternityChronicles-cxfeecyapagbpvhjkxorybtywawf/Build/Products/Debug/CodeGenKit.framework"; sourceTree = "<group>"; };
 		3A6E42511388789400138ABA /* SVSetCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVSetCommand.h; sourceTree = "<group>"; };
 		3A6E42521388789400138ABA /* SVSetCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVSetCommand.m; sourceTree = "<group>"; };
 		3A6E425513888D2100138ABA /* library.sv */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = library.sv; sourceTree = "<group>"; };
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				3A501C4114DF376400197403 /* CodeGenKit.framework in Frameworks */,
 				3AC934281335CDE7009CB7C6 /* libreadline.dylib in Frameworks */,
 				3ACD0FCF12A9E5BD00CE8E92 /* libffi.dylib in Frameworks */,
 				3A01FFE012A9CE70005A9772 /* Cocoa.framework in Frameworks */,
 		3A01FFCD12A9CE70005A9772 = {
 			isa = PBXGroup;
 			children = (
+				3A501C4014DF376400197403 /* CodeGenKit.framework */,
 				3AC5B7EE13A7A6DE00594730 /* OCHamcrest.framework */,
 				3AC5B7EF13A7A6DE00594730 /* OCMock.framework */,
 				3AC5B7EA13A7A6BB00594730 /* OCLog.framework */,
 				FRAMEWORK_SEARCH_PATHS = (
 					"$(inherited)",
 					"\"$(SRCROOT)\"",
+					"\"$(SRCROOT)/../../../Library/Developer/Xcode/DerivedData/EternityChronicles-cxfeecyapagbpvhjkxorybtywawf/Build/Products/Debug\"",
 				);
 				FRAMEWORK_VERSION = A;
 				GCC_DYNAMIC_NO_PIC = NO;
 				FRAMEWORK_SEARCH_PATHS = (
 					"$(inherited)",
 					"\"$(SRCROOT)\"",
+					"\"$(SRCROOT)/../../../Library/Developer/Xcode/DerivedData/EternityChronicles-cxfeecyapagbpvhjkxorybtywawf/Build/Products/Debug\"",
 				);
 				FRAMEWORK_VERSION = A;
 				GCC_ENABLE_OBJC_EXCEPTIONS = YES;

Tests/SVFunctionTests.m

 #import "SVObjcExtensions.h"
 #import "NSMutableDictionary+SVExtensions.h"
 #import <OCLog/OCLog.h>
+#import <CodeGenKit/CodeGenKit.h>
 #import <objc/runtime.h>
 
 #define P(n) id n = [[context parse] evaluateNode]

Tests/SVOperatorTests.m

     P(var);
     assertThat(var,is(equalTo(N(4))));
 }
+
+- (void) testConditional1 {
+    PC(@"x = 10; y = 0; x > 10 ? y = 5 : y = 15;");
+    P(var);
+    assertThat(var,is(equalTo(N(15))));
+}
+
+- (void) testConditional2 {
+    PC(@"x = 15; y = 0; x > 10 ? y = 5 : y = 15;");
+    P(var);
+    assertThat(var,is(equalTo(N(5))));
+}
 @end
         return self.objectForKey(k)
     }
 }
-
-module SVDynamicIvarKeyValueSupport {
-    def setValue(value,forUndefinedKey:key) {
-        eval('@#{key} = #{value};');
-    };
-    
-    def valueForUndefinedKey(key) {
-        eval('@#{key};');
-    };
-};
     };
 };
 
+module SVDynamicIvarKeyValueSupport {
+    def setValue(value,forUndefinedKey:key) {
+        eval('@#{key} = #{:value};');
+    };
+    
+    def valueForUndefinedKey(key) {
+        eval('@#{key};');
+    };
+};
+
 def range(loc,len) { return SVRange.rangeWithLocation(loc,length:len); };
 
 def isNode?(n) { return n.isKindOfClass(SVNode.class); };