Skip to content

Commit

Permalink
Added more anonymous traversal tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreachild committed Nov 26, 2024
1 parent 66704da commit cfd4624
Showing 1 changed file with 154 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import java.util.function.Function;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.apache.tinkerpop.gremlin.process.traversal.DT;
import org.apache.tinkerpop.gremlin.process.traversal.Operator;
import org.apache.tinkerpop.gremlin.process.traversal.Order;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.Pop;
import org.apache.tinkerpop.gremlin.process.traversal.Scope;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
Expand All @@ -39,6 +41,7 @@
import org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
import org.apache.tinkerpop.gremlin.util.DatetimeHelper;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -303,6 +306,11 @@ public void shouldParseTraversalMethod_choose_Function() throws Exception {
compare(g.V().map(__.choose((Function) label)), eval("g.V().map(__.choose(label))"));
}

@Test
public void shouldParseTraversalMethod_choose_Predicate() throws Exception {
compare(g.V().map(__.choose(P.eq("test"), out("knows"))), eval("g.V().map(__.choose(P.eq(\"test\"), out(\"knows\")))"));
}

@Test
public void shouldParseTraversalMethod_choose_Predicate_Traversal() throws Exception {
compare(g.V().map(__.choose(is(12), values("age"))), eval("g.V().map(__.choose(is(12), values(\"age\")))"));
Expand Down Expand Up @@ -339,6 +347,12 @@ public void shouldParseTraversalMethod_coin() throws Exception {
compare(g.V().map(__.coin(2.5)), eval("g.V().map(__.coin(2.5))"));
}

@Test
public void shouldParseTraversalMethod_coin_GValue() throws Exception {
antlrToLanguage = createAntlr(new VariableResolver.DefaultVariableResolver(ElementHelper.asMap("probability", 2.5)));
compare(g.V().map(__.coin(GValue.of("probability", 2.5))), eval("g.V().map(__.coin(probability))"));
}

@Test
public void shouldParseTraversalMethod_combine_Object() throws Exception {
final ArrayList<Integer> list = new ArrayList<>();
Expand Down Expand Up @@ -532,6 +546,11 @@ public void shouldParseTraversalMethod_has_T_Traversal() throws Exception {
compare(g.V().map(__.has(T.id, bothE())), eval("g.V().map(__.has(id, bothE()))"));
}

@Test
public void shouldParseTraversalMethod_has_GValue() throws Exception {
compare(g.V().map(__.has(GValue.of("foo", "bar"), "b", eq("c"))), eval("g.V().map(__.has(foo, \"b\", eq(\"c\")))"));
}

@Test
public void shouldParseTraversalMethod_hasId_Object_Object() throws Exception {
compare(g.V().map(__.hasId(3, 4)), eval("g.V().map(__.hasId(3, 4))"));
Expand Down Expand Up @@ -564,6 +583,11 @@ public void shouldParseTraversalMethod_hasLabel_String_String() throws Exception
compare(g.V().map(__.hasLabel("age", "3")), eval("g.V().map(__.hasLabel('age', '3'))"));
}

@Test
public void shouldParseTraversalMethod_hasLabel_GValue() throws Exception {
compare(g.V().map(__.hasLabel(GValue.of("foo", "bar"))), eval("g.V().map(__.hasLabel(foo))"));
}

@Test
public void shouldParseTraversalMethod_hasNot() throws Exception {
compare(g.V().map(__.hasNot("know")), eval("g.V().map(__.hasNot('know'))"));
Expand Down Expand Up @@ -919,6 +943,11 @@ public void shouldParseTraversalMethod_repeat() throws Exception {
compare(g.V().map(__.repeat(both())), eval("g.V().map(__.repeat(both()))"));
}

@Test
public void shouldParseTraversalMethod_repeat_String_Traversal() throws Exception {
compare(g.V().map(__.repeat("test", both())), eval("g.V().map(__.repeat(\"test\", both()))"));
}

@Test
public void shouldParseTraversalMethod_sack_BiFunction() throws Exception {
compare(g.V().map(__.sack()), eval("g.V().map(__.sack())"));
Expand Down Expand Up @@ -1403,6 +1432,131 @@ public void shouldParseTraversalMethod_substring_long_long_Scope() throws Except
compare(g.V().map(__.substring(Scope.global, 5, 9)), eval("g.V().map(__.substring(Scope.global, 5, 9))"));
}

@Test
public void shouldParseTraversalMethod_asDate() throws Exception {
compare(g.V().map(__.asDate()), eval("g.V().map(__.asDate())"));
}

@Test
public void shouldParseTraversalMethod_dateAdd() throws Exception {
compare(g.V().map(__.dateAdd(DT.day, 2)), eval("g.V().map(__.dateAdd(DT.day, 2))"));
}

@Test
public void shouldParseTraversalMethod_dateDiff() throws Exception {
compare(g.V().map(__.dateDiff(DatetimeHelper.datetime("2024-11-26"))), eval("g.V().map(__.dateDiff(datetime(\"2024-11-26\")))"));
}

@Test
public void shouldParseTraversalMethod_dateDiff_Traversal() throws Exception {
compare(g.V().map(__.dateDiff(__.constant(DatetimeHelper.datetime("2024-11-26")))), eval("g.V().map(__.dateDiff(__.constant(datetime(\"2024-11-26\"))))"));
}

@Test
public void shouldParseTraversalMethod_difference() throws Exception {
compare(g.V().map(__.difference("test")), eval("g.V().map(__.difference(\"test\"))"));
}

@Test
public void shouldParseTraversalMethod_difference_GValue() throws Exception {
compare(g.V().map(__.difference(GValue.of("foo", "bar"))), eval("g.V().map(__.difference(foo))"));
}

@Test
public void shouldParseTraversalMethod_disjunct() throws Exception {
compare(g.V().map(__.disjunct("test")), eval("g.V().map(__.disjunct(\"test\"))"));
}

@Test
public void shouldParseTraversalMethod_disjunct_GValue() throws Exception {
compare(g.V().map(__.disjunct(GValue.of("foo", "bar"))), eval("g.V().map(__.disjunct(foo))"));
}

@Test
public void shouldParseTraversalMethod_intersect() throws Exception {
compare(g.V().map(__.intersect("test")), eval("g.V().map(__.intersect(\"test\"))"));
}

@Test
public void shouldParseTraversalMethod_intersect_GValue() throws Exception {
compare(g.V().map(__.intersect(GValue.of("foo", "bar"))), eval("g.V().map(__.intersect(foo))"));
}

@Test
public void shouldParseTraversalMethod_conjoin() throws Exception {
compare(g.V().map(__.conjoin("test")), eval("g.V().map(__.conjoin(\"test\"))"));
}

@Test
public void shouldParseTraversalMethod_conjoin_GValue() throws Exception {
compare(g.V().map(__.conjoin(GValue.of("foo", "bar"))), eval("g.V().map(__.conjoin(foo))"));
}

@Test
public void shouldParseTraversalMethod_merge() throws Exception {
compare(g.V().map(__.merge("test")), eval("g.V().map(__.merge(\"test\"))"));
}

@Test
public void shouldParseTraversalMethod_merge_GValue() throws Exception {
compare(g.V().map(__.merge(GValue.of("foo", "bar"))), eval("g.V().map(__.merge(foo))"));
}

@Test
public void shouldParseTraversalMethod_combine() throws Exception {
compare(g.V().map(__.combine("test")), eval("g.V().map(__.combine(\"test\"))"));
}

@Test
public void shouldParseTraversalMethod_combine_GValue() throws Exception {
compare(g.V().map(__.combine(GValue.of("foo", "bar"))), eval("g.V().map(__.combine(foo))"));
}

@Test
public void shouldParseTraversalMethod_product() throws Exception {
compare(g.V().map(__.product("test")), eval("g.V().map(__.product(\"test\"))"));
}

@Test
public void shouldParseTraversalMethod_product_GValue() throws Exception {
compare(g.V().map(__.product(GValue.of("foo", "bar"))), eval("g.V().map(__.product(foo))"));
}

@Test
public void shouldParseTraversalMethod_all() throws Exception {
compare(g.V().map(__.all(P.eq("test"))), eval("g.V().map(__.all(P.eq(\"test\")))"));
}

@Test
public void shouldParseTraversalMethod_any() throws Exception {
compare(g.V().map(__.any(P.eq("test"))), eval("g.V().map(__.any(P.eq(\"test\")))"));
}

@Test
public void shouldParseTraversalMethod_none() throws Exception {
compare(g.V().map(__.none(P.eq("test"))), eval("g.V().map(__.none(P.eq(\"test\")))"));
}

@Test
public void shouldParseTraversalMethod_fail() throws Exception {
compare(g.V().map(__.fail()), eval("g.V().map(__.fail())"));
}

@Test
public void shouldParseTraversalMethod_fail_String() throws Exception {
compare(g.V().map(__.fail("test")), eval("g.V().map(__.fail(\"test\"))"));
}

@Test
public void shouldParseTraversalMethod_element() throws Exception {
compare(g.V().map(__.element()), eval("g.V().map(__.element())"));
}

@Test
public void shouldParseTraversalMethod_call() throws Exception {
compare(g.V().map(__.call("test")), eval("g.V().map(__.call(\"test\"))"));
}

private void compare(Object expected, Object actual) {
assertEquals(((DefaultGraphTraversal) expected).asAdmin().getGremlinLang(),
((DefaultGraphTraversal) actual).asAdmin().getGremlinLang());
Expand Down

0 comments on commit cfd4624

Please sign in to comment.