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

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

TestParser.m: Define ICCF_ErrString to permit linking; log
exceptions; print only if parsing fails.

ICeCoffEE.xcodeproj: Update to Xcode 2.4 format (with Xcode 3.0); make
TestParser compile.

English.lproj/APEInfo.rtfd: Update release notes.

English.lproj/Localizable.strings: Fix a reference to the "APE
Manager" preference pane.

File size: 2.9 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 ps(NSString *format, ...) {
19 va_list args;
20 va_start(args, format);
21 NSString *s = [[NSString alloc] initWithFormat: format arguments: args];
22 va_end(args);
23 printf("%s\n", [s cString]);
24 [s release];
25}
26
27void pr(NSString *s, NSRange r) {
28 ps([[NSString alloc] initWithFormat: @"%@%@>%@<",
29 s, [@"" stringByPaddingToLength: r.location withString: @" " startingAtIndex: 0],
30 [@"" stringByPaddingToLength: r.length withString: @"-" startingAtIndex: 0]]);
31}
32
33CFBundleRef ICCF_bundle = NULL;
34
35int main(int argc, char *argv[]) {
36 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
37
38 NSArray *a = [NSArray arrayWithContentsOfFile: @"urls.plist"];
39 NSCAssert(a != nil, @"Can't get array from urls.plist (wrong cwd? invalid format?)");
40
41 ICCF_StartIC();
42
43 unsigned pass = 0, fail = 0;
44
45 NSEnumerator *e = [a objectEnumerator];
46 NSDictionary *d;
47 while ( (d = [e nextObject]) != nil) {
48 ps(@"");
49
50 NSString *uri = [d objectForKey: @"uri"];
51 NSString *text = [d objectForKey: @"text"];
52 NSCAssert1(uri != nil, @"No URI in test case description %@", d);
53
54 NSRange delimitedURIRange;
55 if (text != nil) {
56 NSArray *bits = [text componentsSeparatedByString: @"|"];
57 NSCAssert1([bits count] == 3, @"Sample text is not of the form 'foo|bar|baz': %@", text);
58 text = [bits componentsJoinedByString: @""];
59 delimitedURIRange.location = [(NSString *)[bits objectAtIndex: 0] length];
60 delimitedURIRange.length = [(NSString *)[bits objectAtIndex: 1] length];
61 } else {
62 text = uri;
63 delimitedURIRange.location = 0;
64 delimitedURIRange.length = [uri length];
65 }
66
67 // XXX can't yet select by word, so just try a middle-ish character
68 NSRange initialSelectionRange = {
69 delimitedURIRange.location + (delimitedURIRange.length / 2),
70 delimitedURIRange.length != 0
71 };
72
73 // XXX figure XFAIL-type error checking
74
75 NSRange enclosingRange;
76 NSString *parsedURI = nil;
77 NSException *parseException = nil;
78 @try {
79 enclosingRange = ICCF_URLEnclosingRange(text, delimitedURIRange);
80 parsedURI = [text substringWithRange: enclosingRange];
81 } @catch (NSException *e) {
82 parseException = e;
83 }
84
85 if ([uri isEqualToString: parsedURI]) {
86 ++pass;
87 continue;
88 }
89
90 ps(@"Text %@", text);
91 pr(@"Available ", delimitedURIRange);
92 pr(@"Starting ", initialSelectionRange);
93
94 if (parseException != nil) {
95 ps(@"Exception %@", parseException);
96 continue;
97 }
98
99 pr(@"Parsed ", enclosingRange);
100 ps(@"Parsed %@", parsedURI);
101 ps(@"Desired %@", uri);
102 ++fail;
103 }
104
105 ICCF_StopIC();
106
107 [pool release];
108}
Note: See TracBrowser for help on using the repository browser.