tests.rs (8465B)
1 use super::{Cmd, E, Opts}; 2 #[expect(clippy::too_many_lines, reason = "a lot of permutations to test")] 3 #[test] 4 fn successes() { 5 assert_eq!( 6 Cmd::try_from_args(["".into()]), 7 Ok(Cmd::Deny(Opts { 8 all_lints: false, 9 allow_undefined_lints: false, 10 read_stdin: false, 11 })) 12 ); 13 assert_eq!( 14 Cmd::try_from_args(["".into(), "--all".into()]), 15 Ok(Cmd::Deny(Opts { 16 all_lints: true, 17 allow_undefined_lints: false, 18 read_stdin: false, 19 })) 20 ); 21 assert_eq!( 22 Cmd::try_from_args(["".into(), "--allow-undefined-lints".into()]), 23 Ok(Cmd::Deny(Opts { 24 all_lints: false, 25 allow_undefined_lints: true, 26 read_stdin: false, 27 })) 28 ); 29 assert_eq!( 30 Cmd::try_from_args(["".into(), "-".into()]), 31 Ok(Cmd::Deny(Opts { 32 all_lints: false, 33 allow_undefined_lints: false, 34 read_stdin: true, 35 })) 36 ); 37 assert_eq!( 38 Cmd::try_from_args(["".into(), "--all".into(), "--allow-undefined-lints".into()]), 39 Ok(Cmd::Deny(Opts { 40 all_lints: true, 41 allow_undefined_lints: true, 42 read_stdin: false, 43 })) 44 ); 45 assert_eq!( 46 Cmd::try_from_args(["".into(), "--all".into(), "-".into()]), 47 Ok(Cmd::Deny(Opts { 48 all_lints: true, 49 allow_undefined_lints: false, 50 read_stdin: true, 51 })) 52 ); 53 assert_eq!( 54 Cmd::try_from_args(["".into(), "--allow-undefined-lints".into(), "-".into()]), 55 Ok(Cmd::Deny(Opts { 56 all_lints: false, 57 allow_undefined_lints: true, 58 read_stdin: true, 59 })) 60 ); 61 assert_eq!( 62 Cmd::try_from_args([ 63 "".into(), 64 "--all".into(), 65 "--allow-undefined-lints".into(), 66 "-".into() 67 ]), 68 Ok(Cmd::Deny(Opts { 69 all_lints: true, 70 allow_undefined_lints: true, 71 read_stdin: true, 72 })) 73 ); 74 assert_eq!( 75 Cmd::try_from_args(["".into(), "allow".into()]), 76 Ok(Cmd::Allow(Opts { 77 all_lints: false, 78 allow_undefined_lints: false, 79 read_stdin: false, 80 })) 81 ); 82 assert_eq!( 83 Cmd::try_from_args(["".into(), "allow".into(), "--all".into()]), 84 Ok(Cmd::Allow(Opts { 85 all_lints: true, 86 allow_undefined_lints: false, 87 read_stdin: false, 88 })) 89 ); 90 assert_eq!( 91 Cmd::try_from_args(["".into(), "allow".into(), "--allow-undefined-lints".into()]), 92 Ok(Cmd::Allow(Opts { 93 all_lints: false, 94 allow_undefined_lints: true, 95 read_stdin: false, 96 })) 97 ); 98 assert_eq!( 99 Cmd::try_from_args(["".into(), "allow".into(), "-".into()]), 100 Ok(Cmd::Allow(Opts { 101 all_lints: false, 102 allow_undefined_lints: false, 103 read_stdin: true, 104 })) 105 ); 106 assert_eq!( 107 Cmd::try_from_args([ 108 "".into(), 109 "allow".into(), 110 "--allow-undefined-lints".into(), 111 "--all".into() 112 ]), 113 Ok(Cmd::Allow(Opts { 114 all_lints: true, 115 allow_undefined_lints: true, 116 read_stdin: false, 117 })) 118 ); 119 assert_eq!( 120 Cmd::try_from_args(["".into(), "allow".into(), "--all".into(), "-".into(),]), 121 Ok(Cmd::Allow(Opts { 122 all_lints: true, 123 allow_undefined_lints: false, 124 read_stdin: true, 125 })) 126 ); 127 assert_eq!( 128 Cmd::try_from_args([ 129 "".into(), 130 "allow".into(), 131 "--all".into(), 132 "--allow-undefined-lints".into(), 133 "-".into(), 134 ]), 135 Ok(Cmd::Allow(Opts { 136 all_lints: true, 137 allow_undefined_lints: true, 138 read_stdin: true, 139 })) 140 ); 141 assert_eq!( 142 Cmd::try_from_args(["".into(), "deny".into()]), 143 Ok(Cmd::Deny(Opts { 144 all_lints: false, 145 allow_undefined_lints: false, 146 read_stdin: false, 147 })) 148 ); 149 assert_eq!( 150 Cmd::try_from_args(["".into(), "deny".into(), "--all".into()]), 151 Ok(Cmd::Deny(Opts { 152 all_lints: true, 153 allow_undefined_lints: false, 154 read_stdin: false, 155 })) 156 ); 157 assert_eq!( 158 Cmd::try_from_args(["".into(), "deny".into(), "--allow-undefined-lints".into()]), 159 Ok(Cmd::Deny(Opts { 160 all_lints: false, 161 allow_undefined_lints: true, 162 read_stdin: false, 163 })) 164 ); 165 assert_eq!( 166 Cmd::try_from_args(["".into(), "deny".into(), "-".into()]), 167 Ok(Cmd::Deny(Opts { 168 all_lints: false, 169 allow_undefined_lints: false, 170 read_stdin: true, 171 })) 172 ); 173 assert_eq!( 174 Cmd::try_from_args([ 175 "".into(), 176 "deny".into(), 177 "--all".into(), 178 "--allow-undefined-lints".into() 179 ]), 180 Ok(Cmd::Deny(Opts { 181 all_lints: true, 182 allow_undefined_lints: true, 183 read_stdin: false, 184 })) 185 ); 186 assert_eq!( 187 Cmd::try_from_args([ 188 "".into(), 189 "deny".into(), 190 "--allow-undefined-lints".into(), 191 "-".into(), 192 ]), 193 Ok(Cmd::Deny(Opts { 194 all_lints: false, 195 allow_undefined_lints: true, 196 read_stdin: true, 197 })) 198 ); 199 assert_eq!( 200 Cmd::try_from_args([ 201 "".into(), 202 "deny".into(), 203 "--allow-undefined-lints".into(), 204 "--all".into(), 205 "-".into(), 206 ]), 207 Ok(Cmd::Deny(Opts { 208 all_lints: true, 209 allow_undefined_lints: true, 210 read_stdin: true, 211 })) 212 ); 213 assert_eq!( 214 Cmd::try_from_args(["".into(), "help".into()]), 215 Ok(Cmd::Help) 216 ); 217 assert_eq!( 218 Cmd::try_from_args(["doesn't matter what this is".into(), "version".into()]), 219 Ok(Cmd::Version) 220 ); 221 } 222 #[test] 223 fn errs() { 224 assert_eq!(Cmd::try_from_args([]), Err(E::NoArgs)); 225 assert_eq!( 226 Cmd::try_from_args(["".into(), "".into()]), 227 Err(E::UnknownArg("".into())) 228 ); 229 assert_eq!( 230 Cmd::try_from_args(["".into(), "foo".into()]), 231 Err(E::UnknownArg("foo".into())) 232 ); 233 assert_eq!( 234 Cmd::try_from_args(["".into(), "help".into(), "version".into()]), 235 Err(E::UnknownArg("version".into())) 236 ); 237 assert_eq!( 238 Cmd::try_from_args(["".into(), "version".into(), "allow".into()]), 239 Err(E::UnknownArg("allow".into())) 240 ); 241 assert_eq!( 242 Cmd::try_from_args(["".into(), "allow".into(), "allow".into()]), 243 Err(E::UnknownArg("allow".into())) 244 ); 245 assert_eq!( 246 Cmd::try_from_args(["".into(), "deny".into(), "allow".into()]), 247 Err(E::UnknownArg("allow".into())) 248 ); 249 assert_eq!( 250 Cmd::try_from_args(["".into(), "--all".into(), "allow".into()]), 251 Err(E::UnknownArg("allow".into())) 252 ); 253 assert_eq!( 254 Cmd::try_from_args(["".into(), "--allow-undefined-lints".into(), "deny".into()]), 255 Err(E::UnknownArg("deny".into())) 256 ); 257 assert_eq!( 258 Cmd::try_from_args(["".into(), "deny".into(), "--all".into(), "".into()]), 259 Err(E::UnknownArg("".into())) 260 ); 261 assert_eq!( 262 Cmd::try_from_args([ 263 "".into(), 264 "--all".into(), 265 "--allow-undefined-lints".into(), 266 "--all".into() 267 ]), 268 Err(E::UnknownArg("--all".into())) 269 ); 270 assert_eq!( 271 Cmd::try_from_args([ 272 "".into(), 273 "deny".into(), 274 "--all".into(), 275 "--allow-undefined-lints".into(), 276 "foo".into() 277 ]), 278 Err(E::UnknownArg("foo".into())) 279 ); 280 assert_eq!( 281 Cmd::try_from_args(["".into(), "-".into(), "deny".into(),]), 282 Err(E::UnknownArg("deny".into())) 283 ); 284 assert_eq!( 285 Cmd::try_from_args(["".into(), "-".into(), "--all".into(),]), 286 Err(E::UnknownArg("--all".into())) 287 ); 288 assert_eq!( 289 Cmd::try_from_args([ 290 "".into(), 291 "allow".into(), 292 "-".into(), 293 "--allow-undefined-lints".into() 294 ]), 295 Err(E::UnknownArg("--allow-undefined-lints".into())) 296 ); 297 }