1pub type IcDbmsError = wasm_dbms_api::error::DbmsError;
3
4pub type IcDbmsResult<T> = wasm_dbms_api::error::DbmsResult<T>;
6
7#[cfg(test)]
8mod test {
9
10 use wasm_dbms_api::prelude::{MemoryError, QueryError, TableError, TransactionError};
11
12 use super::*;
13
14 #[test]
15 fn test_should_display_memory_error() {
16 let error = IcDbmsError::Memory(MemoryError::OutOfBounds);
17 assert_eq!(
18 error.to_string(),
19 "Memory error: Stable memory access out of bounds"
20 );
21 }
22
23 #[test]
24 fn test_should_display_query_error() {
25 let error = IcDbmsError::Query(QueryError::UnknownColumn("foo".to_string()));
26 assert_eq!(error.to_string(), "Query error: Unknown column: foo");
27 }
28
29 #[test]
30 fn test_should_display_sanitize_error() {
31 let error = IcDbmsError::Sanitize("invalid input".to_string());
32 assert_eq!(error.to_string(), "Sanitize error: invalid input");
33 }
34
35 #[test]
36 fn test_should_display_table_error() {
37 let error = IcDbmsError::Table(TableError::TableNotFound);
38 assert_eq!(error.to_string(), "Table error: Table not found");
39 }
40
41 #[test]
42 fn test_should_display_transaction_error() {
43 let error = IcDbmsError::Transaction(TransactionError::NoActiveTransaction);
44 assert_eq!(
45 error.to_string(),
46 "Transaction error: No active transaction"
47 );
48 }
49
50 #[test]
51 fn test_should_display_validation_error() {
52 let error = IcDbmsError::Validation("invalid email".to_string());
53 assert_eq!(error.to_string(), "Validation error: invalid email");
54 }
55
56 #[test]
57 fn test_should_convert_from_memory_error() {
58 let error: IcDbmsError = MemoryError::OutOfBounds.into();
59 assert!(matches!(
60 error,
61 IcDbmsError::Memory(MemoryError::OutOfBounds)
62 ));
63 }
64
65 #[test]
66 fn test_should_convert_from_query_error() {
67 let error: IcDbmsError = QueryError::UnknownColumn("col".to_string()).into();
68 assert!(matches!(error, IcDbmsError::Query(_)));
69 }
70
71 #[test]
72 fn test_should_convert_from_table_error() {
73 let error: IcDbmsError = TableError::TableNotFound.into();
74 assert!(matches!(error, IcDbmsError::Table(_)));
75 }
76
77 #[test]
78 fn test_should_convert_from_transaction_error() {
79 let error: IcDbmsError = TransactionError::NoActiveTransaction.into();
80 assert!(matches!(error, IcDbmsError::Transaction(_)));
81 }
82}