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 |
|
---|
14 | void ps(NSString *format, ...) {
|
---|
15 | va_list args;
|
---|
16 | va_start(args, format);
|
---|
17 | NSString *s = [[NSString alloc] initWithFormat: format arguments: args];
|
---|
18 | va_end(args);
|
---|
19 | printf("%s\n", [s cString]);
|
---|
20 | [s release];
|
---|
21 | }
|
---|
22 |
|
---|
23 | void pr(NSString *s, NSRange r) {
|
---|
24 | ps([[NSString alloc] initWithFormat: @"%@%@>%@<",
|
---|
25 | s, [@"" stringByPaddingToLength: r.location withString: @" " startingAtIndex: 0],
|
---|
26 | [@"" stringByPaddingToLength: r.length withString: @"-" startingAtIndex: 0]]);
|
---|
27 | }
|
---|
28 |
|
---|
29 | CFBundleRef ICCF_bundle = NULL;
|
---|
30 |
|
---|
31 | int main(int argc, char *argv[]) {
|
---|
32 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
---|
33 |
|
---|
34 | NSArray *a = [NSArray arrayWithContentsOfFile: @"urls.plist"];
|
---|
35 | NSCAssert(a != nil, @"Can't get array from urls.plist (wrong cwd? invalid format?)");
|
---|
36 |
|
---|
37 | ICCF_StartIC();
|
---|
38 |
|
---|
39 | NSEnumerator *e = [a objectEnumerator];
|
---|
40 | NSDictionary *d;
|
---|
41 | while ( (d = [e nextObject]) != nil) {
|
---|
42 | NSString *uri = [d objectForKey: @"uri"];
|
---|
43 | NSString *text = [d objectForKey: @"text"];
|
---|
44 | NSCAssert1(uri != nil, @"No URI in test case description %@", d);
|
---|
45 |
|
---|
46 | NSRange delimitedURIRange;
|
---|
47 | if (text != nil) {
|
---|
48 | NSArray *bits = [text componentsSeparatedByString: @"|"];
|
---|
49 | NSCAssert1([bits count] == 3, @"Sample text is not of the form 'foo|bar|baz': %@", text);
|
---|
50 | text = [bits componentsJoinedByString: @""];
|
---|
51 | delimitedURIRange.location = [(NSString *)[bits objectAtIndex: 0] length];
|
---|
52 | delimitedURIRange.length = [(NSString *)[bits objectAtIndex: 1] length];
|
---|
53 | } else {
|
---|
54 | text = uri;
|
---|
55 | delimitedURIRange.location = 0;
|
---|
56 | delimitedURIRange.length = [uri length];
|
---|
57 | }
|
---|
58 |
|
---|
59 | // XXX can't yet select by word, so just try a middle-ish character
|
---|
60 | NSRange initialSelectionRange = {
|
---|
61 | delimitedURIRange.location + (delimitedURIRange.length / 2),
|
---|
62 | delimitedURIRange.length != 0
|
---|
63 | };
|
---|
64 |
|
---|
65 | // XXX figure XFAIL-type error checking
|
---|
66 |
|
---|
67 | // XXX figure out a way to plot a range underneath a string, like:
|
---|
68 | // foo(https://www-s.acm.uiuc.edu/wiki/space/usermloar2)bar
|
---|
69 | // >--------------------------------------------------<
|
---|
70 | ps(@"Text %@", text);
|
---|
71 | pr(@"Available ", delimitedURIRange);
|
---|
72 | pr(@"Starting ", initialSelectionRange);
|
---|
73 |
|
---|
74 | NSRange enclosingRange = ICCF_URLEnclosingRange(text, delimitedURIRange);
|
---|
75 | pr(@"Parsed ", enclosingRange);
|
---|
76 |
|
---|
77 | ps(@"Parsed %@", [text substringWithRange: enclosingRange]);
|
---|
78 | ps(@"Desired %@", uri);
|
---|
79 | ps(@"");
|
---|
80 | }
|
---|
81 |
|
---|
82 | ICCF_StopIC();
|
---|
83 |
|
---|
84 | [pool release];
|
---|
85 | }
|
---|