Every flag we add, the name (displayed also in usage) should normalized
(t *testing.T)
| 839 | |
| 840 | // Every flag we add, the name (displayed also in usage) should normalized |
| 841 | func TestNormalizationFuncShouldChangeFlagName(t *testing.T) { |
| 842 | // Test normalization after addition |
| 843 | f := NewFlagSet("normalized", ContinueOnError) |
| 844 | |
| 845 | f.Bool("valid_flag", false, "bool value") |
| 846 | if f.Lookup("valid_flag").Name != "valid_flag" { |
| 847 | t.Error("The new flag should have the name 'valid_flag' instead of ", f.Lookup("valid_flag").Name) |
| 848 | } |
| 849 | |
| 850 | f.SetNormalizeFunc(wordSepNormalizeFunc) |
| 851 | if f.Lookup("valid_flag").Name != "valid.flag" { |
| 852 | t.Error("The new flag should have the name 'valid.flag' instead of ", f.Lookup("valid_flag").Name) |
| 853 | } |
| 854 | |
| 855 | // Test normalization before addition |
| 856 | f = NewFlagSet("normalized", ContinueOnError) |
| 857 | f.SetNormalizeFunc(wordSepNormalizeFunc) |
| 858 | |
| 859 | f.Bool("valid_flag", false, "bool value") |
| 860 | if f.Lookup("valid_flag").Name != "valid.flag" { |
| 861 | t.Error("The new flag should have the name 'valid.flag' instead of ", f.Lookup("valid_flag").Name) |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | // Related to https://github.com/spf13/cobra/issues/521. |
| 866 | func TestNormalizationSharedFlags(t *testing.T) { |
nothing calls this directly
no test coverage detected