Permalink
Browse files

Added more dumping routines, made sure it worked on Mac OS X 10.6, tu…

…rned on -Werror.
  • Loading branch information...
1 parent 5280f11 commit 462fee9d93681cc42c99169a07bd302ac2bc29fe Patrick Thomson committed Jul 10, 2009
Showing with 90 additions and 19 deletions.
  1. +15 −8 YAMLKit.xcodeproj/project.pbxproj
  2. +7 −2 src/YAMLKit.h
  3. +40 −2 src/YAMLKit.m
  4. +1 −1 src/YKConstants.h
  5. +1 −1 src/YKEmitter.h
  6. +8 −3 src/YKEmitter.m
  7. +7 −0 src/YKParser.m
  8. +11 −2 test/TestHighLevelAccess.m
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ 72C6DBDA1007D396008D7A84 /* libyaml.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72C6DBD91007D396008D7A84 /* libyaml.dylib */; };
8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */; };
CD1DE6870F0960D3006FDAB3 /* YAMLKit.h in Headers */ = {isa = PBXBuildFile; fileRef = CD1DE6860F0960D3006FDAB3 /* YAMLKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -15,7 +16,6 @@
CD312F630F09A0E50004C345 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD312F620F09A0E50004C345 /* SenTestingKit.framework */; };
CD312F930F09A1A00004C345 /* TestHighLevelAccess.m in Sources */ = {isa = PBXBuildFile; fileRef = CD69C2420F098A540011BAB6 /* TestHighLevelAccess.m */; };
CD4669530F0A98330047C2BF /* verysimple.yaml in Resources */ = {isa = PBXBuildFile; fileRef = CD4669520F0A98330047C2BF /* verysimple.yaml */; };
- CD4669600F0A99130047C2BF /* libyaml.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CD46695F0F0A99130047C2BF /* libyaml.dylib */; };
CD4669650F0A996A0047C2BF /* TestParsing.m in Sources */ = {isa = PBXBuildFile; fileRef = CD69C23A0F098A2F0011BAB6 /* TestParsing.m */; };
CD46698D0F0A9A040047C2BF /* YAMLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* YAMLKit.framework */; };
CD69C2200F097CEE0011BAB6 /* YKEmitter.h in Headers */ = {isa = PBXBuildFile; fileRef = CD69C21E0F097CEE0011BAB6 /* YKEmitter.h */; };
@@ -42,14 +42,14 @@
089C1667FE841158C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
32DBCF5E0370ADEE00C91783 /* YAMLKit_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YAMLKit_Prefix.pch; sourceTree = "<group>"; };
+ 72C6DBD91007D396008D7A84 /* libyaml.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libyaml.dylib; path = /usr/local/lib/libyaml.dylib; sourceTree = "<absolute>"; };
8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8DC2EF5B0486A6940098B216 /* YAMLKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = YAMLKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
CD1DE6860F0960D3006FDAB3 /* YAMLKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YAMLKit.h; sourceTree = "<group>"; };
CD2913040F0E85930003FE76 /* YKConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YKConstants.h; sourceTree = "<group>"; };
CD312F560F09A0A40004C345 /* Run Tests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Run Tests.octest"; sourceTree = BUILT_PRODUCTS_DIR; };
CD312F620F09A0E50004C345 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
CD4669520F0A98330047C2BF /* verysimple.yaml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = verysimple.yaml; sourceTree = "<group>"; };
- CD46695F0F0A99130047C2BF /* libyaml.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libyaml.dylib; path = /usr/local/lib/libyaml.dylib; sourceTree = "<absolute>"; };
CD69C21E0F097CEE0011BAB6 /* YKEmitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YKEmitter.h; sourceTree = "<group>"; };
CD69C21F0F097CEE0011BAB6 /* YKEmitter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YKEmitter.m; sourceTree = "<group>"; };
CD69C2330F0983A90011BAB6 /* YKParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YKParser.h; sourceTree = "<group>"; };
@@ -72,7 +72,7 @@
buildActionMask = 2147483647;
files = (
8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */,
- CD4669600F0A99130047C2BF /* libyaml.dylib in Frameworks */,
+ 72C6DBDA1007D396008D7A84 /* libyaml.dylib in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -148,9 +148,9 @@
1058C7B0FEA5585E11CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
- CD46695F0F0A99130047C2BF /* libyaml.dylib */,
CD312F620F09A0E50004C345 /* SenTestingKit.framework */,
1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */,
+ 72C6DBD91007D396008D7A84 /* libyaml.dylib */,
);
name = "Linked Frameworks";
sourceTree = "<group>";
@@ -353,6 +353,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = NO;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
@@ -363,6 +364,8 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = YAMLKit_Prefix.pch;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ GCC_WARN_PEDANTIC = NO;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Library/Frameworks";
PRODUCT_NAME = YAMLKit;
@@ -381,17 +384,20 @@
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = YAMLKit_Prefix.pch;
+ GCC_TREAT_WARNINGS_AS_ERRORS = YES;
+ GCC_WARN_PEDANTIC = NO;
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Library/Frameworks";
PRODUCT_NAME = YAMLKit;
+ SDKROOT = macosx10.6;
WRAPPER_EXTENSION = framework;
};
name = Release;
};
1DEB91B208733DA50010E9CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_ENABLE_OBJC_GC = supported;
GCC_OPTIMIZATION_LEVEL = 0;
@@ -403,15 +409,15 @@
LIBRARY_SEARCH_PATHS = /usr/local/lib/;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
- SDKROOT = macosx10.5;
+ SDKROOT = macosx10.6;
WARNING_CFLAGS = "-Wall";
};
name = Debug;
};
1DEB91B308733DA50010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ARCHS = "$(ARCHS_STANDARD_32_BIT)";
+ ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = c99;
GCC_ENABLE_OBJC_GC = supported;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
@@ -420,8 +426,9 @@
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = /usr/local/include/;
LIBRARY_SEARCH_PATHS = /usr/local/lib/;
+ ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
- SDKROOT = macosx10.5;
+ SDKROOT = macosx10.6;
WARNING_CFLAGS = "-Wall";
};
name = Release;
View
@@ -15,7 +15,12 @@
}
-+ (NSString *)dump:(id)object;
-+ (id)load:(NSString *)aString;
++ (NSString *)dumpObject:(id)object;
++ (BOOL)dumpObject:(id)object toFile:(NSString *)path;
++ (BOOL)dumpObject:(id)object toURL:(NSURL *)path;
+
++ (id)loadFromString:(NSString *)aString;
++ (id)loadFromFile:(NSString *)path;
++ (id)loadFromURL:(NSURL *)url;
@end
View
@@ -10,7 +10,7 @@
@implementation YAMLKit
-+ (id)load:(NSString *)str
++ (id)loadFromString:(NSString *)str
{
YKParser *p = [[[YKParser alloc] init] autorelease];
[p readString:str];
@@ -22,13 +22,51 @@ + (id)load:(NSString *)str
return result;
}
-+ (NSString *)dump:(id)object
++ (id)loadFromFile:(NSString *)path
+{
+ NSString *contents = [NSString stringWithContentsOfFile:path
+ encoding:NSUTF8StringEncoding
+ error:NULL];
+ if(contents == nil) return nil; // if there was an error reading from the file
+ return [self loadFromString:contents];
+}
+
++ (id)loadFromURL:(NSURL *)url
+{
+ NSString *contents = [NSString stringWithContentsOfURL:url
+ encoding:NSUTF8StringEncoding
+ error:NULL];
+ if(contents == nil) return nil; // if there was an error reading from the URL
+ return [self loadFromString:contents];
+}
+
++ (NSString *)dumpObject:(id)object
{
YKEmitter *e = [[[YKEmitter alloc] init] autorelease];
[e emitItem:object];
return [e emittedString];
}
++ (BOOL)dumpObject:(id)object toFile:(NSString *)path
+{
+ YKEmitter *e = [[[YKEmitter alloc] init] autorelease];
+ [e emitItem:object];
+ return [[e emittedString] writeToFile:path
+ atomically:YES
+ encoding:NSUTF8StringEncoding
+ error:NULL];
+}
+
++ (BOOL)dumpObject:(id)object toURL:(NSURL *)path
+{
+ YKEmitter *e = [[[YKEmitter alloc] init] autorelease];
+ [e emitItem:object];
+ return [[e emittedString] writeToURL:path
+ atomically:YES
+ encoding:NSUTF8StringEncoding
+ error:NULL];
+}
+
@end
View
@@ -9,7 +9,7 @@
-const NSString *YKErrorDomain = @"YKErrorDomain";
+NSString *YKErrorDomain = @"YKErrorDomain";
const NSString *YKProblemValueKey = @"YKProblemValue";
const NSString *YKProblemOffsetKey = @"YKProblemOffset";
const NSString *YKProblemIndexKey = @"YKProblemIndex";
View
@@ -16,11 +16,11 @@
}
- (void)emitItem:(id)item;
-- (int)_writeItem:(id)item toDocument:(yaml_document_t *)document;
- (NSString *)emittedString;
- (NSData *)emittedData;
@property(assign) BOOL usesExplicitDelimiters;
@property(assign) NSStringEncoding encoding;
+
@end
View
@@ -7,8 +7,13 @@
#import "YKEmitter.h"
-@implementation YKEmitter
+@interface YKEmitter (YKEmitterPrivateMEthods)
+
+- (int)_writeItem:(id)item toDocument:(yaml_document_t *)document;
+@end
+
+@implementation YKEmitter
@synthesize usesExplicitDelimiters, encoding;
@@ -22,7 +27,7 @@ - (id)init
// Coincidentally, the order of arguments to CFDataAppendBytes are just right
// such that if I pass the buffer as the data parameter, I can just use
// a pointer to CFDataAppendBytes to tell the emitter to write to the NSMutableData.
- yaml_emitter_set_output(&emitter, CFDataAppendBytes, buffer);
+ yaml_emitter_set_output(&emitter, (yaml_write_handler_t*)CFDataAppendBytes, buffer);
[self setUsesExplicitDelimiters:NO];
}
return self;
@@ -42,7 +47,7 @@ - (void)emitItem:(id)item
yaml_document_delete(&document);
}
-- (int)_writeItem:(id)item toDocument:(yaml_document_t *)doc;
+- (int)_writeItem:(id)item toDocument:(yaml_document_t *)doc
{
int nodeID = 0;
// #keyEnumerator covers NSMapTable/NSHashTable/NSDictionary
View
@@ -8,6 +8,13 @@
#import "YKParser.h"
#import "YKConstants.h"
+@interface YKParser (YKParserPrivateMethods)
+
+- (id)_interpretObjectFromEvent:(yaml_event_t)event;
+- (NSError *)_constructErrorFromParser:(yaml_parser_t *)p;
+
+@end
+
@implementation YKParser
@synthesize readyToParse;
View
@@ -12,16 +12,25 @@ @implementation TestHighLevelAccess
- (void)testStringDumping
{
NSArray *a = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];
- NSString *dumped = [YAMLKit dump:a];
+ NSString *dumped = [YAMLKit dumpObject:a];
STAssertEqualObjects(dumped, @"- one\n- two\n- three\n", @"was not the same when dumped");
}
- (void)testStringLoading
{
NSString *dumped = @"- one\n- two\n- three";
- NSArray *a = [YAMLKit load:dumped];
+ NSArray *a = [YAMLKit loadFromString:dumped];
NSArray *b = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];
STAssertEqualObjects(a, b, @"was not the same when loaded");
}
+- (void)testFileDumpingAndLoading
+{
+ NSArray *a = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];
+ NSString *path = @"/tmp/yamlkit_test.yaml";
+ STAssertTrue([YAMLKit dumpObject:a toFile:path], @"did not dump successfully");
+ STAssertEqualObjects(a, [YAMLKit loadFromFile:path], @"was not the same when loaded");
+}
+
+
@end

0 comments on commit 462fee9

Please sign in to comment.