move Positions and Comments into parser package

This commit is contained in:
z7zmey
2018-04-15 22:02:07 +03:00
parent 781a55659b
commit 56127a4a2c
14 changed files with 142 additions and 76 deletions

View File

@@ -6,29 +6,9 @@ import (
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/comment"
"github.com/z7zmey/php-parser/node"
)
func TestComments(t *testing.T) {
n := node.NewIdentifier("test")
commentGroup := []*comment.Comment{
comment.NewComment("/** hello world */", nil),
comment.NewComment("// hello world", nil),
}
comments := comment.Comments{}
comments.AddComments(n, commentGroup)
if comments[n][0].String() != "/** hello world */" {
t.Errorf("expected and actual are not equal\n")
}
if comments[n][1].String() != "// hello world" {
t.Errorf("expected and actual are not equal\n")
}
}
func TestCommentPos(t *testing.T) {
func TestCommentGetPosition(t *testing.T) {
expected := position.NewPosition(0, 0, 0, 0)
comment := comment.NewComment("/** hello world */", expected)
@@ -39,3 +19,15 @@ func TestCommentPos(t *testing.T) {
t.Errorf("expected and actual are not equal\n")
}
}
func TestCommentPrint(t *testing.T) {
expected := "/** hello world */"
comment := comment.NewComment(expected, nil)
actual := comment.String()
if expected != actual {
t.Errorf("expected and actual are not equal\n")
}
}

View File

@@ -1,11 +0,0 @@
package comment
import "github.com/z7zmey/php-parser/node"
// Comments a collection of comment groups assigned to nodes
type Comments map[node.Node][]*Comment
// AddComments add comment group to the collection
func (c Comments) AddComments(node node.Node, comments []*Comment) {
c[node] = append(c[node], comments...)
}