public void simple_tokens() { StringTokenizer t = new StringTokenizer("2 + 96"); t.Match(TokenType.None).Should().BeTrue(); t.MatchInteger(out var i).Should().BeTrue(); i.Should().Be(2); t.Match(TokenType.Plus).Should().BeTrue(); t.MatchInteger(out i).Should().BeTrue(); i.Should().Be(96); }
public void basic_test() { var tokenizer = new StringTokenizer("42 + 3712"); tokenizer.GetNextToken().Should().Be(TokenType.Integer); tokenizer.MatchInteger(out var i).Should().BeTrue(); i.Should().Be(42); tokenizer.CurrentToken.Should().Be(TokenType.Plus); tokenizer.GetNextToken().Should().Be(TokenType.Integer); tokenizer.MatchInteger(out i).Should().BeTrue(); i.Should().Be(3712); }
public void floating() { var tokenizer = new StringTokenizer("37.12e3 + 4.E2"); tokenizer.GetNextToken().Should().Be(TokenType.Double); tokenizer.MatchInteger(out _).Should().BeFalse(); tokenizer.MatchDouble(out var d).Should().BeTrue(); d.Should().BeApproximately(37.12e3, double.Epsilon); tokenizer.CurrentToken.Should().Be(TokenType.Plus); tokenizer.GetNextToken().Should().Be(TokenType.Double); tokenizer.MatchDouble(out d).Should().BeTrue(); d.Should().BeApproximately(4E2, double.Epsilon); }