diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-01 17:49:08 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-01 17:49:08 +0100 |
| commit | 2fe2e8cdbc3bb520994ff0944188f2fa657c546a (patch) | |
| tree | 10f29b4dd62c2b8127d20f0bffd4325b3ca0bfd2 /tests/version.rs | |
| parent | docs: add the phased GUI plan (diff) | |
| download | zagan-bet-2fe2e8cdbc3bb520994ff0944188f2fa657c546a.tar.gz zagan-bet-2fe2e8cdbc3bb520994ff0944188f2fa657c546a.zip | |
v4.0.0: require HELLO MAJOR.MINOR lockstep before auth
Diffstat (limited to '')
| -rw-r--r-- | tests/version.rs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/version.rs b/tests/version.rs new file mode 100644 index 0000000..ef58601 --- /dev/null +++ b/tests/version.rs | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | use zagan_bet::version::{ | ||
| 2 | compatible, hello_line, is_newer, parse_hello, Version, VERSION, | ||
| 3 | }; | ||
| 4 | |||
| 5 | #[test] | ||
| 6 | fn versions_parse_and_reject_nonsense() { | ||
| 7 | assert_eq!( | ||
| 8 | Version::parse("4.0.0"), | ||
| 9 | Some(Version { | ||
| 10 | major: 4, | ||
| 11 | minor: 0, | ||
| 12 | patch: 0 | ||
| 13 | }) | ||
| 14 | ); | ||
| 15 | assert_eq!( | ||
| 16 | Version::parse("v4.1.2"), | ||
| 17 | Some(Version { | ||
| 18 | major: 4, | ||
| 19 | minor: 1, | ||
| 20 | patch: 2 | ||
| 21 | }) | ||
| 22 | ); | ||
| 23 | assert_eq!( | ||
| 24 | Version::parse("4.0.0-rc1").map(|v| (v.major, v.minor, v.patch)), | ||
| 25 | Some((4, 0, 0)) | ||
| 26 | ); | ||
| 27 | assert_eq!( | ||
| 28 | Version::parse("4.0.0+build7").map(|v| v.patch), | ||
| 29 | Some(0) | ||
| 30 | ); | ||
| 31 | |||
| 32 | for bad in ["", "4", "4.0", "4.0.0.1", "x.0.0", "4.x.0", "4.0.0-"] { | ||
| 33 | assert!(Version::parse(bad).is_none(), "{bad:?} should not parse"); | ||
| 34 | } | ||
| 35 | |||
| 36 | assert!(Version::parse(VERSION).is_some(), "the build version must parse"); | ||
| 37 | } | ||
| 38 | |||
| 39 | #[test] | ||
| 40 | fn compatibility_is_major_and_minor_only() { | ||
| 41 | assert!(compatible("4.0.0", "4.0.9")); | ||
| 42 | assert!(compatible("4.2.7", "4.2.1")); | ||
| 43 | assert!(!compatible("4.0.0", "4.1.0")); | ||
| 44 | assert!(!compatible("4.0.0", "5.0.0")); | ||
| 45 | assert!(!compatible("nope", "4.0.0")); | ||
| 46 | } | ||
| 47 | |||
| 48 | #[test] | ||
| 49 | fn newer_versions_are_ordered_by_major_minor_patch() { | ||
| 50 | assert!(is_newer("4.0.1", "4.0.0")); | ||
| 51 | assert!(is_newer("4.1.0", "4.0.9")); | ||
| 52 | assert!(is_newer("5.0.0", "4.9.9")); | ||
| 53 | assert!(!is_newer("4.0.0", "4.0.0")); | ||
| 54 | assert!(!is_newer("4.0.0", "4.0.1")); | ||
| 55 | assert!(!is_newer("nonsense", "4.0.0")); | ||
| 56 | } | ||
| 57 | |||
| 58 | #[test] | ||
| 59 | fn the_hello_reply_round_trips() { | ||
| 60 | let line = hello_line("4.0.0", "4.1.2", "https://zagan.example/"); | ||
| 61 | let reply = parse_hello(&line).expect("parse a generated reply"); | ||
| 62 | |||
| 63 | assert_eq!(reply.version, "4.0.0"); | ||
| 64 | assert_eq!(reply.latest, "4.1.2"); | ||
| 65 | assert_eq!(reply.url, "https://zagan.example/"); | ||
| 66 | |||
| 67 | assert!(parse_hello("HELLO 4.0.0 url=https://x/").is_none(), "latest is required"); | ||
| 68 | assert!(parse_hello("HELLO 4.0.0 latest=4.0.0").is_none(), "url is required"); | ||
| 69 | assert!(parse_hello("PONG").is_none()); | ||
| 70 | assert!(parse_hello("HELLO").is_none()); | ||
| 71 | } | ||
