Exemplo n.º 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");
        }
Exemplo n.º 2
0
        private static OPathVariable GetVariable(string xpathName, OPathVariable[] variables)
        {
            OPathVariable variable =
                Array.Find(variables, delegate(OPathVariable v) { return(v.XPathName == xpathName); });

            return(variable);
        }
Exemplo n.º 3
0
        private static void AssertVariableMethodPart(OPathVariable variable, int partIndex, string expectedMethodName)
        {
            OPathMethodPart part = variable.OPathParts[partIndex] as OPathMethodPart;

            Assert.IsNotNull(part, "Part " + partIndex);

            Assert.AreEqual(expectedMethodName, part.MethodName, "part.MethodName");
        }
Exemplo n.º 4
0
        private static void AssertVariableStringKeyPart(OPathVariable variable, int partIndex, string expectedKeyValue)
        {
            OPathStringKeyPart part = variable.OPathParts[partIndex] as OPathStringKeyPart;

            Assert.IsNotNull(part, "Part " + partIndex);

            Assert.AreEqual(expectedKeyValue, part.KeyValue, "part.KeyValue");
        }
Exemplo n.º 5
0
        private static void AssertVariableIntIndexPart(OPathVariable variable, int partIndex, int expectedIndex)
        {
            OPathIntIndexerPart part = variable.OPathParts[partIndex] as OPathIntIndexerPart;

            Assert.IsNotNull(part, "Part " + partIndex);

            Assert.AreEqual(expectedIndex, part.IndexValue, "part.IndexValue");
        }
Exemplo n.º 6
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");
        }
Exemplo n.º 7
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");
        }
Exemplo n.º 8
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");
        }
Exemplo n.º 9
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");
        }
Exemplo n.º 10
0
        public void Parse_VariableWithNegativeIntIndexer_ExpectedResult()
        {
            OPathParseResult parseResult = OPathParser.Parse("Variable1[-1] = 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]", variable1.GetOPath(), "variable1.GetOPath()");

            Assert.AreEqual(1, variable1.OPathParts.Length, "variable1.OPathParts.Length");
            AssertVariableIntIndexPart(variable1, 0, -1);
        }
Exemplo n.º 11
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");
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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");
        }