diff options
author | Brian Olsen <brian@maven-group.org> | 2024-11-03T19·15+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-11-03T23·43+0000 |
commit | 6f914bc0fa6aa480fed6c500dc0ee26eaefbf1b6 (patch) | |
tree | 1de521384bd771d8efc23b6a1fa0c39c7a79b0c1 | |
parent | 28dbf5f0eb0306d7675ec83475e14c79b05b310d (diff) |
fix(tvix/nix-compat-derive-tests) More enum tests r/8885
Before this commit only deriving of tuple enums where tested. This adds a few tests to cover the other types of enums. Change-Id: I62f311e4db98cab84bd4ac164d50051e9aab0d4d Reviewed-on: https://cl.tvl.fyi/c/depot/+/12725 Autosubmit: Brian Olsen <me@griff.name> Reviewed-by: Vladimir Kryachko <v.kryachko@gmail.com> Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
-rw-r--r-- | tvix/nix-compat-derive-tests/tests/read_derive.rs | 71 |
1 files changed, 65 insertions, 6 deletions
diff --git a/tvix/nix-compat-derive-tests/tests/read_derive.rs b/tvix/nix-compat-derive-tests/tests/read_derive.rs index 055d70cf046e..e47c8ad4346f 100644 --- a/tvix/nix-compat-derive-tests/tests/read_derive.rs +++ b/tvix/nix-compat-derive-tests/tests/read_derive.rs @@ -356,16 +356,35 @@ async fn read_from_u64_reader_error() { #[derive(Debug, PartialEq, Eq, NixDeserialize)] enum TestEnum { #[nix(version = "..=19")] - Pre20(TestTryFromU64), - #[nix(version = "20..")] + Pre20(TestTryFromU64, #[nix(version = "10..")] u64), + #[nix(version = "20..=29")] Post20(StructVersionTest), + #[nix(version = "30..=39")] + Post30, + #[nix(version = "40..")] + Post40 { + msg: String, + #[nix(version = "45..")] + level: u64, + }, +} + +#[tokio::test] +async fn read_enum_9() { + let mut mock = Builder::new().version((1, 9)).read_number(42).build(); + let value = mock.read_value::<TestEnum>().await.unwrap(); + assert_eq!(TestEnum::Pre20(TestTryFromU64, 0), value); } #[tokio::test] async fn read_enum_19() { - let mut mock = Builder::new().version((1, 19)).read_number(42).build(); + let mut mock = Builder::new() + .version((1, 19)) + .read_number(42) + .read_number(666) + .build(); let value = mock.read_value::<TestEnum>().await.unwrap(); - assert_eq!(TestEnum::Pre20(TestTryFromU64), value); + assert_eq!(TestEnum::Pre20(TestTryFromU64, 666), value); } #[tokio::test] @@ -386,6 +405,46 @@ async fn read_enum_20() { } #[tokio::test] +async fn read_enum_30() { + let mut mock = Builder::new().version((1, 30)).build(); + let value = mock.read_value::<TestEnum>().await.unwrap(); + assert_eq!(TestEnum::Post30, value); +} + +#[tokio::test] +async fn read_enum_40() { + let mut mock = Builder::new() + .version((1, 40)) + .read_slice(b"hello world") + .build(); + let value = mock.read_value::<TestEnum>().await.unwrap(); + assert_eq!( + TestEnum::Post40 { + msg: "hello world".into(), + level: 0, + }, + value + ); +} + +#[tokio::test] +async fn read_enum_45() { + let mut mock = Builder::new() + .version((1, 45)) + .read_slice(b"hello world") + .read_number(9001) + .build(); + let value = mock.read_value::<TestEnum>().await.unwrap(); + assert_eq!( + TestEnum::Post40 { + msg: "hello world".into(), + level: 9001, + }, + value + ); +} + +#[tokio::test] async fn read_enum_reader_error() { let mut mock = Builder::new() .version((1, 19)) @@ -396,8 +455,8 @@ async fn read_enum_reader_error() { } #[tokio::test] -async fn read_enum_invalid_data_19() { - let mut mock = Builder::new().version((1, 19)).read_number(666).build(); +async fn read_enum_invalid_data_9() { + let mut mock = Builder::new().version((1, 9)).read_number(666).build(); let err = mock.read_value::<TestEnum>().await.unwrap_err(); assert_eq!(Error::InvalidData("666".into()), err); } |