Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 39585ec

Browse files
author
Juanjo Alvarez
committed
Fixed the reverse opJoinNamesArray transofrmation
Signed-off-by: Juanjo Alvarez <[email protected]>
1 parent 8d1ecc3 commit 39585ec

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

driver/normalizer/normalizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (op opJoinNamesArray) Check(st *State, n nodes.Node) (bool, error) {
7878
qual.Names = append(qual.Names, id)
7979
}
8080

81-
n, err := uast.ToNode(qual)
81+
n, err := uast.ToNode(qual.Names)
8282
if err != nil {
8383
return false, err
8484
}
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package normalizer
22

33
import (
4-
"fmt"
54
"github.com/stretchr/testify/require"
65
"gopkg.in/bblfsh/sdk.v2/uast/nodes"
76
"testing"
@@ -13,7 +12,6 @@ func TestOpJoinNamesArray(t *testing.T) {
1312
op := opJoinNamesArray{Var("x")}
1413
st := NewState()
1514
n1 := nodes.String("a::b::c")
16-
fmt.Println(string(n1) == "a::b::c") // true
1715

1816
res, err := op.Check(st, n1)
1917
require.NoError(t, err)
@@ -22,17 +20,29 @@ func TestOpJoinNamesArray(t *testing.T) {
2220
n2, ok := st.GetVar("x")
2321
require.True(t, ok)
2422
require.NotNil(t, n2)
25-
//fmt.Println(n2) // prints the QualifiedIdentifier correctly
23+
require.Equal(t, nodes.Array{
24+
nodes.Object{
25+
"@type": nodes.String("uast:Identifier"),
26+
"@pos":nodes.Object{"@type":nodes.String("uast:Positions")},
27+
"Name": nodes.String("a"),
28+
},
29+
nodes.Object{
30+
"@type": nodes.String("uast:Identifier"),
31+
"@pos":nodes.Object{"@type":nodes.String("uast:Positions")},
32+
"Name": nodes.String("b"),
33+
},
34+
nodes.Object{
35+
"@type": nodes.String("uast:Identifier"),
36+
"@pos":nodes.Object{"@type":nodes.String("uast:Positions")},
37+
"Name": nodes.String("c"),
38+
},
39+
}, n2)
2640

2741
n3, err := op.Construct(st, nil)
2842
require.NotNil(t, n3)
2943
require.NoError(t, err)
30-
fmt.Println("XXX n3")
31-
fmt.Println(n3)
32-
x, ok := n3.(nodes.String)
44+
n4, ok := n3.(nodes.String)
3345
require.True(t, ok)
34-
fmt.Println("XXX should be String")
35-
fmt.Println(x) // empty
36-
fmt.Println(string(x))
37-
fmt.Println(string(x) == "a::b::c") // false
46+
require.Equal(t, n1, n4)
47+
require.Equal(t, string(n4), "a::b::c")
3848
}

0 commit comments

Comments
 (0)