From ad255099f99143955f936a416cac20f723cae195 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Tue, 6 Aug 2024 12:03:21 +0200 Subject: [PATCH] Adding a few tests for decoder deserialization. --- tokenizers/src/decoders/mod.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tokenizers/src/decoders/mod.rs b/tokenizers/src/decoders/mod.rs index 682e63b50..5f0968fcb 100644 --- a/tokenizers/src/decoders/mod.rs +++ b/tokenizers/src/decoders/mod.rs @@ -94,6 +94,33 @@ mod tests { #[test] fn decoder_serialization_no_decode() { let json = r#"{"type":"Sequence","decoders":[{},{"type":"Metaspace","replacement":"▁","prepend_scheme":"always"}]}"#; - assert!(serde_json::from_str::(json).is_err()); + let parse = serde_json::from_str::(json); + match parse { + Err(err) => assert_eq!( + format!("{err}"), + "data did not match any variant of untagged enum DecoderWrapper" + ), + _ => panic!("Expected error"), + } + + let json = r#"{"replacement":"▁","prepend_scheme":"always"}"#; + let parse = serde_json::from_str::(json); + match parse { + Err(err) => assert_eq!( + format!("{err}"), + "data did not match any variant of untagged enum DecoderWrapper" + ), + _ => panic!("Expected error"), + } + + let json = r#"{"type":"Sequence","prepend_scheme":"always"}"#; + let parse = serde_json::from_str::(json); + match parse { + Err(err) => assert_eq!( + format!("{err}"), + "data did not match any variant of untagged enum DecoderWrapper" + ), + _ => panic!("Expected error"), + } } }