Skip to content

Commit

Permalink
feat: add unit tests for lexer scanner functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Akash <[email protected]>
  • Loading branch information
SkySingh04 committed Jan 15, 2025
1 parent d717a4e commit b462f85
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
41 changes: 41 additions & 0 deletions lexer/lexer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package lexer

import (
"testing"
)

func TestNewScanner(t *testing.T) {
src := "fn main() {}"
scanner := NewScanner(src)
if scanner.source != src {
t.Errorf("Expected source %q, got %q", src, scanner.source)
}
if scanner.line != 1 {
t.Errorf("Expected line to be 1, got %d", scanner.line)
}
}

func TestScanTokens_EmptySource(t *testing.T) {
scanner := NewScanner("")
tokens, errs := scanner.ScanTokens()
if len(tokens) != 1 {
t.Errorf("Expected 1 token (EOF), got %d", len(tokens))
}
if len(errs) != 0 {
t.Errorf("Expected no errors, got %d", len(errs))
}
if tokens[0].Type != EOF {
t.Errorf("Expected EOF token, got %v", tokens[0].Type)
}
}

func TestScanTokens_ValidSource(t *testing.T) {
scanner := NewScanner("fn main() {}")
tokens, errs := scanner.ScanTokens()
if len(errs) != 0 {
t.Errorf("Expected no errors, got %d", len(errs))
}
if len(tokens) == 0 {
t.Error("Expected some tokens, got none")
}
}
1 change: 0 additions & 1 deletion transpiler/transpiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"GoCrab/lexer"
"GoCrab/parser"
"fmt"

)

var hasError bool
Expand Down

0 comments on commit b462f85

Please sign in to comment.