1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00
otto/ast/comments_test.go
Steven Hartland 98effe01d8
chore: update ci versions (#519)
Update go, golangci-lint and action versions.

Address new lint failures flagged by updated golangci-lint version.
2024-04-13 17:05:50 +01:00

63 lines
1.4 KiB
Go

package ast
import (
"testing"
"github.com/robertkrimen/otto/file"
)
func TestCommentMap(t *testing.T) {
statement := &EmptyStatement{file.Idx(1)}
comment := &Comment{Begin: 1, Text: "test", Position: LEADING}
cm := CommentMap{}
cm.AddComment(statement, comment)
if cm.Size() != 1 {
t.Errorf("the number of comments is %v, not 1", cm.Size())
}
if len(cm[statement]) != 1 {
t.Errorf("the number of comments is %v, not 1", cm.Size())
}
if cm[statement][0].Text != "test" {
t.Errorf("the text is %v, not \"test\"", cm[statement][0].Text)
}
}
func TestCommentMap_move(t *testing.T) {
statement1 := &EmptyStatement{file.Idx(1)}
statement2 := &EmptyStatement{file.Idx(2)}
comment := &Comment{Begin: 1, Text: "test", Position: LEADING}
cm := CommentMap{}
cm.AddComment(statement1, comment)
if cm.Size() != 1 {
t.Errorf("the number of comments is %v, not 1", cm.Size())
}
if len(cm[statement1]) != 1 {
t.Errorf("the number of comments is %v, not 1", cm.Size())
}
if len(cm[statement2]) != 0 {
t.Errorf("the number of comments is %v, not 0", cm.Size())
}
cm.MoveComments(statement1, statement2, LEADING)
if cm.Size() != 1 {
t.Errorf("the number of comments is %v, not 1", cm.Size())
}
if len(cm[statement2]) != 1 {
t.Errorf("the number of comments is %v, not 1", cm.Size())
}
if len(cm[statement1]) != 0 {
t.Errorf("the number of comments is %v, not 0", cm.Size())
}
}