|
| 1 | +package argumentative |
| 2 | + |
| 3 | +import "testing" |
| 4 | + |
| 5 | +func TestNewStringFlag(t *testing.T) { |
| 6 | + flag := NewStringFlag("longname", "s", true, "default", "description") |
| 7 | + |
| 8 | + if flag.Longflag != "longname" { |
| 9 | + t.Errorf("Longflag assignment wrong, got [%s], want [%s]", flag.Longflag, "longname") |
| 10 | + } |
| 11 | + |
| 12 | + if flag.Shortflag != "s" { |
| 13 | + t.Errorf("Shortflag assignment wrong, got [%s], want [%s]", flag.Shortflag, "s") |
| 14 | + } |
| 15 | + |
| 16 | + if flag.Default != "default" { |
| 17 | + t.Errorf("Default assignment wrong, got [%s], want [%s]", flag.Default, "default") |
| 18 | + } |
| 19 | + |
| 20 | + if flag.Description != "description" { |
| 21 | + t.Errorf("Description assignment wrong, got [%s], want [%s]", flag.Description, "description") |
| 22 | + } |
| 23 | + |
| 24 | + if *flag.Value != "default" { |
| 25 | + t.Errorf("Assignment of default to value wrong, got [%s], want [%s]", *flag.Value, flag.Default) |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +func TestGetLongDescription(t *testing.T) { |
| 30 | + flag := NewStringFlag("longname", "s", true, "default", "description") |
| 31 | + result := flag.GetLongDescription() |
| 32 | + await := "-s, --longname description (Default: default)" |
| 33 | + |
| 34 | + if result != await { |
| 35 | + t.Errorf("Generation of long description failed, got [%s], want [%s]", result, await) |
| 36 | + } |
| 37 | + |
| 38 | + flag = NewStringFlag("longname", "s", true, "", "description") |
| 39 | + result = flag.GetLongDescription() |
| 40 | + await = "-s, --longname description" |
| 41 | + |
| 42 | + if result != await { |
| 43 | + t.Errorf("Generation of long description without default failed, got [%s], want [%s]", result, await) |
| 44 | + } |
| 45 | + |
| 46 | + flag = NewStringFlag("longname", "s", false, "", "description") |
| 47 | + result = flag.GetLongDescription() |
| 48 | + await = "-s, --longname description" |
| 49 | + |
| 50 | + if result != await { |
| 51 | + t.Errorf("Generation of long description without default failed, got [%s], want [%s]", result, await) |
| 52 | + } |
| 53 | + |
| 54 | + flag = NewStringFlag("longname", "", true, "", "description") |
| 55 | + result = flag.GetLongDescription() |
| 56 | + await = "--longname description" |
| 57 | + |
| 58 | + if result != await { |
| 59 | + t.Errorf("Generation of long description without shortname failed, got [%s], want [%s]", result, await) |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +func TestGetShortDescription(t *testing.T) { |
| 64 | + flag := NewStringFlag("longname", "s", true, "default", "description") |
| 65 | + result := flag.GetShortDescription() |
| 66 | + await := " -s" // @todo: remove space |
| 67 | + |
| 68 | + if result != await { |
| 69 | + t.Errorf("Generation of short description failed, got [%s], want [%s]", result, await) |
| 70 | + } |
| 71 | + |
| 72 | + flag = NewStringFlag("longname", "s", false, "", "description") |
| 73 | + result = flag.GetShortDescription() |
| 74 | + await = " [-s]" // @todo remove space |
| 75 | + |
| 76 | + if result != await { |
| 77 | + t.Errorf("Generation of short description no required failed, got [%s], want [%s]", result, await) |
| 78 | + } |
| 79 | + |
| 80 | + flag = NewStringFlag("longname", "", false, "", "description") |
| 81 | + result = flag.GetShortDescription() |
| 82 | + await = " [--longname]" // @todo remove space |
| 83 | + |
| 84 | + if result != await { |
| 85 | + t.Errorf("Generation of short description no short name failed, got [%s], want [%s]", result, await) |
| 86 | + } |
| 87 | +} |
0 commit comments