about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tvix/nix-compat-derive-tests/tests/read_derive.rs71
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);
 }