Skip to content

Commit a141bb4

Browse files
committed
add test for 'simple' case, but not happy yet
also formatting and restructure of test
1 parent f2d3dce commit a141bb4

File tree

2 files changed

+41
-29
lines changed

2 files changed

+41
-29
lines changed

gremlin-scala/src/main/scala/gremlin/scala/GremlinScala.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,8 @@ class ProjectionBuilder[T <: Product] private[gremlin] (
10481048
map buildResult(map) :+ map.get(label).asInstanceOf[U])
10491049
}
10501050

1051-
def and[U, TR <: Product](by: By[U])
1052-
(implicit prepend: TuplePrepend.Aux[T, Tuple1[U], TR]): ProjectionBuilder[TR] = apply(by)
1051+
def and[U, TR <: Product](by: By[U])(
1052+
implicit prepend: TuplePrepend.Aux[T, Tuple1[U], TR]): ProjectionBuilder[TR] = apply(by)
10531053

10541054
private[gremlin] def build(g: GremlinScala[_]): GremlinScala[T] = {
10551055
GremlinScala(addBy(g.traversal.project(labels.head, labels.tail: _*))).map(buildResult)

gremlin-scala/src/test/scala/gremlin/scala/ProjectSpec.scala

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,46 @@ import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory
44
import org.scalatest.{Matchers, WordSpec}
55

66
class ProjectSpec extends WordSpec with Matchers {
7-
def graph: ScalaGraph = TinkerFactory.createModern.asScala()
87

9-
"project steps" should {
10-
"provide type safe result" in {
11-
val result = graph
12-
.V()
8+
"projecting by one thing" in {
9+
// val result: String = //fails
10+
// val result: (String) = //fails
11+
val result: Tuple1[String] =
12+
// val result =
13+
graph.V
14+
.has(name.of("marko"))
15+
.project(_(By(name)))
16+
.head
17+
println(result) //(marko)
18+
println(result.getClass) // scala.Tuple1
19+
}
20+
21+
"projecting by two traversals" in {
22+
val result: (java.lang.Long, java.lang.Long) =
23+
graph.V
24+
.has(name.of("marko"))
25+
.project(_(By(__.outE.count)).and(By(__.inE.count)))
26+
.head
27+
28+
result shouldBe (3, 0)
29+
}
30+
31+
"projecting by property and traversal" in {
32+
val result: List[(String, java.lang.Long)] =
33+
graph.V
1334
.out("created")
14-
.project(_(By(Key[String]("name")))
15-
.and(By(__.in("created").count())))
16-
.toList()
17-
18-
result shouldBe List(
19-
("lop", 3),
20-
("lop",3),
21-
("lop",3),
22-
("ripple", 1)
23-
)
24-
}
25-
26-
"provide other type safe result" in {
27-
val result = graph
28-
.V()
29-
.has(Key("name").of("marko"))
30-
.project(_(By(__.outE().count()))
31-
.and(By(__.inE().count())))
32-
.head()
33-
34-
result shouldBe (3, 0)
35-
}
35+
.project(_(By(name)).and(By(__.in("created").count)))
36+
.toList
37+
38+
result shouldBe List(
39+
("lop", 3),
40+
("lop", 3),
41+
("lop", 3),
42+
("ripple", 1)
43+
)
3644
}
45+
46+
def graph: ScalaGraph = TinkerFactory.createModern.asScala
47+
val name = Key[String]("name")
48+
3749
}

0 commit comments

Comments
 (0)