save comment position
This commit is contained in:
@@ -1,17 +1,28 @@
|
||||
package comment
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
)
|
||||
|
||||
// Comment aggrigates information about comment /**
|
||||
type Comment struct {
|
||||
value string
|
||||
value string
|
||||
position *position.Position
|
||||
}
|
||||
|
||||
// NewComment - Comment constructor
|
||||
func NewComment(value string) *Comment {
|
||||
func NewComment(value string, pos *position.Position) *Comment {
|
||||
return &Comment{
|
||||
value,
|
||||
pos,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Comment) String() string {
|
||||
return c.value
|
||||
}
|
||||
|
||||
// Position returns comment position
|
||||
func (c *Comment) Position() *position.Position {
|
||||
return c.position
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package comment_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
|
||||
"github.com/z7zmey/php-parser/comment"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
)
|
||||
@@ -11,8 +13,8 @@ func TestComments(t *testing.T) {
|
||||
n := node.NewIdentifier("test")
|
||||
|
||||
commentGroup := []*comment.Comment{
|
||||
comment.NewComment("/** hello world */"),
|
||||
comment.NewComment("// hello world"),
|
||||
comment.NewComment("/** hello world */", nil),
|
||||
comment.NewComment("// hello world", nil),
|
||||
}
|
||||
|
||||
comments := comment.Comments{}
|
||||
@@ -25,3 +27,15 @@ func TestComments(t *testing.T) {
|
||||
t.Errorf("expected and actual are not equal\n")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommentPos(t *testing.T) {
|
||||
expected := position.NewPosition(0, 0, 0, 0)
|
||||
|
||||
comment := comment.NewComment("/** hello world */", expected)
|
||||
|
||||
actual := comment.Position()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("expected and actual are not equal\n")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user