From 7f5e6c5b6e6556f06daa57bea471a8493c496f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Wed, 2 Jan 2019 21:48:58 +0100 Subject: [PATCH] test: Add test to the DocumentKeyAttr slice repr --- src/database/document_key.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/database/document_key.rs b/src/database/document_key.rs index cfcb34ad6..77f2ee43f 100644 --- a/src/database/document_key.rs +++ b/src/database/document_key.rs @@ -8,7 +8,7 @@ use crate::database::schema::SchemaAttr; use crate::DocumentId; const DOC_KEY_LEN: usize = 4 + size_of::(); -const DOC_KEY_ATTR_LEN: usize = DOC_KEY_LEN + 1 + size_of::(); +const DOC_KEY_ATTR_LEN: usize = DOC_KEY_LEN + 1 + size_of::(); #[derive(Copy, Clone)] pub struct DocumentKey([u8; DOC_KEY_LEN]); @@ -126,3 +126,20 @@ impl fmt::Debug for DocumentKeyAttr { .finish() } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn keep_as_ref_order() { + for (a, b) in (0..).zip(1..).take(u16::max_value() as usize - 1) { + let id = DocumentId(0); + let a = DocumentKeyAttr::new(id, SchemaAttr(a)); + let b = DocumentKeyAttr::new(id, SchemaAttr(b)); + + assert!(a < b); + assert!(a.as_ref() < b.as_ref()); + } + } +}