public void TokenPushedBackWhenAtStartOfLineThrowsException(bool throwsException) { ProgramLine programLine = new ProgramLine(30, _tokens); var token = throwsException ? new Token(")", TokenClass.Seperator, TokenType.CloseBracket) : programLine.NextToken(); Test.Throws <InvalidOperationException>(() => programLine.PushToken(token), throwsException); }
public void ProgramLineEndOfLineIsFalseIfEolPlusTokenIsPushedBack() { ProgramLine programLine = new ProgramLine(30, _tokens); programLine.NextToken(); var token1 = programLine.NextToken(); var token2 = programLine.NextToken(); var eolToken = programLine.NextToken(); programLine.PushToken(eolToken); Assert.IsTrue(programLine.EndOfLine); programLine.PushToken(token2); programLine.PushToken(token1); Assert.IsFalse(programLine.EndOfLine); var nextToken = programLine.NextToken(); Assert.AreEqual(token1, nextToken); nextToken = programLine.NextToken(); Assert.AreEqual(token2, nextToken); }
public void WrongTokenPushedBackThrowsException(bool throwsException) { ProgramLine programLine = new ProgramLine(30, _tokens); programLine.NextToken(); var secondToken = programLine.NextToken(); var thirdToken = programLine.NextToken(); var token = throwsException ? secondToken : thirdToken; Test.Throws <InvalidOperationException>(() => programLine.PushToken(token), throwsException); }
public void ProgramLineEndOfLineIsFalseIfLastTokenPushedBack() { ProgramLine programLine = new ProgramLine(30, _tokens); programLine.NextToken(); programLine.NextToken(); var lastToken = programLine.NextToken(); Assert.IsTrue(programLine.EndOfLine); programLine.PushToken(lastToken); Assert.IsFalse(programLine.EndOfLine); }
public void ProgramLineEndOfLineIsTrueIfEolIsPushedBack() { ProgramLine programLine = new ProgramLine(30, _tokens); programLine.NextToken(); programLine.NextToken(); programLine.NextToken(); var eolToken = programLine.NextToken(); programLine.PushToken(eolToken); Assert.IsTrue(programLine.EndOfLine); var nextToken = programLine.NextToken(); Assert.AreEqual(TokenType.EndOfLine, nextToken.Seperator); }
public void IfLastTokenPushedBackThenNextTokenReturnsIt() { ProgramLine programLine = new ProgramLine(30, _tokens); programLine.NextToken(); programLine.NextToken(); var lastToken = programLine.NextToken(); Assert.IsTrue(programLine.EndOfLine); programLine.PushToken(lastToken); Assert.IsFalse(programLine.EndOfLine); var nextToken = programLine.NextToken(); Assert.AreEqual("THREE", nextToken.Text); }