| 1 | package cliscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.22 fmt/" |
| 5 | "testingscip-go gomod github.com/golang/go/src go1.22 testing/" |
| 6 | |
| 7 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/" |
| 8 | ) |
| 9 | |
| 10 | func TestFlagDefaultValidationscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestFlagDefaultValidation().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 11 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 12 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "foo", |
| 13 | Flagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Flags.: []Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#{ |
| 14 | &Int64Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Int64Flag#{ |
| 15 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Name.: "if", |
| 16 | Valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Value.: 2, // this value should fail validation |
| 17 | Validatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Validator.: func(i int64) error { |
| 18 | if (i >= 3 && i <= 10) || (i >= 20 && i <= 24) { |
| 19 | return nil |
| 20 | } |
| 21 | return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22 fmt/Errorf().("Value %d not in range [3,10] or [20,24]", i) |
| 22 | }, |
| 23 | ValidateDefaultsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#ValidateDefaults.: true, |
| 24 | }, |
| 25 | }, |
| 26 | } |
| 27 | |
| 28 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 29 | |
| 30 | // this is a simple call to test PreParse failure before |
| 31 | // parsing has been done |
| 32 | r.Errorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Error().(cmd.Setscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Set().("if", "11")) |
| 33 | |
| 34 | // Default value of flag is 2 which should fail validation |
| 35 | err := cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", "--if", "5"}) |
| 36 | r.Errorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Error().(err) |
| 37 | } |
| 38 | |
| 39 | func TestBoolInverseFlagDefaultValidationscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestBoolInverseFlagDefaultValidation().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 40 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 41 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "foo", |
| 42 | Flagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Flags.: []Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#{ |
| 43 | &BoolWithInverseFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/BoolWithInverseFlag#{ |
| 44 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/BoolWithInverseFlag#Name.: "bif", |
| 45 | Valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/BoolWithInverseFlag#Value.: true, // this value should fail validation |
| 46 | Validatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/BoolWithInverseFlag#Validator.: func(i bool) error { |
| 47 | if i { |
| 48 | return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22 fmt/Errorf().("invalid value") |
| 49 | } |
| 50 | return nil |
| 51 | }, |
| 52 | ValidateDefaultsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/BoolWithInverseFlag#ValidateDefaults.: true, |
| 53 | }, |
| 54 | }, |
| 55 | } |
| 56 | |
| 57 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 58 | |
| 59 | // Default value of flag is 2 which should fail validation |
| 60 | err := cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", "--bif"}) |
| 61 | r.Errorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Error().(err) |
| 62 | } |
| 63 | |
| 64 | func TestFlagValidationscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestFlagValidation().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 65 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 66 | |
| 67 | testCases := []struct { |
| 68 | name string |
| 69 | arg string |
| 70 | errExpected bool |
| 71 | }{ |
| 72 | { |
| 73 | name: "first range less than min", |
| 74 | arg: "2", |
| 75 | errExpected: true, |
| 76 | }, |
| 77 | { |
| 78 | name: "first range min", |
| 79 | arg: "3", |
| 80 | }, |
| 81 | { |
| 82 | name: "first range mid", |
| 83 | arg: "7", |
| 84 | }, |
| 85 | { |
| 86 | name: "first range max", |
| 87 | arg: "10", |
| 88 | }, |
| 89 | { |
| 90 | name: "first range greater than max", |
| 91 | arg: "15", |
| 92 | errExpected: true, |
| 93 | }, |
| 94 | { |
| 95 | name: "second range less than min", |
| 96 | arg: "19", |
| 97 | errExpected: true, |
| 98 | }, |
| 99 | { |
| 100 | name: "second range min", |
| 101 | arg: "20", |
| 102 | }, |
| 103 | { |
| 104 | name: "second range mid", |
| 105 | arg: "21", |
| 106 | }, |
| 107 | { |
| 108 | name: "second range max", |
| 109 | arg: "24", |
| 110 | }, |
| 111 | { |
| 112 | name: "second range greater than max", |
| 113 | arg: "27", |
| 114 | errExpected: true, |
| 115 | }, |
| 116 | } |
| 117 | |
| 118 | for _, testCase := range testCases { |
| 119 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 120 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "foo", |
| 121 | Flagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Flags.: []Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#{ |
| 122 | &Int64Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Int64Flag#{ |
| 123 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Name.: "it", |
| 124 | Valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Value.: 5, // note that this value should pass validation |
| 125 | Validatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Validator.: func(i int64) error { |
| 126 | if (i >= 3 && i <= 10) || (i >= 20 && i <= 24) { |
| 127 | return nil |
| 128 | } |
| 129 | return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22 fmt/Errorf().("Value %d not in range [3,10]U[20,24]", i) |
| 130 | }, |
| 131 | }, |
| 132 | }, |
| 133 | } |
| 134 | |
| 135 | err := cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", "--it", testCase.arg}) |
| 136 | if !testCase.errExpected { |
| 137 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 138 | } else { |
| 139 | r.Errorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Error().(err) |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | func TestBoolInverseFlagValidationscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestBoolInverseFlagValidation().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 145 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 146 | |
| 147 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 148 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "foo", |
| 149 | Flagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Flags.: []Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#{ |
| 150 | &BoolWithInverseFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/BoolWithInverseFlag#{ |
| 151 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/BoolWithInverseFlag#Name.: "it", |
| 152 | Validatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/BoolWithInverseFlag#Validator.: func(b bool) error { |
| 153 | if b { |
| 154 | return nil |
| 155 | } |
| 156 | return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22 fmt/Errorf().("not valid") |
| 157 | }, |
| 158 | }, |
| 159 | }, |
| 160 | } |
| 161 | |
| 162 | err := cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", "--it=false"}) |
| 163 | r.Errorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Error().(err) |
| 164 | } |