Beispiel #1
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
}
Beispiel #2
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
	}))
}
Beispiel #3
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
}
Beispiel #4
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
}
Beispiel #5
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)
}
Beispiel #6
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())

}
Beispiel #7
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()
}