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