source: trunk/ICeCoffEE/ICeCoffEE/TestParser.m@ 375

Last change on this file since 375 was 375, checked in by Nicholas Riley, 16 years ago

ICeCoffEE.[hm]: Restore ICCF_CheckRange, moved in [322], as we don't
want the range limited in TestParser.

ICeCoffEEParser.m: Remove ICCF_CheckRange. Comment out expandFront
URL/parens stuff; it's as yet untested. Handle {...} in URLs. Don't
assert when )/} is last character in string. Fix indentation.

ICeCoffEE.xcodeproj: Link TestParser to Cocoa normally. Remove
obsolete build settings.

TestParser.m: Stub out ICCF_CheckRange. Test beginning with
one-character ranges all the way through the string. Output summary
stats at end.

File size: 3.1 KB
Line 
1//
2// TestParser.m
3// ICeCoffEE
4//
5// Created by Nicholas Riley on 6/22/07.
6// Copyright 2007 Nicholas Riley. All rights reserved.
7//
8
9#import <Foundation/Foundation.h>
10#import "ICeCoffEEParser.h"
11
12#include <stdarg.h>
13
14NSString *ICCF_ErrString(OSStatus err, NSString *context) {
15 return [NSString stringWithFormat: @"%@ (%d)", context, (int)err];
16}
17
18void ICCF_CheckRange(NSRange range) {}
19
20void ps(NSString *format, ...) {
21 va_list args;
22 va_start(args, format);
23 NSString *s = [[NSString alloc] initWithFormat: format arguments: args];
24 va_end(args);
25 printf("%s\n", [s cString]);
26 [s release];
27}
28
29void pr(NSString *s, NSRange r) {
30 ps([[NSString alloc] initWithFormat: @"%@%@>%@<",
31 s, [@"" stringByPaddingToLength: r.location withString: @" " startingAtIndex: 0],
32 [@"" stringByPaddingToLength: r.length withString: @"-" startingAtIndex: 0]]);
33}
34
35CFBundleRef ICCF_bundle = NULL;
36
37int main(int argc, char *argv[]) {
38 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
39
40 NSArray *a = [NSArray arrayWithContentsOfFile: @"urls.plist"];
41 NSCAssert(a != nil, @"Can't get array from urls.plist (wrong cwd? invalid format?)");
42
43 ICCF_StartIC();
44
45 unsigned pass = 0, fail = 0;
46
47 NSEnumerator *e = [a objectEnumerator];
48 NSDictionary *d;
49 while ( (d = [e nextObject]) != nil) {
50 ps(@"");
51
52 NSString *uri = [d objectForKey: @"uri"];
53 NSString *text = [d objectForKey: @"text"];
54 NSCAssert1(uri != nil, @"No URI in test case description %@", d);
55
56 NSRange delimitedURIRange;
57 if (text != nil) {
58 NSArray *bits = [text componentsSeparatedByString: @"|"];
59 NSCAssert1([bits count] == 3, @"Sample text is not of the form 'foo|bar|baz': %@", text);
60 text = [bits componentsJoinedByString: @""];
61 delimitedURIRange.location = [(NSString *)[bits objectAtIndex: 0] length];
62 delimitedURIRange.length = [(NSString *)[bits objectAtIndex: 1] length];
63 } else {
64 text = uri;
65 delimitedURIRange.location = 0;
66 delimitedURIRange.length = [uri length];
67 }
68
69 for (unsigned startOffset = 0 ; startOffset < delimitedURIRange.length ; ++startOffset) {
70 NSRange initialSelectionRange = {
71 delimitedURIRange.location + startOffset,
72 delimitedURIRange.length != 0
73 };
74
75 // XXX figure XFAIL-type error checking
76
77 NSRange enclosingRange;
78 NSString *parsedURI = nil;
79 NSException *parseException = nil;
80 @try {
81 enclosingRange = ICCF_URLEnclosingRange(text, delimitedURIRange);
82 parsedURI = [text substringWithRange: enclosingRange];
83 } @catch (NSException *e) {
84 parseException = e;
85 }
86
87 if ([uri isEqualToString: parsedURI]) {
88 ++pass;
89 continue;
90 }
91
92 ps(@"Text %@", text);
93 pr(@"Available ", delimitedURIRange);
94 pr(@"Starting ", initialSelectionRange);
95
96 if (parseException != nil) {
97 ps(@"Exception %@", parseException);
98 } else {
99 pr(@"Parsed ", enclosingRange);
100 ps(@"Parsed %@", parsedURI);
101 ps(@"Desired %@", uri);
102 }
103 ++fail;
104 goto summary;
105 }
106 }
107
108summary:
109 ps(@"PASS %d FAIL %d", pass, fail);
110
111 ICCF_StopIC();
112
113 [pool release];
114}
Note: See TracBrowser for help on using the repository browser.