From 9c0bf11dd144d09c20f16acaf3d40030b4534ec8 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sat, 3 May 2008 10:10:32 +0000 Subject: Fix testdriver to accept # in input Significantly more tests for the lexer -- this basically covers all the non-OOD/EOF cases Fix bug in lexing of "/x" -- the CHAR(/) was getting dropped by the "don't emit comment tokens" logic svn path=/trunk/libcss/; revision=4120 --- test/data/lex/tests1.dat | 608 +++++++++++++++++++++++++++++++++++++++++++++++ test/lex-auto.c | 21 +- 2 files changed, 624 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/data/lex/tests1.dat b/test/data/lex/tests1.dat index 3b6b149..8f7783c 100644 --- a/test/data/lex/tests1.dat +++ b/test/data/lex/tests1.dat @@ -1,3 +1,305 @@ +#data +a +#expected +IDENT:a +S +EOF +#reset + +#data +Z +#expected +IDENT:Z +S +EOF +#reset + +#data +- +#expected +CHAR:- +S +EOF +#reset + +#data +_ +#expected +IDENT:_ +S +EOF +#reset + +#data +@ +#expected +CHAR:@ +S +EOF +#reset + +#data +# +#expected +CHAR:# +S +EOF +#reset + +#data +0 +#expected +NUMBER:0 +S +EOF +#reset + +#data +0.0 +#expected +NUMBER:0.0 +S +EOF +#reset + +#data +.0 +#expected +NUMBER:.0 +S +EOF +#reset + +#data +10% +#expected +PERCENTAGE:10 +S +EOF +#reset + +#data +10.5% +#expected +PERCENTAGE:10.5 +S +EOF +#reset + +#data +.5% +#expected +PERCENTAGE:.5 +S +EOF +#reset + +#data +50px +#expected +DIMENSION:50px +S +EOF +#reset + +#data +50.5px +#expected +DIMENSION:50.5px +S +EOF +#reset + +#data +.4px +#expected +DIMENSION:.4px +S +EOF +#reset + +#data +url() +#expected +URI: +S +EOF +#reset + +#data +url(123456\)); +#expected +URI:123456) +CHAR:; +S +EOF +#reset + +#data +url("123456)"); +#expected +URI:123456) +CHAR:; +S +EOF +#reset + +#data +url('123456)'); +#expected +URI:123456) +CHAR:; +S +EOF +#reset + +#data +U+? +#expected +UNICODE-RANGE:? +S +EOF +#reset + +#data +U+?????1 +#expected +UNICODE-RANGE:?????1 +S +EOF +#reset + +#data +U+ffffff-000000 +#expected +UNICODE-RANGE:ffffff-000000 +S +EOF +#reset + +#data +U+02468ac +#expected +UNICODE-RANGE:02468a +IDENT:c +S +EOF +#reset + +#data +< +#expected +CHAR:< +S +EOF +#reset + +#data + +#expected +CDC +S +EOF +#reset + +#data + +#expected +S +EOF +#reset + +#data +/* *** / *** */ +#expected +S +EOF +#reset + +#data +foo( +#expected +FUNCTION:foo +S +EOF +#reset + +#data +~= +#expected +INCLUDES +S +EOF +#reset + +#data +|= +#expected +DASHMATCH +S +EOF +#reset + +#data +^= +#expected +PREFIXMATCH +S +EOF +#reset + +#data +$= +#expected +SUFFIXMATCH +S +EOF +#reset + +#data +*= +#expected +SUBSTRINGMATCH +S +EOF +#reset + #data body #expected @@ -6,3 +308,309 @@ S EOF #reset +#data +@foo +#expected +ATKEYWORD:foo +S +EOF +#reset + +#data +#blah +#expected +HASH:blah +S +EOF +#reset + +#data +"foo" +#expected +STRING:foo +S +EOF +#reset + +#data +'foo' +#expected +STRING:foo +S +EOF +#reset + +#data +'foo\'' +#expected +STRING:foo' +S +EOF +#reset + +#data +'blah \ + xyz' +#expected +STRING:blah\n xyz +S +EOF +#reset + +#data +url( foo); +#expected +URI:foo +CHAR:; +S +EOF +#reset + +#data +url(foo ); +#expected +URI:foo +CHAR:; +S +EOF +#reset + +#data +url( "foo" ); +#expected +URI:foo +CHAR:; +S +EOF +#reset + +#data +@he\llo +#expected +ATKEYWORD:hello +S +EOF +#reset + +#data +-foo +#expected +IDENT:-foo +S +EOF +#reset + +#data +--x +#expected +CHAR:- +IDENT:-x +S +EOF +#reset + +#data +-\x +#expected +IDENT:-x +S +EOF +#reset + +#data +/x +#expected +CHAR:/ +IDENT:x +S +EOF +#reset + +#data +/***** *** /// ** +#expected +EOF +#reset + +#data +/* */ +/* +*/ +#expected +S +S +EOF +#reset + +#data +\moo +#expected +IDENT:moo +S +EOF +#reset + +#data +~x +#expected +CHAR:~ +IDENT:x +S +EOF +#reset + +#data +. +#expected +CHAR:. +S +EOF +#reset + +#data +0.5\px +#expected +DIMENSION:0.5px +S +EOF +#reset + +#data +@\x +#expected +ATKEYWORD:x +S +EOF +#reset + +#data +0. +#expected +NUMBER:0 +CHAR:. +S +EOF +#reset + +#data +ugh +#expected +IDENT:ugh +S +EOF +#reset + +#data +urx +#expected +IDENT:urx +S +EOF +#reset + +#data +urlx +#expected +IDENT:urlx +S +EOF +#reset + +#data +url(foo +#expected +FUNCTION:url +IDENT:foo +S +EOF +#reset + +#data +url(foo x +#expected +FUNCTION:url +IDENT:foo +S +IDENT:x +S +EOF +#reset + +#data +U+ +#expected +IDENT:U +CHAR:+ +S +EOF +#reset + +#data +U+0-x +#expected +UNICODE-RANGE:0 +IDENT:-x +S +EOF +#reset + +#data +"foo'" +#expected +STRING:foo' +S +EOF +#reset + +#data +'foo"' +#expected +STRING:foo" +S +EOF +#reset + +#data +blah\2022 +#expected +IDENT:blah• +EOF +#reset + +#data +blah\2022x +#expected +IDENT:blah•x +S +EOF +#reset + +#data +blah\2022 f +#expected +IDENT:blah•f +S +EOF +#reset + +#data +\123\456 +#expected +IDENT: +EOF +#reset + +#data +\789\abc +#expected +IDENT: +EOF +#reset + +#data +\def +#expected +IDENT: +EOF +#reset + diff --git a/test/lex-auto.c b/test/lex-auto.c index 196836b..9e2d018 100644 --- a/test/lex-auto.c +++ b/test/lex-auto.c @@ -107,8 +107,16 @@ bool handle_line(const char *data, size_t datalen, void *pw) ctx->expused = 0; } - ctx->indata = (strncasecmp(data+1, "data", 4) == 0); - ctx->inexp = (strncasecmp(data+1, "expected", 8) == 0); + if (ctx->indata && strncasecmp(data+1, "expected", 8) == 0) { + ctx->indata = false; + ctx->inexp = true; + } else if (!ctx->indata) { + ctx->indata = (strncasecmp(data+1, "data", 4) == 0); + ctx->inexp = (strncasecmp(data+1, "expected", 8) == 0); + } else { + memcpy(ctx->buf + ctx->bufused, data, datalen); + ctx->bufused += datalen; + } } else { if (ctx->indata) { memcpy(ctx->buf + ctx->bufused, data, datalen); @@ -137,13 +145,16 @@ void parse_expected(line_ctx *ctx, const char *data, size_t len) /* Append to list of expected tokens */ if (ctx->expused == ctx->explen) { + size_t num = ctx->explen == 0 ? 4 : ctx->explen; + exp_entry *temp = realloc(ctx->exp, - ctx->explen * 2 * sizeof(exp_entry)); - if (temp == NULL) + num * 2 * sizeof(exp_entry)); + if (temp == NULL) { assert(0 && "No memory for expected tokens"); + } ctx->exp = temp; - ctx->explen *= 2; + ctx->explen = num * 2; } ctx->exp[ctx->expused].type = type; -- cgit v1.2.3