Пример #1
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");
        }
Пример #2
0
        public void Parse_VariableWithIntIndexersWithWhitespace_ExpectedResult()
        {
            OPathParseResult parseResult = OPathParser.Parse("Variable1 [ 1 ] [ 2 ] = 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", variable1.Name, "variable1.Name");
            Assert.AreEqual("[1][2]", variable1.GetOPath(), "variable1.GetOPath()");

            Assert.AreEqual(2, variable1.OPathParts.Length, "variable1.OPathParts.Length");
            AssertVariableIntIndexPart(variable1, 0, 1);
            AssertVariableIntIndexPart(variable1, 1, 2);
        }
Пример #3
0
        public void TestParsing()
        {
            HiPerfTimer handRolledTimer = new HiPerfTimer();

            handRolledTimer.Start();

            for (int i = 0; i < EVALUATION_COUNT; i++)
            {
                OPathParser.Parse(EXPRESSION);
            }

            handRolledTimer.Stop();

            Console.WriteLine("Hand-rolled parsing did {0} in {1:0.000} millis",
                              EVALUATION_COUNT, (handRolledTimer.Duration * 1000));
        }
Пример #4
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");
        }
Пример #5
0
        public void Parse_MultipleVariables_ExpectedResult()
        {
            OPathParseResult parseResult = OPathParser.Parse("Variable1 = Variable2");

            Assert.AreEqual("$Var1 = $Var2", parseResult.GetXPath(), "parseResult.GetXPath()");
            Assert.AreEqual(2, 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");

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

            Assert.AreEqual("Variable2", variable2.GetReference(), "variable1.GetReference()");
            Assert.AreEqual(0, variable2.OPathParts.Length, "variable1.OPathParts.Length");
        }