class test sequence pattern
private boolean match a(character c) pure
return c == 'a' || c == 'A'
private boolean match b(character c) pure
return c == 'b' || c == 'B'
private boolean match c(character c) pure
return c == 'c' || c == 'C'
testcase test match()
assert the pattern("abc")
assert the pattern("AC")
assert the pattern("AaaCcc")
assert the pattern("AaaBBBCcc")
assert !the pattern("bac")
assert !the pattern("aabb")
assert !the pattern("aaca")
testcase test viable prefix()
assert the pattern • is viable prefix("")
assert the pattern • is viable prefix("a")
assert the pattern • is viable prefix("aAa")
assert the pattern • is viable prefix("aabb")
assert the pattern • is viable prefix("aacc")
assert the pattern • is viable prefix("aaBcc")
assert !the pattern • is viable prefix("x")
assert !the pattern • is viable prefix("xyz")
assert !the pattern • is viable prefix("bbb")
assert !the pattern • is viable prefix("bcc")
assert !the pattern • is viable prefix("Ccc")
assert the pattern2 • is viable prefix("")
assert the pattern2 • is viable prefix("a")
assert the pattern2 • is viable prefix("aAa")
assert the pattern2 • is viable prefix("aabb")
assert the pattern2 • is viable prefix("aaBcc")
assert !the pattern2 • is viable prefix("x")
assert !the pattern2 • is viable prefix("xyz")
assert !the pattern2 • is viable prefix("bbb")
assert !the pattern2 • is viable prefix("bcc")
assert !the pattern2 • is viable prefix("Ccc")
testcase test match prefix()
assert the pattern • match prefix("") is null
assert the pattern • match prefix("a") is null
assert the pattern • match prefix("x") is null
assert the pattern • match prefix("xabc") is null
assert the pattern • match prefix("abc") == 3
assert the pattern • match prefix("abcdef") == 3
assert the pattern • match prefix("aAbBcCdef") == 6
assert the pattern • match prefix("aAbCdef") == 4
assert the pattern • match prefix("aaabbbcccddd") == 9
testcase test find first()
assert the pattern • find first("", 0) is null
assert the pattern • find first("foo", 0) is null
assert the pattern • find first("abcfoo", 3) is null
match : the pattern • find first("xxaabbcczz", 0)
assert match is_not null
assert match • begin == 2
assert match • end == 8
match2 : the pattern • find first("aaabbbAAACCCBBB", 1)
assert match2 is_not null
assert match2 • begin == 6
assert match2 • end == 12
match3 : the pattern • find first("fooACxyzABC", 0)
assert match3 is_not null
assert match3 • begin == 3
assert match3 • end == 5
testcase test find first more()
pattern[character] beta : sequence pattern[character] • new([match zero or more b, match one or more c])
match : beta • find first("aaabbbAAACCCBBB", 9)
assert match is_not null
assert match • begin == 9
assert match • end == 12
testcase test split()
split0 : the pattern • split("foo")
assert split0 • size == 1
assert equals(split0[0], "foo")
split1 : the pattern • split("fooACxyzABC")
assert split1 • size == 3
assert equals(split1[0], "foo")
assert equals(split1[1], "xyz")
assert equals(split1[2], "")
split2 : the pattern • split("aaabc1ac2ABC3")
assert split2 • size == 4
assert equals(split2[0], "")
assert equals(split2[1], "1")
assert equals(split2[2], "2")
assert equals(split2[3], "3")
boolean equals(immutable list[character] s0, string s1)
return (s0 !> string) == s1