From 96c02a9c27886d246d28db95d63a63545d7f2b2d Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Tue, 8 Oct 2024 01:40:29 +0900 Subject: [PATCH] add unit tests for string with spaces --- evaluator/evaluator_test.go | 5 +++++ lexer/lexer_test.go | 10 ++++++++++ parser/parser_test.go | 5 +++++ 3 files changed, 20 insertions(+) diff --git a/evaluator/evaluator_test.go b/evaluator/evaluator_test.go index b6d046d..dec9738 100644 --- a/evaluator/evaluator_test.go +++ b/evaluator/evaluator_test.go @@ -325,6 +325,11 @@ func TestEvalStringExpression(t *testing.T) { input: `"hello"`, expected: "hello", }, + { + name: "string with space", + input: `"hello world"`, + expected: "hello world", + }, } for _, tt := range tests { diff --git a/lexer/lexer_test.go b/lexer/lexer_test.go index 14159e1..f15c06b 100644 --- a/lexer/lexer_test.go +++ b/lexer/lexer_test.go @@ -63,6 +63,16 @@ func TestSingleProgram(t *testing.T) { {Type: token.EOF, Literal: ""}, }, }, + { + name: "string literal with space", + input: `"hello world"`, + expected: []token.Token{ + {Type: token.DOUBLE_QUOTE, Literal: "\""}, + {Type: token.STRING, Literal: "hello world"}, + {Type: token.DOUBLE_QUOTE, Literal: "\""}, + {Type: token.EOF, Literal: ""}, + }, + }, { name: "array", input: "[1, 2]", diff --git a/parser/parser_test.go b/parser/parser_test.go index f893e36..346eb21 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -58,6 +58,11 @@ func TestStringAtom(t *testing.T) { input: `"hello"`, expected: "hello", }, + { + name: "string with space", + input: `"hello world"`, + expected: "hello world", + }, } for _, tt := range tests {