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

Function TestOptionalMatch

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

Source from the content-addressed store, hash-verified

522}
523
524func TestOptionalMatch(t *testing.T) {
525 v, w, x := newOptional(newOption("-a", "", 0, false)).match(
526 &patternList{newOption("-a", "", 0, false)}, nil)
527 y := patternList{newOption("-a", "", 0, false)}
528 if v != true ||
529 reflect.DeepEqual(*w, patternList{}) != true ||
530 reflect.DeepEqual(*x, y) != true {
531 t.Fail()
532 }
533
534 v, w, x = newOptional(newOption("-a", "", 0, false)).match(
535 &patternList{}, nil)
536 if v != true ||
537 reflect.DeepEqual(*w, patternList{}) != true ||
538 reflect.DeepEqual(*x, patternList{}) != true {
539 t.Fail()
540 }
541
542 v, w, x = newOptional(newOption("-a", "", 0, false)).match(
543 &patternList{newOption("-x", "", 0, false)}, nil)
544 y = patternList{newOption("-x", "", 0, false)}
545 if v != true ||
546 reflect.DeepEqual(*w, y) != true ||
547 reflect.DeepEqual(*x, patternList{}) != true {
548 t.Fail()
549 }
550
551 v, w, x = newOptional(newOption("-a", "", 0, false),
552 newOption("-b", "", 0, false)).match(
553 &patternList{newOption("-a", "", 0, false)}, nil)
554 y = patternList{newOption("-a", "", 0, false)}
555 if v != true ||
556 reflect.DeepEqual(*w, patternList{}) != true ||
557 reflect.DeepEqual(*x, y) != true {
558 t.Fail()
559 }
560
561 v, w, x = newOptional(newOption("-a", "", 0, false),
562 newOption("-b", "", 0, false)).match(
563 &patternList{newOption("-b", "", 0, false)}, nil)
564 y = patternList{newOption("-b", "", 0, false)}
565 if v != true ||
566 reflect.DeepEqual(*w, patternList{}) != true ||
567 reflect.DeepEqual(*x, y) != true {
568 t.Fail()
569 }
570
571 v, w, x = newOptional(newOption("-a", "", 0, false),
572 newOption("-b", "", 0, false)).match(
573 &patternList{newOption("-x", "", 0, false)}, nil)
574 y = patternList{newOption("-x", "", 0, false)}
575 if v != true ||
576 reflect.DeepEqual(*w, y) != true ||
577 reflect.DeepEqual(*x, patternList{}) != true {
578 t.Fail()
579 }
580
581 v, w, x = newOptional(newArgument("N", nil)).match(

Callers

nothing calls this directly

Calls 4

newOptionalFunction · 0.85
newOptionFunction · 0.85
newArgumentFunction · 0.85
matchMethod · 0.45

Tested by

no test coverage detected