public CommonFunctions.WarewolfEvalResult Eval(string exp, int update, bool throwsifnotexists, bool shouldEscape) { try { return(PublicFunctions.EvalEnvExpression(exp, update, shouldEscape, _env)); } catch (IndexOutOfRangeException) { throw; } catch (Exception e) { if (throwsifnotexists) { if (e is NullValueInVariableException variableException && e.Message.Contains("variable not found")) { throw new WarewolfExecutionEnvironmentException("variable { " + DataListUtilBase.StripLeadingAndTrailingBracketsFromValue(variableException.VariableName) + " } not found"); } if (e is IndexOutOfRangeException || e.Message.Contains(@"index was not an int")) { throw; } throw new WarewolfExecutionEnvironmentException(e.Message + "{ " + DataListUtilBase.StripLeadingAndTrailingBracketsFromValue(exp) + " }"); } return(CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(DataStorage.WarewolfAtom.Nothing)); } }
public WarewolfDataEvaluationCommon.WarewolfEvalResult EvalForJson(string exp) { if (string.IsNullOrEmpty(exp)) { return(WarewolfDataEvaluationCommon.WarewolfEvalResult.NewWarewolfAtomResult(DataASTMutable.WarewolfAtom.Nothing)); } try { return(PublicFunctions.EvalEnvExpression(exp, 0, _env)); } catch (IndexOutOfRangeException) { throw; } catch (Exception e) { if (e is IndexOutOfRangeException) { throw; } if (IsRecordsetIdentifier(exp)) { var res = new WarewolfAtomList <DataASTMutable.WarewolfAtom>(DataASTMutable.WarewolfAtom.Nothing); res.AddNothing(); return(WarewolfDataEvaluationCommon.WarewolfEvalResult.NewWarewolfAtomListresult(res)); } return(WarewolfDataEvaluationCommon.WarewolfEvalResult.NewWarewolfAtomResult(DataASTMutable.WarewolfAtom.Nothing)); } }
public CommonFunctions.WarewolfEvalResult Eval(string exp, int update, bool throwsifnotexists, bool shouldEscape) { try { return(PublicFunctions.EvalEnvExpression(exp, update, shouldEscape, _env)); } catch (IndexOutOfRangeException) { throw; } catch (Exception e) { if (throwsifnotexists && e is NullValueInVariableException && e.Message.Contains("variable not found")) { throw new Exception(string.Format("variable {0} not found", (e as NullValueInVariableException).VariableName)); } if (throwsifnotexists || e is IndexOutOfRangeException || e.Message.Contains(@"index was not an int")) { throw; } return(CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(DataStorage.WarewolfAtom.Nothing)); } }
public void AssignEvaluation_assignGivenAnArrayValueCreatesValidJson_StarIndex_MutateArray_AndAddAProperty() { 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 thirdResult = PublicFunctions.EvalEnvExpression("[[rec(3).a]]", 0, false, env); var parsed = EvaluationFunctions.parseLanguageExpressionWithoutUpdate("[[@Person.Child().Name]]"); var parsed2 = EvaluationFunctions.parseLanguageExpressionWithoutUpdate("[[@Person.Child(*).Name]]"); var parsed3 = EvaluationFunctions.parseLanguageExpressionWithoutUpdate("[[@Person.Age]]"); var val = (LanguageAST.LanguageExpression.JsonIdentifierExpression)parsed; var val2 = (LanguageAST.LanguageExpression.JsonIdentifierExpression)parsed2; var val3 = (LanguageAST.LanguageExpression.JsonIdentifierExpression)parsed3; // ReSharper disable once RedundantAssignment var env2 = AssignEvaluation.assignGivenAValue(env, result, val.Item); env2 = AssignEvaluation.assignGivenAValue(env2, secondResult, val.Item); env2 = AssignEvaluation.assignGivenAValue(env2, thirdResult, val2.Item); env2 = AssignEvaluation.assignGivenAValue(env2, result, val3.Item); Assert.IsTrue(env2.JsonObjects.ContainsKey("Person")); var obj = env2.JsonObjects["Person"]; Assert.AreEqual(obj.ToString(), "{\r\n \"Child\": [\r\n {\r\n \"Name\": \"Bob\"\r\n },\r\n {\r\n \"Name\": \"Bob\"\r\n }\r\n ],\r\n \"Age\": \"2\"\r\n}"); }
public CommonFunctions.WarewolfEvalResult EvalForJson(string exp, bool shouldEscape) { if (string.IsNullOrEmpty(exp)) { return(CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(DataStorage.WarewolfAtom.Nothing)); } try { return(PublicFunctions.EvalEnvExpression(exp, 0, shouldEscape, _env)); } catch (IndexOutOfRangeException) { throw; } catch (Exception) { if (!IsRecordsetIdentifier(exp)) { return(CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(DataStorage.WarewolfAtom.Nothing)); } var res = new WarewolfAtomList <DataStorage.WarewolfAtom>(DataStorage.WarewolfAtom.Nothing); res.AddNothing(); return(CommonFunctions.WarewolfEvalResult.NewWarewolfAtomListresult(res)); } }
public void ExecutionEnvironmentSortRecordSet_ShouldSortRecordSets() { Assert.IsNotNull(_environment); _environment.Assign("[[rec().a]]", "sanele", 0); var evalMultiAssign = EvalMultiAssign(); PublicFunctions.EvalEnvExpression("[[rec(*).a]]", 0, false, evalMultiAssign); _environment.SortRecordSet("[[rec().a]]", true, 0); }
public void AssignEvaluation_FailsIfExpressionIsNotOfCorrectType() { var env = CreateTestEnvWithData(); var result = PublicFunctions.EvalEnvExpression("[[rec(1).a]]", 0, false, env); var val = LanguageAST.JsonIdentifierExpression.Terminal; AssignEvaluation.assignGivenAValue(env, result, val); }
public void GivenRecSet_ExecutionEnvironmentEvalAssignFromNestedLast_Should() { Assert.IsNotNull(_environment); var evalMultiAssign = EvalMultiAssign(); var items = PublicFunctions.EvalEnvExpression("[[rec(*).a]]", 0, false, evalMultiAssign); var warewolfAtomListresult = items as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult; _environment.EvalAssignFromNestedLast("[[rec(*).a]]", warewolfAtomListresult, 0); }
public void ExecutionEnvironmentAssignFromNestedNumeric_Should() { Assert.IsNotNull(_environment); _environment.Assign("[[rec().a]]", "sanele", 0); var evalMultiAssign = EvalMultiAssign(); var items = PublicFunctions.EvalEnvExpression("[[rec(*).a]]", 0, false, evalMultiAssign); var warewolfAtomListresult = items as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult; _environment.EvalAssignFromNestedNumeric("[[rec().a]]", warewolfAtomListresult, 0); }
public void AssignEvaluation_assignGivenAValue_addsObjectIfItDoesNotExist() { var env = CreateTestEnvWithData(); var result = PublicFunctions.EvalEnvExpression("[[a]]", 0, false, env); var env2 = AssignEvaluation.assignGivenAValue(env, result, LanguageAST.JsonIdentifierExpression.NewNestedNameExpression(new LanguageAST.JsonPropertyIdentifier("Person", LanguageAST.JsonIdentifierExpression.NewNameExpression(new LanguageAST.JsonIdentifier("Person"))))); Assert.IsTrue(env2.JsonObjects.ContainsKey("Person")); }
public void AssignEvaluation_assignGivenAnArrayValueCreatesValidJson_Invalid() { var env = CreateTestEnvWithData(); JArray x = new JArray(); var result = PublicFunctions.EvalEnvExpression("[[rec(1).a]]", 0, false, env); var parsed = EvaluationFunctions.parseLanguageExpressionWithoutUpdate("[[@Person.Child(1).Name]]"); var val = (LanguageAST.LanguageExpression.JsonIdentifierExpression)parsed; var env2 = AssignEvaluation.assignGivenAValue(env, result, 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}"); }
public void AssignEvaluation_assignGivenAValueCreatesValidJson_addsObjectIfItDoesNotExist() { var env = CreateTestEnvWithData(); var result = PublicFunctions.EvalEnvExpression("[[a]]", 0, false, env); var env2 = AssignEvaluation.assignGivenAValue(env, result, LanguageAST.JsonIdentifierExpression.NewNestedNameExpression(new LanguageAST.JsonPropertyIdentifier("Bob", LanguageAST.JsonIdentifierExpression.NewNameExpression(new LanguageAST.JsonIdentifier("Age"))))); Assert.IsTrue(env2.JsonObjects.ContainsKey("Bob")); Assert.AreEqual(env2.JsonObjects["Bob"].ToString(), @"{ ""Age"": ""5"" }"); }
public void AssignEvaluation_assignObject_ArrayJson_Last_TwoObjects() { var env = CreateTestEnvWithData(); var env2 = AssignEvaluation.evalJsonAssign(new AssignValue("[[Person()]]", "{\"Name\":\"a\"}"), 0, env); var env3 = AssignEvaluation.evalJsonAssign(new AssignValue("[[Person()]]", "{\"Name\":\"h\"}"), 0, env2); Assert.IsTrue(env2.JsonObjects.ContainsKey("Person")); var nameValue = PublicFunctions.EvalEnvExpression("[[@Person().Name]]", 0, false, env3); Assert.IsNotNull(nameValue); var warewolfAtomResult = nameValue as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult; Assert.IsNotNull(warewolfAtomResult); Assert.AreEqual("h", warewolfAtomResult.Item.ToString()); }
public void GivenRecSet_ExecutionEnvironmentEvalAssignFromNestedLast_TwoColumn_Should() { Assert.IsNotNull(_environment); var evalMultiAssign = EvalMultiAssignTwoColumn(); var items = PublicFunctions.EvalEnvExpression("[[rec(*).a]]", 0, false, evalMultiAssign); var warewolfAtomListresult = items as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult; _environment.EvalAssignFromNestedLast("[[rec().a]]", warewolfAtomListresult, 0); items = PublicFunctions.EvalEnvExpression("[[rec(*).b]]", 0, false, evalMultiAssign); warewolfAtomListresult = items as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult; _environment.EvalAssignFromNestedLast("[[rec().b]]", warewolfAtomListresult, 0); items = PublicFunctions.EvalEnvExpression("[[rec(*).c]]", 0, false, evalMultiAssign); warewolfAtomListresult = items as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult; _environment.EvalAssignFromNestedLast("[[rec().c]]", warewolfAtomListresult, 0); evalMultiAssign = EvalMultiAssignTwoColumn(); items = PublicFunctions.EvalEnvExpression("[[rec(*).a]]", 0, false, evalMultiAssign); warewolfAtomListresult = items as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult; _environment.EvalAssignFromNestedLast("[[rec().a]]", warewolfAtomListresult, 0); items = PublicFunctions.EvalEnvExpression("[[rec(*).b]]", 0, false, evalMultiAssign); warewolfAtomListresult = items as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult; _environment.EvalAssignFromNestedLast("[[rec().b]]", warewolfAtomListresult, 0); items = PublicFunctions.EvalEnvExpression("[[rec(*).c]]", 0, false, evalMultiAssign); warewolfAtomListresult = items as CommonFunctions.WarewolfEvalResult.WarewolfAtomListresult; _environment.EvalAssignFromNestedLast("[[rec().c]]", warewolfAtomListresult, 0); var list_a = _environment.EvalAsListOfStrings("[[rec(*).a]]", 0); var list_b = _environment.EvalAsListOfStrings("[[rec(*).b]]", 0); var list_c = _environment.EvalAsListOfStrings("[[rec(*).c]]", 0); Assert.AreEqual(list_a.Count, 4); Assert.AreEqual(list_b.Count, 4); Assert.AreEqual(list_c.Count, 4); Assert.IsTrue(list_a[0].Equals("a11")); Assert.IsTrue(list_a[1].Equals("ayy")); Assert.IsTrue(list_a[2].Equals("a11")); Assert.IsTrue(list_a[3].Equals("ayy")); Assert.IsTrue(list_b[0].Equals("")); Assert.IsTrue(list_b[1].Equals("b33")); Assert.IsTrue(list_b[2].Equals("")); Assert.IsTrue(list_b[3].Equals("b33")); Assert.IsTrue(list_c[0].Equals("c22")); Assert.IsTrue(list_c[1].Equals("czz")); Assert.IsTrue(list_c[2].Equals("c22")); Assert.IsTrue(list_c[3].Equals("czz")); }
public void AssignEvaluation_assignGivenAnArrayValueCreatesValidJson_LastIndex_MutateArray_differentProperties() { var env = CreateTestEnvWithData(); var 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 parsed2 = EvaluationFunctions.parseLanguageExpressionWithoutUpdate("[[@Person.Child().Age]]"); var val = (LanguageAST.LanguageExpression.JsonIdentifierExpression)parsed; var val2 = (LanguageAST.LanguageExpression.JsonIdentifierExpression)parsed2; var env2 = AssignEvaluation.assignGivenAValue(env, result, val.Item); env2 = AssignEvaluation.assignGivenAValue(env2, secondResult, val2.Item); Assert.IsTrue(env2.JsonObjects.ContainsKey("Person")); Assert.AreEqual("{\r\n \"Child\": [\r\n {\r\n \"Name\": \"2\",\r\n \"Age\": \"4\"\r\n }\r\n ]\r\n}", env2.JsonObjects["Person"].ToString()); }
public void Assign_Given_Value_ContainsOpeningLanguageBracktes_Should_Assign_Value_Correclty_JsonObjects() { //------------Setup for test-------------------------- var emptyenv = CreateEmptyEnvironment(); var value = "na[[thi"; var exp = "[[@myValue().name]]"; //------------Execute Test--------------------------- var envTemp = PublicFunctions.EvalAssignWithFrameStrict(new AssignValue(exp, value), 1, emptyenv); //------------Assert Results------------------------- Assert.IsNotNull(envTemp.RecordSets); Assert.AreEqual(1, envTemp.RecordSets.Count); var a = PublicFunctions.EvalEnvExpression(exp, 0, false, envTemp); var valueFromEnv = ExecutionEnvironment.WarewolfEvalResultToString(a); Assert.AreEqual(value, valueFromEnv); }
public CommonFunctions.WarewolfEvalResult Eval(string exp, int update, bool throwsifnotexists = false, bool shouldEscape = false) { try { return(PublicFunctions.EvalEnvExpression(exp, update, shouldEscape, _env)); } catch (IndexOutOfRangeException) { throw; } catch (Exception e) { if (throwsifnotexists || e is IndexOutOfRangeException || e.Message.Contains(@"index was not an int")) { throw; } return(CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(DataStorage.WarewolfAtom.Nothing)); } }
public WarewolfDataEvaluationCommon.WarewolfEvalResult Eval(string exp, int update, bool throwsifnotexists = false) { try { return(PublicFunctions.EvalEnvExpression(exp, update, _env)); } catch (IndexOutOfRangeException) { throw; } catch (Exception e) { if (throwsifnotexists || e is IndexOutOfRangeException || e.Message.Contains("index was not an int")) { throw; } return(WarewolfDataEvaluationCommon.WarewolfEvalResult.NewWarewolfAtomResult(DataASTMutable.WarewolfAtom.Nothing)); } }
public WarewolfDataEvaluationCommon.WarewolfEvalResult Eval(string exp) { if (string.IsNullOrEmpty(exp)) { return(WarewolfDataEvaluationCommon.WarewolfEvalResult.NewWarewolfAtomResult(DataASTMutable.WarewolfAtom.Nothing)); } try { return(PublicFunctions.EvalEnvExpression(exp, _env)); } catch (IndexOutOfRangeException) { throw; } catch (Exception e) { if (e is IndexOutOfRangeException || e.Message.Contains("index was not an int")) { throw; } return(WarewolfDataEvaluationCommon.WarewolfEvalResult.NewWarewolfAtomResult(DataASTMutable.WarewolfAtom.Nothing)); } }
public void WarewolfIterator_SetupForWarewolfRecordSetResult_Should() { var listResult = CommonFunctions.WarewolfEvalResult.NewWarewolfAtomResult(DataStorage.WarewolfAtom.Nothing); var atomIterator = new WarewolfIterator(listResult); Assert.IsNotNull(atomIterator); var privateObj = new PrivateObject(atomIterator); var assigns = new List <IAssignValue> { new AssignValue("[[rec(25).a]]", "25"), new AssignValue("[[rec(27).b]]", "33"), new AssignValue("[[rec(29).b]]", "26") }; var testEnv = WarewolfTestData.CreateTestEnvEmpty(""); var testEnv3 = PublicFunctions.EvalMultiAssign(assigns, 0, testEnv); var res = PublicFunctions.EvalEnvExpression("[[rec(27)]]", 0, false, testEnv3); Assert.IsTrue(res.IsWarewolfRecordSetResult); object[] arg = { res }; privateObj.Invoke("SetupForWarewolfRecordSetResult", arg); var scalarRes = privateObj.GetField("_scalarResult") as CommonFunctions.WarewolfEvalResult.WarewolfAtomResult; Assert.IsNotNull(scalarRes); }