crates/graphar-falkordb/src/tests.rs
#[cfg(test)]
mod cypher_tests {
use std::sync::Arc;
use arrow_array::{Int64Array, RecordBatch, StringArray};
use arrow_schema::{DataType, Field, Schema};
use crate::cypher::{EdgeRow, arrow_value_to_cypher, unwind_create_query, unwind_edge_query};
fn make_batch() -> RecordBatch {
let schema = Arc::new(Schema::new(vec![
Field::new("id", DataType::Int64, false),
Field::new("name", DataType::Utf8, true),
]));
RecordBatch::try_new(
schema,
vec![
Arc::new(Int64Array::from(vec![1i64, 2, 3])),
Arc::new(StringArray::from(vec!["Alice", "Bob", "Carol"])),
],
)
.unwrap()
}
#[test]
fn int64_to_cypher() {
let arr = Int64Array::from(vec![42i64]);
let lit = arrow_value_to_cypher(&arr, 0).unwrap();
assert_eq!(lit, "42");
}
#[test]
fn string_to_cypher_escapes_quotes() {
let arr = StringArray::from(vec!["it's a \"test\""]);
let lit = arrow_value_to_cypher(&arr, 0).unwrap();
assert_eq!(lit, "'it\\'s a \"test\"'");
}
#[test]
fn null_to_cypher() {
let arr = Int64Array::from(vec![None::<i64>]);
let lit = arrow_value_to_cypher(&arr, 0).unwrap();
assert_eq!(lit, "null");
}
#[test]
fn unwind_create_query_format() {
let maps = vec![
"{`_gar_id`: 0, `id`: 1, `name`: 'Alice'}".to_string(),
"{`_gar_id`: 1, `id`: 2, `name`: 'Bob'}".to_string(),
];
let q = unwind_create_query("Person", &maps);
assert!(q.contains("UNWIND ["));
assert!(q.contains("CREATE (n:`Person`)"));
assert!(q.contains("SET n = row"));
}
#[test]
fn unwind_edge_query_format() {
let rows = vec![EdgeRow {
src_id: vec!["0".into()],
dst_id: vec!["1".into()],
props: vec![("since".into(), "2020".into())],
}];
let q = unwind_edge_query("Person", "KNOWS", "Person", "_gar_id", "_gar_id", &rows);
assert!(q.contains("MATCH (a:`Person`"));
assert!(q.contains("CREATE (a)-[r:`KNOWS`]->(b)"));
assert!(q.contains("REMOVE r._src, r._dst"));
}
// `insert_vertices_builds_correct_queries` used to live here. It asserted
// `make_batch().num_rows() == 3` — its OWN fixture — while its name promised
// query verification and its comment claimed it inspected generated Cypher
// "via a test-only FalkorDbLoader backed by a mock that captures queries".
// No such mock existed, and the comment pointed at an integration-test file
// that has never existed in this repo (the live-DB tests are in
// `tests/integration_falkordb.rs`, and they are `#[ignore]`d). It could not
// fail unless the fixture itself was edited.
//
// The dead path is deliberately NOT spelled out here: `crates/knut-tracing/
// tests/no_phantom_guard_citations.rs` fails on any comment naming a file that
// does not exist, and it is right to — it cannot tell a post-mortem from a claim.
//
// What it claimed to cover is now genuinely covered, connection-free, in
// `loader::render_tests`:
// * `vertex_row_shape_is_exact_at_its_single_writer` — the exact row map,
// `_gar_id` included, at `push_vertex_row`;
// * `single_vertex_row_writer` — that there is only one such writer;
// * `vertex_render_exact_and_gar_ids_across_batches` — the whole emitted
// `UNWIND … CREATE` query, byte for byte.
}