| { | ||
| "git": { | ||
| "sha1": "a14f2dad852be26bad277ae704abf27a15cbfed1" | ||
| "sha1": "c56bbb5a7b47409759113903764c456f13b418e5" | ||
| }, | ||
| "path_in_vcs": "utils/zerovec" | ||
| } |
+3
-3
@@ -981,3 +981,3 @@ # This file is automatically @generated by Cargo. | ||
| name = "zerovec" | ||
| version = "0.11.7" | ||
| version = "0.11.8" | ||
| dependencies = [ | ||
@@ -1006,5 +1006,5 @@ "bincode", | ||
| name = "zerovec-derive" | ||
| version = "0.11.4" | ||
| version = "0.11.5" | ||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| checksum = "47402523226a02bfe5230160dc3ccc089aa6f6f19e7fcbb4e6f824bbb1b4aa62" | ||
| checksum = "9f212a141d820099d57ffafb9569be9617a6f27d3dc881fbee8fb56642f917a9" | ||
| dependencies = [ | ||
@@ -1011,0 +1011,0 @@ "proc-macro2", |
+2
-2
@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "zerovec" | ||
| version = "0.11.7" | ||
| version = "0.11.8" | ||
| authors = ["The ICU4X Project Developers"] | ||
@@ -153,3 +153,3 @@ build = false | ||
| [dependencies.zerovec-derive] | ||
| version = "0.11.4" | ||
| version = "0.11.5" | ||
| optional = true | ||
@@ -156,0 +156,0 @@ default-features = false |
+42
-0
@@ -17,2 +17,9 @@ // This file is part of ICU4X. For terms of use, please see the file | ||
| fn validate_bytes(bytes: &[u8]) -> Result<(), UleError> { | ||
| if N == 0 { | ||
| // ZSTs shouldn't be ULE | ||
| return Err(UleError::length::<Self>(bytes.len())); | ||
| } | ||
| if bytes.len() % size_of::<Self>() != 0 { | ||
| return Err(UleError::length::<Self>(bytes.len())); | ||
| } | ||
| // a slice of multiple Selfs is equivalent to just a larger slice of Ts | ||
@@ -104,1 +111,36 @@ T::validate_bytes(bytes) | ||
| } | ||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::ZeroSlice; | ||
| #[test] | ||
| fn test_array_ule_validate() { | ||
| let bytes: &[u8] = &[1, 2, 3, 4, 5, 6]; | ||
| assert!(<[u8; 2] as ULE>::validate_bytes(bytes).is_ok()); | ||
| assert!(<[u8; 3] as ULE>::validate_bytes(bytes).is_ok()); | ||
| assert!(<[u8; 6] as ULE>::validate_bytes(bytes).is_ok()); | ||
| // Length not a multiple of array size | ||
| assert!(<[u8; 4] as ULE>::validate_bytes(bytes).is_err()); | ||
| assert!(<[u8; 5] as ULE>::validate_bytes(bytes).is_err()); | ||
| assert!(<[u8; 7] as ULE>::validate_bytes(bytes).is_err()); | ||
| // Multi-byte element types (CharULE is 3 bytes, [CharULE; 2] is 6 bytes) | ||
| let chars_6b: &[u8] = &[0x61, 0x00, 0x00, 0x62, 0x00, 0x00]; // 'a', 'b' | ||
| assert!(<[CharULE; 2] as ULE>::validate_bytes(chars_6b).is_ok()); | ||
| let chars_9b: &[u8] = &[0x61, 0x00, 0x00, 0x62, 0x00, 0x00, 0x63, 0x00, 0x00]; // 'a', 'b', 'c' (9 bytes: multiple of CharULE (3), but not [CharULE; 2] (6)) | ||
| assert!(<[CharULE; 2] as ULE>::validate_bytes(chars_9b).is_err()); | ||
| // ZeroSlice::parse_bytes | ||
| assert!(ZeroSlice::<[u8; 3]>::parse_bytes(bytes).is_ok()); | ||
| assert!(ZeroSlice::<[u8; 4]>::parse_bytes(bytes).is_err()); | ||
| // Zero-length arrays unconditionally error | ||
| assert!(<[u8; 0] as ULE>::validate_bytes(&[]).is_err()); | ||
| assert!(<[u8; 0] as ULE>::validate_bytes(bytes).is_err()); | ||
| assert!(ZeroSlice::<[u8; 0]>::parse_bytes(&[]).is_err()); | ||
| assert!(ZeroSlice::<[u8; 0]>::parse_bytes(bytes).is_err()); | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet