mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-09-08 10:14:35 +08:00
refactor: use slices.Contains to simplify code (#16680)
### Summary There is a [new function](https://pkg.go.dev/slices@go1.21.0#Contains) added in the go1.21 standard library, which can make the code more concise and easy to read. Signed-off-by: weifanglab <weifanglab@outlook.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
@@ -713,14 +714,7 @@ func TestPretokenWithNumbers(t *testing.T) {
|
||||
t.Run("num=false filters single digits", func(t *testing.T) {
|
||||
result := d.Pretoken("5", false, true)
|
||||
// Single digit should be filtered when num=false
|
||||
found := false
|
||||
for _, r := range result {
|
||||
if r == "5" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
if slices.Contains(result, "5") {
|
||||
t.Error("Single digit should be filtered when num=false")
|
||||
}
|
||||
})
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"slices"
|
||||
"sort"
|
||||
"testing"
|
||||
)
|
||||
@@ -122,14 +123,7 @@ func TestSynsets(t *testing.T) {
|
||||
names[i] = s.Name
|
||||
}
|
||||
for _, expectedName := range tt.checkNames {
|
||||
found := false
|
||||
for _, name := range names {
|
||||
if name == expectedName {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
if !slices.Contains(names, expectedName) {
|
||||
t.Errorf("Synsets(%q, %q) did not contain expected synset %q, got %v",
|
||||
tt.lemma, tt.pos, expectedName, names)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user