TypeName Parameterized Rule Test

Here is an example of the types of tests I’ve been writing recently, see if you can figure out what it’s doing:

[Test]
public void TypeNameParameterizedRuleSuccess()
{
    string expected = "a.b.c";
    var stream = new TextStream(expected);

    var list = new Func<PatternMatch, PatternMatch, PatternMatch>(
        (exp, separator) =>
        {
            return Pattern.And(
                exp,
                Pattern.ZeroOrMore(
                    Pattern.And(
                        separator,
                        exp)));
        });

    var pattern = Pattern.Projection(
        list(
            Pattern.Range('a', 'z'),
            Pattern.Value('.')),
        match => match.AsString());

    var actual = pattern(stream);
    Assert.AreEqual(expected, ((ValueNode)actual).Value);
}

beautiful!

Advertisements

Drop a brain bomb

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s