1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! Backend-specific functionality tests.
//!
//! These tests verify backend-specific operations that are only available
//! with certain feature flags enabled.
//!
//! Run with:
//! cargo test # SQLite backend (default)
use splice::graph::BackendType;
use splice::CodeGraph;
use std::fs;
use std::io::Write;
use tempfile::TempDir;
///////////////////////////////////////////////////////////////////////////////
// SQLite backend specific tests
///////////////////////////////////////////////////////////////////////////////
#[cfg(feature = "sqlite")]
#[test]
fn test_sqlite_header_detection() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let db_path = temp_dir.path().join("test_sqlite_header.db");
// Write SQLite format 3 header
{
let mut file = fs::File::create(&db_path).expect("Failed to create file");
file.write_all(b"SQLite format 3\0")
.expect("Failed to write header");
}
let detected = CodeGraph::detect_backend(&db_path).expect("Detection failed");
assert_eq!(BackendType::SQLite, detected, "Should detect SQLite format");
}
#[cfg(feature = "sqlite")]
#[test]
fn test_sqlite_graph_open_existing() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let db_path = temp_dir.path().join("test_sqlite_open.db");
let _ = fs::remove_file(&db_path);
// Create a SQLite format file first
{
let mut file = fs::File::create(&db_path).expect("Failed to create file");
file.write_all(b"SQLite format 3\0")
.expect("Failed to write header");
}
// Open should detect SQLite format and use appropriate backend
let _graph = CodeGraph::open(&db_path);
// This might fail because we only wrote the header, not a complete database
// But the important part is that it detected the format correctly
// Verify it's detected as SQLite
let detected = CodeGraph::detect_backend(&db_path).expect("Detection failed");
assert_eq!(
BackendType::SQLite,
detected,
"Should detect SQLite format from header"
);
}
///////////////////////////////////////////////////////////////////////////////
// Cross-backend compatibility tests
///////////////////////////////////////////////////////////////////////////////
#[test]
fn test_backend_format_detectable() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
// Test non-existent file
let nonexistent = temp_dir.path().join("nonexistent.db");
let detected = CodeGraph::detect_backend(&nonexistent).expect("Detection failed");
assert_eq!(
BackendType::SQLite,
detected,
"Non-existent file should default to SQLite"
);
}
///////////////////////////////////////////////////////////////////////////////
// Feature flag test
///////////////////////////////////////////////////////////////////////////////
#[test]
fn test_sqlite_backend_active() {
// Verify that the sqlite backend is active by default
let sqlite_enabled = cfg!(feature = "sqlite");
assert!(
sqlite_enabled,
"SQLite backend should be enabled by default"
);
}