Skip to content

Commit

Permalink
up(dump,arr): update some dump, arr check func logic
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Apr 9, 2022
1 parent 5137df3 commit dec75c4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
7 changes: 5 additions & 2 deletions arrutil/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func Int64sHas(ints []int64, val int64) bool {
return false
}

// InStrings alias of StringsHas()
func InStrings(elem string, ss []string) bool { return StringsHas(ss, elem) }

// StringsHas check the []string contains the given element
func StringsHas(ss []string, val string) bool {
for _, ele := range ss {
Expand All @@ -37,12 +40,12 @@ func StringsHas(ss []string, val string) bool {
return false
}

// HasValue check array(strings, intXs, uintXs) should be contains the given value(int(X),string).
// HasValue check array(strings, intXs, uintXs) should be contained the given value(int(X),string).
func HasValue(arr, val interface{}) bool {
return Contains(arr, val)
}

// Contains check array(strings, intXs, uintXs) should be contains the given value(int(X),string).
// Contains check array(strings, intXs, uintXs) should be contained the given value(int(X),string).
func Contains(arr, val interface{}) bool {
if val == nil || arr == nil {
return false
Expand Down
3 changes: 3 additions & 0 deletions arrutil/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ func TestStringsHas(t *testing.T) {
ss := []string{"a", "b"}
assert.True(t, arrutil.StringsHas(ss, "a"))
assert.True(t, arrutil.StringsHas(ss, "b"))
assert.True(t, arrutil.InStrings("b", ss))

assert.False(t, arrutil.StringsHas(ss, "c"))
assert.False(t, arrutil.InStrings("c", ss))
}

func TestContains(t *testing.T) {
Expand Down
6 changes: 1 addition & 5 deletions dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ func Fprint(w io.Writer, vs ...interface{}) {
func Format(vs ...interface{}) string {
w := &bytes.Buffer{}

NewWithOptions(func(opts *Options) {
opts.Output = w
opts.ShowFlag = Fnopos
}).Println(vs...)

std2.Fprint(w, vs...)
return w.String()
}

Expand Down

0 comments on commit dec75c4

Please sign in to comment.