Skip to content

Commit 9e5847f

Browse files
authored
docs: finish up examples (#136)
1 parent beadf51 commit 9e5847f

2 files changed

Lines changed: 236 additions & 72 deletions

File tree

examples_test.go

Lines changed: 118 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,11 @@ func ExampleDirExistsFS() {
232232
// Output:
233233
}
234234

235-
// DirNotExists
236235
func ExampleDirNotExists() {
237236
DirNotExists(t, "/does/not/exist")
238237
// Output:
239238
}
240239

241-
// DirNotExistsFS
242240
func ExampleDirNotExistsFS() {
243241
DirNotExistsFS(t, os.DirFS("/"), "does/not/exist")
244242
// Output:
@@ -257,14 +255,12 @@ func ExampleEq() {
257255
// Output:
258256
}
259257

260-
// EqError
261258
func ExampleEqError() {
262259
err := errors.New("undefined error")
263260
EqError(t, err, "undefined error")
264261
// Output:
265262
}
266263

267-
// EqFunc
268264
func ExampleEqFunc() {
269265
EqFunc(t, "abcd", "dcba", func(a, b string) bool {
270266
if len(a) != len(b) {
@@ -281,41 +277,35 @@ func ExampleEqFunc() {
281277
// Output:
282278
}
283279

284-
// EqJSON
285280
func ExampleEqJSON() {
286281
a := `{"foo":"bar","numbers":[1,2,3]}`
287282
b := `{"numbers":[1,2,3],"foo":"bar"}`
288283
EqJSON(t, a, b)
289284
// Output:
290285
}
291286

292-
// EqOp
293287
func ExampleEqOp() {
294288
EqOp(t, 123, 123)
295289
// Output:
296290
}
297291

298-
// Equal
299292
func ExampleEqual() {
300293
// score implements .Equal method
301294
Equal(t, score(1000), score(1000))
302295
// Output:
303296
}
304297

305-
// Error
306298
func ExampleError() {
307299
Error(t, errors.New("error"))
308300
// Output:
309301
}
310302

311-
// ErrorContains
312303
func ExampleErrorContains() {
313304
err := errors.New("error beer not found")
314305
ErrorContains(t, err, "beer")
315306
// Output:
316307
}
317308

318-
// ErrorIs
319309
func ExampleErrorIs() {
320310
e1 := errors.New("e1")
321311
e2 := errors.New("e2")
@@ -325,67 +315,57 @@ func ExampleErrorIs() {
325315
// Output:
326316
}
327317

328-
// False
329318
func ExampleFalse() {
330319
False(t, 1 == int('a'))
331320
// Output:
332321
}
333322

334-
// FileContains
335323
func ExampleFileContains() {
336324
_ = os.WriteFile("/tmp/example", []byte("foo bar baz"), fs.FileMode(0600))
337325
FileContains(t, "/tmp/example", "bar")
338326
// Output:
339327
}
340328

341-
// FileContainsFS
342329
func ExampleFileContainsFS() {
343330
_ = os.WriteFile("/tmp/example", []byte("foo bar baz"), fs.FileMode(0600))
344331
FileContainsFS(t, os.DirFS("/tmp"), "example", "bar")
345332
// Output:
346333
}
347334

348-
// FileExists
349335
func ExampleFileExists() {
350336
_ = os.WriteFile("/tmp/example", []byte{}, fs.FileMode(0600))
351337
FileExists(t, "/tmp/example")
352338
// Output:
353339
}
354340

355-
// FileExistsFS
356341
func ExampleFileExistsFS() {
357342
_ = os.WriteFile("/tmp/example", []byte{}, fs.FileMode(0600))
358343
FileExistsFS(t, os.DirFS("/tmp"), "example")
359344
// Output:
360345
}
361346

362-
// FileMode
363347
func ExampleFileMode() {
364348
_ = os.WriteFile("/tmp/example_fm", []byte{}, fs.FileMode(0600))
365349
FileMode(t, "/tmp/example_fm", fs.FileMode(0600))
366350
// Output:
367351
}
368352

369-
// FileModeFS
370353
func ExampleFileModeFS() {
371354
_ = os.WriteFile("/tmp/example_fm", []byte{}, fs.FileMode(0600))
372355
FileModeFS(t, os.DirFS("/tmp"), "example_fm", fs.FileMode(0600))
373356
// Output:
374357
}
375358

376-
// FileNotExists
377359
func ExampleFileNotExists() {
378360
FileNotExists(t, "/tmp/not_existing_file")
379361
// Output:
380362
}
381363

382-
// FileNotExistsFS
383364
func ExampleFileNotExistsFS() {
384365
FileNotExistsFS(t, os.DirFS("/tmp"), "not_existing_file")
385366
// Output:
386367
}
387368

388-
// FilePathValid
389369
func ExampleFilePathValid() {
390370
FilePathValid(t, "foo/bar/baz")
391371
// Output:
@@ -445,65 +425,167 @@ func ExampleLesser() {
445425
// Output:
446426
}
447427

448-
// MapContainsKey
449428
func ExampleMapContainsKey() {
450429
numbers := map[string]int{"one": 1, "two": 2, "three": 3}
451430
MapContainsKey(t, numbers, "one")
452431
// Output:
453432
}
454433

455-
// MapContainsKeys
456434
func ExampleMapContainsKeys() {
457435
numbers := map[string]int{"one": 1, "two": 2, "three": 3}
458436
keys := []string{"one", "two"}
459437
MapContainsKeys(t, numbers, keys)
460438
// Output:
461439
}
462440

463-
// MapContainsValues
464441
func ExampleMapContainsValues() {
465442
numbers := map[string]int{"one": 1, "two": 2, "three": 3}
466443
values := []int{1, 2}
467444
MapContainsValues(t, numbers, values)
468445
// Output:
469446
}
470447

471-
// MapContainsValuesEqual
448+
func ExampleMapContainsValuesEqual() {
449+
// employee implements .Equal
450+
m := map[int]*employee{
451+
0: {first: "armon", id: 101},
452+
1: {first: "mitchell", id: 100},
453+
2: {first: "dave", id: 102},
454+
}
455+
expect := []*employee{
456+
{first: "armon", id: 101},
457+
{first: "dave", id: 102},
458+
}
459+
MapContainsValuesEqual(t, m, expect)
460+
// Output:
461+
}
472462

473-
// MapContainsValuesFunc
463+
func ExampleMapContainsValuesFunc() {
464+
m := map[int]string{
465+
0: "Zero",
466+
1: "ONE",
467+
2: "two",
468+
}
469+
f := func(a, b string) bool {
470+
return strings.EqualFold(a, b)
471+
}
472+
MapContainsValuesFunc(t, m, []string{"one", "two"}, f)
473+
// Output:
474+
}
474475

475-
// MapEmpty
476476
func ExampleMapEmpty() {
477477
m := make(map[int]int)
478478
MapEmpty(t, m)
479479
// Output:
480480
}
481481

482-
// MapEq
483482
func ExampleMapEq() {
484483
m1 := map[string]int{"one": 1, "two": 2, "three": 3}
485484
m2 := map[string]int{"one": 1, "two": 2, "three": 3}
486485
MapEq(t, m1, m2)
487486
// Output:
488487
}
489488

490-
// MapEqFunc
489+
func ExampleMapEqFunc() {
490+
m1 := map[int]string{
491+
0: "Zero",
492+
1: "one",
493+
2: "TWO",
494+
}
495+
m2 := map[int]string{
496+
0: "ZERO",
497+
1: "ONE",
498+
2: "TWO",
499+
}
500+
MapEqFunc(t, m1, m2, func(a, b string) bool {
501+
return strings.EqualFold(a, b)
502+
})
503+
// Output:
504+
}
491505

492-
// MapEqual
506+
func ExampleMapEqual() {
507+
armon := &employee{first: "armon", id: 101}
508+
mitchell := &employee{first: "mitchell", id: 100}
509+
m1 := map[int]*employee{
510+
0: mitchell,
511+
1: armon,
512+
}
513+
m2 := map[int]*employee{
514+
0: mitchell,
515+
1: armon,
516+
}
517+
MapEqual(t, m1, m2)
518+
// Output:
519+
}
493520

494-
// MapLen
521+
func ExampleMapLen() {
522+
m := map[int]string{
523+
1: "one",
524+
2: "two",
525+
}
526+
MapLen(t, 2, m)
527+
// Output:
528+
}
495529

496-
// MapNotContainsKey
530+
func ExampleMapNotContainsKey() {
531+
m := map[string]int{
532+
"one": 1,
533+
"two": 2,
534+
"three": 3,
535+
}
536+
MapNotContainsKey(t, m, "four")
537+
// Output:
538+
}
497539

498-
// MapNotContainsKeys
540+
func ExampleMapNotContainsKeys() {
541+
m := map[string]int{
542+
"one": 1,
543+
"two": 2,
544+
}
545+
MapNotContainsKeys(t, m, []string{"three", "four"})
546+
// Output:
547+
}
499548

500-
// MapNotContainsValues
549+
func ExampleMapNotContainsValues() {
550+
m := map[int]string{
551+
1: "one",
552+
2: "two",
553+
}
554+
MapNotContainsValues(t, m, []string{"three", "four"})
555+
// Output:
556+
}
501557

502-
// MapNotContainsValuesEqual
558+
func ExampleMapNotContainsValuesEqual() {
559+
m := map[int]*employee{
560+
0: {first: "mitchell", id: 100},
561+
1: {first: "armon", id: 101},
562+
}
563+
MapNotContainsValuesEqual(t, m, []*employee{
564+
{first: "dave", id: 103},
565+
})
566+
// Output:
567+
}
503568

504-
// MapNotContainsValuesFunc
569+
func ExampleMapNotContainsValuesFunc() {
570+
m := map[int]string{
571+
1: "One",
572+
2: "TWO",
573+
3: "three",
574+
}
575+
f := func(a, b string) bool {
576+
return strings.EqualFold(a, b)
577+
}
578+
MapNotContainsValuesFunc(t, m, []string{"four", "five"}, f)
579+
// Output:
580+
}
505581

506-
// MapNotEmpty
582+
func ExampleMapNotEmpty() {
583+
m := map[string]int{
584+
"one": 1,
585+
}
586+
MapNotEmpty(t, m)
587+
// Output:
588+
}
507589

508590
func ExampleMax() {
509591
s := scores{89, 88, 91, 90, 87}

0 commit comments

Comments
 (0)