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

Commit 84cbc64

Browse files
committed
test: move all filter tests together
Signed-off-by: Alexander Bezzubov <[email protected]>
1 parent 616daf1 commit 84cbc64

File tree

3 files changed

+49
-47
lines changed

3 files changed

+49
-47
lines changed

src/test/scala/org/bblfsh/client/v2/BblfshClientBaseTest.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package org.bblfsh.client.v2
22

33
import gopkg.in.bblfsh.sdk.v2.protocol.driver.ParseResponse
4-
import org.scalatest.{BeforeAndAfter, BeforeAndAfterAll, FlatSpec, Matchers}
4+
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, FlatSpec, Matchers}
55

66
import scala.io.Source
77

88
class BblfshClientBaseTest extends FlatSpec
9-
with BeforeAndAfter
9+
with BeforeAndAfterEach
1010
with BeforeAndAfterAll
1111
with Matchers {
1212

1313
val client = BblfshClient("localhost", 9432)
1414
val fileName = "src/test/resources/SampleJavaFile.java"
1515
var resp: ParseResponse = _
1616

17-
before {
17+
override def beforeEach() = {
1818
val fileContent = Source.fromFile(fileName).getLines.mkString("\n")
1919
resp = client.parse(fileName, fileContent)
2020
}

src/test/scala/org/bblfsh/client/v2/BblfshClientParseTest.scala

-38
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package org.bblfsh.client.v2
22

33
import java.nio.ByteBuffer
44

5-
import gopkg.in.bblfsh.sdk.v2.protocol.driver.Mode
6-
75
import scala.io.Source
86

97
class BblfshClientParseTest extends BblfshClientBaseTest {
@@ -15,42 +13,6 @@ class BblfshClientParseTest extends BblfshClientBaseTest {
1513
assert(resp.errors.isEmpty)
1614
}
1715

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-
5416
"Decoded UAST after parsing" should "not be NULL" in {
5517
val uast = resp.uast.decode()
5618

src/test/scala/org/bblfsh/client/v2/FilterManagedTest.scala

+46-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package org.bblfsh.client.v2
22

3+
import gopkg.in.bblfsh.sdk.v2.protocol.driver.Mode
34
import org.bblfsh.client.v2.libuast.Libuast
4-
import org.scalatest.{BeforeAndAfter, BeforeAndAfterAll, FlatSpec, Matchers}
55

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
1011

1112
var ctx: Context = _
1213
val managedRoot = JArray(
@@ -19,15 +20,18 @@ class FilterManagedTest extends FlatSpec
1920
))
2021

2122
override def beforeAll() = {
23+
super.beforeAll()
2224
System.err.println(s"Libuast.loaded: ${Libuast.loaded}")
2325
// to load native JNI lib \wo the full client
2426
}
2527

26-
before {
28+
override def beforeEach() = {
29+
super.beforeEach()
2730
ctx = Context()
2831
}
2932

3033
override def afterAll() = {
34+
super.afterAll()
3135
System.runFinalization()
3236
System.gc()
3337
}
@@ -43,4 +47,40 @@ class FilterManagedTest extends FlatSpec
4347
it.hasNext() should be(false)
4448
}
4549

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+
4686
}

0 commit comments

Comments
 (0)