public void Constructor() { void ConstructorTest(int startIndex, string text, PkgdefTokenType tokenType, Exception expectedException = null) { if (expectedException != null) { AssertEx.Throws(() => new PkgdefToken(startIndex, text, tokenType), expectedException); } else { PkgdefToken token = new PkgdefToken(startIndex, text, tokenType); Assert.AreEqual(startIndex, token.GetStartIndex()); Assert.AreEqual(text, token.GetText()); Assert.AreEqual(tokenType, token.GetTokenType()); Assert.AreEqual(text.Length, token.GetLength()); Assert.AreEqual(startIndex + text.Length, token.GetAfterEndIndex()); Assert.AreEqual(startIndex + text.Length - 1, token.GetEndIndex()); } } ConstructorTest(-1, "hello", PkgdefTokenType.Unrecognized, expectedException: new PreConditionException("startIndex (-1) must be greater than or equal to 0.")); ConstructorTest(0, null, PkgdefTokenType.Unrecognized, expectedException: new PreConditionException("text cannot be null.")); ConstructorTest(0, "", PkgdefTokenType.Unrecognized, expectedException: new PreConditionException("text cannot be empty.")); ConstructorTest(0, "abc", PkgdefTokenType.Unrecognized); }
public void Unrecognized() { PkgdefToken token = PkgdefToken.Unrecognized(1, '&'); Assert.AreEqual(1, token.GetStartIndex()); Assert.AreEqual("&", token.GetText()); Assert.AreEqual(PkgdefTokenType.Unrecognized, token.GetTokenType()); }
public void Whitespace() { PkgdefToken token = PkgdefToken.Whitespace(1, " \t"); Assert.AreEqual(1, token.GetStartIndex()); Assert.AreEqual(" \t", token.GetText()); Assert.AreEqual(PkgdefTokenType.Whitespace, token.GetTokenType()); }