Skip to content

Commit 240d8d5

Browse files
committed
test/lex: add failing test
1 parent e9e85d8 commit 240d8d5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

test/data/lex/regression.dat

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,26 @@ S
4646
EOF
4747
#reset
4848

49+
#data:trunc
50+
"\"}\
51+
#expected
52+
INVALID:"}
53+
EOF
54+
#reset
55+
56+
#data:trunc
57+
url("\"}\
58+
#expected
59+
FUNCTION:url
60+
INVALID:"}
61+
EOF
62+
#reset
63+
64+
#data:trunc
65+
url(x\
66+
#expected
67+
FUNCTION:url
68+
IDENT:x
69+
CHAR:\\
70+
EOF
71+
#reset

test/lex-auto.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ typedef struct line_ctx {
3131
size_t expused;
3232
exp_entry *exp;
3333

34+
bool truncate_input;
3435
bool indata;
3536
bool inexp;
3637
} line_ctx;
@@ -67,6 +68,7 @@ int main(int argc, char **argv)
6768
ctx.explen = 0;
6869
ctx.expused = 0;
6970
ctx.exp = NULL;
71+
ctx.truncate_input = false;
7072
ctx.indata = false;
7173
ctx.inexp = false;
7274

@@ -102,19 +104,27 @@ bool handle_line(const char *data, size_t datalen, void *pw)
102104
}
103105

104106
if (ctx->indata && strncasecmp(data+1, "expected", 8) == 0) {
107+
ctx->truncate_input = false;
105108
ctx->indata = false;
106109
ctx->inexp = true;
107110
} else if (!ctx->indata) {
111+
ctx->truncate_input = (strncasecmp(data+1, "data:trunc", 10) == 0);
108112
ctx->indata = (strncasecmp(data+1, "data", 4) == 0);
109113
ctx->inexp = (strncasecmp(data+1, "expected", 8) == 0);
110114
} else {
111115
memcpy(ctx->buf + ctx->bufused, data, datalen);
112116
ctx->bufused += datalen;
117+
if (ctx->truncate_input) {
118+
ctx->bufused--;
119+
}
113120
}
114121
} else {
115122
if (ctx->indata) {
116123
memcpy(ctx->buf + ctx->bufused, data, datalen);
117124
ctx->bufused += datalen;
125+
if (ctx->truncate_input) {
126+
ctx->bufused--;
127+
}
118128
}
119129
if (ctx->inexp) {
120130
if (data[datalen - 1] == '\n')

0 commit comments

Comments
 (0)