How to use hasStr method of got Package

Best Got code snippet using got.hasStr

assertions.go

Source:assertions.go Github

copy

Full Screen

...175// Has asserts that container has item.176// The container can be a string, []byte, slice, array, or map177func (as Assertions) Has(container, item interface{}) {178	as.Helper()179	if c, ok := container.(string); ok && hasStr(c, item) {180		return181	} else if c, ok := container.([]byte); ok && hasStr(string(c), item) {182		return183	}184	cv := reflect.Indirect(reflect.ValueOf(container))185	switch cv.Kind() {186	case reflect.Slice, reflect.Array:187		for i := 0; i < cv.Len(); i++ {188			if utils.SmartCompare(cv.Index(i).Interface(), item) == 0 {189				return190			}191		}192	case reflect.Map:193		keys := cv.MapKeys()194		for _, k := range keys {195			if utils.SmartCompare(cv.MapIndex(k).Interface(), item) == 0 {196				return197			}198		}199	}200	as.err(AssertionHas, container, item)201}202// Len asserts that the length of list equals l203func (as Assertions) Len(list interface{}, l int) {204	as.Helper()205	actual := reflect.ValueOf(list).Len()206	if actual == l {207		return208	}209	as.err(AssertionLen, actual, l, list)210}211// Err asserts that the last item in args is error212func (as Assertions) Err(args ...interface{}) {213	as.Helper()214	if len(args) == 0 {215		as.err(AssertionNoArgs)216		return217	}218	last := args[len(args)-1]219	if err, _ := last.(error); err != nil {220		return221	}222	as.err(AssertionErr, last, args)223}224// E is a shortcut for Must().Nil(args...)225func (as Assertions) E(args ...interface{}) {226	as.Helper()227	as.Must().Nil(args...)228}229// Panic executes fn and asserts that fn panics230func (as Assertions) Panic(fn func()) (val interface{}) {231	as.Helper()232	defer func() {233		as.Helper()234		val = recover()235		if val == nil {236			as.err(AssertionPanic, fn)237		}238	}()239	fn()240	return241}242// Is asserts that x is kind of y, it uses reflect.Kind to compare.243// If x and y are both error type, it will use errors.Is to compare.244func (as Assertions) Is(x, y interface{}) {245	as.Helper()246	if x == nil && y == nil {247		return248	}249	if ae, ok := x.(error); ok {250		if be, ok := y.(error); ok {251			if ae == be {252				return253			}254			if errors.Is(ae, be) {255				return256			}257			as.err(AssertionIsInChain, x, y)258			return259		}260	}261	at := reflect.TypeOf(x)262	bt := reflect.TypeOf(y)263	if x != nil && y != nil && at.Kind() == bt.Kind() {264		return265	}266	as.err(AssertionIsKind, x, y)267}268// Count asserts that the returned function will be called n times269func (as Assertions) Count(n int) func() {270	as.Helper()271	count := int64(0)272	as.Cleanup(func() {273		c := int(atomic.LoadInt64(&count))274		if c != n {275			as.Helper()276			as.err(AssertionCount, n, c)277		}278	})279	return func() {280		atomic.AddInt64(&count, 1)281	}282}283func (as Assertions) err(t AssertionErrType, details ...interface{}) {284	as.Helper()285	if as.desc != "" {286		as.Logf("%s", as.desc)287	}288	// TODO: we should take advantage of the Helper function289	_, f, l, _ := runtime.Caller(2)290	c := &AssertionCtx{291		Type:    t,292		Details: details,293		File:    f,294		Line:    l,295	}296	as.Logf("%s", as.ErrorHandler.Report(c))297	if as.must {298		as.FailNow()299		return300	}301	as.Fail()302}303// the first return value is true if x is nilable304func isNil(x interface{}) (bool, bool) {305	if x == nil {306		return true, true307	}308	val := reflect.ValueOf(x)309	k := val.Kind()310	nilable := k == reflect.Chan ||311		k == reflect.Func ||312		k == reflect.Interface ||313		k == reflect.Map ||314		k == reflect.Ptr ||315		k == reflect.Slice316	if nilable {317		return true, val.IsNil()318	}319	return false, false320}321func hasStr(c string, item interface{}) bool {322	if it, ok := item.(string); ok {323		if strings.Contains(c, it) {324			return true325		}326	} else if it, ok := item.([]byte); ok {327		if strings.Contains(c, string(it)) {328			return true329		}330	} else if it, ok := item.(rune); ok {331		if strings.ContainsRune(c, it) {332			return true333		}334	}335	return false...

Full Screen

Full Screen

common.go

Source:common.go Github

copy

Full Screen

...215func fileExists(filepath string) bool {216	_, err := os.Stat(filepath)217	return err == nil218}219func hasStr(a []string, x string) bool {220	for _, n := range a {221		if x == n {222			return true223		}224	}225	return false226}227func delSliceElement(a []string, x string) []string {228	b := make([]string, 0)229	for _, y := range a {230		if y != x {231			b = append(b, y)232		}233	}234	return b235}236func sortIPSlice(ips []string) []string {237	ipmap := map[string]string{}238	ipns := []string{}239	for _, ip := range ips {240		if ip == "" {241			continue242		}243		ipstrs := strings.Split(ip, ".")244		for i, ipstr := range ipstrs {245			ipstrs[i] = fmt.Sprintf("%03s", ipstr)246		}247		ipstr := strings.Join(ipstrs, "")248		ipmap[ipstr] = ip249		ipns = append(ipns, ipstr)250	}251	sort.Strings(ipns)252	newIPs := make([]string, len(ipns))253	for i, ipn := range ipns {254		newIPs[i] = ipmap[ipn]255	}256	return newIPs257}258func checkID(id string) bool {259	return regexp.MustCompile(`^[a-zA-Z0-9\.\_\-]+$`).Match([]byte(id))260}261func getRemovedElesFromSlice(a, b []string) []string {262	c := make([]string, 0)263	for _, ae := range a {264		if hasStr(b, ae) == false {265			c = append(c, ae)266		}267	}268	return c269}...

Full Screen

Full Screen

kits_test.go

Source:kits_test.go Github

copy

Full Screen

1// Copyright (c) 2017-2022 Roland Schultheiß. All rights reserved.2// License information can be found in the LICENSE file.3package forge4import (5	"testing"6)7// =============================================================================8/*func TestSample_InferKit(t *testing.T) {9	conf := Config{10		KitFolder: "",11	}12	type test struct {13		inSample Sample14		want     string // kit name15	}16	tests := []test{17		{18			Sample{Loci: []Locus{{ID: "SE33"}, {ID: "VWA"}, {ID: "TH01"}}},19			"PPL ESX17",20		},21		{22			Sample{Loci: []Locus{{ID: "FGA"}, {ID: "D3S1358"}, {ID: "SE33"}}},23			"NGM-Detect",24		},25		{26			Sample{Loci: []Locus{{ID: "DYS19"}, {ID: "DYS391"}, {ID: "DYS448"}}},27			"PPL Y23",28		},29		{30			Sample{Loci: []Locus{{ID: "SE33"}, {ID: "VWA"}, {ID: "DYS385"}}},31			"unknown Kit",32		},33	}34	for i, tc := range tests {35		tc.inSample.InferKit()36		if tc.inSample.Kit.ID != tc.want {37			t.Fatalf("test %d: expected: %v, got: %v", i+1, tc.want, tc.inSample.Kit.ID)38		}39	}40}41*/42// =============================================================================43func TestKit_HasSTR(t *testing.T) {44	type test struct {45		inKit Kit46		inSTR string47		want  bool48	}49	tests := []test{50		{51			Kit{52				ID: "Ifiler Plus",53				STRs: []STR{54					{ID: "D8S1179", Dye: "blue"},55					{ID: "D21S11", Dye: "blue"},56					{ID: "D7S820", Dye: "blue"},57					{ID: "CSF1PO", Dye: "blue"},58					{ID: "D3S1358", Dye: "green"},59					{ID: "TH01", Dye: "green"},60					{ID: "D13S317", Dye: "green"},61					{ID: "D16S539", Dye: "green"},62					{ID: "D2S1338", Dye: "green"},63					{ID: "D19S433", Dye: "yellow"},64					{ID: "VWA", Dye: "yellow"},65					{ID: "TPOX", Dye: "yellow"},66					{ID: "D18S51", Dye: "yellow"},67					{ID: "AMEL", Dye: "red"},68					{ID: "D5S818", Dye: "red"},69					{ID: "FGA", Dye: "red"},70				},71			},72			"D19S433",73			true,74		},75		{76			Kit{77				ID: "Ifiler Plus",78				STRs: []STR{79					{ID: "D8S1179", Dye: "blue"},80					{ID: "D21S11", Dye: "blue"},81					{ID: "D7S820", Dye: "blue"},82					{ID: "CSF1PO", Dye: "blue"},83					{ID: "D3S1358", Dye: "green"},84					{ID: "TH01", Dye: "green"},85					{ID: "D13S317", Dye: "green"},86					{ID: "D16S539", Dye: "green"},87					{ID: "D2S1338", Dye: "green"},88					{ID: "D19S433", Dye: "yellow"},89					{ID: "VWA", Dye: "yellow"},90					{ID: "TPOX", Dye: "yellow"},91					{ID: "D18S51", Dye: "yellow"},92					{ID: "AMEL", Dye: "red"},93					{ID: "D5S818", Dye: "red"},94					{ID: "FGA", Dye: "red"},95				},96			},97			"DYS437",98			false,99		},100	}101	for i, tc := range tests {102		res := tc.inKit.HasSTR(tc.inSTR)103		if res != tc.want {104			t.Fatalf("test %d: expected: %v, got: %v", i+1, tc.want, res)105		}106	}107}...

Full Screen

Full Screen

hasStr

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3	fmt.Println(got.hasStr("hello"))4}5import "fmt"6func main() {7	fmt.Println(got.hasStr("hello"))8}9import "fmt"10func main() {11	fmt.Println(got.hasStr("hello"))12}13import "fmt"14func main() {15	fmt.Println(got.hasStr("hello"))16}17import "fmt"18func main() {19	fmt.Println(got.hasStr("hello"))20}21import "fmt"22func main() {23	fmt.Println(got.hasStr("hello"))24}25import "fmt"26func main() {27	fmt.Println(got.hasStr("hello"))28}29import "fmt"30func main() {31	fmt.Println(got.hasStr("hello"))32}33import "fmt"34func main() {35	fmt.Println(got.hasStr("hello"))36}37import "fmt"38func main() {39	fmt.Println(got.hasStr("hello"))40}41import "fmt"42func main() {43	fmt.Println(got.hasStr("hello"))44}45import "fmt"46func main() {47	fmt.Println(got.hasStr("hello"))48}49import "fmt"50func main() {51	fmt.Println(got.hasStr("hello"))52}

Full Screen

Full Screen

hasStr

Using AI Code Generation

copy

Full Screen

1func main(){2    got := got{}3    got.hasStr("Hello")4}5func main(){6    got := got{}7    got.hasStr("Hello")8}

Full Screen

Full Screen

hasStr

Using AI Code Generation

copy

Full Screen

1import (2func main() {3	fmt.Println(got.HasStr("hello", "ll"))4}5func HasStr(s, substr string) bool {6	return strings.Contains(s, substr)7}8import "testing"9func TestHasStr(t *testing.T) {10	if !HasStr("hello", "ll") {11		t.Error("HasStr failed")12	}13}14import "strings"15func HasStr(s, substr string) bool {16	return strings.Contains(s, substr)17}18import "testing"19func TestHasStr(t *testing.T) {20	if !HasStr("hello", "ll") {21		t.Error("HasStr failed")22	}23}24import "strings"25func HasStr(s, substr string) bool {26	return strings.Contains(s, substr)27}28import "testing"29func TestHasStr(t *testing.T) {30	if !HasStr("hello", "ll") {31		t.Error("HasStr failed")32	}33}34import "strings"35func HasStr(s, substr string) bool {36	return strings.Contains(s, substr)37}38import "testing"39func TestHasStr(t *testing.T) {40	if !HasStr("hello", "ll") {41		t.Error("HasStr failed")42	}43}44import "strings"45func HasStr(s, substr string) bool {46	return strings.Contains(s, substr)47}48import "testing"49func TestHasStr(t *testing.T) {50	if !HasStr("hello", "ll") {51		t.Error("HasStr failed")52	}53}54import "strings"55func HasStr(s, substr string) bool {56	return strings.Contains(s, substr)57}58import "testing"59func TestHasStr(t *testing.T) {60	if !HasStr("hello", "ll") {61		t.Error("HasStr failed")62	}63}64import

Full Screen

Full Screen

hasStr

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3    fmt.Println("Hello, World!")4    got := got{"Hello World"}5    fmt.Println(got.hasStr("Hello"))6    fmt.Println(got.hasStr("World"))7}

Full Screen

Full Screen

hasStr

Using AI Code Generation

copy

Full Screen

1func main() {2    got := got{}3    fmt.Println(got.hasStr(str))4}5        /usr/local/go/src/got (from $GOROOT)6        /home/sam/go/src/got (from $GOPATH)7        /usr/local/go/src/fmt (from $GOROOT)8        /home/sam/go/src/fmt (from $GOPATH)9        /usr/local/go/src/got (from $GOROOT)10        /home/sam/go/src/got (from $GOPATH)11        /usr/local/go/src/fmt (from $GOROOT)12        /home/sam/go/src/fmt (from $GOPATH)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful