public void EnforceTwoPartIdentifierChain()
        {
            Tokenizer testSubject = new Tokenizer();

            Assert.AreEqual(false, testSubject.EnforceTwoPartIdentifierChain);

            testSubject.EnforceTwoPartIdentifierChain = true;

            Assert.AreEqual(true, testSubject.EnforceTwoPartIdentifierChain);

            testSubject.Reset("foo.bar.baz");

            try
            {
                testSubject.GetNextAsName();
            }
            catch (HsqlDataSourceException hdse)
            {
                Assert.AreEqual(org.hsqldb.Trace.THREE_PART_IDENTIFIER, -hdse.ErrorCode);
            }

            testSubject.EnforceTwoPartIdentifierChain = false;

            testSubject.Reset("foo.\"bar\".baz.null.true.false");

            testSubject.GetNextAsName();

            Token[] expected = new Token[]
            {
                new Token("FOO",SqlTokenType.Name),
                new Token("bar",SqlTokenType.DelimitedIdentifier),
                new Token("BAZ",SqlTokenType.Name),
                new Token("NULL",SqlTokenType.Name),
                new Token("TRUE",SqlTokenType.Name),
                new Token("FALSE",SqlTokenType.Name),
            };

            int i = 0;

            foreach (Token token in testSubject.IdentifierChain)
            {
                Console.WriteLine(token);
                Console.WriteLine(expected[i]);
                Assert.AreEqual(expected[i], token);

                i++;
            }
        }
        public void TokenTypeTest()
        {
            Tokenizer testSubject = new Tokenizer();

            Assert.AreEqual(SqlTokenType.None, testSubject.TokenType);

            object[][] values = new object[][]
            {
            new object[] {"2147483649", SqlTokenType.BigIntLiteral},
            new object[] {Token.ValueFor.TRUE, SqlTokenType.BooleanLiteral},
            new object[] {"'2009-01-01'", SqlTokenType.DateLiteral},
            new object[] {"123.0123", SqlTokenType.DecimalLiteral},
            new object[] {"\"foo\"", SqlTokenType.DelimitedIdentifier},
            new object[] {"123.1e-23", SqlTokenType.FloatLiteral},
            new object[] {"foo.bar", SqlTokenType.IdentifierChain},
            new object[] {int.MaxValue.ToString(), SqlTokenType.IntegerLiteral},
            new object[] {"column_one", SqlTokenType.Name},
            new object[] {"@MyNamedParameter", SqlTokenType.NamedParameter},
            new object[] {"?", SqlTokenType.ParameterMarker},
            new object[] {"<", SqlTokenType.Special},
            new object[] {"'''foo'' they said.'", SqlTokenType.StringLiteral},
            new object[] {"'12:23:02'", SqlTokenType.TimeLiteral},
            new object[] {"'2009-01-01 12:23:02.123456789'", SqlTokenType.TimestampLiteral}
            };

            foreach (object[] row in values)
            {
                testSubject.Reset(row[0].ToString());

                testSubject.GetNextAsString();

                Assert.AreEqual((SqlTokenType)row[1], testSubject.TokenType);
            }
        }
        public void TokenTypeName()
        {
            Tokenizer testSubject = new Tokenizer();

            Assert.AreEqual("None", testSubject.TokenTypeName);

            object[][] values = new object[][]
            {
            new object[] {"2147483649", "BigInt"},
            new object[] {Token.ValueFor.TRUE, "Boolean"},
            new object[] {"'2009-01-01'", "Date"},
            new object[] {"123.0123", "Decimal"},
            new object[] {"\"foo\"", "Delimited Identifier"},
            new object[] {"123.1e-23", "Float"},
            new object[] {"foo.bar", "Identifier Chain"},
            new object[] {int.MaxValue.ToString(), "Integer"},
            new object[] {"column_one", "Name"},
            new object[] {"@MyNamedParameter", "Named Parameter"},
            new object[] {"?", "Parameter Marker"},
            new object[] {"<", "Special"},
            new object[] {"'''foo'' they said.'","String"},
            new object[] {"'12:23:02'", "Time"},
            new object[] {"'2009-01-01 12:23:02.123456789'", "Timestamp"}
            };

            foreach (object[] row in values)
            {
                testSubject.Reset(row[0].ToString());

                testSubject.GetNextAsString();

                Assert.AreEqual((string)row[1], testSubject.TokenTypeName);
            }
        }
        public void Reset()
        {
            Tokenizer testSubject = new Tokenizer("Foo Bar BAz");

            string source1 = testSubject.GetPart(0, "Foo Bar BAz".Length);

            testSubject.Reset("baZ BAR foo");

            string source2 = testSubject.GetPart(0, "baZ BAR foo".Length);

            Assert.AreNotEqual(source1, source2);

            Assert.AreEqual("Foo Bar BAz", source1);
            Assert.AreEqual("baZ BAR foo", source2);
        }
        public void Length()
        {
            StringBuilder sb = new StringBuilder();
            Tokenizer testSubject = new Tokenizer();

            for (int i = 0; i < 30; i++)
            {
                testSubject.Reset(sb.ToString());

                Assert.AreEqual(i, testSubject.Length);

                sb.Append(' ');
            }
        }
        public void IdentiferChainPredecessor()
        {
            Tokenizer testSubject = new Tokenizer("foo.bar.baz");

            string token = testSubject.GetNextAsString();

            Assert.AreEqual("BAR", testSubject.IdentifierChainPredecessor);

            testSubject.Reset("bing.foo.\"bar\".baz");

            token = testSubject.GetNextAsString();

            Assert.AreEqual("bar", testSubject.IdentifierChainPredecessor);
        }
        public void GetNextAsLiteralValue()
        {
            // Create Constructor Parameters

            Tokenizer testSubject = new Tokenizer();

            List<NextAsLiteralValueTestParameters> testParameters =
                new List<NextAsLiteralValueTestParameters>();

            // Array Literal

            testParameters.Add(new NextAsLiteralValueTestParameters(
                "foo",
                HsqlProviderType.Array,
                null,
                org.hsqldb.Trace.UNEXPECTED_TOKEN,
                "SQL ARRAY literal tokens are not supposed to be supported"));

            // BigInt Literal

            testParameters.Add(new NextAsLiteralValueTestParameters(
                "-1",
                HsqlProviderType.BigInt,
                null,
                org.hsqldb.Trace.UNEXPECTED_TOKEN,
                "Atomic retrieval of a negative BIGINT literal is not supposed to be supported."));

            testParameters.Add(new NextAsLiteralValueTestParameters(
                "0",
                HsqlProviderType.BigInt,
                new java.lang.Long(0),
                null,
                null));

            testParameters.Add(new NextAsLiteralValueTestParameters(
                "1",
                HsqlProviderType.BigInt,
                new java.lang.Long(1),
                null,
                null));

            testParameters.Add(new NextAsLiteralValueTestParameters(
                long.MaxValue.ToString(),
                HsqlProviderType.BigInt,
                new java.lang.Long(long.MaxValue),
                null,
                null));

            testParameters.Add(new NextAsLiteralValueTestParameters(
                long.MinValue.ToString(),
                HsqlProviderType.BigInt,
                null,
                org.hsqldb.Trace.UNEXPECTED_TOKEN,
                "Atomic retrieval of a negative BIGINT literal is not supposed to be supported."));

            // Binary Literal

            testParameters.Add(new NextAsLiteralValueTestParameters(
                "/* a binary literal value */ 'AFD14E7B9F82' ",
                HsqlProviderType.Binary,
                new org.hsqldb.types.Binary(HsqlStringConverter.hexToByte("AFD14E7B9F82"),false),
                null,
                null));

            foreach (NextAsLiteralValueTestParameters parameters in
                testParameters)
            {
                Console.WriteLine(parameters);

                testSubject.Reset(parameters.Chars);

                try
                {
                    object value = testSubject.GetNextAsLiteralValue(
                        parameters.ProviderType);

                    if (parameters.ErrorMessage != null) {
                        Assert.Fail(parameters.ErrorMessage);
                    }

                    System.Type expectedValueType =
                        HsqlConvert.ToProviderSpecificDataType(
                        parameters.ProviderType);

                    Assert.IsAssignableFrom(expectedValueType,
                        parameters.Value);
                    Assert.IsAssignableFrom(expectedValueType,
                        value);

                    Assert.AreEqual(parameters.Value, value);
                }
                catch(AssertionException)
                {
                    throw;
                }
                catch(HsqlDataSourceException hdse)
                {
                    Assert.AreEqual(parameters.ErrorCode, -hdse.ErrorCode);
                }
            }

            //testSubject.Reset("'AFD14E7B9F82'");

            //object bytes = testSubject.GetNextAsLiteralValue(HsqlProviderType.Binary);

            //Assert.IsInstanceOfType(typeof(org.hsqldb.types.Binary), bytes);

            //testSubject.Reset("'CAFEBABE'");

            //try
            //{
            //    testSubject.GetNextAsLiteralValue(HsqlProviderType.Blob);

            //    Assert.Fail("SQL BLOB literal tokens are not supposed to be supported at this time");
            //}
            //catch (HsqlDataSourceException)
            //{
            //}

            //testSubject.Reset("TRUE");

            //testSubject.GetNextAsLiteralValue(HsqlProviderType.Boolean);

            //testSubject.Reset("FALSE");

            //testSubject.GetNextAsLiteralValue(HsqlProviderType.Boolean);

            //testSubject.Reset("NULL");

            //testSubject.GetNextAsLiteralValue(HsqlProviderType.Boolean);

            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Char);
            //try
            //{
            //    testSubject.GetNextAsLiteralValue(HsqlProviderType.Clob);

            //    Assert.Fail("SQL CLOB literal tokens are not supposed to be supported at this time");
            //}
            //catch (HsqlDataSourceException)
            //{
            //}
            //try
            //{
            //    testSubject.GetNextAsLiteralValue(HsqlProviderType.DataLink);

            //    Assert.Fail("SQL DATALINK literal tokens are not supposed to be supported at this time");
            //}
            //catch (HsqlDataSourceException)
            //{
            //}
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Date);
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Decimal);
            //try
            //{
            //    testSubject.GetNextAsLiteralValue(HsqlProviderType.Distinct);

            //    Assert.Fail("SQL DISTINCT literal tokens are not supposed to be supported");
            //}
            //catch (HsqlDataSourceException)
            //{
            //}
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Double);
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Float);
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Integer);
            //try
            //{
            //    testSubject.GetNextAsLiteralValue(HsqlProviderType.JavaObject);

            //    Assert.Fail("SQL JAVA_OBJECT literal tokens are not supposed to be supported at this time");
            //}
            //catch (HsqlDataSourceException)
            //{
            //}
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.LongVarBinary);
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.LongVarChar);
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Null);
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Numeric);
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Object);
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Real);
            //try
            //{
            //    testSubject.GetNextAsLiteralValue(HsqlProviderType.Ref);

            //    Assert.Fail("SQL REF literal tokens are not supposed to be supported");
            //}
            //catch (HsqlDataSourceException)
            //{
            //}
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.SmallInt);
            //try
            //{
            //    testSubject.GetNextAsLiteralValue(HsqlProviderType.Struct);

            //    Assert.Fail("SQL STRUCT literal tokens are not supposed to be supported");
            //}
            //catch (HsqlDataSourceException)
            //{
            //}
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.Time);
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.TimeStamp);
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.TinyInt);
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.VarBinary);
            ////testSubject.GetNextAsLiteralValue(HsqlProviderType.VarChar);
            //try
            //{
            //    testSubject.GetNextAsLiteralValue(HsqlProviderType.Xml);

            //    Assert.Fail("SQL XML literal tokens are not supposed to be supported at this time");
            //}
            //catch (HsqlDataSourceException)
            //{
            //}
        }