コード例 #1
0
        public static string ConvertToIndex(string outputVar, int i)
        {
            var output = EvaluationFunctions.parseLanguageExpression(outputVar, 0, ShouldTypeCast.Yes);

            if (output.IsRecordSetExpression && output is LanguageAST.LanguageExpression.RecordSetExpression recSetExpr)
            {
                var outputidentifier = recSetExpr.Item;
                if (Equals(outputidentifier?.Index, LanguageAST.Index.Star))
                {
                    return($"[[{outputidentifier?.Name}({i}).{outputidentifier?.Column}]]");
                }
            }

            return(outputVar);
        }
コード例 #2
0
        public void ParseLanguage_RecsetIndexExpression()
        {
            //------------Setup for test--------------------------
            var data = CreateEnvironmentWithData();

            //------------Execute Test---------------------------
            var x = EvaluationFunctions.parseLanguageExpression("[[rec([[a]])]]", 1);

            //------------Assert Results-------------------------
            Assert.AreEqual(x.IsRecordSetNameExpression, true);
            var rec = x as LanguageAST.LanguageExpression.RecordSetNameExpression;

            // ReSharper disable once PossibleNullReferenceException
            Assert.IsTrue(rec.Item.Index.IsIndexExpression);
        }
コード例 #3
0
ファイル: TestUpdate.cs プロジェクト: Warewolf-ESB/Warewolf
        public void UpdateInPlace_Update_ApplyLambda_ExpectError_Complex()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();

            //------------Execute Test---------------------------

            var updated = PublicFunctions.EvalUpdate("[[s]]", env, 0, a => DataStorage.WarewolfAtom.NewDataString("[[s]]"));

            updated = PublicFunctions.EvalUpdate("[[[[s]]]]", updated, 0, a => DataStorage.WarewolfAtom.NewDataString("e"));
            //------------Assert Results-------------------------
            var res = CommonFunctions.evalResultToString(EvaluationFunctions.eval(updated, 0, false, "[[s]]"));

            Assert.AreEqual(res, "e");
        }
コード例 #4
0
        public void BuildJObjectArrayIndexMapHelper_Build_GivenObjectWithChildThatHasListOfStrings_SelectNonExistentItem_ExpectNoIndexMap()
        {
            var env = new ExecutionEnvironment();

            env.AssignJson(new AssignValue("[[@ob]]", "{\"addresses\":[],\"user\":{\"name\":\"bob\", \"friends\":[{\"name\":\"joe\"},{\"name\":\"jef\"}]}}"), 0);

            var test = new BuildJObjectArrayIndexMapHelper(env);

            const string exp = "[[@ob.user.addresses(*).name]]";

            var parsedExpression = EvaluationFunctions.parseLanguageExpressionWithoutUpdate(exp, ShouldTypeCast.Yes) as LanguageAST.LanguageExpression.JsonIdentifierExpression;

            var indexMap = test.Build(parsedExpression.Item, exp);

            Assert.AreEqual(0, indexMap.Count);
        }
コード例 #5
0
        public static string GetPositionColumnExpression(string recordset)
        {
            var rec = EvaluationFunctions.parseLanguageExpression(recordset, 0);

            if (!rec.IsRecordSetExpression && !rec.IsRecordSetNameExpression)
            {
                return(recordset);
            }

            var recordSetExpression     = rec as LanguageAST.LanguageExpression.RecordSetExpression;
            var recordSetNameExpression = rec as LanguageAST.LanguageExpression.RecordSetNameExpression;

            var index = recordSetExpression?.Item?.Name ?? recordSetNameExpression?.Item?.Name;

            return($"[[{index}(*).{EvaluationFunctions.PositionColumn}]]");
        }
コード例 #6
0
        public void AssignEvaluation_assignGivenAnArrayValueCreatesValidJson_LastIndex_MutateArray()
        {
            var    env = CreateTestEnvWithData();
            JArray x   = new JArray();

            var result       = PublicFunctions.EvalEnvExpression("[[rec(1).a]]", 0, false, env);
            var secondResult = PublicFunctions.EvalEnvExpression("[[rec(2).a]]", 0, false, env);
            var parsed       = EvaluationFunctions.parseLanguageExpressionWithoutUpdate("[[@Person.Child().Name]]");

            var val = (LanguageAST.LanguageExpression.JsonIdentifierExpression)parsed;
            // ReSharper disable once RedundantAssignment
            var env2 = AssignEvaluation.assignGivenAValue(env, result, val.Item);

            env2 = AssignEvaluation.assignGivenAValue(env2, secondResult, val.Item);
            Assert.IsTrue(env2.JsonObjects.ContainsKey("Person"));
            Assert.AreEqual(env2.JsonObjects["Person"].ToString(), "{\r\n  \"Child\": [\r\n    {\r\n      \"Name\": \"2\"\r\n    },\r\n    {\r\n      \"Name\": \"4\"\r\n    }\r\n  ]\r\n}");
        }
コード例 #7
0
        public void BuildJObjectArrayIndexMapHelper_Build_GivenObjectWithListOfStrings_ExpectIndexForEachArrayItem()
        {
            var env = new ExecutionEnvironment();

            env.AssignJson(new AssignValue("[[@ob]]", "{\"addresses\":[],\"users\":[{\"name\":\"bob\"},{\"name\":\"joe\"},{\"name\":\"jef\"}],\"tags\":[]}"), 0);

            var          test = new BuildJObjectArrayIndexMapHelper(env);
            const string exp  = "[[@ob.users(*).name]]";

            var parsedExpression = EvaluationFunctions.parseLanguageExpressionWithoutUpdate(exp, ShouldTypeCast.Yes) as LanguageAST.LanguageExpression.JsonIdentifierExpression;

            var indexMap = test.Build(parsedExpression.Item, exp);

            Assert.AreEqual(3, indexMap.Count);
            Assert.AreEqual("[[@ob.users(1).name]]", indexMap[0]);
            Assert.AreEqual("[[@ob.users(2).name]]", indexMap[1]);
            Assert.AreEqual("[[@ob.users(3).name]]", indexMap[2]);
        }
コード例 #8
0
        public void GivenContainer_ExecutionEnvironmentBuildIndexMap_ShouldBuildMapForChildObj()
        {
            Assert.IsNotNull(_environment);
            _environment.AssignJson(new AssignValue(ChildNameExpression, "Sanele"), 0);
            var privateObj = new PrivateObject(_environment);
            var var        = EvaluationFunctions.parseLanguageExpressionWithoutUpdate(ChildNameExpression);
            var jsonIdentifierExpression = var as LanguageAST.LanguageExpression.JsonIdentifierExpression;
            var obj = new JArray(ChildNameExpression);

            if (jsonIdentifierExpression == null)
            {
                return;
            }
            var mapItems = new List <string>();

            object[] args = { jsonIdentifierExpression.Item, "", mapItems, obj };
            privateObj.Invoke("BuildIndexMap", args);
        }
コード例 #9
0
 public static bool IsValidVariableExpression(string expression, out string errorMessage, int update)
 {
     errorMessage = string.Empty;
     try
     {
         var x = EvaluationFunctions.parseLanguageExpression(expression, update, ShouldTypeCast.Yes);
         if (x.IsRecordSetExpression || x.IsScalarExpression || x.IsJsonIdentifierExpression ||
             x.IsRecordSetNameExpression)
         {
             return(true);
         }
     }
     catch (Exception e)
     {
         errorMessage = e.Message;
         return(false);
     }
     return(false);
 }
コード例 #10
0
        public void AssignEvaluation_LanguageExpressionToJsonExpression()
        {
            var parsed = EvaluationFunctions.parseLanguageExpressionWithoutUpdate("[[Child(1).Name]]");
            var exp    = AssignEvaluation.languageExpressionToJsonIdentifier(parsed);

            Assert.IsTrue(exp.IsIndexNestedNameExpression);
            var exp2  = (exp as LanguageAST.JsonIdentifierExpression.IndexNestedNameExpression).Item;
            var index = exp2.Index;

            Assert.IsTrue(index.IsIntIndex);
            var bob = (index as LanguageAST.Index.IntIndex).Item;

            Assert.AreEqual(1, bob);
            Assert.AreEqual("Child", exp2.ObjectName);
            Assert.IsTrue(exp2.Next.IsNameExpression);
            var x2 = (exp2.Next as LanguageAST.JsonIdentifierExpression.NameExpression).Item;

            Assert.AreEqual(x2.Name, "Name");
        }
コード例 #11
0
ファイル: TestEvaluation.cs プロジェクト: malotho-zz/Warewolf
        public void CreateJSONAndEvalPartialObject()
        {
            //------------Setup for test--------------------------
            var createDataSet = WarewolfTestData.CreateTestEnvWithData;
            var j             = JObject.FromObject(new Person()
            {
                Name = "n", Children = new List <Person>()
            });
            var added = WarewolfDataEvaluationCommon.addToJsonObjects(createDataSet, "bob", j);

            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
            Assert.IsTrue(added.JsonObjects.ContainsKey("bob"));
            Assert.AreEqual((added.JsonObjects["bob"] as JObject).GetValue("Name").ToString(), "n");
            var evalled = CommonFunctions.evalResultToString(EvaluationFunctions.eval(added, 0, false, "[[@bob.Name]]"));

            Assert.AreEqual(evalled, "n");
        }
コード例 #12
0
 static void MockConstructorExecution(IDSFDataObject dataObject, IServiceTestStep serviceTestStep, ref PluginExecutionDto pluginExecutionDto)
 {
     if (!string.IsNullOrEmpty(serviceTestStep.StepOutputs?[0].Variable))
     {
         try
         {
             var languageExpression = EvaluationFunctions.parseLanguageExpression(serviceTestStep.StepOutputs?[0].Variable, 0);
             if (languageExpression.IsJsonIdentifierExpression)
             {
                 var jToken = JToken.Parse(serviceTestStep.StepOutputs?[0].Value) as JContainer ?? serviceTestStep.StepOutputs?[0].Value.DeserializeToObject();
                 dataObject.Environment.AddToJsonObjects(serviceTestStep.StepOutputs[0].Variable, jToken);
                 pluginExecutionDto.ObjectString = serviceTestStep.StepOutputs[0].Value;
             }
         }
         catch (Exception e)
         {
             dataObject.Environment.Errors.Add(e.Message);
         }
     }
 }
コード例 #13
0
        public void Distinct_EvalDistinct_HappyPath_Last_ExpectDistinctResults()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();

            //------------Execute Test---------------------------
            var modified = Distinct.evalDistinct(env, new List <string>()
            {
                "[[Rec(*).a]]"
            }, new List <string> {
                "[[Rec(*).a]]"
            }, 0, new List <string> {
                "[[Bec().a]]"
            });

            //------------Assert Results-------------------------
            var res = CommonFunctions.evalResultToString(EvaluationFunctions.eval(modified, 0, false, "[[Bec(*).a]]"));

            Assert.AreEqual(res, "1,2,3");
        }
コード例 #14
0
        public string ToStar(string expression)
        {
            var exp = EvaluationFunctions.parseLanguageExpression(expression, 0, ShouldTypeCast.Yes);

            if (exp.IsRecordSetExpression && exp is LanguageAST.LanguageExpression.RecordSetExpression rec)
            {
                return($"[[{rec.Item.Name}(*).{rec.Item.Column}]]");
            }

            if (exp.IsRecordSetNameExpression && exp is LanguageAST.LanguageExpression.RecordSetNameExpression recNameExp)
            {
                return($"[[{recNameExp.Item.Name}(*)]]");
            }

            if (exp.IsJsonIdentifierExpression)
            {
                var replace = expression.Replace(@"()", @"(*)");
                return(replace);
            }
            return(expression);
        }
コード例 #15
0
        public static string GetPositionColumnExpression(string recordset)
        {
            var rec = EvaluationFunctions.parseLanguageExpression(recordset, 0, ShouldTypeCast.Yes);

            if (!rec.IsRecordSetExpression && !rec.IsRecordSetNameExpression)
            {
                return(recordset);
            }

            if (rec is LanguageAST.LanguageExpression.RecordSetExpression recordSetExpression)
            {
                var index = recordSetExpression.Item?.Name;
                return($"[[{index}(*).{EvaluationFunctions.PositionColumn}]]");
            }
            if (rec is LanguageAST.LanguageExpression.RecordSetNameExpression recordSetNameExpression)
            {
                var index = recordSetNameExpression.Item?.Name;
                return($"[[{index}(*).{EvaluationFunctions.PositionColumn}]]");
            }
            // This is a fail safe
            throw new Exception("Unhandled Recordset LanguageExpression");
        }
コード例 #16
0
ファイル: TestEvaluation.cs プロジェクト: malotho-zz/Warewolf
        public void CreateJSONAndEvalEntireObject()
        {
            //------------Setup for test--------------------------
            var createDataSet = WarewolfTestData.CreateTestEnvWithData;
            var j             = JObject.FromObject(new Person()
            {
                Name = "n", Children = new List <Person>()
            });
            var added = WarewolfDataEvaluationCommon.addToJsonObjects(createDataSet, "bob", j);

            //------------Execute Test---------------------------

            //------------Assert Results-------------------------
            Assert.IsTrue(added.JsonObjects.ContainsKey("bob"));
            Assert.AreEqual((added.JsonObjects["bob"] as JObject).GetValue("Name").ToString(), "n");
            var evalled = EvaluationFunctions.eval(added, 0, false, "[[@bob]]");

            Assert.IsTrue(evalled.IsWarewolfAtomResult);
            var res = (evalled as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult).Item;
            var str = (res as DataStorage.WarewolfAtom.DataString).ToString();

            Assert.AreEqual(str, j.ToString());
        }
コード例 #17
0
        public JContainer EvalJContainer(string exp)
        {
            if (string.IsNullOrEmpty(exp))
            {
                return(null);
            }

            var parsedExpression = EvaluationFunctions.parseLanguageExpressionWithoutUpdate(exp, ShouldTypeCast.Yes);

            if (parsedExpression.IsJsonIdentifierExpression && parsedExpression is LanguageAST.LanguageExpression.JsonIdentifierExpression jsonIdentifierExpression)
            {
                if (jsonIdentifierExpression.Item is LanguageAST.JsonIdentifierExpression.NameExpression nameExpression)
                {
                    return(_env.JsonObjects[nameExpression.Item.Name]);
                }
                if (jsonIdentifierExpression.Item is LanguageAST.JsonIdentifierExpression.IndexNestedNameExpression arrayExpression)
                {
                    return(_env.JsonObjects[arrayExpression.Item.ObjectName]);
                }
            }
            // BUG: if any other types are added to JsonIdentifierExpression this method will no longer be correct.
            return(null);
        }
コード例 #18
0
 public string EvalToExpression(string exp, int update) => string.IsNullOrEmpty(exp) ? string.Empty : EvaluationFunctions.evalToExpression(_env, update, exp);
コード例 #19
0
 public static LanguageAST.LanguageExpression ParseLanguageExpressionWithoutUpdate(string expression)
 {
     return(EvaluationFunctions.parseLanguageExpressionWithoutUpdate(expression));
 }
コード例 #20
0
 public static LanguageAST.LanguageExpression ParseLanguageExpression(string sourceName, int update)
 {
     return(EvaluationFunctions.parseLanguageExpression(sourceName, update));
 }
コード例 #21
0
 public static string LanguageExpressionToString(LanguageAST.LanguageExpression exp)
 {
     return(EvaluationFunctions.languageExpressionToString(exp));
 }
コード例 #22
0
 public void AssignEvaluation_LanguageExpressionToJsonExpression_Complex()
 {
     var parsed = EvaluationFunctions.parseLanguageExpressionWithoutUpdate("[[[[bob]]]]");
     var exp    = AssignEvaluation.languageExpressionToJsonIdentifier(parsed);
 }
コード例 #23
0
 public static LanguageAST.LanguageExpression ParseLanguageExpression(string sourceName, int update) => EvaluationFunctions.parseLanguageExpression(sourceName, update, ShouldTypeCast.Yes);
コード例 #24
0
 public static string LanguageExpressionToString(LanguageAST.LanguageExpression exp) => EvaluationFunctions.languageExpressionToString(exp);
コード例 #25
0
 public static LanguageAST.LanguageExpression ParseLanguageExpressionWithoutUpdate(string expression) => EvaluationFunctions.parseLanguageExpressionWithoutUpdate(expression, ShouldTypeCast.Yes);
コード例 #26
0
 public void CommonFunctions_EvalResultToJsonCompatableJson()
 {
     var env = CreateEnvironmentWithData();
     var a   = CommonFunctions.evalResultToJsonCompatibleObject(EvaluationFunctions.eval(env, 0, false, "[[Rec(*)]]"));
 }
コード例 #27
0
        public void Eval_RecSet_AsStringind()
        {
            //------------Setup for test--------------------------
            var env = CreateEnvironmentWithData();



            //------------Execute Test---------------------------
            var res = EvaluationFunctions.evalRecordSetAsString(env, ((LanguageAST.LanguageExpression.RecordSetExpression)EvaluationFunctions.parseLanguageExpressionWithoutUpdate("[[Rec(1).a]]")).Item);

            //------------Assert Results-------------------------
            Assert.AreEqual(CommonFunctions.atomtoString(res), "1");
        }