Esempio n. 1
0
        /// <summary>
        /// Verifies that two query tokens are equal.
        /// </summary>
        /// <param name="expected">The expected query token.</param>
        /// <param name="actual">The actual query token.</param>
        /// <param name="assert">Assertion handler to use.</param>
        internal static void VerifyQueryTokensAreEqual(QueryToken expected, QueryToken actual, AssertionHandler assert)
        {
            try
            {
                if (!VerifyNullnessMatches(expected, actual, assert, "token"))
                {
                    return;
                }

                assert.AreEqual(expected.Kind, actual.Kind, "The token kinds are different.");

                switch (expected.Kind)
                {
                case QueryTokenKind.Literal:
                    VerifyLiteralQueryTokensAreEqual((LiteralToken)expected, (LiteralToken)actual, assert);
                    break;

                case QueryTokenKind.BinaryOperator:
                    VerifyBinaryOperatorQueryTokensAreEqual((BinaryOperatorToken)expected, (BinaryOperatorToken)actual, assert);
                    break;

                case QueryTokenKind.UnaryOperator:
                    VerifyUnaryOperatorQueryTokensAreEqual((UnaryOperatorToken)expected, (UnaryOperatorToken)actual, assert);
                    break;

                case QueryTokenKind.EndPath:
                    VerifyPropertyAccessQueryTokensAreEqual((EndPathToken)expected, (EndPathToken)actual, assert);
                    break;

                case QueryTokenKind.InnerPath:
                    VerifyNonRootSegmentQueryTokensAreEqual((InnerPathToken)expected, (InnerPathToken)actual, assert);
                    break;

                case QueryTokenKind.FunctionCall:
                    VerifyFunctionCallQueryTokensAreEqual((FunctionCallToken)expected, (FunctionCallToken)actual, assert);
                    break;

                case QueryTokenKind.CustomQueryOption:
                    VerifyCustomQueryOptionQueryTokensAreEqual((CustomQueryOptionToken)expected, (CustomQueryOptionToken)actual, assert);
                    break;

                case QueryTokenKind.OrderBy:
                    VerifyOrderByQueryTokensAreEqual((OrderByToken)expected, (OrderByToken)actual, assert);
                    break;

                case QueryTokenKind.Select:
                    VerifySelectQueryTokensAreEqual((SelectToken)expected, (SelectToken)actual, assert);
                    break;

                case QueryTokenKind.Star:
                    VerifyStarQueryTokensAreEqual((StarToken)expected, (StarToken)actual, assert);
                    break;

                case QueryTokenKind.FunctionParameter:
                    VerifyFunctionParameterTokensAreEqual((FunctionParameterToken)expected, (FunctionParameterToken)actual, assert);
                    break;

                default:
                    assert.Fail("The token kind '" + expected.Kind.ToString() + "' is not a lexical node.");
                    break;
                }
            }
            catch (Exception)
            {
                assert.Warn("Expected query token: " + expected.ToDebugString());
                assert.Warn("Actual query token: " + actual.ToDebugString());
                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Verifies that two query tokens are equal.
        /// </summary>
        /// <param name="expected">The expected query token.</param>
        /// <param name="actual">The actual query token.</param>
        /// <param name="assert">Assertion handler to use.</param>
        internal static void VerifyQueryTokensAreEqual(QueryToken expected, QueryToken actual, AssertionHandler assert)
        {
            try
            {
                if(!VerifyNullnessMatches(expected, actual, assert, "token")) return;

                assert.AreEqual(expected.Kind, actual.Kind, "The token kinds are different.");

                switch (expected.Kind)
                {
                    case QueryTokenKind.Literal:
                        VerifyLiteralQueryTokensAreEqual((LiteralToken)expected, (LiteralToken)actual, assert);
                        break;
                    case QueryTokenKind.BinaryOperator:
                        VerifyBinaryOperatorQueryTokensAreEqual((BinaryOperatorToken)expected, (BinaryOperatorToken)actual, assert);
                        break;
                    case QueryTokenKind.UnaryOperator:
                        VerifyUnaryOperatorQueryTokensAreEqual((UnaryOperatorToken)expected, (UnaryOperatorToken)actual, assert);
                        break;
                    case QueryTokenKind.EndPath:
                        VerifyPropertyAccessQueryTokensAreEqual((EndPathToken)expected, (EndPathToken)actual, assert);
                        break;
                    case QueryTokenKind.InnerPath:
                        VerifyNonRootSegmentQueryTokensAreEqual((InnerPathToken) expected,(InnerPathToken) actual, assert);
                        break;
                    case QueryTokenKind.FunctionCall:
                        VerifyFunctionCallQueryTokensAreEqual((FunctionCallToken)expected, (FunctionCallToken)actual, assert);
                        break;
                    case QueryTokenKind.CustomQueryOption:
                        VerifyCustomQueryOptionQueryTokensAreEqual((CustomQueryOptionToken)expected, (CustomQueryOptionToken)actual, assert);
                        break;
                    case QueryTokenKind.OrderBy:
                        VerifyOrderByQueryTokensAreEqual((OrderByToken)expected, (OrderByToken)actual, assert);
                        break;
                    case QueryTokenKind.Select:
                        VerifySelectQueryTokensAreEqual((SelectToken)expected, (SelectToken)actual, assert);
                        break;
                    case QueryTokenKind.Star:
                        VerifyStarQueryTokensAreEqual((StarToken)expected, (StarToken)actual, assert);
                        break;
                    case QueryTokenKind.FunctionParameter:
                        VerifyFunctionParameterTokensAreEqual((FunctionParameterToken)expected, (FunctionParameterToken)actual, assert);
                        break;
                    default:
                        assert.Fail("The token kind '" + expected.Kind.ToString() + "' is not a lexical node.");
                        break;
                }
            }
            catch (Exception)
            {
                assert.Warn("Expected query token: " + expected.ToDebugString());
                assert.Warn("Actual query token: " + actual.ToDebugString());
                throw;
            }
        }