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 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 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""
}");
        }
Beispiel #6
0
        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());
        }