From b17cb56dee5a21574d3a35b2e92a17f04a44db47 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Thu, 16 May 2024 18:13:27 +0200 Subject: [PATCH] Test array of vectors --- milli/src/vector/parsed_vectors.rs | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/milli/src/vector/parsed_vectors.rs b/milli/src/vector/parsed_vectors.rs index bf4b9ea83..4e06177de 100644 --- a/milli/src/vector/parsed_vectors.rs +++ b/milli/src/vector/parsed_vectors.rs @@ -147,3 +147,62 @@ impl VectorOrArrayOfVectors { Self { inner: Some(either::Either::Right(array_of_vec)) } } } + +#[cfg(test)] +mod test { + use super::VectorOrArrayOfVectors; + + #[test] + fn array_of_vectors() { + let null: VectorOrArrayOfVectors = serde_json::from_str("null").unwrap(); + let empty: VectorOrArrayOfVectors = serde_json::from_str("[]").unwrap(); + let one: VectorOrArrayOfVectors = serde_json::from_str("[0.1]").unwrap(); + let two: VectorOrArrayOfVectors = serde_json::from_str("[0.1, 0.2]").unwrap(); + let one_vec: VectorOrArrayOfVectors = serde_json::from_str("[[0.1, 0.2]]").unwrap(); + let two_vecs: VectorOrArrayOfVectors = + serde_json::from_str("[[0.1, 0.2], [0.3, 0.4]]").unwrap(); + + insta::assert_json_snapshot!(null.into_array_of_vectors(), @"null"); + // 👇 is the the intended behavior? would rather expect [] here, but changing that is a breaking change... + insta::assert_json_snapshot!(empty.into_array_of_vectors(), @r###" + [ + [] + ] + "###); + insta::assert_json_snapshot!(one.into_array_of_vectors(), @r###" + [ + [ + 0.1 + ] + ] + "###); + insta::assert_json_snapshot!(two.into_array_of_vectors(), @r###" + [ + [ + 0.1, + 0.2 + ] + ] + "###); + insta::assert_json_snapshot!(one_vec.into_array_of_vectors(), @r###" + [ + [ + 0.1, + 0.2 + ] + ] + "###); + insta::assert_json_snapshot!(two_vecs.into_array_of_vectors(), @r###" + [ + [ + 0.1, + 0.2 + ], + [ + 0.3, + 0.4 + ] + ] + "###); + } +}