MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / test_realistic_rust_module

Function test_realistic_rust_module

atomic-semantic/src/parsers/rust.rs:966–1068  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

964
965 #[test]
966 fn test_realistic_rust_module() {
967 let mut parser = RustParser::new();
968 let source = r#"
969//! Repository module for data access.
970
971use std::collections::HashMap;
972use thiserror::Error;
973
974/// Error type for repository operations.
975#[derive(Debug, Error)]
976pub enum RepoError {
977 #[error("Not found: {0}")]
978 NotFound(String),
979 #[error("Duplicate key: {0}")]
980 DuplicateKey(String),
981}
982
983/// A generic in-memory repository.
984pub struct Repository<T: Clone> {
985 data: HashMap<String, T>,
986}
987
988impl<T: Clone> Repository<T> {
989 /// Create a new empty repository.
990 pub fn new() -> Self {
991 Self {
992 data: HashMap::new(),
993 }
994 }
995
996 /// Find an item by key.
997 pub fn find(&self, key: &str) -> Result<&T, RepoError> {
998 self.data.get(key).ok_or_else(|| RepoError::NotFound(key.to_string()))
999 }
1000
1001 /// Insert an item.
1002 pub fn insert(&mut self, key: String, value: T) -> Result<(), RepoError> {
1003 if self.data.contains_key(&key) {
1004 return Err(RepoError::DuplicateKey(key));
1005 }
1006 self.data.insert(key, value);
1007 Ok(())
1008 }
1009
1010 /// Get the count of items.
1011 pub fn count(&self) -> usize {
1012 self.data.len()
1013 }
1014}
1015
1016pub type Result<T> = std::result::Result<T, RepoError>;
1017
1018pub const MAX_ITEMS: usize = 10_000;
1019
1020#[cfg(test)]
1021mod tests {
1022 use super::*;
1023

Callers

nothing calls this directly

Calls 4

extractMethod · 0.45
iterMethod · 0.45
as_strMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected