1
1
package org .bblfsh .client .v2
2
2
3
+ import gopkg .in .bblfsh .sdk .v2 .protocol .driver .Mode
3
4
import org .bblfsh .client .v2 .libuast .Libuast
4
- import org .scalatest .{BeforeAndAfter , BeforeAndAfterAll , FlatSpec , Matchers }
5
5
6
- class FilterManagedTest extends FlatSpec
7
- with Matchers
8
- with BeforeAndAfter
9
- with BeforeAndAfterAll {
6
+ import scala .io .Source
7
+
8
+ class FilterManagedTest extends BblfshClientBaseTest {
9
+
10
+ import BblfshClient ._ // enables uast.* methods
10
11
11
12
var ctx : Context = _
12
13
val managedRoot = JArray (
@@ -19,15 +20,18 @@ class FilterManagedTest extends FlatSpec
19
20
))
20
21
21
22
override def beforeAll () = {
23
+ super .beforeAll()
22
24
System .err.println(s " Libuast.loaded: ${Libuast .loaded}" )
23
25
// to load native JNI lib \wo the full client
24
26
}
25
27
26
- before {
28
+ override def beforeEach () = {
29
+ super .beforeEach()
27
30
ctx = Context ()
28
31
}
29
32
30
33
override def afterAll () = {
34
+ super .afterAll()
31
35
System .runFinalization()
32
36
System .gc()
33
37
}
@@ -43,4 +47,40 @@ class FilterManagedTest extends FlatSpec
43
47
it.hasNext() should be(false )
44
48
}
45
49
50
+ " Filtering UAST" should " work in Native mode" in {
51
+ val fileContent = Source .fromFile(fileName).getLines.mkString(" \n " )
52
+ val resp = client.parse(fileName, fileContent, Mode .NATIVE )
53
+ val node = resp.get
54
+
55
+ val iter = BblfshClient .filter(node, " //SimpleName" )
56
+ iter.toList should have size (10 ) // number of Identifiers in the file
57
+ iter.close()
58
+ }
59
+
60
+ // TODO(#110) implement value type returns
61
+ // "Filtering UAST" should "work for Value types" in {
62
+ // val iter = BblfshClient.filterNumber(resp.get, "count(//*)")
63
+ // iter.toList should have size (517) // total number of nodes (not the number of results which is 1)
64
+ // }
65
+
66
+ " Filtering UAST" should " work in Annotated mode" in {
67
+ val fileContent = Source .fromFile(fileName).getLines.mkString(" \n " )
68
+ val resp = client.parse(fileName, fileContent, Mode .ANNOTATED )
69
+ val node = resp.get
70
+
71
+ val iter = BblfshClient .filter(node, " //SimpleName[@role='Call']" )
72
+ iter.toList should have size (1 ) // number of function called in the file
73
+ iter.close()
74
+ }
75
+
76
+ " Filtering UAST" should " work in Semantic mode" in {
77
+ val fileContent = Source .fromFile(fileName).getLines.mkString(" \n " )
78
+ val resp = client.parse(fileName, fileContent, Mode .SEMANTIC )
79
+ val node = resp.get
80
+
81
+ val iter = BblfshClient .filter(node, " //uast:Identifier[@role='Call']" )
82
+ iter.toList should have size (1 ) // number of function called in the file
83
+ iter.close()
84
+ }
85
+
46
86
}
0 commit comments