@@ -2,46 +2,42 @@ package org.bblfsh.client.v2
22
33import gopkg .in .bblfsh .sdk .v2 .protocol .driver .Mode
44import org .bblfsh .client .v2 .libuast .Libuast
5+ import org .scalatest .prop .TableDrivenPropertyChecks ._
56
67import scala .io .Source
78
89class FilterManagedTest extends BblfshClientBaseTest {
910
1011 import BblfshClient ._ // enables uast.* methods
1112
12- var ctx : Context = _
13+ val ctx : Context = Context ()
1314 val managedRoot = JArray (
1415 JObject (
1516 " @type" -> JString (" file" ),
1617 " k1" -> JString (" v1" ),
1718 " k2" -> JObject (
18- " k3" -> JInt (24 )
19+ " k3" -> JInt (24 ),
20+ " k4" -> JFloat (1.0 ),
21+ " k5" -> JArray (
22+ JObject (
23+ " k6" -> JBool (true ),
24+ " k7" -> JString (" v2" ),
25+ " k8" -> JObject (
26+ " k9" -> JBool (false ),
27+ " k10" -> JFloat (2.0 )
28+ )
29+ )
30+ )
1931 )
20- ))
21-
22- override def beforeAll () = {
23- super .beforeAll()
24- System .err.println(s " Libuast.loaded: ${Libuast .loaded}" )
25- // to load native JNI lib \wo the full client
26- }
27-
28- override def beforeEach () = {
29- super .beforeEach()
30- ctx = Context ()
31- }
32-
33- override def afterAll () = {
34- super .afterAll()
35- System .runFinalization()
36- System .gc()
37- }
32+ )
33+ )
3834
3935 " XPath filter" should " find all positions under context" in {
4036 val it = ctx.filter(" //file" , managedRoot)
4137 it.hasNext() should be(true )
4238
4339 val pos = it.toList
44- pos should have size (1 ) // Tiny.java contains 1 file node
40+ pos should have size (1 ) // managedRoot contains only a node JObject
4541
4642 it.close()
4743 it.hasNext() should be(false )
@@ -57,11 +53,26 @@ class FilterManagedTest extends BblfshClientBaseTest {
5753 iter.close()
5854 }
5955
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- // }
56+ val valueFilters =
57+ Table (
58+ (" filter" , " expected" ),
59+ (BblfshClient .filterInt _, List (JInt (24 ))),
60+ (BblfshClient .filterBool _, List (JBool (true ), JBool (false ))),
61+ (BblfshClient .filterString _, List (JString (" file" ), JString (" v1" ), JString (" v2" ))),
62+ (BblfshClient .filterFloat _, List (JFloat (1.0 ), JFloat (2.0 )))
63+ )
64+
65+ " Filtering UAST" should " work for Value types" in {
66+ val iterCount = BblfshClient .filterInt(managedRoot, " count(//*)" )
67+ val allNodesIt = BblfshClient .filter(managedRoot, " //*" )
68+ val numNodes = allNodesIt.size
69+ iterCount.toList should be (List (JInt (numNodes))) // number of nodes
70+
71+ forAll (valueFilters) { (filter, expected : List [JNode ]) =>
72+ val it = filter(managedRoot, " //*" )
73+ it.toList should be (expected)
74+ }
75+ }
6576
6677 " Filtering UAST" should " work in Annotated mode" in {
6778 val fileContent = Source .fromFile(fileName).getLines.mkString(" \n " )
0 commit comments