github.com/WindomZ/go-commander@v1.2.2/regexp_test.go (about) 1 package commander 2 3 import ( 4 "github.com/WindomZ/testify/assert" 5 "testing" 6 ) 7 8 func TestRegexp_RegexpCommand(t *testing.T) { 9 assert.Equal(t, 10 regexpCommand("new <name>"), 11 []string{"new"}, 12 ) 13 assert.Equal(t, 14 regexpCommand("ship <name> move <x> <y>"), 15 []string{"ship"}, 16 ) 17 assert.Equal(t, 18 regexpCommand("(set|remove) <x> <y> [--moored|--drifting]"), 19 []string{"set", "remove"}, 20 ) 21 } 22 23 func TestRegexp_RegexpArgument(t *testing.T) { 24 assert.Equal(t, 25 regexpArgument("new <name>"), 26 []string{"<name>"}, 27 ) 28 assert.Equal(t, 29 regexpArgument("ship <name> move <x> <y>"), 30 []string{"<name>", "<x>", "<y>"}, 31 ) 32 assert.Equal(t, 33 regexpArgument("(set|remove) <x> <y> [--moored|--drifting]"), 34 []string{"<x>", "<y>"}, 35 ) 36 } 37 38 func TestRegexp_RegexpOption(t *testing.T) { 39 assert.Equal(t, 40 regexpOption("new <name>"), 41 []string(nil), 42 ) 43 assert.Equal(t, 44 regexpOption("-p <x-y>"), 45 []string{"-p"}, 46 ) 47 assert.Equal(t, 48 regexpOption("-p"), 49 []string{"-p"}, 50 ) 51 assert.Equal(t, 52 regexpOption("-p, --pepper"), 53 []string{"-p", "--pepper"}, 54 ) 55 assert.Equal(t, 56 regexpOption("--pepper"), 57 []string{"--pepper"}, 58 ) 59 assert.Equal(t, 60 regexpOption("(set|remove) <x> <y> [--not-ss | -a | --moored|--drifting]"), 61 []string{"--not-ss", "-a", "--moored", "--drifting"}, 62 ) 63 } 64 65 func TestRegexp_ReplaceCommand(t *testing.T) { 66 assert.Equal(t, 67 replaceCommand("new <name>", "new", "(new|n)"), 68 "(new|n) <name>", 69 ) 70 assert.Equal(t, 71 replaceCommand("(new|n) <name>", "(new|n)", "(new|n|add)"), 72 "(new|n|add) <name>", 73 ) 74 } 75 76 func TestRegexp_FirstParameter(t *testing.T) { 77 assert.Equal(t, 78 firstParameter("new <name>"), 79 "new", 80 ) 81 assert.Equal(t, 82 firstParameter("(new|n|add) <name>"), 83 "(new|n|add)", 84 ) 85 assert.Equal(t, 86 firstParameter("<hello> <world>"), 87 "<hello>", 88 ) 89 assert.Equal(t, 90 firstParameter("--hello=<world>"), 91 "--hello", 92 ) 93 }