(t *testing.T)
| 861 | } |
| 862 | |
| 863 | func TestBasicPatternMatching(t *testing.T) { |
| 864 | // ( -a N [ -x Z ] ) |
| 865 | p := newRequired( |
| 866 | newOption("-a", "", 0, false), |
| 867 | newArgument("N", nil), |
| 868 | newOptional( |
| 869 | newOption("-x", "", 0, false), |
| 870 | newArgument("Z", nil))) |
| 871 | |
| 872 | // -a N |
| 873 | q := patternList{newOption("-a", "", 0, false), newArgument("", 9)} |
| 874 | y := patternList{newOption("-a", "", 0, false), newArgument("N", 9)} |
| 875 | v, w, x := p.match(&q, nil) |
| 876 | if v != true || |
| 877 | reflect.DeepEqual(*w, patternList{}) != true || |
| 878 | reflect.DeepEqual(*x, y) != true { |
| 879 | t.Fail() |
| 880 | } |
| 881 | |
| 882 | // -a -x N Z |
| 883 | q = patternList{newOption("-a", "", 0, false), |
| 884 | newOption("-x", "", 0, false), |
| 885 | newArgument("", 9), newArgument("", 5)} |
| 886 | y = patternList{} |
| 887 | z := patternList{newOption("-a", "", 0, false), newArgument("N", 9), |
| 888 | newOption("-x", "", 0, false), newArgument("Z", 5)} |
| 889 | v, w, x = p.match(&q, nil) |
| 890 | if v != true || |
| 891 | reflect.DeepEqual(*w, y) != true || |
| 892 | reflect.DeepEqual(*x, z) != true { |
| 893 | t.Fail() |
| 894 | } |
| 895 | |
| 896 | // -x N Z # BZZ! |
| 897 | q = patternList{newOption("-x", "", 0, false), |
| 898 | newArgument("", 9), newArgument("", 5)} |
| 899 | y = patternList{newOption("-x", "", 0, false), |
| 900 | newArgument("", 9), newArgument("", 5)} |
| 901 | z = patternList{} |
| 902 | v, w, x = p.match(&q, nil) |
| 903 | if v != false || |
| 904 | reflect.DeepEqual(*w, y) != true || |
| 905 | reflect.DeepEqual(*x, z) != true { |
| 906 | t.Fail() |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | func TestPatternEither(t *testing.T) { |
| 911 | p := newOption("-a", "", 0, false).transform() |
nothing calls this directly
no test coverage detected