Differences From Artifact [ff036615fe]:
- File
tests/OFXMLParserTests.m
— part of check-in
[9d79d92d9a]
at
2010-06-12 19:47:43
on branch trunk
— Several OFXMLParser improvements. See details.
* found* renamed to didFind*.
* Support for parsing CDATA.
* Handle comments with - correctly.
* Don't strip leading and trailing whitespaces in comments.
* Rename a few states for more clarity.
* More OFXMLParser tests. (user: js, size: 9798) [annotate] [blame] [check-ins using]
To Artifact [5780bef1f6]:
- File tests/OFXMLParserTests.m — part of check-in [c53d661daf] at 2010-06-16 19:54:57 on branch trunk — Rename a methods in OFXMLParserDelegate and add -[parser:foundCDATA]. (user: js, size: 9995) [annotate] [blame] [check-ins using]
| ︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 |
static OFString *module = @"OFXMLParser";
static int i = 0;
enum event_type {
TAG_START,
TAG_END,
STRING,
COMMENT
};
@implementation TestsAppDelegate (OFXMLParser)
| > | | | | | | | | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
static OFString *module = @"OFXMLParser";
static int i = 0;
enum event_type {
TAG_START,
TAG_END,
STRING,
CDATA,
COMMENT
};
@implementation TestsAppDelegate (OFXMLParser)
- (void)parserCallbackWithEventType: (enum event_type)et
name: (OFString*)name
prefix: (OFString*)prefix
namespace: (OFString*)ns
attributes: (OFArray*)attrs
string: (OFString*)string
comment: (OFString*)comment
{
OFString *msg;
i++;
msg = [OFString stringWithFormat: @"Parsing part #%d", i];
switch (i) {
case 1:
TEST(msg, et == TAG_START && [name isEqual: @"root"] &&
prefix == nil && ns == nil && [attrs count] == 0)
break;
case 2:
TEST(msg, et == STRING && [string isEqual: @"\n "])
break;
case 3:
TEST(msg, et == CDATA && [string isEqual: @"f<oo"])
break;
case 4:
TEST(msg, et == TAG_START && [name isEqual: @"bar"] &&
prefix == nil && ns == nil && attrs == nil)
break;
case 5:
TEST(msg, et == TAG_END && [name isEqual: @"bar"] &&
|
| ︙ | ︙ | |||
223 224 225 226 227 228 229 | case 30: TEST(msg, et == TAG_END && [name isEqual: @"root"] && prefix == nil && ns == nil); break; } } | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > > > > > > > > > > | | | | | | | | | | | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
case 30:
TEST(msg, et == TAG_END && [name isEqual: @"root"] &&
prefix == nil && ns == nil);
break;
}
}
- (void)parser: (OFXMLParser*)parser
didStartElement: (OFString*)name
withPrefix: (OFString*)prefix
namespace: (OFString*)ns
attributes: (OFArray*)attrs
{
[self parserCallbackWithEventType: TAG_START
name: name
prefix: prefix
namespace: ns
attributes: attrs
string: nil
comment: nil];
}
- (void)parser: (OFXMLParser*)parser
didEndElement: (OFString*)name
withPrefix: (OFString*)prefix
namespace: (OFString*)ns
{
[self parserCallbackWithEventType: TAG_END
name: name
prefix: prefix
namespace: ns
attributes: nil
string: nil
comment: nil];
}
- (void)parser: (OFXMLParser*)parser
foundCharacters: (OFString*)string
{
[self parserCallbackWithEventType: STRING
name: nil
prefix: nil
namespace: nil
attributes: nil
string: string
comment: nil];
}
- (void)parser: (OFXMLParser*)parser
foundCDATA: (OFString*)cdata
{
[self parserCallbackWithEventType: CDATA
name: nil
prefix: nil
namespace: nil
attributes: nil
string: cdata
comment: nil];
}
- (void)parser: (OFXMLParser*)parser
foundComment: (OFString*)comment
{
[self parserCallbackWithEventType: COMMENT
name: nil
prefix: nil
namespace: nil
attributes: nil
string: nil
comment: comment];
}
- (OFString*)parser: (OFXMLParser*)parser
foundUnknownEntityNamed: (OFString*)entity
{
if ([entity isEqual: @"foo"])
return @"foobar";
return nil;
}
|
| ︙ | ︙ |