Mercurial > projects > dil
diff trunk/src/Lexer.d @ 39:69b940398d7b
- Added unittest to test correct parsing of operator tokens.
author | aziz |
---|---|
date | Tue, 26 Jun 2007 10:06:01 +0000 |
parents | 640c45aaaaee |
children | 9d5ceb0f8be9 |
line wrap: on
line diff
--- a/trunk/src/Lexer.d Tue Jun 26 08:58:02 2007 +0000 +++ b/trunk/src/Lexer.d Tue Jun 26 10:06:01 2007 +0000 @@ -170,8 +170,11 @@ this.fileName = fileName; this.text = text; - this.text.length = this.text.length + 1; - this.text[$-1] = 0; + if (text[$-1] != 0) + { + this.text.length = this.text.length + 1; + this.text[$-1] = 0; + } this.p = this.text.ptr; this.end = this.p + this.text.length; @@ -939,3 +942,23 @@ return tokens; } } + +unittest +{ + string[] ops = [">", ">=", ">>", ">>=", ">>>", ">>>=", "<", "<=", "<>", "<>=", "<<", "<<=", "!", "!<", "!>", "!<=", "!>=", "!<>", "!<>=", ".", "..", "...", "&", "&&", "&=", "+", "++", "+=", "-", "--", "-=", "=", "==", "~", "~=", "*", "*=", "^", "^=", "%", "%="]; + + char[] src; + + foreach (op; ops) + src ~= op ~ " "; + + auto lx = new Lexer(src, ""); + auto tokens = lx.getTokens(); + + tokens = tokens[0..$-1]; // exclude TOK.EOF + + assert(tokens.length == 41 ); + + foreach (i, t; tokens) + assert(t.span == ops[i], std.string.format("Lexed '%s' but expected '%s'", t.span, ops[i])); +} \ No newline at end of file