From a2991b978a309d4c3a9c480aad4e4e657ae82597 Mon Sep 17 00:00:00 2001 From: franck cuny Date: Sat, 11 Jan 2020 14:27:18 +0100 Subject: lexer: test the new keywords are parsed correctly. Ensure that the new keywords added (`if`, `else`, `true`, `false`, `return`) are parsed correctly. --- users/fcuny/exp/monkey/pkg/lexer/lexer_test.go | 28 +++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'users/fcuny') 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) -- cgit 1.4.1