diff options
author | franck cuny <franck@fcuny.net> | 2020-01-11 14:27:18 +0100 |
---|---|---|
committer | franck cuny <franck@fcuny.net> | 2020-01-11 14:27:18 +0100 |
commit | a2991b978a309d4c3a9c480aad4e4e657ae82597 (patch) | |
tree | 8dc132109fda9450961c0d0591aa38d4853feefa /users/fcuny/exp/monkey | |
parent | token: support more keywords (diff) | |
download | world-a2991b978a309d4c3a9c480aad4e4e657ae82597.tar.gz |
lexer: test the new keywords are parsed correctly.
Ensure that the new keywords added (`if`, `else`, `true`, `false`, `return`) are parsed correctly.
Diffstat (limited to 'users/fcuny/exp/monkey')
-rw-r--r-- | users/fcuny/exp/monkey/pkg/lexer/lexer_test.go | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/users/fcuny/exp/monkey/pkg/lexer/lexer_test.go b/users/fcuny/exp/monkey/pkg/lexer/lexer_test.go index 22dbfcb..df1b392 100644 --- a/users/fcuny/exp/monkey/pkg/lexer/lexer_test.go +++ b/users/fcuny/exp/monkey/pkg/lexer/lexer_test.go @@ -15,7 +15,13 @@ let add = fn(x, y) { let result = add(five, ten); !-/*5; -5 < 10 > 5; +10 > 5; + +if (5 < 10) { + return true; +} else { + return false; +} ` tests := []struct { @@ -68,12 +74,28 @@ let result = add(five, ten); {token.INT, "5"}, {token.SEMICOLON, ";"}, - {token.INT, "5"}, - {token.LT, "<"}, {token.INT, "10"}, {token.GT, ">"}, {token.INT, "5"}, {token.SEMICOLON, ";"}, + + {token.IF, "if"}, + {token.LPAREN, "("}, + {token.INT, "5"}, + {token.LT, "<"}, + {token.INT, "10"}, + {token.RPAREN, ")"}, + {token.LBRACE, "{"}, + {token.RETURN, "return"}, + {token.TRUE, "true"}, + {token.SEMICOLON, ";"}, + {token.RBRACE, "}"}, + {token.ELSE, "else"}, + {token.LBRACE, "{"}, + {token.RETURN, "return"}, + {token.FALSE, "false"}, + {token.SEMICOLON, ";"}, + {token.RBRACE, "}"}, } l := New(input) |