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

Commit 0c39f34

Browse files
committed
Brings data for iterators tests closer to python-client
Includes positions mainly, to be able to test against all new orders in libuast Signed-off-by: ncordon <[email protected]>
1 parent d8e2c8f commit 0c39f34

File tree

1 file changed

+55
-16
lines changed

1 file changed

+55
-16
lines changed

src/test/scala/org/bblfsh/client/v2/libuast/IteratorManagedTest.scala

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,64 @@ class IteratorManagedTest extends FlatSpec
4242
nodes.size should be(3) // number of composite nodes
4343
}
4444

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+
4850
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)
5363
)
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+
)
6099
)
61100
)
62101
)
63-
)
102+
}
64103

65104
def getNodeTypes(iterator: Libuast.UastIter): List[String] =
66105
iterator
@@ -71,7 +110,7 @@ class IteratorManagedTest extends FlatSpec
71110
// Equivalent of the test.py#testIteratorPreOrder
72111
// https://github.com/bblfsh/python-client/blob/15ffb98bfa09e6aae4d1580f0e4f02eb2a530205/bblfsh/test.py#L270
73112
"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)
75114
val nodes = getNodeTypes(preIter)
76115

77116
val poActual = Seq("root", "son1", "son1_1", "son1_2", "son2", "son2_1", "son2_2")
@@ -82,7 +121,7 @@ class IteratorManagedTest extends FlatSpec
82121
}
83122

84123
"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)
86125
val nodes = getNodeTypes(postIter)
87126

88127
val poActual = Seq("son1_1", "son1_2", "son1", "son2_1", "son2_2", "son2", "root")

0 commit comments

Comments
 (0)