Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 129 lines (99 sloc) 3.602 kb
05eedb5 @itod initial add
authored
1 // Copyright 2010 Todd Ditchendorf
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #import "TDDifferenceTest.h"
16
17 @implementation TDDifferenceTest
18
19 - (void)testFoo {
20 PKWord *word = [PKWord word];
21 PKLiteral *foo = [PKLiteral literalWithString:@"foo"];
22 d = [PKDifference differenceWithSubparser:word minus:foo];
23
24 s = @"bar";
25 a = [PKTokenAssembly assemblyWithString:s];
26 res = [d bestMatchFor:a];
27 TDEqualObjects(@"[bar]bar^", [res description]);
28
29 s = @"foo";
30 a = [PKTokenAssembly assemblyWithString:s];
31 res = [d bestMatchFor:a];
32 NSLog(@"res: %@", res);
33 TDNil(res);
34
35 s = @"wee";
36 a = [PKTokenAssembly assemblyWithString:s];
37 res = [d bestMatchFor:a];
38 TDEqualObjects(@"[wee]wee^", [res description]);
39 }
40
41
42 - (void)testAlt {
43 PKWord *word = [PKWord word];
44 PKAlternation *list = [PKAlternation alternation];
45 [list add:[PKLiteral literalWithString:@"foo"]];
46 [list add:[PKLiteral literalWithString:@"bar"]];
47
48 d = [PKDifference differenceWithSubparser:word minus:list];
49
50 s = @"baz";
51 a = [PKTokenAssembly assemblyWithString:s];
52 res = [d bestMatchFor:a];
53 TDEqualObjects(@"[baz]baz^", [res description]);
54
55 s = @"foo";
56 a = [PKTokenAssembly assemblyWithString:s];
57 res = [d bestMatchFor:a];
58 TDNil(res);
59
60 s = @"bar";
61 a = [PKTokenAssembly assemblyWithString:s];
62 res = [d bestMatchFor:a];
63 TDNil(res);
64
65 s = @"%";
66 a = [PKTokenAssembly assemblyWithString:s];
67 res = [d bestMatchFor:a];
68 TDNil(res);
69
70 s = @"wee";
71 a = [PKTokenAssembly assemblyWithString:s];
72 res = [d bestMatchFor:a];
73 TDEqualObjects(@"[wee]wee^", [res description]);
74 }
75
76
77 - (void)testAlt2 {
78 PKAlternation *ok = [PKAlternation alternation];
79 [ok add:[PKLiteral literalWithString:@"foo"]];
80 [ok add:[PKLiteral literalWithString:@"baz"]];
81
82 PKAlternation *list = [PKAlternation alternation];
83 [list add:[PKLiteral literalWithString:@"foo"]];
84 [list add:[PKLiteral literalWithString:@"bar"]];
85
86 d = [PKDifference differenceWithSubparser:ok minus:list];
87
88 s = @"baz";
89 a = [PKTokenAssembly assemblyWithString:s];
90 res = [d bestMatchFor:a];
91 TDEqualObjects(@"[baz]baz^", [res description]);
92
93 s = @"foo";
94 a = [PKTokenAssembly assemblyWithString:s];
95 res = [d bestMatchFor:a];
96 TDNil(res);
97
98 s = @"wee";
99 a = [PKTokenAssembly assemblyWithString:s];
100 res = [d bestMatchFor:a];
101 TDNil(res);
102 }
103
104
105 - (void)testParserNamed {
106 PKWord *w = [PKWord word];
107 w.name = @"w";
108
109 PKCollectionParser *m = [PKAlternation alternation];
110 m.name = @"m";
111
112 PKParser *foo = [PKLiteral literalWithString:@"foo"];
113 foo.name = @"foo";
114 [m add:foo];
115
116 PKParser *bar = [PKLiteral literalWithString:@"bar"];
117 bar.name = @"bar";
118 [m add:bar];
119
120 d = [PKDifference differenceWithSubparser:w minus:m];
121
122 TDEquals(w, [d parserNamed:@"w"]);
123 TDEquals(m, [d parserNamed:@"m"]);
124 TDEquals(foo, [d parserNamed:@"foo"]);
125 TDEquals(bar, [d parserNamed:@"bar"]);
126 }
127
128 @end
Something went wrong with that request. Please try again.