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    // Re-export KotobaError to avoid version conflicts
16    pub use kotoba_errors::KotobaError;
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22    use crate::types::*;
23
24    #[test]
25    fn test_value_serialization() {
26        // Test Value enum serialization
27        let null_val = Value::Null;
28        let json = serde_json::to_string(&null_val).unwrap();
29        assert_eq!(json, "null");
30
31        let bool_val = Value::Bool(true);
32        let json = serde_json::to_string(&bool_val).unwrap();
33        assert_eq!(json, "true");
34
35        let int_val = Value::Int(42);
36        let json = serde_json::to_string(&int_val).unwrap();
37        assert_eq!(json, "42");
38
39        let str_val = Value::String("hello".to_string());
40        let json = serde_json::to_string(&str_val).unwrap();
41        assert_eq!(json, "\"hello\"");
42    }
43
44    #[test]
45    fn test_value_deserialization() {
46        // Test Value enum deserialization
47        let null_val: Value = serde_json::from_str("null").unwrap();
48        assert_eq!(null_val, Value::Null);
49
50        let bool_val: Value = serde_json::from_str("true").unwrap();
51        assert_eq!(bool_val, Value::Bool(true));
52
53        let int_val: Value = serde_json::from_str("42").unwrap();
54        assert_eq!(int_val, Value::Int(42));
55
56        let str_val: Value = serde_json::from_str("\"hello\"").unwrap();
57        assert_eq!(str_val, Value::String("hello".to_string()));
58    }
59
60    #[test]
61    fn test_content_hash() {
62        // Test ContentHash generation
63        let data = [42u8; 32];
64        let hash = ContentHash::sha256(data);
65        assert!(!hash.0.is_empty());
66
67        // Test that same data produces same hash
68        let hash2 = ContentHash::sha256(data);
69        assert_eq!(hash, hash2);
70    }
71
72    #[test]
73    fn test_uuid_types() {
74        // Test that VertexId and EdgeId are UUIDs
75        let vertex_id = VertexId::new_v4();
76        let edge_id = EdgeId::new_v4();
77
78        assert_ne!(vertex_id, edge_id); // Should be different UUIDs
79        assert_eq!(vertex_id.get_version_num(), 4); // Should be v4 UUIDs
80        assert_eq!(edge_id.get_version_num(), 4);
81    }
82}