MCPcopy Create free account
hub / github.com/docopt/docopt.go / TestCommandMatch

Function TestCommandMatch

docopt_test.go:479–522  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

477}
478
479func TestCommandMatch(t *testing.T) {
480 v, w, x := newCommand("c", false).match(
481 &patternList{newArgument("", "c")}, nil)
482 y := patternList{newCommand("c", true)}
483 if v != true ||
484 reflect.DeepEqual(*w, patternList{}) != true ||
485 reflect.DeepEqual(*x, y) != true {
486 t.Fail()
487 }
488
489 v, w, x = newCommand("c", false).match(
490 &patternList{newOption("-x", "", 0, false)}, nil)
491 y = patternList{newOption("-x", "", 0, false)}
492 if v != false ||
493 reflect.DeepEqual(*w, y) != true ||
494 reflect.DeepEqual(*x, patternList{}) != true {
495 t.Fail()
496 }
497
498 v, w, x = newCommand("c", false).match(
499 &patternList{
500 newOption("-x", "", 0, false),
501 newOption("-a", "", 0, false),
502 newArgument("", "c")}, nil)
503 y = patternList{newOption("-x", "", 0, false),
504 newOption("-a", "", 0, false)}
505 z := patternList{newCommand("c", true)}
506 if v != true ||
507 reflect.DeepEqual(*w, y) != true ||
508 reflect.DeepEqual(*x, z) != true {
509 t.Fail()
510 }
511
512 v, w, x = newEither(
513 newCommand("add", false),
514 newCommand("rm", false)).match(
515 &patternList{newArgument("", "rm")}, nil)
516 y = patternList{newCommand("rm", true)}
517 if v != true ||
518 reflect.DeepEqual(*w, patternList{}) != true ||
519 reflect.DeepEqual(*x, y) != true {
520 t.Fail()
521 }
522}
523
524func TestOptionalMatch(t *testing.T) {
525 v, w, x := newOptional(newOption("-a", "", 0, false)).match(

Callers

nothing calls this directly

Calls 5

newCommandFunction · 0.85
newArgumentFunction · 0.85
newOptionFunction · 0.85
newEitherFunction · 0.85
matchMethod · 0.45

Tested by

no test coverage detected