Пример #1
0
    public void testConsumeText()
    {
        var p = new Parsable("123  4567890");

        Assert.IsTrue(p.Consume("123"));
        Assert.IsTrue(p.Consume("456")); // skipping whitespace
    }
Пример #2
0
    public void testLinePosition()
    {
        var p = new Parsable("1234567890\n1234567890\n1234567890\n1234567890");

        p.Consume("1234567890"); // skipping also \n whitespace
        p.Consume("1234567890");
        p.Consume("12345");
        Assert.AreEqual(27, p.Position);
        Assert.AreEqual(2, p.Line);
        Assert.AreEqual(5, p.LinePosition);
    }
Пример #3
0
    public void testFailurePosition()
    {
        var p = new Parsable("1234567890\n1234567890\n1234567890\n1234567890");

        p.Consume("1234567890"); // skipping also \n whitespace
        p.Consume("1234567890");
        p.Consume("12345");
        try {
            p.Consume("FAIL");
            Assert.Fail("Should have thrown ParseException");
        } catch (ParseException e) {
            Assert.AreEqual(27, e.Position);
            Assert.AreEqual(2, e.Line);
            Assert.AreEqual(5, e.LinePosition);
        }
    }