Cole-Greer commented on code in PR #3309: URL: https://github.com/apache/tinkerpop/pull/3309#discussion_r2876117520
########## gremlin-dotnet/test/Gremlin.Net.UnitTest/Process/Traversal/GremlinLangTests.cs: ########## @@ -0,0 +1,1016 @@ +#region License + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#endregion + +using System; +using System.Collections.Generic; +using System.Numerics; +using Gremlin.Net.Process.Traversal; +using Gremlin.Net.Process.Traversal.Strategy.Decoration; +using Gremlin.Net.Process.Traversal.Strategy.Verification; +using Gremlin.Net.Structure; +using Xunit; + +namespace Gremlin.Net.UnitTest.Process.Traversal +{ + public class GremlinLangTests : IDisposable + { + private readonly GraphTraversalSource _g; + + public GremlinLangTests() + { + GremlinLang.ResetCounter(); + _g = new GraphTraversalSource(); + } + + public void Dispose() + { + } + + // --- Core Traversal Tests 1-30 --- + + [Fact] + public void g_V() + { + Assert.Equal("g.V()", _g.V().GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_1234() + { + Assert.Equal("g.V(\"1\",\"2\",\"3\",\"4\")", _g.V("1", "2", "3", "4").GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_3_ValueMap_true() + { + Assert.Equal("g.V(\"3\").valueMap(true)", _g.V("3").ValueMap<object, object>(true).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Constant_5() + { + Assert.Equal("g.V().constant(5)", _g.V().Constant(5).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Constant_1_5() + { + Assert.Equal("g.V().constant(1.5D)", _g.V().Constant(1.5).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Constant_Hello() + { + Assert.Equal("g.V().constant(\"Hello\")", _g.V().Constant("Hello").GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_HasLabel_airport_Limit_5() + { + Assert.Equal("g.V().hasLabel(\"airport\").limit(5L)", _g.V().HasLabel("airport").Limit<object>(5).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_HasLabel_P_Within() + { + Assert.Equal("g.V().hasLabel(within([\"a\",\"b\",\"c\"]))", _g.V().HasLabel(P.Within("a", "b", "c")).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_HasLabel_airport_continent_Out_Limit_5() + { + Assert.Equal("g.V().hasLabel(\"airport\",\"continent\").out().limit(5L)", + _g.V().HasLabel("airport", "continent").Out().Limit<object>(5).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_HasLabel_airport_Out_Values_code_Limit_5() + { + Assert.Equal("g.V().hasLabel(\"airport\").out().values(\"code\").limit(5L)", + _g.V().HasLabel("airport").Out().Values<object>("code").Limit<object>(5).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_3_As_a_Out_route_Limit_10_Where_Eq_a_By_region() + { + Assert.Equal("g.V(\"3\").as(\"a\").out(\"route\").limit(10L).where(eq(\"a\")).by(\"region\")", + _g.V("3").As("a").Out("route").Limit<object>(10).Where(P.Eq("a")).By("region").GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_3_Repeat_Out_route_SimplePath_Times_2_Path_By_code() + { + Assert.Equal("g.V(\"3\").repeat(__.out(\"route\").simplePath()).times(2).path().by(\"code\")", + _g.V("3").Repeat(__.Out("route").SimplePath()).Times(2).Path().By("code").GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_HasLabel_airport_Out_Has_region_USTX_Values_code_Limit_5() + { + Assert.Equal("g.V().hasLabel(\"airport\").out().has(\"region\",\"US-TX\").values(\"code\").limit(5L)", + _g.V().HasLabel("airport").Out().Has("region", "US-TX").Values<object>("code").Limit<object>(5).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_HasLabel_airport_Union_Values_city_Values_region_Limit_5() + { + Assert.Equal("g.V().hasLabel(\"airport\").union(__.values(\"city\"),__.values(\"region\")).limit(5L)", + _g.V().HasLabel("airport").Union<object>(__.Values<object>("city"), __.Values<object>("region")).Limit<object>(5).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_3_As_a_Out_route_routes() + { + Assert.Equal("g.V(\"3\").as(\"a\").out(\"route\",\"routes\")", + _g.V("3").As("a").Out("route", "routes").GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Where_Values_runways_Is_5() + { + Assert.Equal("g.V().where(__.values(\"runways\").is(5))", + _g.V().Where(__.Values<object>("runways").Is(5)).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_3_Repeat_Out_SimplePath_Until_Has_code_AGR_Path_By_code_Limit_5() + { + Assert.Equal("g.V(\"3\").repeat(__.out().simplePath()).until(__.has(\"code\",\"AGR\")).path().by(\"code\").limit(5L)", + _g.V("3").Repeat(__.Out().SimplePath()).Until(__.Has("code", "AGR")).Path().By("code").Limit<object>(5).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_HasLabel_airport_Order_By_Id() + { + Assert.Equal("g.V().hasLabel(\"airport\").order().by(__.id())", + _g.V().HasLabel("airport").Order().By(__.Id()).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_HasLabel_airport_Order_By_T_Id() + { + Assert.Equal("g.V().hasLabel(\"airport\").order().by(T.id)", + _g.V().HasLabel("airport").Order().By(T.Id).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_HasLabel_airport_Order_By_Id_Desc() + { + Assert.Equal("g.V().hasLabel(\"airport\").order().by(__.id(),Order.desc)", + _g.V().HasLabel("airport").Order().By(__.Id(), Order.Desc).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_HasLabel_airport_Order_By_code_Desc() + { + Assert.Equal("g.V().hasLabel(\"airport\").order().by(\"code\",Order.desc)", + _g.V().HasLabel("airport").Order().By("code", Order.Desc).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_123_Local_Out_Out_Dedup_Fold() + { + Assert.Equal("g.V(\"1\",\"2\",\"3\").local(__.out().out().dedup().fold())", + _g.V("1", "2", "3").Local<object>(__.Out().Out().Dedup().Fold()).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_3_Out_Path_Count_Scope_Local() + { + Assert.Equal("g.V(\"3\").out().path().count(Scope.local)", + _g.V("3").Out().Path().Count(Scope.Local).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_E_Count() + { + Assert.Equal("g.E().count()", _g.E().Count().GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_5_OutE_route_InV_Path_Limit_10() + { + Assert.Equal("g.V(\"5\").outE(\"route\").inV().path().limit(10L)", + _g.V("5").OutE("route").InV().Path().Limit<object>(10).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_5_PropertyMap_Select_Column_Keys() + { + Assert.Equal("g.V(\"5\").propertyMap().select(Column.keys)", + _g.V("5").PropertyMap<object>().Select<object>(Column.Keys).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_5_PropertyMap_Select_Column_Values() + { + Assert.Equal("g.V(\"5\").propertyMap().select(Column.values)", + _g.V("5").PropertyMap<object>().Select<object>(Column.Values).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_3_Values_runways_Math() + { + Assert.Equal("g.V(\"3\").values(\"runways\").math(\"_ + 1\")", + _g.V("3").Values<object>("runways").Math("_ + 1").GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_3_Emit_Repeat_Out_SimplePath_Times_3_Limit_5_Path() + { + Assert.Equal("g.V(\"3\").emit().repeat(__.out().simplePath()).times(3).limit(5L).path()", + _g.V("3").Emit().Repeat(__.Out().SimplePath()).Times(3).Limit<object>(5).Path().GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Match_As_a_Has_code_LHR_As_b_Select_b_By_code() + { + Assert.Equal("g.V().match(__.as(\"a\").has(\"code\",\"LHR\").as(\"b\")).select(\"b\").by(\"code\")", + _g.V().Match<object>(__.As("a").Has("code", "LHR").As("b")).Select<object>("b").By("code").GremlinLang.GetGremlin()); + } + + // --- Core Traversal Tests 31-60 --- + + [Fact] + public void g_V_Has_keyword_property_repeat() + { + Assert.Equal("g.V().has(\"test-using-keyword-as-property\",\"repeat\")", + _g.V().Has("test-using-keyword-as-property", "repeat").GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_1_AddE_test_To_V_4() + { + Assert.Equal("g.V(\"1\").addE(\"test\").to(__.V(\"4\"))", + _g.V("1").AddE("test").To(__.V("4")).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Values_runways_Max() + { + Assert.Equal("g.V().values(\"runways\").max()", + _g.V().Values<object>("runways").Max<object>().GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Values_runways_Min() + { + Assert.Equal("g.V().values(\"runways\").min()", + _g.V().Values<object>("runways").Min<object>().GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Values_runways_Sum() + { + Assert.Equal("g.V().values(\"runways\").sum()", + _g.V().Values<object>("runways").Sum<object>().GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Values_runways_Mean() + { + Assert.Equal("g.V().values(\"runways\").mean()", + _g.V().Values<object>("runways").Mean<object>().GremlinLang.GetGremlin()); + } + + [Fact] + public void g_WithSack_0_V_35_Sack_Operator_Sum_By_runways_Sack() + { + Assert.Equal("g.withSack(0).V(\"3\",\"5\").sack(Operator.sum).by(\"runways\").sack()", + _g.WithSack(0).V("3", "5").Sack(Operator.Sum).By("runways").Sack<object>().GremlinLang.GetGremlin()); + } + + [Fact] + public void g_Inject_3_4_5() + { + Assert.Equal("g.inject(3,4,5)", _g.Inject(3, 4, 5).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_Inject_List_3_4_5() + { + Assert.Equal("g.inject([3,4,5])", + _g.Inject(new List<object> { 3, 4, 5 }).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_Inject_3_4_5_Count() + { + Assert.Equal("g.inject(3,4,5).count()", _g.Inject(3, 4, 5).Count().GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Has_runways_Gt_5_Count() + { + Assert.Equal("g.V().has(\"runways\",gt(5)).count()", + _g.V().Has("runways", P.Gt(5)).Count().GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Has_runways_Lte_5_3_Count() + { + Assert.Equal("g.V().has(\"runways\",lte(5.3D)).count()", + _g.V().Has("runways", P.Lte(5.3)).Count().GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Has_code_Within_123_124() + { + Assert.Equal("g.V().has(\"code\",within([123,124]))", + _g.V().Has("code", P.Within(123, 124)).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Has_code_Within_123_abc() + { + Assert.Equal("g.V().has(\"code\",within([123,\"abc\"]))", + _g.V().Has("code", P.Within(123, "abc")).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Has_code_Within_abc_123() + { + Assert.Equal("g.V().has(\"code\",within([\"abc\",123]))", + _g.V().Has("code", P.Within("abc", 123)).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Has_code_Within_abc_xyz() + { + Assert.Equal("g.V().has(\"code\",within([\"abc\",\"xyz\"]))", + _g.V().Has("code", P.Within("abc", "xyz")).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_12_Has_region_Within_USTX_USGA() + { + Assert.Equal("g.V(\"1\",\"2\").has(\"region\",within([\"US-TX\",\"US-GA\"]))", + _g.V("1", "2").Has("region", P.Within("US-TX", "US-GA")).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_And_Has_runways_Gt_5_Has_region_USTX() + { + Assert.Equal("g.V().and(__.has(\"runways\",gt(5)),__.has(\"region\",\"US-TX\"))", + _g.V().And(__.Has("runways", P.Gt(5)), __.Has("region", "US-TX")).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_Union_Has_runways_Gt_5_Has_region_USTX() + { + Assert.Equal("g.V().union(__.has(\"runways\",gt(5)),__.has(\"region\",\"US-TX\"))", + _g.V().Union<object>(__.Has("runways", P.Gt(5)), __.Has("region", "US-TX")).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_3_Choose_Values_runways_Is_3_Constant_three_Constant_not_three() + { + Assert.Equal("g.V(\"3\").choose(__.values(\"runways\").is(3),__.constant(\"three\"),__.constant(\"not three\"))", + _g.V("3").Choose<object>(__.Values<object>("runways").Is(3), __.Constant("three"), __.Constant("not three")).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_3_Choose_Values_runways_Option_1_Option_2() + { + Assert.Equal("g.V(\"3\").choose(__.values(\"runways\")).option(1,__.constant(\"three\")).option(2,__.constant(\"not three\"))", + _g.V("3").Choose<object>(__.Values<object>("runways")).Option(1, __.Constant("three")).Option(2, __.Constant("not three")).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_3_Choose_Values_runways_Option_1_5_Option_2() + { + Assert.Equal("g.V(\"3\").choose(__.values(\"runways\")).option(1.5D,__.constant(\"one and a half\")).option(2,__.constant(\"not three\"))", + _g.V("3").Choose<object>(__.Values<object>("runways")).Option(1.5, __.Constant("one and a half")).Option(2, __.Constant("not three")).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_3_Repeat_Out_SimplePath_Until_Loops_Is_1_Count() + { + Assert.Equal("g.V(\"3\").repeat(__.out().simplePath()).until(__.loops().is(1)).count()", + _g.V("3").Repeat(__.Out().SimplePath()).Until(__.Loops().Is(1)).Count().GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_HasLabel_airport_Limit_20_Group_By_region_By_code_Order_Local_By_Keys() + { + Assert.Equal("g.V().hasLabel(\"airport\").limit(20L).group().by(\"region\").by(\"code\").order(Scope.local).by(Column.keys)", + _g.V().HasLabel("airport").Limit<object>(20).Group<object, object>().By("region").By("code").Order(Scope.Local).By(Column.Keys).GremlinLang.GetGremlin()); + } + + [Fact] + public void g_V_1_As_a_V_2_As_a_Select_Pop_All_a() + { + Assert.Equal("g.V(\"1\").as(\"a\").V(\"2\").as(\"a\").select(Pop.all,\"a\")", + _g.V("1").As("a").V("2").As("a").Select<object>(Pop.All, "a").GremlinLang.GetGremlin()); + } + + [Fact] + public void g_AddV_test_Property_Cardinality_Set_p1_10() + { + Assert.Equal("g.addV(\"test\").property(Cardinality.set,\"p1\",10)", + _g.AddV("test").Property(Cardinality.Set, "p1", 10).GremlinLang.GetGremlin()); Review Comment: Could you add some more complex cases for Cardinality in property such as ``` g.V(1).property(list, ['age': single(36), 'city': 'wilmington', 'state': 'delaware']) ``` Sourced from reference docs: https://tinkerpop.apache.org/docs/current/reference/#property-step -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
