Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Nov 25, 2024
1 parent 3a0cd5f commit a7db7a4
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion stopwrods_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package stopwords_test

import (
"iter"
"strings"
"testing"

"github.com/matryer/is"
"github.com/orsinium-labs/stopwords"
)

func TestFind_Contains(t *testing.T) {
func TestContains_English(t *testing.T) {
is := is.New(t)
sw := stopwords.MustGet("en")

Expand All @@ -21,3 +23,27 @@ func TestFind_Contains(t *testing.T) {
is.True(!sw.Contains("django"))
is.True(!sw.Contains("Django"))
}

func iter2text(ms iter.Seq[stopwords.Match]) string {
result := make([]string, 0)
for m := range ms {
result = append(result, m.Word)
}
return strings.Join(result, " ")
}

func TestFind_English(t *testing.T) {
is := is.New(t)
sw := stopwords.MustGet("en")

is.Equal(iter2text(sw.Find("never gonna give you up")), "never give you up")
is.Equal(iter2text(sw.Find("I want an")), "I want an")
}

func TestExclude_English(t *testing.T) {
is := is.New(t)
sw := stopwords.MustGet("en")

is.Equal(iter2text(sw.Exclude("never gonna give you up")), "gonna")
is.Equal(iter2text(sw.Exclude("I want an apple")), "apple")
}

0 comments on commit a7db7a4

Please sign in to comment.