Skip to content

Commit

Permalink
Added some tests and fixed an issue with the optional quantifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeaster30 committed Apr 29, 2023
1 parent c6acc4f commit 16682cc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
10 changes: 7 additions & 3 deletions libvore/parser_regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,14 @@ func parse_regexp_quantifier(regexp_token *Token, regexp string, index int) (*As
exp = nil
end_idx = index
}
exp.fewest = end_idx < len(regexp) && regexp[end_idx] == '?'
if exp.fewest {
end_idx += 1

if exp != nil {
exp.fewest = end_idx < len(regexp) && regexp[end_idx] == '?'
if exp.fewest {
end_idx += 1
}
}

return exp, end_idx, nil
}

Expand Down
56 changes: 56 additions & 0 deletions libvore/vore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,59 @@ func TestRegexp12(t *testing.T) {
{3, `aa--a-a`, None[string](), []TestVar{}},
})
}

func TestRegexp13(t *testing.T) {
vore, err := Compile("find all @/test/")
checkNoError(t, err)
results := vore.Run("this is a test")
matches(t, results, []TestMatch{
{10, "test", None[string](), []TestVar{}},
})
}

func TestRegexp14(t *testing.T) {
vore, err := Compile("find all @/a|b/")
checkNoError(t, err)
results := vore.Run("abc")
matches(t, results, []TestMatch{
{0, "a", None[string](), []TestVar{}},
{1, "b", None[string](), []TestVar{}},
})
}

func TestRegexp15(t *testing.T) {
vore, err := Compile("find all @/^test/")
checkNoError(t, err)
results := vore.Run("test a test")
matches(t, results, []TestMatch{
{0, "test", None[string](), []TestVar{}},
})
}

func TestRegexp16(t *testing.T) {
vore, err := Compile("find all @/test$/")
checkNoError(t, err)
results := vore.Run("test a test")
matches(t, results, []TestMatch{
{7, "test", None[string](), []TestVar{}},
})
}

func TestRegexp17(t *testing.T) {
vore, err := Compile("find all @/[^abc]*/")
checkNoError(t, err)
results := vore.Run("I really hate the abc's")
matches(t, results, []TestMatch{
{0, "I re", None[string](), []TestVar{}},
{5, "lly h", None[string](), []TestVar{}},
{11, "te the ", None[string](), []TestVar{}},
{21, "'s", None[string](), []TestVar{}},
})
}

func TestRegexp18(t *testing.T) {
vore, err := Compile("find all @/[]/")
checkNoError(t, err)
results := vore.Run("This is not a match")
matches(t, results, []TestMatch{})
}

0 comments on commit 16682cc

Please sign in to comment.