Пример #1
0
        public void Parse_MultipleVariablesWithMultipleMembers_ExpectedResult()
        {
            OPathParseResult parseResult = OPathParser.Parse(
                @"(listDictionary [ ""Key1"" ] [ 0 ] . Trim() . Length * 2)"
                + @" != "
                + @"(listDictionary[""Key2""][0].Trim().Length + listDictionary[""Key3""][0].Trim().Length)");

            Assert.AreEqual("($Var1 * 2) != ($Var2 + $Var3)", parseResult.GetXPath(), "parseResult.GetXPath()");
            Assert.AreEqual(3, parseResult.GetVariables().Length, "parseResult.GetVariables().Length");

            OPathVariable variable1 = GetVariable("Var1", parseResult.GetVariables());

            Assert.AreEqual(@"listDictionary[""Key1""][0].Trim().Length", variable1.GetReference(), "variable1.GetReference()");
            Assert.AreEqual(4, variable1.OPathParts.Length, "variable1.OPathParts.Length");

            OPathVariable variable2 = GetVariable("Var2", parseResult.GetVariables());

            Assert.AreEqual(@"listDictionary[""Key2""][0].Trim().Length", variable2.GetReference(), "variable3.GetReference()");
            Assert.AreEqual(4, variable1.OPathParts.Length, "variable2.OPathParts.Length");

            OPathVariable variable3 = GetVariable("Var3", parseResult.GetVariables());

            Assert.AreEqual(@"listDictionary[""Key3""][0].Trim().Length", variable3.GetReference(), "variable3.GetReference()");
            Assert.AreEqual(4, variable1.OPathParts.Length, "variable3.OPathParts.Length");
        }
Пример #2
0
        public void Parse_DuplicateVariables_ExpectedResult()
        {
            OPathParseResult parseResult = OPathParser.Parse("Variable1 = Variable1");

            Assert.AreEqual("$Var1 = $Var1", parseResult.GetXPath(), "parseResult.GetXPath()");
            Assert.AreEqual(1, parseResult.GetVariables().Length, "parseResult.GetVariables().Length");

            OPathVariable variable1 = GetVariable("Var1", parseResult.GetVariables());

            Assert.AreEqual("Variable1", variable1.GetReference(), "variable1.GetReference()");
            Assert.AreEqual(0, variable1.OPathParts.Length, "variable1.OPathParts.Length");
        }
Пример #3
0
        public void Parse_VariableWithStringKeyWithWhitespace_ExpectedResult()
        {
            OPathParseResult parseResult = OPathParser.Parse(@"Variable1[ ""Key"" ] = 1");

            Assert.AreEqual("$Var1 = 1", parseResult.GetXPath(), "parseResult.GetXPath()");
            Assert.AreEqual(1, parseResult.GetVariables().Length, "parseResult.GetVariables().Length");

            OPathVariable variable1 = GetVariable("Var1", parseResult.GetVariables());

            Assert.AreEqual(@"Variable1[""Key""]", variable1.GetReference(), "variable1.GetReference()");

            Assert.AreEqual(1, variable1.OPathParts.Length, "variable1.OPathParts.Length");
            AssertVariableStringKeyPart(variable1, 0, @"Key");
        }
Пример #4
0
        public void Parse_VariableWithEmptyMethodAtEnd_ExpectedResult()
        {
            OPathParseResult parseResult = OPathParser.Parse("1 = Variable1.Method()");

            Assert.AreEqual("1 = $Var1", parseResult.GetXPath(), "parseResult.GetXPath()");
            Assert.AreEqual(1, parseResult.GetVariables().Length, "parseResult.GetVariables().Length");

            OPathVariable variable1 = GetVariable("Var1", parseResult.GetVariables());

            Assert.AreEqual("Variable1.Method()", variable1.GetReference(), "variable1.GetReference()");

            Assert.AreEqual(1, variable1.OPathParts.Length, "variable1.OPathParts.Length");
            AssertVariableMethodPart(variable1, 0, "Method");
        }
Пример #5
0
        public void Parse_VariableWithPropertyAtEndWithWhitespace_ExpectedResult()
        {
            OPathParseResult parseResult = OPathParser.Parse("1 = Variable1.Property ");

            Assert.AreEqual("1 = $Var1", parseResult.GetXPath(), "parseResult.GetXPath()");
            Assert.AreEqual(1, parseResult.GetVariables().Length, "parseResult.GetVariables().Length");

            OPathVariable variable1 = GetVariable("Var1", parseResult.GetVariables());

            Assert.AreEqual("Variable1.Property", variable1.GetReference(), "variable1.GetReference()");

            Assert.AreEqual(1, variable1.OPathParts.Length, "variable1.OPathParts.Length");
            AssertVariablePropertyPart(variable1, 0, "Property");
        }
Пример #6
0
        public void Parse_VariableWithMultiplePropertiesWithWhitespace_ExpectedResult()
        {
            OPathParseResult parseResult = OPathParser.Parse("Variable1 . Property1 . Property2 = 1");

            Assert.AreEqual("$Var1 = 1", parseResult.GetXPath(), "parseResult.GetXPath()");
            Assert.AreEqual(1, parseResult.GetVariables().Length, "parseResult.GetVariables().Length");

            OPathVariable variable1 = GetVariable("Var1", parseResult.GetVariables());

            Assert.AreEqual("Variable1.Property1.Property2", variable1.GetReference(), "variable1.GetReference()");

            Assert.AreEqual(2, variable1.OPathParts.Length, "variable1.OPathParts.Length");
            AssertVariablePropertyPart(variable1, 0, "Property1");
            AssertVariablePropertyPart(variable1, 1, "Property2");
        }
Пример #7
0
        public void Parse_VariableWithMultipleMembers_ExpectedResult()
        {
            OPathParseResult parseResult = OPathParser.Parse(@"listDictionary[""Key1""][1].Trim().Length != 6");

            Assert.AreEqual("$Var1 != 6", parseResult.GetXPath(), "parseResult.GetXPath()");
            Assert.AreEqual(1, parseResult.GetVariables().Length, "parseResult.GetVariables().Length");

            OPathVariable variable1 = GetVariable("Var1", parseResult.GetVariables());

            Assert.AreEqual(@"listDictionary[""Key1""][1].Trim().Length", variable1.GetReference(), "variable1.GetReference()");

            Assert.AreEqual(4, variable1.OPathParts.Length, "variable1.OPathParts.Length");
            AssertVariableStringKeyPart(variable1, 0, "Key1");
            AssertVariableIntIndexPart(variable1, 1, 1);
            AssertVariableMethodPart(variable1, 2, "Trim");
            AssertVariablePropertyPart(variable1, 3, "Length");
        }