@@ -42,25 +42,64 @@ class IteratorManagedTest extends FlatSpec
42
42
nodes.size should be(3 ) // number of composite nodes
43
43
}
44
44
45
- val pyClientTestRoot = JObject (
46
- " @type" -> JString (" root" ),
47
- " children" -> JArray (
45
+ def testTree : JObject = {
46
+ // Helper to get a position encoded into JObject
47
+ def encodePosition (startOffset : Int , startLine : Int , startCol : Int ,
48
+ endOffset : Int , endLine : Int , endCol : Int ): JObject = {
49
+
48
50
JObject (
49
- " @type" -> JString (" son1" ),
50
- " children" -> JArray (
51
- JObject (" @type" -> JString (" son1_1" )),
52
- JObject (" @type" -> JString (" son1_2" ))
51
+ " @type" -> JString (" uast:Positions" ),
52
+ " start" -> JObject (
53
+ " @type" -> JString (" uast:Position" ),
54
+ " offset" -> JInt (startOffset),
55
+ " line" -> JInt (startLine),
56
+ " col" -> JInt (startCol)
57
+ ),
58
+ " end" -> JObject (
59
+ " @type" -> JString (" uast:Position" ),
60
+ " offset" -> JInt (endOffset),
61
+ " line" -> JInt (endLine),
62
+ " col" -> JInt (endCol)
53
63
)
54
- ),
55
- JObject (
56
- " @type" -> JString (" son2" ),
57
- " children" -> JArray (
58
- JObject (" @type" -> JString (" son2_1" )),
59
- JObject (" @type" -> JString (" son2_2" ))
64
+ )
65
+ }
66
+
67
+ // The actual tree
68
+ JObject (
69
+ " @type" -> JString (" root" ),
70
+ " @pos" -> encodePosition(0 ,1 ,1 , 1 ,1 ,2 ),
71
+ " children" -> JArray (
72
+ JObject (
73
+ " @type" -> JString (" son1" ),
74
+ " @pos" -> encodePosition(2 ,2 ,2 , 3 ,2 ,3 ),
75
+ " children" -> JArray (
76
+ JObject (
77
+ " @type" -> JString (" son1_1" ),
78
+ " @pos" -> encodePosition(10 ,10 ,1 , 12 ,2 ,2 )
79
+ ),
80
+ JObject (
81
+ " @type" -> JString (" son1_2" ),
82
+ " @pos" -> encodePosition(10 ,10 ,1 , 12 ,2 ,2 )
83
+ )
84
+ )
85
+ ),
86
+ JObject (
87
+ " @type" -> JString (" son2" ),
88
+ " @pos" -> encodePosition(100 ,100 ,1 , 101 ,100 ,2 ),
89
+ " children" -> JArray (
90
+ JObject (
91
+ " @type" -> JString (" son2_1" ),
92
+ " @pos" -> encodePosition(5 ,5 ,1 , 6 ,5 ,2 )
93
+ ),
94
+ JObject (
95
+ " @type" -> JString (" son2_2" ),
96
+ " @pos" -> encodePosition(15 ,15 ,1 , 16 ,15 ,2 )
97
+ )
98
+ )
60
99
)
61
100
)
62
101
)
63
- )
102
+ }
64
103
65
104
def getNodeTypes (iterator : Libuast .UastIter ): List [String ] =
66
105
iterator
@@ -71,7 +110,7 @@ class IteratorManagedTest extends FlatSpec
71
110
// Equivalent of the test.py#testIteratorPreOrder
72
111
// https://github.com/bblfsh/python-client/blob/15ffb98bfa09e6aae4d1580f0e4f02eb2a530205/bblfsh/test.py#L270
73
112
" Managed UAST iterator" should " return nodes in PreOrder" in {
74
- val preIter = BblfshClient .iterator(pyClientTestRoot , BblfshClient .PreOrder )
113
+ val preIter = BblfshClient .iterator(testTree , BblfshClient .PreOrder )
75
114
val nodes = getNodeTypes(preIter)
76
115
77
116
val poActual = Seq (" root" , " son1" , " son1_1" , " son1_2" , " son2" , " son2_1" , " son2_2" )
@@ -82,7 +121,7 @@ class IteratorManagedTest extends FlatSpec
82
121
}
83
122
84
123
" Managed UAST iterator" should " return nodes in PostOrder" in {
85
- val postIter = BblfshClient .iterator(pyClientTestRoot , BblfshClient .PostOrder )
124
+ val postIter = BblfshClient .iterator(testTree , BblfshClient .PostOrder )
86
125
val nodes = getNodeTypes(postIter)
87
126
88
127
val poActual = Seq (" son1_1" , " son1_2" , " son1" , " son2_1" , " son2_2" , " son2" , " root" )
0 commit comments