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

Last change on this file since 322 was 322, checked in by Nicholas Riley, 17 years ago

ICeCoffEE.[hm]: Move parsing functions (ICCF_CheckRange,
ICCF_Delimiters, ICCF_ParseURL) and Internet Config start/stop
routines (ICCF_Stop/StartIC) to ICeCoffEEParser.[hm] so they can be
tested outside the APE. Also move ICCF_MAX_URL_LEN definition, and
extract guts of NSTextView parsing into ICCF_URLEnclosingRange.
Remove comment about TXNClick; if MLTE is deprecated I'm not going to
mess with it.

ICeCoffEEParser.[hm]: Moved everything discussed above to here.

ICeCoffEEServices.m: Some comments, now I realize how irritating the
service localization problem is.

ICeCoffEETerminal.m: Remove long-unused reference to
ICeCoffEEScanner.h (was from 1.2?).

ICeCoffEEScanner.[hm]: Removed, no longer in use.

TestParser.m: Very simple first pass at testing. There's much more I
want to do here.

urls.plist: First pass at URL test cases.

ICeCoffEE.xcodeproj: Add TestParser target (yes, it uses ZeroLink
because my machine is slow and it actually helps).

File size: 2.6 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
14void 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
23void 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
29CFBundleRef ICCF_bundle = NULL;
30
31int 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}
Note: See TracBrowser for help on using the repository browser.