Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions evaluator/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,10 @@ func TestMathModule(t *testing.T) {
input string
expected interface{}
}{
{`Math.abs(123)`, 123},
{`Math.abs(-123)`, 123},
{`Math.abs("foo")`, "first argument to 'Math.abs' must be NUMBER, got STRING on line 1"},
{`Math.abs()`, "wrong number of arguments: 0 while expected: 1 on line 1"},
{`math.abs(123)`, 123},
{`math.abs(-123)`, 123},
{`math.abs("foo")`, "first argument to 'Math.abs' must be NUMBER, got STRING on line 1"},
{`math.abs()`, "wrong number of arguments: 0 while expected: 1 on line 1"},
}

for _, tt := range tests {
Expand Down
12 changes: 12 additions & 0 deletions lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ func (lexer *Lexer) readNumber() string {
lexer.readCharacter()
}

if lexer.character == rune('e') {
lexer.readCharacter()

if lexer.character == rune('-') {
lexer.readCharacter()
}

for isDigit(lexer.character) {
lexer.readCharacter()
}
}

return string(lexer.input[position:lexer.position])
}

Expand Down
4 changes: 4 additions & 0 deletions lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ for (key, value in data) {
}
こんにちは
世界
123e4
123e-4
`

tests := []struct {
Expand Down Expand Up @@ -200,6 +202,8 @@ for (key, value in data) {
{token.RBRACE, "}", 49},
{token.IDENTIFIER, "こんにちは", 50},
{token.IDENTIFIER, "世界", 51},
{token.NUMBER, "123e4", 52},
{token.NUMBER, "123e-4", 53},
{token.EOF, "", 0},
}

Expand Down