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 GetNextAsInt() { Tokenizer testSubject = new Tokenizer("123456789"); int expected = 123456789; int actual = testSubject.GetNextAsInt(); Assert.AreEqual(expected, actual); }
/// <summary> /// Parses the given value by treating it as an HSQLDB SQL INTEGER literal. /// </summary> /// <remarks> /// The legal input formats are those supported by /// <c>java.lang.Integer.ParseInt</c> /// </remarks> /// <param name="value">The value to parse.</param> /// <returns>a <c>System.Int32</c> representation of the string</returns> /// <exception cref="HsqlDataSourceException"> /// When a number format exception is encountered. /// </exception> public static int ParseInteger(string value) { try { Tokenizer tokenizer = new Tokenizer(value); return tokenizer.GetNextAsInt(); } catch (Exception e) { throw new HsqlDataSourceException(Trace.error( Trace.INVALID_CONVERSION, e.Message)); } }