1
1
package org .bblfsh .client .v2
2
2
3
3
import java .nio .ByteBuffer
4
+
5
+ import gopkg .in .bblfsh .sdk .v2 .protocol .driver .Mode
6
+
4
7
import scala .io .Source
5
8
6
9
class BblfshClientParseTest extends BblfshClientBaseTest {
@@ -12,20 +15,54 @@ class BblfshClientParseTest extends BblfshClientBaseTest {
12
15
assert(resp.errors.isEmpty)
13
16
}
14
17
18
+ " Filtering UAST" should " work in Native mode" in {
19
+ val fileContent = Source .fromFile(fileName).getLines.mkString(" \n " )
20
+ val resp = client.parse(fileName, fileContent, Mode .NATIVE )
21
+ val node = resp.get
22
+
23
+ val iter = BblfshClient .filter(node, " //SimpleName" )
24
+ iter.toList should have size (10 ) // number of Identifiers in the file
25
+ iter.close()
26
+ }
27
+
28
+ // TODO(#110) implement value type returns
29
+ // "Filtering UAST" should "work for Value types" in {
30
+ // val iter = BblfshClient.filterNumber(resp.get, "count(//*)")
31
+ // iter.toList should have size (517) // total number of nodes (not the number of results which is 1)
32
+ // }
33
+
34
+ " Filtering UAST" should " work in Annotated mode" in {
35
+ val fileContent = Source .fromFile(fileName).getLines.mkString(" \n " )
36
+ val resp = client.parse(fileName, fileContent, Mode .ANNOTATED )
37
+ val node = resp.get
38
+
39
+ val iter = BblfshClient .filter(node, " //SimpleName[@role='Call']" )
40
+ iter.toList should have size (1 ) // number of function called in the file
41
+ iter.close()
42
+ }
43
+
44
+ " Filtering UAST" should " work in Semantic mode" in {
45
+ val fileContent = Source .fromFile(fileName).getLines.mkString(" \n " )
46
+ val resp = client.parse(fileName, fileContent, Mode .SEMANTIC )
47
+ val node = resp.get
48
+
49
+ val iter = BblfshClient .filter(node, " //uast:Identifier[@role='Call']" )
50
+ iter.toList should have size (1 ) // number of function called in the file
51
+ iter.close()
52
+ }
53
+
15
54
" Decoded UAST after parsing" should " not be NULL" in {
16
55
val uast = resp.uast.decode()
17
56
18
57
assert(uast != null )
19
58
assert(uast.nativeContext != 0 )
20
59
21
- println(uast)
22
60
uast.dispose()
23
61
}
24
62
25
63
" Decoded UAST RootNode" should " not be NULL" in {
26
64
val uast = resp.uast.decode()
27
65
val rootNode : NodeExt = uast.root()
28
- println(rootNode.getClass)
29
66
30
67
rootNode should not be null
31
68
rootNode.ctx should not be (0 )
@@ -37,15 +74,11 @@ class BblfshClientParseTest extends BblfshClientBaseTest {
37
74
" Encoding UAST to the same ContextExt" should " produce the same bytes" in {
38
75
val uastCtx : ContextExt = resp.uast.decode()
39
76
val rootNode : NodeExt = uastCtx.root()
40
- println(s " Root node: $rootNode" )
41
77
42
78
val encodedBytes : ByteBuffer = uastCtx.encode(rootNode)
43
79
44
80
encodedBytes.capacity should be(resp.uast.asReadOnlyByteBuffer.capacity)
45
81
encodedBytes shouldEqual resp.uast.asReadOnlyByteBuffer
46
-
47
- println(resp.uast.asReadOnlyByteBuffer)
48
- println(encodedBytes)
49
82
}
50
83
51
84
" Encoding java UAST to a new Context" should " produce the same bytes" in {
@@ -62,7 +95,6 @@ class BblfshClientParseTest extends BblfshClientBaseTest {
62
95
63
96
64
97
" Encoding python UAST to a new Context" should " produce the same bytes" in {
65
- val client = BblfshClient (" localhost" , 9432 )
66
98
val fileName = " src/test/resources/python_file.py"
67
99
val fileContent = Source .fromFile(fileName).getLines.mkString(" \n " )
68
100
val resp = client.parse(fileName, fileContent)
0 commit comments