-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add unit tests for lexer scanner functionality
Signed-off-by: Akash <[email protected]>
- Loading branch information
1 parent
d717a4e
commit b462f85
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import ( | |
"GoCrab/lexer" | ||
"GoCrab/parser" | ||
"fmt" | ||
|
||
) | ||
|
||
var hasError bool | ||
|