Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: class-dump/src/UnitTests/CDTypeLexerUnitTest.m

Issue 7793008: Add the 3.3.3 sources for class-dump. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // This file is part of class-dump, a utility for examining the Objective-C seg ment of Mach-O files.
2 // Copyright (C) 1997-1998, 2000-2001, 2004-2010 Steve Nygard.
3
4 #import "CDTypeLexerUnitTest.h"
5
6 #import <Foundation/Foundation.h>
7 #import "CDTypeLexer.h"
8
9 struct tokenValuePair {
10 int token;
11 NSString *value;
12 int nextState;
13 };
14
15 @implementation CDTypeLexerUnitTest
16
17 - (void)setUp;
18 {
19 }
20
21 - (void)tearDown;
22 {
23 }
24
25 - (void)_setupLexerForString:(NSString *)str;
26 {
27 lexer = [[CDTypeLexer alloc] initWithString:str];
28 }
29
30 - (void)_cleanupLexer;
31 {
32 [lexer release];
33 lexer = nil;
34 }
35
36 - (void)_showScannedTokens;
37 {
38 int token;
39
40 NSLog(@"----------------------------------------");
41 STAssertNotNil(lexer, @"");
42
43 NSLog(@"str: %@", [lexer string]);
44
45 [lexer setShouldShowLexing:YES];
46
47 token = [lexer scanNextToken];
48 while (token != TK_EOS)
49 token = [lexer scanNextToken];
50 NSLog(@"----------------------------------------");
51 }
52
53 - (void)showScannedTokensForString:(NSString *)str;
54 {
55 [self _setupLexerForString:str];
56 [self _showScannedTokens];
57 [self _cleanupLexer];
58 }
59
60 // The last token in expectedResults must be TK_EOS.
61 - (void)testLexingString:(NSString *)str expectedResults:(struct tokenValuePair *)expectedResults;
62 {
63 int token;
64
65 [self _setupLexerForString:str];
66 //NSLog(@"str: %@", [lexer string]);
67 //[lexer setShouldShowLexing:YES];
68
69 while (expectedResults->token != TK_EOS) {
70 token = [lexer scanNextToken];
71 STAssertEquals(expectedResults->token, token, @"");
72 if (expectedResults->value != nil)
73 STAssertEqualObjects(expectedResults->value, [lexer lexText], @"");
74 if (expectedResults->nextState != -1)
75 [lexer setState:expectedResults->nextState];
76 expectedResults++;
77 }
78
79 token = [lexer scanNextToken];
80 STAssertEquals(TK_EOS, token, @"");
81
82 [self _cleanupLexer];
83 }
84
85 - (void)testSimpleTokens;
86 {
87 NSString *str = @"i^@";
88 struct tokenValuePair tokens[] = {
89 { 'i', nil, -1 },
90 { '^', nil, -1 },
91 { '@', nil, -1 },
92 { TK_EOS, nil, -1 },
93 };
94
95 [self testLexingString:str expectedResults:tokens];
96 }
97
98 - (void)testQuotedStringToken;
99 {
100 NSString *str = @"@\"NSObject\"";
101 struct tokenValuePair tokens[] = {
102 { '@', nil, -1 },
103 { TK_QUOTED_STRING, @"NSObject", -1 },
104 { TK_EOS, nil, -1 },
105 };
106
107 [self testLexingString:str expectedResults:tokens];
108 }
109
110 - (void)testEmptyQuotedStringToken;
111 {
112 NSString *str = @"@\"\"";
113 struct tokenValuePair tokens[] = {
114 { '@', nil, -1 },
115 { TK_QUOTED_STRING, @"", -1 },
116 { TK_EOS, nil, -1 },
117 };
118
119 [self testLexingString:str expectedResults:tokens];
120 }
121
122 - (void)testUnterminatedQuotedString;
123 {
124 NSString *str = @"@\"NSObject";
125 struct tokenValuePair tokens[] = {
126 { '@', nil, -1 },
127 { TK_QUOTED_STRING, @"NSObject", -1 },
128 { TK_EOS, nil, -1 },
129 };
130
131 [self testLexingString:str expectedResults:tokens];
132 }
133
134 // The lexer should automatically switch back to normal mode after scanning one identifier.
135 - (void)testIdentifierToken;
136 {
137 NSString *str = @"iii)ii";
138 struct tokenValuePair tokens[] = {
139 { 'i', nil, CDTypeLexerStateIdentifier },
140 { TK_IDENTIFIER, @"ii", -1 },
141 { ')', nil, -1 },
142 { 'i', nil, -1 },
143 { 'i', nil, -1 },
144 { TK_EOS, nil, -1 },
145 };
146
147 [self testLexingString:str expectedResults:tokens];
148 }
149
150
151 // This tests a more complicated C++ template type, and makes sure the space bet ween the '>'s is ignored.
152 - (void)testTemplateTokens;
153 {
154 NSString *str = @"{vector<IPPhotoInfo*,std::allocator<IPPhotoInfo*> >=iic}";
155 struct tokenValuePair tokens[] = {
156 { '{', nil, CDTypeLexerStateIdentifier },
157 { TK_IDENTIFIER, @"vector", -1 },
158 { '<', nil, CDTypeLexerStateTemplateTypes },
159 { TK_TEMPLATE_TYPE, @"IPPhotoInfo*", -1 },
160 { ',', nil, -1 },
161 { TK_TEMPLATE_TYPE, @"std::allocator", -1 },
162 { '<', nil, CDTypeLexerStateTemplateTypes },
163 { TK_TEMPLATE_TYPE, @"IPPhotoInfo*", -1 },
164 { '>', nil, -1 },
165 { '>', nil, CDTypeLexerStateNormal },
166 { '=', nil, -1 },
167 { 'i', nil, -1 },
168 { 'i', nil, -1 },
169 { 'c', nil, -1 },
170 { '}', nil, -1 },
171 { TK_EOS, nil, -1 },
172 };
173
174 [self testLexingString:str expectedResults:tokens];
175 }
176
177 @end
OLDNEW
« no previous file with comments | « class-dump/src/UnitTests/CDTypeLexerUnitTest.h ('k') | class-dump/src/UnitTests/CDTypeParserUnitTest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698