public void is_a_string_token() { StringTokenizer st = new StringTokenizer("\"\"coucou\"a string\" 1454 toto"); string s; // we must have "" Assert.That(st.IsString(out s)); Assert.That(s, Is.EqualTo("")); // we must have coucou Assert.That(st.MatchIdentifier("coucou")); // we must have "" Assert.That(st.IsString(out s) && s == "a string"); Assert.That(st.IsString(out s), Is.False); Assert.That(st.IsIdentifier(out s), Is.False); Assert.That(st.Match(TokenType.OpenCurly), Is.False); Assert.That(st.MatchIdentifier("b"), Is.False); int i; Assert.That(st.IsInteger(out i) && i == 1454); Assert.That(st.IsString(out s), Is.False); Assert.That(st.IsInteger(out i), Is.False); Assert.That(st.Match(TokenType.SemiColon), Is.False); Assert.That(st.MatchIdentifier("YOYO"), Is.False); Assert.That(st.MatchIdentifier("toto")); Assert.That(st.Match(TokenType.EndOfInput)); }
public void identifiers() { var tokenizer = new StringTokenizer("Count * ( _frequency - 1 )"); tokenizer.GetNextToken().Should().Be(TokenType.Identifier); tokenizer.MatchIdentifier(out var id).Should().BeTrue(); id.Should().Be("Count"); tokenizer.CurrentToken.Should().Be(TokenType.Multiplicative); tokenizer.GetNextToken().Should().Be(TokenType.OpenParenthesis); tokenizer.GetNextToken().Should().Be(TokenType.Identifier); tokenizer.MatchIdentifier(out id).Should().BeTrue( ); id.Should().Be("_frequency"); tokenizer.CurrentToken.Should().Be(TokenType.Minus); tokenizer.GetNextToken().Should().Be(TokenType.Integer); tokenizer.MatchInteger(out var i).Should().BeTrue(); i.Should().Be(1); tokenizer.CurrentToken.Should().Be(TokenType.CloseParenthesis); }