Exemplo n.º 1
0
    public void Repeat0Parser()
    {
        var emptyStream    = new MemoryStream <char>(string.Empty.AsMemory());
        var nonEmptyStream = new MemoryStream <char>("aaa".AsMemory());

        var p = Combinator.Rep0(Combinator.Char('a'));

        var r1 = p.Parse(emptyStream);
        var r2 = p.Parse(nonEmptyStream);

        Assert.True(r1.IsOk);
        Assert.True(r2.IsOk);
        Assert.Equal(0, r1.Ok.Value.Count);
        Assert.Equal(3, r2.Ok.Value.Count);
        Assert.Equal('a', r2.Ok.Value[0]);
        Assert.Equal('a', r2.Ok.Value[1]);
        Assert.Equal('a', r2.Ok.Value[2]);
    }