Example #1
0
func TestStringSliceReduce(t *testing.T) {
	l := utils.StringSlice{"Maybe", "GoLang", "should"}
	assert.EqualValues(t, []string{"GoLang"}, l.Reduce(func(s string) bool {
		return s == "GoLang"
	}).ToString())
	assert.Len(t, l, 1)
}
Example #2
0
// BenchmarkUnique	 2000000	       612 ns/op	     160 B/op	       2 allocs/op
func BenchmarkStringSliceUnique(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		l := utils.StringSlice{"Maybe", "GoLang", "GoLang", "GoLang", "or", "or", "RostLang", "RostLang"}
		l.Unique()
		benchStringSliceUnique = l
	}
}
Example #3
0
func TestStringSliceAny(t *testing.T) {
	l := utils.StringSlice{"c", "a", "z", "b"}
	assert.True(t, l.Any(func(s string) bool {
		return s == "z"
	}))
	assert.False(t, l.Any(func(s string) bool {
		return s == "zx"
	}))
}
Example #4
0
func defaultIsCountryAllowed(_ *store.Store, c *IPCountry, allowedCountries utils.StringSlice, r *http.Request) bool {
	if false == allowedCountries.Include(c.Country.Country.IsoCode) {
		if PkgLog.IsInfo() {
			PkgLog.Info("geoip.checkAllow", "IPCountry", c, "allowedCountries", allowedCountries, "request", r)
		}
		return false
	}
	return true
}
Example #5
0
// Human readable representation of the permissions
func (bits Perm) Human() utils.StringSlice {
	var ret utils.StringSlice
	var i uint
	for i = 0; i < 64; i++ {
		bit := ((bits & (1 << i)) != 0)
		if bit {
			ret.Append(Scope(i).String())
		}
	}
	return ret
}
Example #6
0
// Codes returns a StringSlice with all store codes
func (s StoreSlice) Codes() utils.StringSlice {
	if len(s) == 0 {
		return nil
	}
	var c utils.StringSlice
	for _, st := range s {
		if st != nil {
			c.Append(st.Data().Code.String)
		}
	}
	return c
}
Example #7
0
func TestStringSliceFilter(t *testing.T) {
	l := utils.StringSlice{"All", "Go", "Code", "is"}
	rl := l.Filter(func(s string) bool {
		return s == "Go"
	}).ToString()
	assert.EqualValues(t, []string{"Go"}, rl)
	assert.Len(t, l, 4)

	l.Append("incredible", "easy", ",", "sometimes")
	assert.Len(t, l, 8)
	assert.EqualValues(t, []string{"Go"}, rl)
}
Example #8
0
// Codes returns a StringSlice with all website codes
func (ws WebsiteSlice) Codes() utils.StringSlice {
	if len(ws) == 0 {
		return nil
	}
	var c utils.StringSlice
	for _, w := range ws {
		if w != nil {
			c.Append(w.Data.Code.String)
		}
	}
	return c
}
Example #9
0
// Codes returns a StringSlice with all store codes
func (s TableStoreSlice) Codes() utils.StringSlice {
	if len(s) == 0 {
		return nil
	}
	var c utils.StringSlice
	for _, store := range s {
		if store != nil {
			c.Append(store.Code.String)
		}
	}
	return c
}
Example #10
0
// BenchmarkReduceContains	 1000000	      1841 ns/op	      96 B/op	       2 allocs/op
func BenchmarkStringSliceReduceContains(b *testing.B) {

	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		l := utils.StringSlice{
			"IFNULL(`scope_table`.`is_visible`, `additional_table`.`is_visible`) AS `is_visible`",
			"IFNULL(`scope_table`.`is_required`, `main_table`.`is_required`) AS `is_required`",
			"IFNULL(`scope_table`.`default_value`, `main_table`.`default_value`) AS `default_value`",
			"IFNULL(`scope_table`.`multiline_count`, `additional_table`.`multiline_count`) AS `multiline_count`",
		}
		l.ReduceContains(benchStringSliceReduceContainsData...)
		benchStringSliceReduceContains = l
	}
}
Example #11
0
func getImportPaths() []string {
	var paths utils.StringSlice

	var getPath = func(s string) string {
		ps, err := codegen.ExtractImportPath(s)
		codegen.LogFatal(err)
		return ps
	}

	for _, et := range codegen.ConfigEntityType {
		paths.Append(
			getPath(et.EntityModel),
			getPath(et.AttributeModel),
			getPath(et.EntityTable),
			getPath(et.IncrementModel),
			getPath(et.AdditionalAttributeTable),
			getPath(et.EntityAttributeCollection),
		)
	}
	return paths.Unique().ToString()
}
Example #12
0
func TestStringSliceAll(t *testing.T) {
	l := utils.StringSlice{"c", "a", "z", "b"}
	assert.True(t, l.All(func(s string) bool {
		return len(s) == 1
	}))
	l.Append("xx")
	assert.False(t, l.All(func(s string) bool {
		return len(s) == 1
	}))
}
Example #13
0
func TestStringSliceSplitStringer8(t *testing.T) {
	tests := []struct {
		haveName  string
		haveIndex []uint8
		want      utils.StringSlice
	}{
		{
			"ScopeAbsentScopeDefaultScopeWebsiteScopeGroupScopeStore",
			[]uint8{0, 11, 23, 35, 45, 55},
			utils.StringSlice{"ScopeAbsent", "ScopeDefault", "ScopeWebsite", "ScopeGroup", "ScopeStore"},
		},
		{
			"TypeCustomTypeHiddenTypeObscureTypeMultiselectTypeSelectTypeTextTypeTime",
			[]uint8{10, 20, 31, 46, 56, 64, 72},
			utils.StringSlice{"TypeHidden", "TypeObscure", "TypeMultiselect", "TypeSelect", "TypeText", "TypeTime"},
		},
	}
	for _, test := range tests {
		var a utils.StringSlice
		have := a.SplitStringer8(test.haveName, test.haveIndex...)
		assert.Exactly(t, test.want, have)
	}
}
Example #14
0
func TestStringSliceSplit(t *testing.T) {
	l := utils.StringSlice{"a", "b"}
	assert.Equal(t, []string{"a", "b", "c", "d"}, l.Split("c,d", ",").ToString())
	assert.Equal(t, []string{"a", "b", "c", "d", "e", "f", ""}, l.Split("e,f,", ",").ToString())
}
Example #15
0
func TestStringSlice(t *testing.T) {
	l := utils.StringSlice{"Maybe", "GoLang", "should", "have", "generics", "but", "who", "needs", "them", "?", ";-)"}
	assert.Len(t, l, l.Len())
	assert.Equal(t, 1, l.Index("GoLang"))
	assert.Equal(t, -1, l.Index("Golang"))
	assert.True(t, l.Include("GoLang"))
	assert.False(t, l.Include("Golang"))

	l2 := utils.StringSlice{"Maybe", "GoLang"}
	l2.Map(func(s string) string {
		return s + "2"
	})
	assert.Equal(t, []string{"Maybe2", "GoLang2"}, l2.ToString())
	l2.Append("will", "be")
	assert.Equal(t, []string{"Maybe2", "GoLang2", "will", "be"}, l2.ToString())

}
Example #16
0
func TestStringSliceDelete(t *testing.T) {
	l := utils.StringSlice{"Maybe", "GoLang", "should"}
	assert.NoError(t, l.Delete(1))
	assert.Equal(t, []string{"Maybe", "should"}, l.ToString())
	assert.NoError(t, l.Delete(1))
	assert.Equal(t, []string{"Maybe"}, l.ToString())
	assert.EqualError(t, l.Delete(1), utils.ErrOutOfRange.Error())
}
Example #17
0
func TestStringSliceUnique(t *testing.T) {
	l := utils.StringSlice{"Maybe", "GoLang", "GoLang", "GoLang", "or", "or", "RostLang", "RostLang"}
	assert.Equal(t, []string{"Maybe", "GoLang", "or", "RostLang"}, l.Unique().ToString())
}
Example #18
0
func TestStringSliceJoin(t *testing.T) {
	l := utils.StringSlice{"a", "b"}
	assert.Equal(t, "a,b", l.Join(","))
}
Example #19
0
func TestStringSliceSort(t *testing.T) {
	l := utils.StringSlice{"c", "a", "z", "b"}
	assert.Equal(t, "a,b,c,z", l.Sort().Join(","))
}