Exemplo n.º 1
0
func TestStringSliceReduce(t *testing.T) {
	l := util.StringSlice{"Maybe", "GoLang", "should"}
	assert.EqualValues(t, []string{"GoLang"}, l.Reduce(func(s string) bool {
		return s == "GoLang"
	}).ToString())
	assert.Len(t, l, 1)
}
Exemplo n.º 2
0
// BenchmarkStringSliceUnique	 2000000	       612 ns/op	     160 B/op	       2 allocs/op <- Go 1.4.2
// BenchmarkStringSliceUnique  	10000000	       179 ns/op	     128 B/op	       1 allocs/op <- Go 1.5
func BenchmarkStringSliceUnique(b *testing.B) {
	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		l := util.StringSlice{"Maybe", "GoLang", "GoLang", "GoLang", "or", "or", "RostLang", "RostLang"}
		l.Unique()
		benchStringSliceUnique = l
	}
}
Exemplo n.º 3
0
func TestStringSliceAny(t *testing.T) {
	l := util.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"
	}))
}
Exemplo n.º 4
0
func defaultIsCountryAllowed(_ *store.Store, c *IPCountry, allowedCountries util.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
}
Exemplo n.º 5
0
// Human readable representation of the permissions
func (bits Perm) Human() util.StringSlice {
	var ret util.StringSlice
	for i := uint(0); i < 64; i++ {
		bit := ((bits & (1 << i)) != 0)
		if bit {
			ret.Append(Scope(i).String())
		}
	}
	return ret
}
Exemplo n.º 6
0
func TestStringSliceFilter(t *testing.T) {
	l := util.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)
}
Exemplo n.º 7
0
// Codes returns a StringSlice with all store codes
func (ss StoreSlice) Codes() util.StringSlice {
	if len(ss) == 0 {
		return nil
	}
	var c util.StringSlice
	for _, st := range ss {
		if st != nil {
			c.Append(st.Data.Code.String)
		}
	}
	return c
}
Exemplo n.º 8
0
// Codes returns a StringSlice with all website codes
func (ws WebsiteSlice) Codes() util.StringSlice {
	if len(ws) == 0 {
		return nil
	}
	var c util.StringSlice
	for _, w := range ws {
		if w != nil {
			c.Append(w.Data.Code.String)
		}
	}
	return c
}
Exemplo n.º 9
0
// BenchmarkStringSliceReduceContains	 1000000	      1841 ns/op	      96 B/op	       2 allocs/op <- Go 1.4.2
// BenchmarkStringSliceReduceContains-4	 1000000	      1250 ns/op	      64 B/op	       1 allocs/op <- Go 1.5
func BenchmarkStringSliceReduceContains(b *testing.B) {

	b.ReportAllocs()
	for i := 0; i < b.N; i++ {
		l := util.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
	}
}
Exemplo n.º 10
0
func getImportPaths() []string {
	var paths util.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()
}
Exemplo n.º 11
0
func TestStringSliceAll(t *testing.T) {
	l := util.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
	}))
}
Exemplo n.º 12
0
func TestStringSliceSplitStringer8(t *testing.T) {
	tests := []struct {
		haveName  string
		haveIndex []uint8
		want      util.StringSlice
	}{
		{
			"ScopeAbsentScopeDefaultScopeWebsiteScopeGroupScopeStore",
			[]uint8{0, 11, 23, 35, 45, 55},
			util.StringSlice{"ScopeAbsent", "ScopeDefault", "ScopeWebsite", "ScopeGroup", "ScopeStore"},
		},
		{
			"TypeCustomTypeHiddenTypeObscureTypeMultiselectTypeSelectTypeTextTypeTime",
			[]uint8{10, 20, 31, 46, 56, 64, 72},
			util.StringSlice{"TypeHidden", "TypeObscure", "TypeMultiselect", "TypeSelect", "TypeText", "TypeTime"},
		},
	}
	for _, test := range tests {
		var a util.StringSlice
		have := a.SplitStringer8(test.haveName, test.haveIndex...)
		assert.Exactly(t, test.want, have)
	}
}
Exemplo n.º 13
0
func TestStringSliceSort(t *testing.T) {
	l := util.StringSlice{"c", "a", "z", "b"}
	assert.Equal(t, "a,b,c,z", l.Sort().Join(","))
}
Exemplo n.º 14
0
func TestStringSliceDelete(t *testing.T) {
	l := util.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), util.ErrOutOfRange.Error())
}
Exemplo n.º 15
0
func TestStringSliceUnique(t *testing.T) {
	l := util.StringSlice{"Maybe", "GoLang", "GoLang", "GoLang", "or", "or", "RostLang", "RostLang"}
	assert.Equal(t, []string{"Maybe", "GoLang", "or", "RostLang"}, l.Unique().ToString())
}
Exemplo n.º 16
0
func TestStringSlice(t *testing.T) {
	l := util.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 := util.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())

}
Exemplo n.º 17
0
func TestStringSliceJoin(t *testing.T) {
	l := util.StringSlice{"a", "b"}
	assert.Equal(t, "a,b", l.Join(","))
}
Exemplo n.º 18
0
func TestStringSliceSplit(t *testing.T) {
	l := util.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())
}