Change capture upper bounds to inclusive
This commit is contained in:
parent
bdd8567f50
commit
4e83fc5867
5 changed files with 29 additions and 30 deletions
|
|
@ -8,17 +8,17 @@ suite "captures":
|
|||
|
||||
test "capture bounds are correct":
|
||||
let ex1 = re("([0-9])")
|
||||
check("1 23".find(ex1).matchBounds == 0 .. 1)
|
||||
check("1 23".find(ex1).captureBounds[0].get == 0 .. 1)
|
||||
check("1 23".find(ex1, 1).matchBounds == 2 .. 3)
|
||||
check("1 23".find(ex1, 3).matchBounds == 3 .. 4)
|
||||
check("1 23".find(ex1).matchBounds == 0 .. 0)
|
||||
check("1 23".find(ex1).captureBounds[0].get == 0 .. 0)
|
||||
check("1 23".find(ex1, 1).matchBounds == 2 .. 2)
|
||||
check("1 23".find(ex1, 3).matchBounds == 3 .. 3)
|
||||
|
||||
let ex2 = re("()()()()()()()()()()([0-9])")
|
||||
check("824".find(ex2).captureBounds[0].get == 0 .. 0)
|
||||
check("824".find(ex2).captureBounds[10].get == 0 .. 1)
|
||||
check("824".find(ex2).captureBounds[0].get == 0 .. -1)
|
||||
check("824".find(ex2).captureBounds[10].get == 0 .. 0)
|
||||
|
||||
let ex3 = re("([0-9]+)")
|
||||
check("824".find(ex3).captureBounds[0].get == 0 .. 3)
|
||||
check("824".find(ex3).captureBounds[0].get == 0 .. 2)
|
||||
|
||||
test "named captures":
|
||||
let ex1 = "foobar".find(re("(?<foo>foo)(?<bar>bar)"))
|
||||
|
|
@ -31,7 +31,7 @@ suite "captures":
|
|||
|
||||
test "named capture bounds":
|
||||
let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?"))
|
||||
check(ex1.captureBounds["foo"] == Some(0..3))
|
||||
check(ex1.captureBounds["foo"] == Some(0..2))
|
||||
check(ex1.captureBounds["bar"] == None[Slice[int]]())
|
||||
|
||||
test "capture count":
|
||||
|
|
@ -42,7 +42,7 @@ suite "captures":
|
|||
test "named capture table":
|
||||
let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?"))
|
||||
check(ex1.captures.toTable == {"foo" : "foo", "bar" : nil}.toTable())
|
||||
check(ex1.captureBounds.toTable == {"foo" : Some(0..3), "bar" : None[Slice[int]]()}.toTable())
|
||||
check(ex1.captureBounds.toTable == {"foo" : Some(0..2), "bar" : None[Slice[int]]()}.toTable())
|
||||
check(ex1.captures.toTable("") == {"foo" : "foo", "bar" : ""}.toTable())
|
||||
|
||||
let ex2 = "foobar".find(re("(?<foo>foo)(?<bar>bar)?"))
|
||||
|
|
@ -51,7 +51,7 @@ suite "captures":
|
|||
test "capture sequence":
|
||||
let ex1 = "foo".find(re("(?<foo>foo)(?<bar>bar)?"))
|
||||
check(ex1.captures.toSeq == @["foo", nil])
|
||||
check(ex1.captureBounds.toSeq == @[Some(0..3), None[Slice[int]]()])
|
||||
check(ex1.captureBounds.toSeq == @[Some(0..2), None[Slice[int]]()])
|
||||
check(ex1.captures.toSeq("") == @["foo", ""])
|
||||
|
||||
let ex2 = "foobar".find(re("(?<foo>foo)(?<bar>bar)?"))
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ suite "find":
|
|||
test "find bounds":
|
||||
check(toSeq(findIter("1 2 3 4 5 ", re" ")).map(
|
||||
proc (a: RegexMatch): Slice[int] = a.matchBounds
|
||||
) == @[1..2, 3..4, 5..6, 7..8, 9..10])
|
||||
) == @[1..1, 3..3, 5..5, 7..7, 9..9])
|
||||
|
||||
test "overlapping find":
|
||||
check("222".findAll(re"22") == @["22"])
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ suite "match":
|
|||
check("abc".match(re"(\w)").captures[0] == "a")
|
||||
check("abc".match(re"(?<letter>\w)").captures["letter"] == "a")
|
||||
check("abc".match(re"(\w)\w").captures[-1] == "ab")
|
||||
check("abc".match(re"(\w)").captureBounds[0].get == 0..1)
|
||||
check("abc".match(re"").captureBounds[-1].get == 0..0)
|
||||
check("abc".match(re"abc").captureBounds[-1].get == 0..3)
|
||||
check("abc".match(re"(\w)").captureBounds[0].get == 0 .. 0)
|
||||
check("abc".match(re"").captureBounds[-1].get == 0 .. -1)
|
||||
check("abc".match(re"abc").captureBounds[-1].get == 0 .. 2)
|
||||
|
||||
test "match test cases":
|
||||
check("123".match(re"").matchBounds == 0..0)
|
||||
check("123".match(re"").matchBounds == 0 .. -1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue