How to use TestContains method of td_test Package

Best Go-testdeep code snippet using td_test.TestContains

td_contains_test.go

Source:td_contains_test.go Github

copy

Full Screen

...10 "reflect"11 "testing"12 "github.com/maxatome/go-testdeep/td"13)14func TestContains(t *testing.T) {15 type (16 MySlice []int17 MyArray [3]int18 MyMap map[string]int19 MyString string20 )21 for idx, got := range []any{22 []int{12, 34, 28},23 MySlice{12, 34, 28},24 [...]int{12, 34, 28},25 MyArray{12, 34, 28},26 map[string]int{"foo": 12, "bar": 34, "zip": 28},27 MyMap{"foo": 12, "bar": 34, "zip": 28},28 } {29 testName := fmt.Sprintf("#%d: got=%v", idx, got)30 checkOK(t, got, td.Contains(34), testName)31 checkOK(t, got, td.Contains(td.Between(30, 35)), testName)32 checkError(t, got, td.Contains(35),33 expectedError{34 Message: mustBe("does not contain"),35 Path: mustBe("DATA"),36 Got: mustContain("34"), // as well as other items in fact...37 Expected: mustBe("Contains(35)"),38 }, testName)39 // Lax40 checkOK(t, got, td.Lax(td.Contains(float64(34))), testName)41 }42 for idx, got := range []any{43 "foobar",44 MyString("foobar"),45 } {46 testName := fmt.Sprintf("#%d: got=%v", idx, got)47 checkOK(t, got, td.Contains(td.Between('n', 'p')), testName)48 checkError(t, got, td.Contains(td.Between('y', 'z')),49 expectedError{50 Message: mustBe("does not contain"),51 Path: mustBe("DATA"),52 Got: mustContain(`"foobar"`), // as well as other items in fact...53 Expected: mustBe(fmt.Sprintf("Contains((int32) %d ≤ got ≤ (int32) %d)", 'y', 'z')),54 }, testName)55 }56}57// nil case.58func TestContainsNil(t *testing.T) {59 type (60 MyPtrSlice []*int61 MyPtrArray [3]*int62 MyPtrMap map[string]*int63 )64 num := 1234564265 for idx, got := range []any{66 []*int{&num, nil},67 MyPtrSlice{&num, nil},68 [...]*int{&num, nil},69 MyPtrArray{&num},70 map[string]*int{"foo": &num, "bar": nil},71 MyPtrMap{"foo": &num, "bar": nil},72 } {73 testName := fmt.Sprintf("#%d: got=%v", idx, got)74 checkOK(t, got, td.Contains(nil), testName)75 checkOK(t, got, td.Contains((*int)(nil)), testName)76 checkOK(t, got, td.Contains(td.Nil()), testName)77 checkOK(t, got, td.Contains(td.NotNil()), testName)78 checkError(t, got, td.Contains((*uint8)(nil)),79 expectedError{80 Message: mustBe("does not contain"),81 Path: mustBe("DATA"),82 Got: mustContain("12345642"),83 Expected: mustBe("Contains((*uint8)(<nil>))"),84 }, testName)85 }86 for idx, got := range []any{87 []any{nil, 12345642},88 []func(){nil, func() {}},89 [][]int{{}, nil},90 [...]any{nil, 12345642},91 [...]func(){nil, func() {}},92 [...][]int{{}, nil},93 map[bool]any{true: nil, false: 12345642},94 map[bool]func(){true: nil, false: func() {}},95 map[bool][]int{true: {}, false: nil},96 } {97 testName := fmt.Sprintf("#%d: got=%v", idx, got)98 checkOK(t, got, td.Contains(nil), testName)99 checkOK(t, got, td.Contains(td.Nil()), testName)100 checkOK(t, got, td.Contains(td.NotNil()), testName)101 }102 for idx, got := range []any{103 []int{1, 2, 3},104 [...]int{1, 2, 3},105 map[string]int{"foo": 12, "bar": 34, "zip": 28},106 } {107 testName := fmt.Sprintf("#%d: got=%v", idx, got)108 checkError(t, got, td.Contains(nil),109 expectedError{110 Message: mustBe("does not contain"),111 Path: mustBe("DATA"),112 // Got113 Expected: mustBe("Contains(nil)"),114 }, testName)115 }116 checkError(t, "foobar", td.Contains(nil),117 expectedError{118 Message: mustBe("cannot check contains"),119 Path: mustBe("DATA"),120 Got: mustBe("string"),121 Expected: mustBe("Contains(nil)"),122 })123 // Caught by deepValueEqual, before Match() call124 checkError(t, nil, td.Contains(nil),125 expectedError{126 Message: mustBe("values differ"),127 Path: mustBe("DATA"),128 Got: mustBe("nil"),129 Expected: mustBe("Contains(nil)"),130 })131}132func TestContainsString(t *testing.T) {133 type MyString string134 for idx, got := range []any{135 "pipo bingo",136 MyString("pipo bingo"),137 []byte("pipo bingo"),138 errors.New("pipo bingo"), // error interface139 MyStringer{}, // fmt.Stringer interface140 } {141 testName := fmt.Sprintf("#%d: got=%v", idx, got)142 checkOK(t, got, td.Contains("pipo"), testName)143 checkOK(t, got, td.Contains("po bi"), testName)144 checkOK(t, got, td.Contains("bingo"), testName)145 checkOK(t, got, td.Contains([]byte("pipo")), testName)146 checkOK(t, got, td.Contains([]byte("po bi")), testName)147 checkOK(t, got, td.Contains([]byte("bingo")), testName)148 checkOK(t, got, td.Contains('o'), testName)149 checkOK(t, got, td.Contains(byte('o')), testName)150 checkOK(t, got, td.Contains(""), testName)151 checkOK(t, got, td.Contains([]byte{}), testName)152 if _, ok := got.([]byte); ok {153 checkOK(t, got,154 td.Contains(td.Code(func(b byte) bool { return b == 'o' })),155 testName)156 } else {157 checkOK(t, got,158 td.Contains(td.Code(func(r rune) bool { return r == 'o' })),159 testName)160 }161 checkError(t, got, td.Contains("zip"),162 expectedError{163 Message: mustBe("does not contain"),164 Path: mustBe("DATA"),165 Got: mustContain(`pipo bingo`),166 Expected: mustMatch(`^Contains\(.*"zip"`),167 })168 checkError(t, got, td.Contains([]byte("zip")),169 expectedError{170 Message: mustBe("does not contain"),171 Path: mustBe("DATA"),172 Got: mustContain(`pipo bingo`),173 Expected: mustMatch(`^(?s)Contains\(.*zip`),174 })175 checkError(t, got, td.Contains('z'),176 expectedError{177 Message: mustBe("does not contain"),178 Path: mustBe("DATA"),179 Got: mustContain(`pipo bingo`),180 Expected: mustBe(`Contains((int32) 122)`),181 })182 checkError(t, got, td.Contains(byte('z')),183 expectedError{184 Message: mustBe("does not contain"),185 Path: mustBe("DATA"),186 Got: mustContain(`pipo bingo`),187 Expected: mustBe(`Contains((uint8) 122)`),188 })189 checkError(t, got, td.Contains(12),190 expectedError{191 Message: mustBe("cannot check contains"),192 Path: mustBe("DATA"),193 Got: mustBe(reflect.TypeOf(got).String()),194 Expected: mustBe("int"),195 })196 checkError(t, got, td.Contains([]int{1, 2, 3}),197 expectedError{198 Message: mustBe("cannot check contains"),199 Path: mustBe("DATA"),200 Got: mustBe(reflect.TypeOf(got).String()),201 Expected: mustBe("[]int"),202 })203 // Lax204 checkOK(t, got,205 td.Lax(td.Contains(td.Code(func(b int) bool { return b == 'o' }))),206 testName)207 }208 checkError(t, 12, td.Contains("bar"),209 expectedError{210 Message: mustBe("bad type"),211 Path: mustBe("DATA"),212 Got: mustBe("int"),213 Expected: mustBe("string (convertible) OR []byte (convertible) OR fmt.Stringer OR error"),214 })215 checkError(t, "pipo", td.Contains(td.Code(func(x int) bool { return true })),216 expectedError{217 Message: mustBe("Code operator has to match rune in string, but it does not"),218 Path: mustBe("DATA"),219 Got: mustBe("int"),220 Expected: mustBe("rune"),221 })222}223func TestContainsSlice(t *testing.T) {224 got := []int{1, 2, 3, 4, 5, 6}225 // Empty slice is always OK226 checkOK(t, got, td.Contains([]int{}))227 // Expected length > got length228 checkError(t, got, td.Contains([]int{1, 2, 3, 4, 5, 6, 7}),229 expectedError{230 Message: mustBe("does not contain"),231 Path: mustBe("DATA"),232 Got: mustContain(`([]int) (len=6 `),233 Expected: mustContain(`Contains(([]int) (len=7 `),234 })235 // Same length236 checkOK(t, got, td.Contains([]int{1, 2, 3, 4, 5, 6}))237 checkError(t, got, td.Contains([]int{8, 8, 8, 8, 8, 8}),238 expectedError{239 Message: mustBe("does not contain"),240 Path: mustBe("DATA"),241 Got: mustContain(`([]int) (len=6 `),242 Expected: mustContain(`Contains(([]int) (len=6 `),243 })244 checkOK(t, got, td.Contains([]int{1, 2, 3}))245 checkOK(t, got, td.Contains([]int{3, 4, 5}))246 checkOK(t, got, td.Contains([]int{4, 5, 6}))247 checkError(t, got, td.Contains([]int{8, 8, 8}),248 expectedError{249 Message: mustBe("does not contain"),250 Path: mustBe("DATA"),251 Got: mustContain(`([]int) (len=6 `),252 Expected: mustContain(`Contains(([]int) (len=3 `),253 })254}255func TestContainsTypeBehind(t *testing.T) {256 equalTypes(t, td.Contains("x"), nil)257}...

Full Screen

Full Screen

TestContains

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 fmt.Println(td_test.TestContains(2, 2))4 fmt.Println(td_test.TestContains(2, 3))5 fmt.Println(td_test.TestContains(2, 4))6 fmt.Println(td_test.TestContains(2, 5))7 fmt.Println(td_test.TestContains(2, 6))8 fmt.Println(td_test.TestContains(2, 7))9 fmt.Println(td_test.TestContains(2, 8))10 fmt.Println(td_test.TestContains(2, 9))11 fmt.Println(td_test.TestContains(2, 10))12}

Full Screen

Full Screen

TestContains

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main() {3 td = td_test{1,2,3,4,5}4 fmt.Println(td.TestContains(2))5 fmt.Println(td.TestContains(6))6}

Full Screen

Full Screen

TestContains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 td_test.TestContains()4}5import (6func main() {7 td_test.TestContainsAny()8}9import (10func main() {11 td_test.TestContainsRune()12}13import (14func main() {15 td_test.TestCount()16}17import (18func main() {19 td_test.TestHasPrefix()20}21import (22func main() {23 td_test.TestHasSuffix()24}25import (26func main() {27 td_test.TestIndex()28}29import (30func main() {31 td_test.TestIndexAny()32}33import (34func main() {35 td_test.TestIndexByte()36}37import (38func main() {39 td_test.TestIndexRune()40}41import (

Full Screen

Full Screen

TestContains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 td1.SetData(1, 2, 3, 4)4 fmt.Println(td1.TestContains(4))5 fmt.Println(td1.TestContains(5))6}7import (8func main() {9 td1.SetData(1, 2, 3, 4)10 fmt.Println(td1.TestContains(4))11 fmt.Println(td1.TestContains(5))12}13import (14func main() {15 td1.SetData(1, 2, 3, 4)16 fmt.Println(td1.TestContains(4))17 fmt.Println(td1.TestContains(5))18}19import (20func main() {21 td1.SetData(1, 2, 3, 4)22 fmt.Println(td1.TestContains(4))23 fmt.Println(td1.TestContains(5))24}25import (26func main() {27 td1.SetData(1, 2, 3, 4)28 fmt.Println(td1.TestContains(4))29 fmt.Println(td1.TestContains(5))30}31import (32func main() {33 td1.SetData(1, 2, 3, 4)34 fmt.Println(td1.TestContains(4))35 fmt.Println(td1.TestContains(5))36}37import (38func main() {39 td1.SetData(1

Full Screen

Full Screen

TestContains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 td := test.NewTestContains()4 fmt.Println(td.TestContains("Hello", "H"))5}6import (7func main() {8 td := test.NewTestContainsAny()9 fmt.Println(td.TestContainsAny("Hello", "H"))10}11import (12func main() {13 td := test.NewTestContainsRune()14 fmt.Println(td.TestContainsRune("Hello", "H"))15}16import (17func main() {18 td := test.NewTestCount()19 fmt.Println(td.TestCount("Hello", "H"))20}21import (22func main() {23 td := test.NewTestHasPrefix()24 fmt.Println(td.TestHasPrefix("Hello", "H"))25}26import (27func main() {28 td := test.NewTestHasSuffix()29 fmt.Println(td.TestHasSuffix("Hello", "o"))30}31import (32func main() {33 td := test.NewTestIndex()34 fmt.Println(td.TestIndex("Hello", "l"))35}36import (37func main() {38 td := test.NewTestIndexAny()39 fmt.Println(td.TestIndexAny("Hello", "l"))40}41import (42func main() {43 td := test.NewTestIndexRune()44 fmt.Println(td.TestIndexRune("Hello",

Full Screen

Full Screen

TestContains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 test := td.NewTest()4 fmt.Println(test.Contains("hello", "ll"))5}6import (7func main() {8 test := td.NewTest()9 fmt.Println(test.Contains("hello", "ll"))10}11import (12func main() {13 test := td.NewTest()14 fmt.Println(test.Contains("hello", "ll"))15}16import (17func main() {18 test := td.NewTest()19 fmt.Println(test.Contains("hello", "ll"))20}21import (22func main() {23 test := td.NewTest()24 fmt.Println(test.Contains("hello", "ll"))25}26import (27func main() {28 test := td.NewTest()29 fmt.Println(test.Contains("hello", "ll"))30}31import (32func main() {33 test := td.NewTest()34 fmt.Println(test.Contains("hello", "ll"))35}

Full Screen

Full Screen

TestContains

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(td.TestContains("Hello", "H"))4 fmt.Println(td.TestContains("Hello", "h"))5}6import (7func main() {8 fmt.Println(td.TestContains("Hello", "H"))9 fmt.Println(td.TestContains("Hello", "h"))10}11import (12func main() {13 fmt.Println(td.TestContains("Hello", "H"))14 fmt.Println(td.TestContains("Hello", "h"))15}16import (17func main() {18 fmt.Println(td.TestContains("Hello", "H"))19 fmt.Println(td.TestContains("Hello", "h"))20}21import (22func main() {23 fmt.Println(td.TestContains("Hello", "H"))24 fmt.Println(td.TestContains("Hello", "h"))25}26import (27func main() {28 fmt.Println(td.TestContains("Hello", "H"))29 fmt.Println(td.TestContains("Hello", "h

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.

Run Go-testdeep automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful