From acd472ae2a246194b1c632e0ab0f91f0f88f60ec Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 15 Mar 2026 23:05:05 +0100 Subject: Formatting --- oryxc/src/arena.rs | 5 +++- oryxc/src/intern.rs | 56 ++++++++++++++++++++---------------------- oryxc/src/unistr.rs | 71 +++++++++++++++++++++++++++++++---------------------- 3 files changed, 72 insertions(+), 60 deletions(-) (limited to 'oryxc') diff --git a/oryxc/src/arena.rs b/oryxc/src/arena.rs index 01a4290..cb05908 100644 --- a/oryxc/src/arena.rs +++ b/oryxc/src/arena.rs @@ -221,7 +221,10 @@ impl<'s, 'a> ScopedArena<'s, 'a> { #[cfg(test)] mod tests { - use super::{GlobalArena, LocalArena}; + use super::{ + GlobalArena, + LocalArena, + }; #[test] fn test_alloc_slice() { diff --git a/oryxc/src/intern.rs b/oryxc/src/intern.rs index 684a693..eea3cfa 100644 --- a/oryxc/src/intern.rs +++ b/oryxc/src/intern.rs @@ -1,6 +1,4 @@ -use std::hash::{ - Hash, -}; +use std::hash::Hash; use boxcar; use dashmap::DashMap; @@ -34,7 +32,7 @@ where if let Some(key) = self.map.get(&value) { return *key; } - let key = self.store.push(value).into(); + let key = self.store.push(value).into(); self.map.insert(value, key); return key; } @@ -42,33 +40,33 @@ where #[cfg(test)] mod tests { - use crate::unistr::UniStr; - use super::Interner; + use super::Interner; + use crate::unistr::UniStr; - #[test] - fn test_interner_intern() { - let xs = [UniStr("fishi"), UniStr("fishi"), UniStr("fishᵢ")]; - let y = UniStr("andy"); + #[test] + fn test_interner_intern() { + let xs = [UniStr("fishi"), UniStr("fishi"), UniStr("fishᵢ")]; + let y = UniStr("andy"); - let mut interner = Interner::<_, usize>::new(); - for i in 0..xs.len() { - for j in i..xs.len() { - assert_eq!(interner.intern(xs[i]), interner.intern(xs[j])); - } - } - for i in 0..xs.len() { - assert_ne!(interner.intern(y), interner.intern(xs[i])); - } - } + let mut interner = Interner::<_, usize>::new(); + for i in 0..xs.len() { + for j in i..xs.len() { + assert_eq!(interner.intern(xs[i]), interner.intern(xs[j])); + } + } + for i in 0..xs.len() { + assert_ne!(interner.intern(y), interner.intern(xs[i])); + } + } - #[test] - fn test_interner_gets_first_inserted() { - let mut interner = Interner::<_, usize>::new(); - let xs = [UniStr("fishi"), UniStr("fishi"), UniStr("fishᵢ")]; - let ys = xs.iter().map(|&x| interner.intern(x)).collect::>(); + #[test] + fn test_interner_gets_first_inserted() { + let mut interner = Interner::<_, usize>::new(); + let xs = [UniStr("fishi"), UniStr("fishi"), UniStr("fishᵢ")]; + let ys = xs.iter().map(|&x| interner.intern(x)).collect::>(); - for i in 0..ys.len() { - assert_eq!(interner.get(ys[i]), xs[0]); - } - } + for i in 0..ys.len() { + assert_eq!(interner.get(ys[i]), xs[0]); + } + } } diff --git a/oryxc/src/unistr.rs b/oryxc/src/unistr.rs index 5dc8160..1d8463d 100644 --- a/oryxc/src/unistr.rs +++ b/oryxc/src/unistr.rs @@ -1,13 +1,20 @@ -use std::hash::{Hash, Hasher}; +use std::hash::{ + Hash, + Hasher, +}; -use unicode_normalization::{self, IsNormalized, UnicodeNormalization}; +use unicode_normalization::{ + self, + IsNormalized, + UnicodeNormalization, +}; #[repr(transparent)] #[derive(Copy, Clone, Debug, Eq)] pub struct UniStr<'a>(pub &'a str); impl Hash for UniStr<'_> { - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { /* In the ASCII common case we use .bytes() to avoid decoding * every codepoint (a no-op in ASCII) */ if self.0.is_ascii() { @@ -19,7 +26,7 @@ impl Hash for UniStr<'_> { } else { self.0.nfkd().for_each(|c| c.hash(state)); } - } + } } impl PartialEq for UniStr<'_> { @@ -52,33 +59,37 @@ impl PartialEq for UniStr<'_> { #[cfg(test)] mod tests { - use std::hash::{DefaultHasher, Hash, Hasher}; + use std::hash::{ + DefaultHasher, + Hash, + Hasher, + }; - use super::UniStr; + use super::UniStr; - #[test] - fn test_unistr_eq() { - assert_eq!(UniStr("fishi"), UniStr("fishᵢ")); - assert_eq!(UniStr("fishi"), UniStr("fishi")); - assert_eq!(UniStr("fishi"), UniStr("fishᵢ")); - assert_eq!(UniStr("fishᵢ"), UniStr("fishᵢ")); - assert_eq!(UniStr("corné"), UniStr("corné")); - } + #[test] + fn test_unistr_eq() { + assert_eq!(UniStr("fishi"), UniStr("fishᵢ")); + assert_eq!(UniStr("fishi"), UniStr("fishi")); + assert_eq!(UniStr("fishi"), UniStr("fishᵢ")); + assert_eq!(UniStr("fishᵢ"), UniStr("fishᵢ")); + assert_eq!(UniStr("corné"), UniStr("corné")); + } - #[test] - fn test_unistr_hash() { - for (lhs, rhs) in &[ - (UniStr("fishi"), UniStr("fishᵢ")), - (UniStr("fishi"), UniStr("fishi")), - (UniStr("fishi"), UniStr("fishᵢ")), - (UniStr("fishᵢ"), UniStr("fishᵢ")), - (UniStr("corné"), UniStr("corné")), - ] { - let mut hashl = DefaultHasher::new(); - let mut hashr = DefaultHasher::new(); - lhs.hash(&mut hashl); - rhs.hash(&mut hashr); - assert_eq!(hashl.finish(), hashr.finish()); - } - } + #[test] + fn test_unistr_hash() { + for (lhs, rhs) in &[ + (UniStr("fishi"), UniStr("fishᵢ")), + (UniStr("fishi"), UniStr("fishi")), + (UniStr("fishi"), UniStr("fishᵢ")), + (UniStr("fishᵢ"), UniStr("fishᵢ")), + (UniStr("corné"), UniStr("corné")), + ] { + let mut hashl = DefaultHasher::new(); + let mut hashr = DefaultHasher::new(); + lhs.hash(&mut hashl); + rhs.hash(&mut hashr); + assert_eq!(hashl.finish(), hashr.finish()); + } + } } -- cgit v1.2.3