kotoba_core/
lib.rs

1//! kotoba-core - Kotoba Core Components
2
3pub mod types;
4pub mod schema;
5pub mod schema_validator;
6// pub mod pgview; // Temporarily disabled due to Value type conflicts
7pub mod ir;
8pub mod prelude {
9    // Re-export commonly used items
10    pub use crate::types::*;
11    pub use crate::schema::*;
12    pub use crate::schema_validator::*;
13    // pub use crate::pgview::*; // Temporarily disabled
14    pub use crate::ir::*;
15}
16
17#[cfg(test)]
18mod tests {
19    use super::*;
20    use crate::types::*;
21
22    #[test]
23    fn test_value_serialization() {
24        // Test Value enum serialization
25        let null_val = Value::Null;
26        let json = serde_json::to_string(&null_val).unwrap();
27        assert_eq!(json, "null");
28
29        let bool_val = Value::Bool(true);
30        let json = serde_json::to_string(&bool_val).unwrap();
31        assert_eq!(json, "true");
32
33        let int_val = Value::Int(42);
34        let json = serde_json::to_string(&int_val).unwrap();
35        assert_eq!(json, "42");
36
37        let str_val = Value::String("hello".to_string());
38        let json = serde_json::to_string(&str_val).unwrap();
39        assert_eq!(json, "\"hello\"");
40    }
41
42    #[test]
43    fn test_value_deserialization() {
44        // Test Value enum deserialization
45        let null_val: Value = serde_json::from_str("null").unwrap();
46        assert_eq!(null_val, Value::Null);
47
48        let bool_val: Value = serde_json::from_str("true").unwrap();
49        assert_eq!(bool_val, Value::Bool(true));
50
51        let int_val: Value = serde_json::from_str("42").unwrap();
52        assert_eq!(int_val, Value::Int(42));
53
54        let str_val: Value = serde_json::from_str("\"hello\"").unwrap();
55        assert_eq!(str_val, Value::String("hello".to_string()));
56    }
57
58    #[test]
59    fn test_content_hash() {
60        // Test ContentHash generation
61        let data = [42u8; 32];
62        let hash = ContentHash::sha256(data);
63        assert!(!hash.0.is_empty());
64
65        // Test that same data produces same hash
66        let hash2 = ContentHash::sha256(data);
67        assert_eq!(hash, hash2);
68    }
69
70    #[test]
71    fn test_uuid_types() {
72        // Test that VertexId and EdgeId are UUIDs
73        let vertex_id = VertexId::new_v4();
74        let edge_id = EdgeId::new_v4();
75
76        assert_ne!(vertex_id, edge_id); // Should be different UUIDs
77        assert_eq!(vertex_id.get_version_num(), 4); // Should be v4 UUIDs
78        assert_eq!(edge_id.get_version_num(), 4);
79    }
80}