2018-07-29 08:44:38 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/kylelemons/godebug/pretty"
|
|
|
|
"github.com/z7zmey/php-parser/meta"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCollectionSetTokenName(t *testing.T) {
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
whiteSpace := &meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: "\n",
|
|
|
|
}
|
|
|
|
comment := &meta.Data{
|
|
|
|
Type: meta.CommentType,
|
|
|
|
Value: "// some comment",
|
|
|
|
}
|
|
|
|
|
|
|
|
baseCollection := meta.Collection{whiteSpace, comment}
|
|
|
|
|
|
|
|
// action
|
|
|
|
|
|
|
|
baseCollection.SetTokenName(meta.OpenParenthesisToken)
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
|
|
|
for _, m := range baseCollection {
|
|
|
|
if m.TokenName != meta.OpenParenthesisToken {
|
|
|
|
t.Error("The TokenName must be set for all Meta objects")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionPush(t *testing.T) {
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
whiteSpace := &meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: "\n",
|
|
|
|
}
|
|
|
|
comment := &meta.Data{
|
|
|
|
Type: meta.CommentType,
|
|
|
|
Value: "// some comment",
|
|
|
|
}
|
|
|
|
|
|
|
|
actualCollection := meta.Collection{whiteSpace}
|
|
|
|
expectedCollection := meta.Collection{whiteSpace, comment}
|
|
|
|
|
|
|
|
// action
|
|
|
|
|
|
|
|
actualCollection.Push(comment)
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCollection, actualCollection) {
|
|
|
|
diff := pretty.Compare(expectedCollection, actualCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionUnshift(t *testing.T) {
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
whiteSpace := &meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: "\n",
|
|
|
|
}
|
|
|
|
comment := &meta.Data{
|
|
|
|
Type: meta.CommentType,
|
|
|
|
Value: "// some comment",
|
|
|
|
}
|
|
|
|
|
|
|
|
actualCollection := meta.Collection{comment}
|
|
|
|
expectedCollection := meta.Collection{whiteSpace, comment}
|
|
|
|
|
|
|
|
// action
|
|
|
|
|
|
|
|
actualCollection.Unshift(whiteSpace)
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCollection, actualCollection) {
|
|
|
|
diff := pretty.Compare(expectedCollection, actualCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionAppendTo(t *testing.T) {
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
whiteSpace := &meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: "\n",
|
|
|
|
}
|
|
|
|
comment := &meta.Data{
|
|
|
|
Type: meta.CommentType,
|
|
|
|
Value: "// some comment",
|
|
|
|
}
|
|
|
|
|
|
|
|
actualCollection := meta.Collection{whiteSpace}
|
|
|
|
expectedCollection := meta.Collection{whiteSpace, comment}
|
|
|
|
|
|
|
|
baseCollection := meta.Collection{comment}
|
|
|
|
|
|
|
|
// action
|
|
|
|
|
|
|
|
baseCollection.AppendTo(&actualCollection)
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCollection, actualCollection) {
|
|
|
|
diff := pretty.Compare(expectedCollection, actualCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEmptyCollectionAppendTo(t *testing.T) {
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
whiteSpace := &meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: "\n",
|
|
|
|
}
|
|
|
|
|
|
|
|
actualCollection := meta.Collection{whiteSpace}
|
|
|
|
expectedCollection := meta.Collection{whiteSpace}
|
|
|
|
|
|
|
|
var baseCollection meta.Collection = nil
|
|
|
|
|
|
|
|
// action
|
|
|
|
|
|
|
|
baseCollection.AppendTo(&actualCollection)
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCollection, actualCollection) {
|
|
|
|
diff := pretty.Compare(expectedCollection, actualCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionPrependTo(t *testing.T) {
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
whiteSpace := &meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: "\n",
|
|
|
|
}
|
|
|
|
comment := &meta.Data{
|
|
|
|
Type: meta.CommentType,
|
|
|
|
Value: "// some comment",
|
|
|
|
}
|
|
|
|
|
|
|
|
actualCollection := meta.Collection{comment}
|
|
|
|
expectedCollection := meta.Collection{whiteSpace, comment}
|
|
|
|
|
|
|
|
baseCollection := meta.Collection{whiteSpace}
|
|
|
|
|
|
|
|
// action
|
|
|
|
|
|
|
|
baseCollection.PrependTo(&actualCollection)
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCollection, actualCollection) {
|
|
|
|
diff := pretty.Compare(expectedCollection, actualCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEmptyCollectionPrependTo(t *testing.T) {
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
comment := &meta.Data{
|
|
|
|
Type: meta.CommentType,
|
|
|
|
Value: "// some comment",
|
|
|
|
}
|
|
|
|
|
|
|
|
actualCollection := meta.Collection{comment}
|
|
|
|
expectedCollection := meta.Collection{comment}
|
|
|
|
|
|
|
|
baseCollection := meta.Collection{}
|
|
|
|
|
|
|
|
// action
|
|
|
|
|
|
|
|
baseCollection.PrependTo(&actualCollection)
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCollection, actualCollection) {
|
|
|
|
diff := pretty.Compare(expectedCollection, actualCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionCutByTokenName(t *testing.T) {
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
whiteSpace := &meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: "\n",
|
|
|
|
}
|
|
|
|
OpenParenthesisComment := &meta.Data{
|
|
|
|
Type: meta.CommentType,
|
|
|
|
Value: "// some comment",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
}
|
|
|
|
OpenParenthesisToken := &meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "(",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
}
|
|
|
|
CloseParenthesisToken := &meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: ")",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
actualCollection := meta.Collection{whiteSpace, OpenParenthesisComment, OpenParenthesisToken, CloseParenthesisToken}
|
|
|
|
|
|
|
|
expectedCollection := meta.Collection{whiteSpace, CloseParenthesisToken}
|
2018-12-10 09:51:56 +00:00
|
|
|
expectedCutCollection := &meta.Collection{OpenParenthesisComment, OpenParenthesisToken}
|
2018-07-29 08:44:38 +00:00
|
|
|
|
|
|
|
// action
|
|
|
|
|
2018-12-10 09:51:56 +00:00
|
|
|
actualCutCollection := actualCollection.Cut(
|
2018-07-29 08:44:38 +00:00
|
|
|
meta.TokenNameFilter(meta.OpenParenthesisToken),
|
|
|
|
)
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCollection, actualCollection) {
|
|
|
|
diff := pretty.Compare(expectedCollection, actualCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 09:51:56 +00:00
|
|
|
if !reflect.DeepEqual(expectedCutCollection, actualCutCollection) {
|
|
|
|
diff := pretty.Compare(expectedCutCollection, actualCutCollection)
|
2018-07-29 08:44:38 +00:00
|
|
|
|
|
|
|
if diff != "" {
|
2018-12-10 09:51:56 +00:00
|
|
|
t.Errorf("\nexpected and actual Cut collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
2018-07-29 08:44:38 +00:00
|
|
|
} else {
|
2018-12-10 09:51:56 +00:00
|
|
|
t.Errorf("\nexpected and actual Cut collections are not equal\n")
|
2018-07-29 08:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionCutByTokenTypes(t *testing.T) {
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
whiteSpace := &meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: "\n",
|
|
|
|
}
|
|
|
|
OpenParenthesisComment := &meta.Data{
|
|
|
|
Type: meta.CommentType,
|
|
|
|
Value: "// some comment",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
}
|
|
|
|
OpenParenthesisToken := &meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "(",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
}
|
|
|
|
CloseParenthesisToken := &meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: ")",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
actualCollection := meta.Collection{whiteSpace, OpenParenthesisComment, OpenParenthesisToken, CloseParenthesisToken}
|
|
|
|
|
|
|
|
expectedCollection := meta.Collection{OpenParenthesisToken, CloseParenthesisToken}
|
2018-12-10 09:51:56 +00:00
|
|
|
expectedCutCollection := &meta.Collection{whiteSpace, OpenParenthesisComment}
|
2018-07-29 08:44:38 +00:00
|
|
|
|
|
|
|
// action
|
|
|
|
|
2018-12-10 09:51:56 +00:00
|
|
|
actualCutCollection := actualCollection.Cut(meta.OrFilter(
|
2018-07-29 08:44:38 +00:00
|
|
|
meta.TypeFilter(meta.CommentType),
|
|
|
|
meta.TypeFilter(meta.WhiteSpaceType)),
|
|
|
|
)
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCollection, actualCollection) {
|
|
|
|
diff := pretty.Compare(expectedCollection, actualCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 09:51:56 +00:00
|
|
|
if !reflect.DeepEqual(expectedCutCollection, actualCutCollection) {
|
|
|
|
diff := pretty.Compare(expectedCutCollection, actualCutCollection)
|
2018-07-29 08:44:38 +00:00
|
|
|
|
|
|
|
if diff != "" {
|
2018-12-10 09:51:56 +00:00
|
|
|
t.Errorf("\nexpected and actual Cut collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
2018-07-29 08:44:38 +00:00
|
|
|
} else {
|
2018-12-10 09:51:56 +00:00
|
|
|
t.Errorf("\nexpected and actual Cut collections are not equal\n")
|
2018-07-29 08:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionCutByTokenNameButNotType(t *testing.T) {
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
whiteSpace := &meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: "\n",
|
|
|
|
}
|
|
|
|
OpenParenthesisComment := &meta.Data{
|
|
|
|
Type: meta.CommentType,
|
|
|
|
Value: "// some comment",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
}
|
|
|
|
OpenParenthesisToken := &meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "(",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
}
|
|
|
|
CloseParenthesisToken := &meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: ")",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
actualCollection := meta.Collection{
|
|
|
|
whiteSpace,
|
|
|
|
OpenParenthesisComment,
|
|
|
|
OpenParenthesisToken,
|
|
|
|
CloseParenthesisToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedCollection := meta.Collection{
|
|
|
|
whiteSpace,
|
|
|
|
OpenParenthesisToken,
|
|
|
|
CloseParenthesisToken,
|
|
|
|
}
|
2018-12-10 09:51:56 +00:00
|
|
|
expectedCutCollection := &meta.Collection{
|
2018-07-29 08:44:38 +00:00
|
|
|
OpenParenthesisComment,
|
|
|
|
}
|
|
|
|
|
|
|
|
// action
|
|
|
|
|
2018-12-10 09:51:56 +00:00
|
|
|
actualCutCollection := actualCollection.Cut(meta.AndFilter(
|
2018-07-29 08:44:38 +00:00
|
|
|
meta.TokenNameFilter(meta.OpenParenthesisToken),
|
|
|
|
meta.NotFilter(meta.TypeFilter(meta.TokenType))),
|
|
|
|
)
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCollection, actualCollection) {
|
|
|
|
diff := pretty.Compare(expectedCollection, actualCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 09:51:56 +00:00
|
|
|
if !reflect.DeepEqual(expectedCutCollection, actualCutCollection) {
|
|
|
|
diff := pretty.Compare(expectedCutCollection, actualCutCollection)
|
2018-07-29 08:44:38 +00:00
|
|
|
|
|
|
|
if diff != "" {
|
2018-12-10 09:51:56 +00:00
|
|
|
t.Errorf("\nexpected and actual Cut collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
2018-07-29 08:44:38 +00:00
|
|
|
} else {
|
2018-12-10 09:51:56 +00:00
|
|
|
t.Errorf("\nexpected and actual Cut collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionCutByValue(t *testing.T) {
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
whiteSpace := &meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: "\n",
|
|
|
|
}
|
|
|
|
OpenParenthesisComment := &meta.Data{
|
|
|
|
Type: meta.CommentType,
|
|
|
|
Value: "// some comment",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
}
|
|
|
|
OpenParenthesisToken := &meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "(",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
}
|
|
|
|
CloseParenthesisToken := &meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: ")",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
actualCollection := meta.Collection{
|
|
|
|
whiteSpace,
|
|
|
|
OpenParenthesisComment,
|
|
|
|
OpenParenthesisToken,
|
|
|
|
CloseParenthesisToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedCollection := meta.Collection{
|
|
|
|
whiteSpace,
|
|
|
|
OpenParenthesisComment,
|
|
|
|
}
|
|
|
|
expectedCutCollection := &meta.Collection{
|
|
|
|
OpenParenthesisToken,
|
|
|
|
CloseParenthesisToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
// action
|
|
|
|
|
|
|
|
actualCutCollection := actualCollection.Cut(meta.ValueFilter("(", ")"))
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCollection, actualCollection) {
|
|
|
|
diff := pretty.Compare(expectedCollection, actualCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCutCollection, actualCutCollection) {
|
|
|
|
diff := pretty.Compare(expectedCutCollection, actualCutCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual Cut collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual Cut collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCollectionCutUntilFirstToken(t *testing.T) {
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
|
|
|
whiteSpace := &meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: "\n",
|
|
|
|
TokenName: meta.NodeStart,
|
|
|
|
}
|
|
|
|
OpenParenthesisComment := &meta.Data{
|
|
|
|
Type: meta.CommentType,
|
|
|
|
Value: "// some comment",
|
|
|
|
TokenName: meta.NodeStart,
|
|
|
|
}
|
|
|
|
OpenParenthesisToken := &meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: "(",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
}
|
|
|
|
CloseParenthesisComment := &meta.Data{
|
|
|
|
Type: meta.WhiteSpaceType,
|
|
|
|
Value: "// some comment",
|
|
|
|
TokenName: meta.OpenParenthesisToken,
|
|
|
|
}
|
|
|
|
CloseParenthesisToken := &meta.Data{
|
|
|
|
Type: meta.TokenType,
|
|
|
|
Value: ")",
|
|
|
|
TokenName: meta.CloseParenthesisToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
actualCollection := meta.Collection{
|
|
|
|
whiteSpace,
|
|
|
|
OpenParenthesisComment,
|
|
|
|
OpenParenthesisToken,
|
|
|
|
CloseParenthesisComment,
|
|
|
|
CloseParenthesisToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedCutCollection := &meta.Collection{
|
|
|
|
whiteSpace,
|
|
|
|
OpenParenthesisComment,
|
|
|
|
}
|
|
|
|
expectedCollection := meta.Collection{
|
|
|
|
OpenParenthesisToken,
|
|
|
|
CloseParenthesisComment, // must not be cut
|
|
|
|
CloseParenthesisToken,
|
|
|
|
}
|
|
|
|
|
|
|
|
// action
|
|
|
|
|
|
|
|
actualCutCollection := actualCollection.Cut(
|
|
|
|
meta.StopOnFailureFilter(
|
|
|
|
meta.NotFilter(
|
|
|
|
meta.TypeFilter(meta.TokenType),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
// check
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCollection, actualCollection) {
|
|
|
|
diff := pretty.Compare(expectedCollection, actualCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual collections are not equal\n")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(expectedCutCollection, actualCutCollection) {
|
|
|
|
diff := pretty.Compare(expectedCutCollection, actualCutCollection)
|
|
|
|
|
|
|
|
if diff != "" {
|
|
|
|
t.Errorf("\nexpected and actual Cut collections are not equal\ndiff: (-expected +actual)\n%s", diff)
|
|
|
|
} else {
|
|
|
|
t.Errorf("\nexpected and actual Cut collections are not equal\n")
|
2018-07-29 08:44:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|