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

Function test_realistic_rust_module

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

Source from the content-addressed store, hash-verified

987
988 #[test]
989 fn test_realistic_rust_module() {
990 let mut parser = RustParser::new();
991 let source = r#"
992//! Repository module for data access.
993
994use std::collections::HashMap;
995use thiserror::Error;
996
997/// Error type for repository operations.
998#[derive(Debug, Error)]
999pub enum RepoError {
1000 #[error("Not found: {0}")]
1001 NotFound(String),
1002 #[error("Duplicate key: {0}")]
1003 DuplicateKey(String),
1004}
1005
1006/// A generic in-memory repository.
1007pub struct Repository<T: Clone> {
1008 data: HashMap<String, T>,
1009}
1010
1011impl<T: Clone> Repository<T> {
1012 /// Create a new empty repository.
1013 pub fn new() -> Self {
1014 Self {
1015 data: HashMap::new(),
1016 }
1017 }
1018
1019 /// Find an item by key.
1020 pub fn find(&self, key: &str) -> Result<&T, RepoError> {
1021 self.data.get(key).ok_or_else(|| RepoError::NotFound(key.to_string()))
1022 }
1023
1024 /// Insert an item.
1025 pub fn insert(&mut self, key: String, value: T) -> Result<(), RepoError> {
1026 if self.data.contains_key(&key) {
1027 return Err(RepoError::DuplicateKey(key));
1028 }
1029 self.data.insert(key, value);
1030 Ok(())
1031 }
1032
1033 /// Get the count of items.
1034 pub fn count(&self) -> usize {
1035 self.data.len()
1036 }
1037}
1038
1039pub type Result<T> = std::result::Result<T, RepoError>;
1040
1041pub const MAX_ITEMS: usize = 10_000;
1042
1043#[cfg(test)]
1044mod tests {
1045 use super::*;
1046

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected