Commit ed304df9 authored by Stig Brautaset's avatar Stig Brautaset

refactor tests a little

parent 17806b87
......@@ -30,7 +30,6 @@
#import "AbstractTest.h"
@interface DataDrivenTest : AbstractTest {
SBJsonWriter *prettyWriter;
NSString *dir;
NSDirectoryEnumerator *files;
}
......
......@@ -37,21 +37,12 @@
[super setUp];
writer.sortKeys = YES;
prettyWriter = [SBJsonWriter new];
prettyWriter.humanReadable = YES;
prettyWriter.sortKeys = YES;
dir = @"Tests/Data";
files = [[NSFileManager defaultManager] enumeratorAtPath:dir];
}
- (void)tearDown {
[prettyWriter release];
[super tearDown];
}
- (void)testTerse {
NSString *file;
- (void)withSuffix:(NSString *)suffix {
NSString *file;
while ((file = [files nextObject])) {
if (![[file pathExtension] isEqualToString:@"json"])
continue;
......@@ -76,54 +67,27 @@
STAssertNotNil(written, jsonPath);
STAssertNil(writer.errorTrace, @"%@: %@", jsonPath, writer.errorTrace);
NSString *tersePath = [jsonPath stringByAppendingPathExtension:@"terse"];
NSString *terseText = [NSString stringWithContentsOfFile:tersePath
encoding:NSUTF8StringEncoding
error:nil];
STAssertNotNil(terseText, @"Could not load %@", tersePath);
NSString *path = [jsonPath stringByAppendingPathExtension:suffix];
NSString *text = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:nil];
STAssertNotNil(text, @"Could not load %@", path);
// Chop off newline at end of string
terseText = [terseText substringToIndex:[terseText length]-1];
STAssertEqualObjects(written, terseText, @"at %@", jsonPath);
text = [text substringToIndex:[text length]-1];
STAssertEqualObjects(written, text, @"at %@", jsonPath);
}
}
- (void)testTerse {
writer.humanReadable = NO;
[self withSuffix:@"terse"];
}
- (void)testPretty {
NSString *file;
while ((file = [files nextObject])) {
if (![[file pathExtension] isEqualToString:@"json"])
continue;
NSRange range = [file rangeOfString:@"fail"];
if (range.location != NSNotFound)
continue;
NSString *jsonPath = [dir stringByAppendingPathComponent:file];
NSString *jsonText = [NSString stringWithContentsOfFile:jsonPath
encoding:NSUTF8StringEncoding
error:nil];
STAssertNotNil(jsonText, @"Could not load %@", jsonPath);
id parsed;
STAssertNoThrow(parsed = [parser objectWithString:jsonText], jsonPath);
STAssertNotNil(parsed, jsonPath);
STAssertNil(parser.errorTrace, @"%@: %@", jsonPath, parser.errorTrace);
NSString *written;
STAssertNoThrow(written = [prettyWriter stringWithObject:parsed], jsonPath);
STAssertNotNil(written, jsonPath);
STAssertNil(prettyWriter.errorTrace, @"%@: %@", jsonPath, prettyWriter.errorTrace);
NSString *prettyPath = [jsonPath stringByAppendingPathExtension:@"pretty"];
NSString *prettyText = [NSString stringWithContentsOfFile:prettyPath
encoding:NSUTF8StringEncoding
error:nil];
STAssertNotNil(prettyText, @"Could not load %@", prettyPath);
// Chop off newline at end of string
prettyText = [prettyText substringToIndex:[prettyText length]-1];
STAssertEqualObjects(written, prettyText, @"at %@", jsonPath);
}
writer.humanReadable = YES;
[self withSuffix:@"pretty"];
}
- (void)testFail {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment