public void LastPart()
        {
            Tokenizer testSubject = new Tokenizer("create table test(id int, \"val\" varchar(12));");

            Assert.AreEqual(Token.ValueFor.CREATE, testSubject.GetNextAsSimpleToken());
            Assert.AreEqual(6, testSubject.Position);
            Assert.AreEqual("create", testSubject.LastPart);

            Assert.AreEqual(Token.ValueFor.TABLE, testSubject.GetNextAsSimpleToken());
            Assert.AreEqual(12, testSubject.Position);
            Assert.AreEqual("create table", testSubject.LastPart);

            testSubject.PartMarker = testSubject.Position + 1;

            Assert.AreEqual("TEST", testSubject.GetNextAsSimpleName());
            Assert.AreEqual(17, testSubject.Position);
            Assert.AreEqual("test", testSubject.LastPart);

            Assert.AreEqual(Token.ValueFor.OPENBRACKET, testSubject.GetNextAsSimpleToken());
            Assert.AreEqual(18, testSubject.Position);
            Assert.AreEqual("test(", testSubject.LastPart);

            Assert.AreEqual("ID", testSubject.GetNextAsSimpleName());
            Assert.AreEqual(20, testSubject.Position);
            Assert.AreEqual("test(id", testSubject.LastPart);

            Assert.AreEqual(Token.ValueFor.INT, testSubject.GetNextAsSimpleToken());
            Assert.AreEqual(24, testSubject.Position);
            Assert.AreEqual("test(id int", testSubject.LastPart);

            testSubject.SetPartMarker();

            Assert.AreEqual(Token.ValueFor.COMMA, testSubject.GetNextAsSimpleToken());
            Assert.AreEqual(25, testSubject.Position);
            Assert.AreEqual(Token.ValueFor.COMMA, testSubject.LastPart);

            Assert.AreEqual("val", testSubject.GetNextAsName());
            Assert.AreEqual(SqlTokenType.DelimitedIdentifier, testSubject.TokenType);
            Assert.AreEqual(31,testSubject.Position);
            Assert.AreEqual(", \"val\"", testSubject.LastPart);

            Assert.AreEqual(Token.ValueFor.VARCHAR, testSubject.GetNextAsSimpleToken());
            Assert.AreEqual(39, testSubject.Position);
            Assert.AreEqual(", \"val\" varchar", testSubject.LastPart);

            Assert.AreEqual(Token.ValueFor.OPENBRACKET, testSubject.GetThis(Token.ValueFor.OPENBRACKET));
            Assert.AreEqual(40, testSubject.Position);
            Assert.AreEqual(", \"val\" varchar(", testSubject.LastPart);

            Assert.AreEqual(12, testSubject.GetNextAsInt());
            Assert.AreEqual(42, testSubject.Position);
            Assert.AreEqual(", \"val\" varchar(12", testSubject.LastPart);

            Assert.AreEqual(Token.ValueFor.CLOSEBRACKET, testSubject.GetThis(Token.ValueFor.CLOSEBRACKET));
            Assert.AreEqual(43, testSubject.Position);
            Assert.AreEqual(", \"val\" varchar(12)", testSubject.LastPart);

            testSubject.SetPartMarker();

            Assert.AreEqual(Token.ValueFor.CLOSEBRACKET, testSubject.GetThis(Token.ValueFor.CLOSEBRACKET));
            Assert.AreEqual(44, testSubject.Position);
            Assert.AreEqual(Token.ValueFor.CLOSEBRACKET, testSubject.LastPart);

            Assert.AreEqual(Token.ValueFor.SEMICOLON, testSubject.GetThis(Token.ValueFor.SEMICOLON));
            Assert.AreEqual(45, testSubject.Position);
            Assert.AreEqual(");", testSubject.LastPart);

            Assert.AreEqual(string.Empty, testSubject.GetNextAsString());

            Assert.AreEqual(45, testSubject.Position);
            Assert.AreEqual(");", testSubject.LastPart);

            testSubject.SetPartMarker();

            Assert.AreEqual(string.Empty, testSubject.LastPart);
        }
        public void MatchFailed()
        {
            // Create Test Method Parameters
            object token = new object();
            object match = new object();

            try
            {
                throw Tokenizer.MatchFailed(token, match);
            }
            catch (HsqlDataSourceException hdse)
            {
               Assert.AreEqual(org.hsqldb.Trace.UNEXPECTED_TOKEN, -hdse.ErrorCode);
                // TODO
               //Assert.IsTrue(hdse.Message.Contains(org.hsqldb.Trace.getMessage(
               //    org.hsqldb.Trace.TOKEN_REQUIRED)));
            }

            Tokenizer testSubject = new Tokenizer("notwhatismatched");

            try
            {
                testSubject.GetThis("whatismatched");

                Assert.Fail("Unexpected successful match of 'whatismatched' to 'notwhatismatched'");
            }
            catch (AssertionException)
            {
                throw;
            }
            catch (HsqlDataSourceException ex)
            {
                Assert.AreEqual(org.hsqldb.Trace.UNEXPECTED_TOKEN, -ex.ErrorCode);
            }
        }
        public void GetThis()
        {
            Tokenizer testSubject = new Tokenizer("create table test(id int, \"val\" varchar(12));");

            Assert.AreEqual(Token.ValueFor.CREATE, testSubject.GetThis(Token.ValueFor.CREATE));
            Assert.AreEqual(Token.ValueFor.TABLE, testSubject.GetThis(Token.ValueFor.TABLE));

            try
            {
                string actual = testSubject.GetThis("test");

                Assert.Fail("successful invocation of GetThis(string) with non-match value");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex);
            }

            Assert.That(testSubject.WasThis("TEST"));
            Assert.That(testSubject.TokenType == SqlTokenType.Name);

            Assert.AreEqual(Token.ValueFor.OPENBRACKET, testSubject.GetThis(Token.ValueFor.OPENBRACKET));
            Assert.AreEqual("ID", testSubject.GetThis("ID"));
            Assert.AreEqual(Token.ValueFor.INT, testSubject.GetThis(Token.ValueFor.INT));
            Assert.AreEqual(Token.ValueFor.COMMA, testSubject.GetThis(Token.ValueFor.COMMA));

            try
            {
                Assert.AreEqual("val", testSubject.GetThis("val"));
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex);
            }
            Assert.That(testSubject.WasDelimitedIdentifier);
            Assert.AreEqual("\"val\"", testSubject.NormalizedToken);

            Assert.AreEqual(Token.ValueFor.VARCHAR, testSubject.GetThis(Token.ValueFor.VARCHAR));
            Assert.AreEqual(Token.ValueFor.OPENBRACKET, testSubject.GetThis(Token.ValueFor.OPENBRACKET));
            Assert.AreEqual("12", testSubject.GetThis("12"));
            Assert.That(testSubject.TokenType == SqlTokenType.IntegerLiteral);
            Assert.That(testSubject.LiteralValueDataType == HsqlProviderType.Integer);
            Assert.AreEqual(Token.ValueFor.CLOSEBRACKET, testSubject.GetThis(Token.ValueFor.CLOSEBRACKET));
            Assert.AreEqual(Token.ValueFor.CLOSEBRACKET, testSubject.GetThis(Token.ValueFor.CLOSEBRACKET));
            Assert.AreEqual(Token.ValueFor.SEMICOLON, testSubject.GetThis(Token.ValueFor.SEMICOLON));
        }
        public void IllegalWaitState()
        {
            try
            {
                throw Tokenizer.IllegalWaitState();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex);
                Assert.AreEqual(org.hsqldb.Trace.ASSERT_FAILED, -((HsqlDataSourceException)ex).ErrorCode);
            }

            Tokenizer testSubject = new Tokenizer("t1 t2 t3");

            testSubject.GetThis("T1");
            object rval;

            if (!testSubject.IsGetThis("T3"))
            {
                try
                {
                    rval = testSubject.IdentifierChainPredecessor;
                }
                catch (Exception ex)
                {
                    Assert.IsInstanceOfType(typeof(HsqlDataSourceException), ex);
                    Assert.AreEqual(org.hsqldb.Trace.ASSERT_FAILED, -((HsqlDataSourceException)ex).ErrorCode);
                }
            }
        }
        public void GetNextAsName()
        {
            Tokenizer testSubject = new Tokenizer("CREATE TABLE \"PUBLIC\".\"Foo \"\"BarBaz\"\"\"");

            testSubject.GetThis("CREATE");
            testSubject.GetThis("TABLE");

            string expectedSubjectPart = "Foo \"BarBaz\"";
            string expectedQualifierPart = "PUBLIC";
            string actualSubjectPart = testSubject.GetNextAsName();
            string actualQualifierPart = testSubject.IdentifierChainPredecessor;

            Assert.AreEqual(expectedQualifierPart, actualQualifierPart, "schema qualifier" );
            Assert.AreEqual(expectedSubjectPart, actualSubjectPart, "object name");
        }
        public void WasThis()
        {
            Tokenizer testSubject = new Tokenizer("foo bar \"baz\" foo.bar");

            testSubject.GetThis("FOO");
            testSubject.GetThis("BAR");

            Assert.AreEqual(true, testSubject.WasThis("BAR"));
            Assert.AreEqual(false, testSubject.WasThis("bar"));
            Assert.AreEqual(false, testSubject.WasThis(" BAR "));
            Assert.AreEqual(false, testSubject.WasThis("NOTBAR"));

            string name = testSubject.GetNextAsName();

            // not for use with delimited identifier.

            Assert.AreEqual(false, testSubject.WasThis("baz"));
            Assert.AreEqual(false, testSubject.WasThis("BAZ"));
            Assert.AreEqual(false, testSubject.WasThis(" baz "));
            Assert.AreEqual(false, testSubject.WasThis("notbaz"));

            string s = testSubject.GetNextAsString();

            // not for use with identifier chain.

            Assert.AreEqual(false, testSubject.WasThis("bar"));
            Assert.AreEqual(false, testSubject.WasThis("BAR"));
            Assert.AreEqual(false, testSubject.WasThis(" bar "));
            Assert.AreEqual(false, testSubject.WasThis("notbar"));
        }
        public void WasParameterMarker()
        {
            Tokenizer testSubject = new Tokenizer("update test set id = ?, val = ?");

            testSubject.GetThis(Token.ValueFor.UPDATE);

            Assert.AreEqual(false, testSubject.WasParameterMarker);

            testSubject.GetThis("TEST");

            Assert.AreEqual(false, testSubject.WasParameterMarker);

            testSubject.GetThis(Token.ValueFor.SET);

            Assert.AreEqual(false, testSubject.WasParameterMarker);

            testSubject.GetThis("ID");

            Assert.AreEqual(false, testSubject.WasParameterMarker);

            testSubject.GetThis(Token.ValueFor.EQUALS);

            Assert.AreEqual(false, testSubject.WasParameterMarker);

            testSubject.GetThis(Token.ValueFor.QUESTION);

            Assert.AreEqual(true, testSubject.WasParameterMarker);

            testSubject.GetThis(Token.ValueFor.COMMA);

            Assert.AreEqual(false, testSubject.WasParameterMarker);

            testSubject.GetThis("VAL");

            Assert.AreEqual(false, testSubject.WasParameterMarker);

            testSubject.GetThis(Token.ValueFor.EQUALS);

            Assert.AreEqual(false, testSubject.WasParameterMarker);

            testSubject.GetThis(Token.ValueFor.QUESTION);

            Assert.AreEqual(true, testSubject.WasParameterMarker);
        }
        public void WasNamedParameter()
        {
            Tokenizer testSubject = new Tokenizer("update test set id = @IdParam, val = :ValParam");

            Assert.AreEqual(false, testSubject.WasNamedParameter);
            Assert.AreEqual(string.Empty, testSubject.ParameterName);
            Assert.AreEqual(' ', testSubject.ParameterNamePrefix);

            testSubject.GetThis(Token.ValueFor.UPDATE);

            Assert.AreEqual(false, testSubject.WasNamedParameter);
            Assert.AreEqual(string.Empty, testSubject.ParameterName);
            Assert.AreEqual(' ', testSubject.ParameterNamePrefix);

            testSubject.GetThis("TEST");

            Assert.AreEqual(false, testSubject.WasNamedParameter);
            Assert.AreEqual(string.Empty, testSubject.ParameterName);
            Assert.AreEqual(' ', testSubject.ParameterNamePrefix);

            testSubject.GetThis(Token.ValueFor.SET);

            Assert.AreEqual(false, testSubject.WasNamedParameter);
            Assert.AreEqual(string.Empty, testSubject.ParameterName);
            Assert.AreEqual(' ', testSubject.ParameterNamePrefix);

            testSubject.GetThis("ID");

            Assert.AreEqual(false, testSubject.WasNamedParameter);
            Assert.AreEqual(string.Empty, testSubject.ParameterName);
            Assert.AreEqual(' ', testSubject.ParameterNamePrefix);

            testSubject.GetThis(Token.ValueFor.EQUALS);

            Assert.AreEqual(false, testSubject.WasNamedParameter);
            Assert.AreEqual(string.Empty, testSubject.ParameterName);
            Assert.AreEqual(' ', testSubject.ParameterNamePrefix);

            testSubject.GetNextAsString();

            Assert.AreEqual(true, testSubject.WasNamedParameter);
            Assert.AreEqual("IdParam", testSubject.ParameterName);
            Assert.AreEqual('@', testSubject.ParameterNamePrefix);

            testSubject.GetThis(Token.ValueFor.COMMA);

            Assert.AreEqual(false, testSubject.WasNamedParameter);
            Assert.AreEqual(string.Empty, testSubject.ParameterName);
            Assert.AreEqual(' ', testSubject.ParameterNamePrefix);

            testSubject.GetThis("VAL");

            Assert.AreEqual(false, testSubject.WasNamedParameter);
            Assert.AreEqual(string.Empty, testSubject.ParameterName);
            Assert.AreEqual(' ', testSubject.ParameterNamePrefix);

            testSubject.GetThis(Token.ValueFor.EQUALS);

            Assert.AreEqual(false, testSubject.WasNamedParameter);
            Assert.AreEqual(string.Empty, testSubject.ParameterName);
            Assert.AreEqual(' ', testSubject.ParameterNamePrefix);

            testSubject.GetNextAsString();

            Assert.AreEqual(true, testSubject.WasNamedParameter);
            Assert.AreEqual("ValParam", testSubject.ParameterName);
            Assert.AreEqual(':', testSubject.ParameterNamePrefix);
        }
        public void WasDelimitedIdentifier()
        {
            Tokenizer testSubject = new Tokenizer("+ join foo \"foo\" bar.\"foo\"");

            testSubject.GetThis(Token.ValueFor.PLUS);

            Assert.AreEqual(false, testSubject.WasDelimitedIdentifier);

            Assert.AreEqual(Token.ValueFor.JOIN, testSubject.GetNextAsSimpleToken());

            Assert.AreEqual(false, testSubject.WasDelimitedIdentifier);

            Assert.AreEqual("FOO", testSubject.GetNextAsName());

            Assert.AreEqual(false, testSubject.WasDelimitedIdentifier);

            Assert.AreEqual("foo", testSubject.GetNextAsName());

            Assert.AreEqual(true, testSubject.WasDelimitedIdentifier);
            Assert.AreEqual(false, testSubject.WasIdentifierChain);
            Assert.AreEqual(null, testSubject.IdentifierChainPredecessor);

            Assert.AreEqual("foo", testSubject.GetNextAsName());

            Assert.AreEqual(true, testSubject.WasDelimitedIdentifier);
            Assert.AreEqual(true, testSubject.WasIdentifierChain);
            Assert.AreEqual(false, testSubject.WasIdentifierChainPredecessorDelimited);
            Assert.AreEqual("BAR", testSubject.IdentifierChainPredecessor);
        }