comments
Some checks failed
Build / build (push) Failing after 1m10s
Test / build (push) Failing after 11m40s

This commit is contained in:
Chuck Smith
2024-03-16 19:31:23 -04:00
parent 7463b3af39
commit 83ad72a7fc
7 changed files with 106 additions and 6 deletions

View File

@@ -1126,3 +1126,48 @@ func testAssignmentStatement(t *testing.T, s ast.Statement, name string) bool {
return true
}
func TestComments(t *testing.T) {
tests := []struct {
input string
expectedComment string
}{
{"// foo", " foo"},
{"#!monkey", "!monkey"},
{"# foo", " foo"},
{" # foo", " foo"},
{" // let x = 1", " let x = 1"},
}
for _, tt := range tests {
l := lexer.New(tt.input)
p := New(l)
program := p.ParseProgram()
checkParserErrors(t, p)
if len(program.Statements) != 1 {
t.Fatalf("program.Statements does not contain 1 statements. got=%d",
len(program.Statements))
}
comment := program.Statements[0]
if !testComment(t, comment, tt.expectedComment) {
return
}
}
}
func testComment(t *testing.T, s ast.Statement, expected string) bool {
comment, ok := s.(*ast.Comment)
if !ok {
t.Errorf("s not *ast.Comment. got=%T", s)
return false
}
if comment.Value != expected {
t.Errorf("comment.Value not '%s'. got=%s", expected, comment.Value)
return false
}
return true
}