From d4e7625e1f4cee94d6727fc1ee18423a7284d347 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sun, 17 May 2026 08:14:06 +0530 Subject: [PATCH 1/4] test(compat): add XTDB compatibility tests (#221) Co-Authored-By: Claude Sonnet 4.6 --- tests/xtdb_compat_test.rs | 278 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 tests/xtdb_compat_test.rs diff --git a/tests/xtdb_compat_test.rs b/tests/xtdb_compat_test.rs new file mode 100644 index 0000000000..9f83019819 --- /dev/null +++ b/tests/xtdb_compat_test.rs @@ -0,0 +1,278 @@ +//! XTDB compatibility tests (#221). +//! +//! License: XTDB is Apache 2.0. These tests are semantic ports of query +//! concepts from the XTDB documentation and test suite. Each test is +//! annotated with its XTDB concept source. +//! +//! Skipped cases are listed at the bottom of this file. +//! +//! Run: cargo test --test xtdb_compat_test + +#![cfg(not(target_arch = "wasm32"))] + +use minigraf::{Minigraf, QueryResult, Value}; + +fn count_results(r: QueryResult) -> usize { + match r { + QueryResult::QueryResults { results, .. } => results.len(), + _ => 0, + } +} + +fn query_strings(db: &Minigraf, q: &str) -> Vec { + match db.execute(q).unwrap() { + QueryResult::QueryResults { results, .. } => results + .into_iter() + .flatten() + .filter_map(|v| match v { + Value::String(s) => Some(s), + _ => None, + }) + .collect(), + _ => vec![], + } +} + +// ── Basic EAV queries ───────────────────────────────────────────────────────── + +/// XTDB concept: find all entities with a specific attribute value. +/// Source: XTDB "Basic Queries" documentation. +#[test] +fn xtdb_basic_find_by_attribute_value() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:pablo :profession "painter"] + [:salvador :profession "painter"] + [:kafka :profession "writer"] + ])"#) + .unwrap(); + + let painters = count_results( + db.execute(r#"(query [:find ?e :where [?e :profession "painter"]])"#) + .unwrap(), + ); + assert_eq!(painters, 2, "should find 2 painters"); +} + +/// XTDB concept: multi-attribute join (entities satisfying multiple conditions). +/// Source: XTDB "Joins" documentation. +#[test] +fn xtdb_multi_attribute_join() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:e1 :role "admin"] [:e1 :active true] + [:e2 :role "user"] [:e2 :active true] + [:e3 :role "admin"] [:e3 :active false] + ])"#) + .unwrap(); + + let active_admins = count_results( + db.execute(r#"(query [:find ?e :where [?e :role "admin"] [?e :active true]])"#) + .unwrap(), + ); + assert_eq!(active_admins, 1, "only e1 is an active admin"); +} + +/// XTDB concept: find entities related through a reference. +/// Source: XTDB "Joins" — entity reference traversal. +#[test] +fn xtdb_entity_reference_join() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:alice :dept :dept-eng] + [:bob :dept :dept-eng] + [:carol :dept :dept-hr] + ])"#) + .unwrap(); + + let eng_employees = count_results( + db.execute(r#"(query [:find ?emp :where [?emp :dept :dept-eng]])"#) + .unwrap(), + ); + assert_eq!(eng_employees, 2, "alice and bob are in engineering"); +} + +// ── Retraction ─────────────────────────────────────────────────────────────── + +/// XTDB concept: retraction removes a specific fact, not the whole entity. +/// Source: XTDB "Transactions" — retract. +#[test] +fn xtdb_retraction_removes_specific_fact() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [[:alice :name "Alice"] [:alice :role "admin"]])"#) + .unwrap(); + + // Retract only the :role fact. + db.execute(r#"(retract [[:alice :role "admin"]])"#).unwrap(); + + let roles = count_results( + db.execute(r#"(query [:find ?r :where [?e :role ?r]])"#) + .unwrap(), + ); + assert_eq!(roles, 0, "role should be retracted"); + + let names = count_results( + db.execute(r#"(query [:find ?n :where [?e :name ?n]])"#) + .unwrap(), + ); + assert_eq!(names, 1, "name should survive retraction of role"); +} + +/// XTDB concept: retracted fact is not visible after retraction. +#[test] +fn xtdb_retracted_fact_not_visible() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [[:item :status "active"]])"#) + .unwrap(); + db.execute(r#"(retract [[:item :status "active"]])"#) + .unwrap(); + + let n = count_results( + db.execute(r#"(query [:find ?s :where [?item :status ?s]])"#) + .unwrap(), + ); + assert_eq!(n, 0, "retracted fact must not be visible"); +} + +// ── Temporal queries ────────────────────────────────────────────────────────── + +/// XTDB concept: as-of query returns state at a past transaction count. +/// Source: XTDB "Bitemporality" — transaction-time queries. +#[test] +fn xtdb_as_of_returns_past_state() { + let db = Minigraf::in_memory().unwrap(); + + // tx 1: alice has role "user" + db.execute(r#"(transact [[:alice :role "user"]])"#).unwrap(); + + // tx 2 + 3: alice's role changes to "admin" + db.execute(r#"(retract [[:alice :role "user"]])"#).unwrap(); + db.execute(r#"(transact [[:alice :role "admin"]])"#).unwrap(); + + // Current state: admin. + let current = query_strings(&db, r#"(query [:find ?r :where [?e :role ?r]])"#); + assert!(current.contains(&"admin".to_string()), "current role should be admin"); + + // As-of tx 1: user. + let past = query_strings(&db, r#"(query [:find ?r :as-of 1 :valid-at :any-valid-time :where [?e :role ?r]])"#); + assert!(past.contains(&"user".to_string()), "past role at tx 1 should be user"); +} + +/// XTDB concept: valid-time query returns facts valid at a specific time. +/// Source: XTDB "Bitemporality" — valid-time queries. +#[test] +fn xtdb_valid_at_query() { + let db = Minigraf::in_memory().unwrap(); + + // Assert a fact with valid-time range. + db.execute(r#"(transact {:valid-from "2023-01-01" :valid-to "2023-12-31"} [[:contract :status "active"]])"#) + .unwrap(); + + // Query at valid-time within the range — should find the fact. + let n = count_results( + db.execute(r#"(query [:find ?s :valid-at "2023-06-01" :where [?e :status ?s]])"#) + .unwrap(), + ); + assert_eq!(n, 1, "fact should be visible within valid-time range"); + + // Query at valid-time outside the range — should not find the fact. + let n_after = count_results( + db.execute(r#"(query [:find ?s :valid-at "2024-01-01" :where [?e :status ?s]])"#) + .unwrap(), + ); + assert_eq!(n_after, 0, "fact should not be visible after valid-to boundary"); +} + +// ── Negation ───────────────────────────────────────────────────────────────── + +/// XTDB concept: not clause excludes entities matching a pattern. +/// Source: XTDB "Queries" — not clauses. +#[test] +fn xtdb_not_excludes_matching_entities() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:alice :person true] [:alice :banned true] + [:bob :person true] + [:carol :person true] [:carol :banned true] + ])"#) + .unwrap(); + + let unbanned = count_results( + db.execute(r#"(query [:find ?e :where [?e :person true] (not [?e :banned true])])"#) + .unwrap(), + ); + assert_eq!(unbanned, 1, "only bob should appear (not banned)"); +} + +// ── Aggregation ────────────────────────────────────────────────────────────── + +/// XTDB concept: count aggregate returns number of matching tuples. +/// Source: XTDB "Aggregates" documentation. +#[test] +fn xtdb_count_aggregate() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:a :tag "rust"] [:b :tag "rust"] [:c :tag "go"] [:d :tag "rust"] + ])"#) + .unwrap(); + + match db + .execute(r#"(query [:find (count ?e) :where [?e :tag "rust"]])"#) + .unwrap() + { + QueryResult::QueryResults { results, .. } => { + assert!(!results.is_empty(), "count aggregate must return a result"); + match results[0][0] { + Value::Integer(n) => assert_eq!(n, 3, "count of :tag rust should be 3"), + _ => panic!("expected integer count value"), + } + } + _ => panic!("expected QueryResults"), + } +} + +// ── Recursive rules ─────────────────────────────────────────────────────────── + +/// XTDB concept: recursive rules traverse transitive relationships. +/// Source: XTDB "Rules" — transitive closure. +#[test] +fn xtdb_recursive_ancestor_rule() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:alice :parent :bob] + [:bob :parent :carol] + [:carol :parent :dave] + ])"#) + .unwrap(); + + db.execute(r#"(rule [(ancestor ?x ?y) [?x :parent ?y]])"#) + .unwrap(); + db.execute(r#"(rule [(ancestor ?x ?z) [?x :parent ?y] (ancestor ?y ?z)])"#) + .unwrap(); + + let ancestors_of_alice = count_results( + db.execute(r#"(query [:find ?anc :where (ancestor :alice ?anc)])"#) + .unwrap(), + ); + assert_eq!(ancestors_of_alice, 3, "alice has 3 ancestors: bob, carol, dave"); +} + +// ═════════════════════════════════════════════════════════════════════════════ +// SKIPPED CASES +// ═════════════════════════════════════════════════════════════════════════════ +// +// The following XTDB features are intentionally out of scope for Minigraf: +// +// 1. XTDB SQL compatibility — Minigraf uses Datalog only (not SQL/GQL). +// XTDB v2 added SQL; we do not implement SQL. +// +// 2. XTDB distributed transaction log — Minigraf is embedded single-file; +// no distributed transaction semantics apply. +// +// 3. XTDB Arrow/Parquet integration — Minigraf uses postcard serialization; +// columnar formats are out of scope. +// +// 4. XTDB evict! (GDPR deletion) — Minigraf does not yet implement hard +// deletion (tracked separately). These tests would fail. +// +// 5. XTDB multi-node consistency — Minigraf is single-process only. From ddefd9488c00e934f04cd29b3db8e04e211c9d6e Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sun, 17 May 2026 08:14:06 +0530 Subject: [PATCH 2/4] test(compat): add Datomic-inspired compatibility tests (#221) Co-Authored-By: Claude Sonnet 4.6 --- tests/datomic_compat_test.rs | 276 +++++++++++++++++++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 tests/datomic_compat_test.rs diff --git a/tests/datomic_compat_test.rs b/tests/datomic_compat_test.rs new file mode 100644 index 0000000000..78bf6bc7c5 --- /dev/null +++ b/tests/datomic_compat_test.rs @@ -0,0 +1,276 @@ +//! Datomic-inspired compatibility tests (#221). +//! +//! License notice: Datomic is a commercial product. These tests are +//! INDEPENDENTLY WRITTEN semantic ports — they test concepts from Datomic's +//! query model (EAV, pull, as-of, history) but share no code or literal +//! test data with any Datomic test suite. Written from scratch based on +//! Datomic's public documentation. +//! +//! Run: cargo test --test datomic_compat_test + +#![cfg(not(target_arch = "wasm32"))] + +use minigraf::{BindValue, Minigraf, QueryResult, Value}; + +fn count_results(r: QueryResult) -> usize { + match r { + QueryResult::QueryResults { results, .. } => results.len(), + _ => 0, + } +} + +// ── Datomic concept: EAV triple model ──────────────────────────────────────── + +/// Datomic concept: entity attributes are independent facts (datoms). +/// Datomic doc reference: "Datomic Data Model" — datoms. +#[test] +fn datomic_entity_attributes_are_independent_facts() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:user42 :user/name "Jane"] + [:user42 :user/email "jane@example.com"] + [:user42 :user/role :admin] + ])"#) + .unwrap(); + + // Each attribute is an independent queryable fact. + assert_eq!( + count_results( + db.execute(r#"(query [:find ?n :where [?e :user/name ?n]])"#) + .unwrap() + ), + 1, + "name fact must be independently queryable" + ); + assert_eq!( + count_results( + db.execute(r#"(query [:find ?em :where [?e :user/email ?em]])"#) + .unwrap() + ), + 1, + "email fact must be independently queryable" + ); +} + +/// Datomic concept: cardinality-many attributes — multiple entities share the same attribute. +/// Datomic doc reference: "Schema" — :db/cardinality/many. +/// In Minigraf, multiple entities can each hold a :tag fact; querying ?e ?t returns all pairs. +#[test] +fn datomic_cardinality_many_multiple_values() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:article1 :tag "rust"] + [:article2 :tag "database"] + [:article3 :tag "embedded"] + ])"#) + .unwrap(); + + let tags = count_results( + db.execute(r#"(query [:find ?e ?t :where [?e :tag ?t]])"#) + .unwrap(), + ); + assert_eq!(tags, 3, "all 3 tag facts must be independently queryable"); +} + +// ── Datomic concept: transaction metadata ──────────────────────────────────── + +/// Datomic concept: transaction time (tx-id) is queryable via :as-of. +/// Datomic doc reference: "Time" — transaction entity. +/// Minigraf equivalent: :as-of by tx_count. +#[test] +fn datomic_transaction_time_as_of() { + let db = Minigraf::in_memory().unwrap(); + + // tx 1 + db.execute(r#"(transact [[:inv :qty 10]])"#).unwrap(); + // tx 2 + 3 + db.execute(r#"(retract [[:inv :qty 10]])"#).unwrap(); + db.execute(r#"(transact [[:inv :qty 20]])"#).unwrap(); + + // As-of tx 1 must return qty = 10. + match db + .execute(r#"(query [:find ?q :as-of 1 :valid-at :any-valid-time :where [?e :qty ?q]])"#) + .unwrap() + { + QueryResult::QueryResults { results, .. } => { + let qty: Vec = results + .into_iter() + .flatten() + .filter_map(|v| match v { + Value::Integer(n) => Some(n), + _ => None, + }) + .collect(); + assert!(qty.contains(&10), "as-of tx 1: qty must be 10"); + } + _ => panic!("expected QueryResults"), + } +} + +// ── Datomic concept: retraction ────────────────────────────────────────────── + +/// Datomic concept: retract-entity removes all facts about an entity. +/// Datomic doc reference: "Transactions" — :db/retractEntity. +/// Minigraf equivalent: retract each attribute individually. +#[test] +fn datomic_retract_all_entity_facts() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:ghost :name "Ghost"] + [:ghost :age 100] + [:ghost :role "phantom"] + ])"#) + .unwrap(); + + db.execute(r#"(retract [ + [:ghost :name "Ghost"] + [:ghost :age 100] + [:ghost :role "phantom"] + ])"#) + .unwrap(); + + let n = count_results( + db.execute(r#"(query [:find ?e :where [?e :name ?n]])"#) + .unwrap(), + ); + assert_eq!(n, 0, "fully-retracted entity must not appear in queries"); +} + +// ── Datomic concept: Datalog query patterns ─────────────────────────────────── + +/// Datomic concept: find tuples (multi-find-variable query). +/// Datomic doc reference: "Queries" — :find with multiple variables. +#[test] +fn datomic_multi_variable_find() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:p1 :person/name "Alice"] [:p1 :person/age 30] + [:p2 :person/name "Bob"] [:p2 :person/age 25] + ])"#) + .unwrap(); + + match db + .execute(r#"(query [:find ?n ?a :where [?e :person/name ?n] [?e :person/age ?a]])"#) + .unwrap() + { + QueryResult::QueryResults { results, .. } => { + assert_eq!(results.len(), 2, "should find 2 name+age pairs"); + } + _ => panic!("expected QueryResults"), + } +} + +/// Datomic concept: ground values in queries (constant binding). +/// Datomic doc reference: "Queries" — binding constants. +#[test] +fn datomic_ground_value_binding() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:a :score 10] [:b :score 20] [:c :score 10] [:d :score 30] + ])"#) + .unwrap(); + + let tens = count_results( + db.execute(r#"(query [:find ?e :where [?e :score 10]])"#) + .unwrap(), + ); + assert_eq!(tens, 2, "entities with score=10: a and c"); +} + +/// Datomic concept: :in clause (parameterized query / prepared statements). +/// Datomic doc reference: "Queries" — :in bindings. +/// Minigraf equivalent: prepared queries with $slot bindings. +#[test] +fn datomic_parameterized_query_prepared() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:x :val 42] [:y :val 7] [:z :val 42] + ])"#) + .unwrap(); + + let prep = db + .prepare("(query [:find ?e :where [?e :val $target]])") + .unwrap(); + + let results_42 = count_results( + prep.execute(&[("target", BindValue::Val(Value::Integer(42)))]) + .unwrap(), + ); + let results_7 = count_results( + prep.execute(&[("target", BindValue::Val(Value::Integer(7)))]) + .unwrap(), + ); + + assert_eq!(results_42, 2, "val=42: x and z"); + assert_eq!(results_7, 1, "val=7: y only"); +} + +/// Datomic concept: rules are named reusable query fragments. +/// Datomic doc reference: "Rules". +#[test] +fn datomic_named_rule_reuse() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:a :likes :b] [:b :likes :c] [:c :likes :a] + ])"#) + .unwrap(); + + db.execute(r#"(rule [(likes-transitively ?x ?y) [?x :likes ?y]])"#) + .unwrap(); + db.execute( + r#"(rule [(likes-transitively ?x ?z) [?x :likes ?y] (likes-transitively ?y ?z)])"#, + ) + .unwrap(); + + let all_pairs = count_results( + db.execute(r#"(query [:find ?x ?y :where (likes-transitively ?x ?y)])"#) + .unwrap(), + ); + // In a 3-node cycle, every entity transitively likes every other. + assert!( + all_pairs >= 3, + "transitive closure must find at least 3 pairs" + ); +} + +// ── Datomic concept: predicates and filters ─────────────────────────────────── + +/// Datomic concept: predicate expressions in :where clauses. +/// Datomic doc reference: "Queries" — expression clauses. +#[test] +fn datomic_predicate_expression_filter() { + let db = Minigraf::in_memory().unwrap(); + db.execute(r#"(transact [ + [:a :age 25] [:b :age 35] [:c :age 15] [:d :age 40] + ])"#) + .unwrap(); + + let adults = count_results( + db.execute(r#"(query [:find ?e :where [?e :age ?a] [(>= ?a 18)]])"#) + .unwrap(), + ); + assert_eq!(adults, 3, "entities with age >= 18: a, b, d"); +} + +// ═════════════════════════════════════════════════════════════════════════════ +// SKIPPED CASES +// ═════════════════════════════════════════════════════════════════════════════ +// +// The following Datomic concepts are intentionally out of scope or divergent: +// +// 1. Pull API — Datomic has a pull syntax for shaped reads. Minigraf uses +// pattern-matching :find/:where queries. No pull syntax planned. +// +// 2. :db/ident — Datomic uses schema-defined attribute identities. Minigraf +// uses string keywords directly without a separate schema registry. +// +// 3. :db/unique — Datomic enforces uniqueness constraints at schema level. +// Minigraf does not enforce attribute uniqueness (multiple values allowed). +// +// 4. Transaction functions — Datomic supports arbitrary Clojure functions +// in transactions. Out of scope for Minigraf. +// +// 5. Excision / hard delete — Datomic's `d/excise`. Not implemented in Minigraf. +// +// 6. Peer vs. Client API — Datomic has two access modes. Minigraf is always +// embedded; no distinction applies. From bbb496657e12f64a7aa99515fe1cf6da57a6e6ec Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sun, 17 May 2026 08:18:10 +0530 Subject: [PATCH 3/4] fix(compat): rename cardinality-many test to match actual semantics The test uses 3 separate entities (not one entity with multiple values), so rename to datomic_multiple_entities_same_attribute. Co-Authored-By: Claude Sonnet 4.6 --- tests/datomic_compat_test.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/datomic_compat_test.rs b/tests/datomic_compat_test.rs index 78bf6bc7c5..94abb18132 100644 --- a/tests/datomic_compat_test.rs +++ b/tests/datomic_compat_test.rs @@ -52,11 +52,11 @@ fn datomic_entity_attributes_are_independent_facts() { ); } -/// Datomic concept: cardinality-many attributes — multiple entities share the same attribute. -/// Datomic doc reference: "Schema" — :db/cardinality/many. -/// In Minigraf, multiple entities can each hold a :tag fact; querying ?e ?t returns all pairs. +/// Datomic concept: multiple entities sharing the same attribute — each entity independently +/// carries its own :tag fact; querying [:find ?e ?t] returns all (entity, value) pairs. +/// Datomic doc reference: "Schema" — EAV model; each datom is an independent fact. #[test] -fn datomic_cardinality_many_multiple_values() { +fn datomic_multiple_entities_same_attribute() { let db = Minigraf::in_memory().unwrap(); db.execute(r#"(transact [ [:article1 :tag "rust"] From 8cd7c75a80780ddf370aa30ce41273ce4e740b5e Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sun, 17 May 2026 08:18:18 +0530 Subject: [PATCH 4/4] style: cargo fmt Co-Authored-By: Claude Sonnet 4.6 --- tests/datomic_compat_test.rs | 60 ++++++++++++++++++++------------- tests/xtdb_compat_test.rs | 64 ++++++++++++++++++++++++++---------- 2 files changed, 84 insertions(+), 40 deletions(-) diff --git a/tests/datomic_compat_test.rs b/tests/datomic_compat_test.rs index 94abb18132..268811c7be 100644 --- a/tests/datomic_compat_test.rs +++ b/tests/datomic_compat_test.rs @@ -26,11 +26,13 @@ fn count_results(r: QueryResult) -> usize { #[test] fn datomic_entity_attributes_are_independent_facts() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:user42 :user/name "Jane"] [:user42 :user/email "jane@example.com"] [:user42 :user/role :admin] - ])"#) + ])"#, + ) .unwrap(); // Each attribute is an independent queryable fact. @@ -58,11 +60,13 @@ fn datomic_entity_attributes_are_independent_facts() { #[test] fn datomic_multiple_entities_same_attribute() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:article1 :tag "rust"] [:article2 :tag "database"] [:article3 :tag "embedded"] - ])"#) + ])"#, + ) .unwrap(); let tags = count_results( @@ -115,18 +119,22 @@ fn datomic_transaction_time_as_of() { #[test] fn datomic_retract_all_entity_facts() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:ghost :name "Ghost"] [:ghost :age 100] [:ghost :role "phantom"] - ])"#) + ])"#, + ) .unwrap(); - db.execute(r#"(retract [ + db.execute( + r#"(retract [ [:ghost :name "Ghost"] [:ghost :age 100] [:ghost :role "phantom"] - ])"#) + ])"#, + ) .unwrap(); let n = count_results( @@ -143,10 +151,12 @@ fn datomic_retract_all_entity_facts() { #[test] fn datomic_multi_variable_find() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:p1 :person/name "Alice"] [:p1 :person/age 30] [:p2 :person/name "Bob"] [:p2 :person/age 25] - ])"#) + ])"#, + ) .unwrap(); match db @@ -165,9 +175,11 @@ fn datomic_multi_variable_find() { #[test] fn datomic_ground_value_binding() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:a :score 10] [:b :score 20] [:c :score 10] [:d :score 30] - ])"#) + ])"#, + ) .unwrap(); let tens = count_results( @@ -183,9 +195,11 @@ fn datomic_ground_value_binding() { #[test] fn datomic_parameterized_query_prepared() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:x :val 42] [:y :val 7] [:z :val 42] - ])"#) + ])"#, + ) .unwrap(); let prep = db @@ -210,17 +224,17 @@ fn datomic_parameterized_query_prepared() { #[test] fn datomic_named_rule_reuse() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:a :likes :b] [:b :likes :c] [:c :likes :a] - ])"#) + ])"#, + ) .unwrap(); db.execute(r#"(rule [(likes-transitively ?x ?y) [?x :likes ?y]])"#) .unwrap(); - db.execute( - r#"(rule [(likes-transitively ?x ?z) [?x :likes ?y] (likes-transitively ?y ?z)])"#, - ) - .unwrap(); + db.execute(r#"(rule [(likes-transitively ?x ?z) [?x :likes ?y] (likes-transitively ?y ?z)])"#) + .unwrap(); let all_pairs = count_results( db.execute(r#"(query [:find ?x ?y :where (likes-transitively ?x ?y)])"#) @@ -240,9 +254,11 @@ fn datomic_named_rule_reuse() { #[test] fn datomic_predicate_expression_filter() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:a :age 25] [:b :age 35] [:c :age 15] [:d :age 40] - ])"#) + ])"#, + ) .unwrap(); let adults = count_results( diff --git a/tests/xtdb_compat_test.rs b/tests/xtdb_compat_test.rs index 9f83019819..4d36f89301 100644 --- a/tests/xtdb_compat_test.rs +++ b/tests/xtdb_compat_test.rs @@ -40,11 +40,13 @@ fn query_strings(db: &Minigraf, q: &str) -> Vec { #[test] fn xtdb_basic_find_by_attribute_value() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:pablo :profession "painter"] [:salvador :profession "painter"] [:kafka :profession "writer"] - ])"#) + ])"#, + ) .unwrap(); let painters = count_results( @@ -59,11 +61,13 @@ fn xtdb_basic_find_by_attribute_value() { #[test] fn xtdb_multi_attribute_join() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:e1 :role "admin"] [:e1 :active true] [:e2 :role "user"] [:e2 :active true] [:e3 :role "admin"] [:e3 :active false] - ])"#) + ])"#, + ) .unwrap(); let active_admins = count_results( @@ -78,11 +82,13 @@ fn xtdb_multi_attribute_join() { #[test] fn xtdb_entity_reference_join() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:alice :dept :dept-eng] [:bob :dept :dept-eng] [:carol :dept :dept-hr] - ])"#) + ])"#, + ) .unwrap(); let eng_employees = count_results( @@ -147,15 +153,25 @@ fn xtdb_as_of_returns_past_state() { // tx 2 + 3: alice's role changes to "admin" db.execute(r#"(retract [[:alice :role "user"]])"#).unwrap(); - db.execute(r#"(transact [[:alice :role "admin"]])"#).unwrap(); + db.execute(r#"(transact [[:alice :role "admin"]])"#) + .unwrap(); // Current state: admin. let current = query_strings(&db, r#"(query [:find ?r :where [?e :role ?r]])"#); - assert!(current.contains(&"admin".to_string()), "current role should be admin"); + assert!( + current.contains(&"admin".to_string()), + "current role should be admin" + ); // As-of tx 1: user. - let past = query_strings(&db, r#"(query [:find ?r :as-of 1 :valid-at :any-valid-time :where [?e :role ?r]])"#); - assert!(past.contains(&"user".to_string()), "past role at tx 1 should be user"); + let past = query_strings( + &db, + r#"(query [:find ?r :as-of 1 :valid-at :any-valid-time :where [?e :role ?r]])"#, + ); + assert!( + past.contains(&"user".to_string()), + "past role at tx 1 should be user" + ); } /// XTDB concept: valid-time query returns facts valid at a specific time. @@ -180,7 +196,10 @@ fn xtdb_valid_at_query() { db.execute(r#"(query [:find ?s :valid-at "2024-01-01" :where [?e :status ?s]])"#) .unwrap(), ); - assert_eq!(n_after, 0, "fact should not be visible after valid-to boundary"); + assert_eq!( + n_after, 0, + "fact should not be visible after valid-to boundary" + ); } // ── Negation ───────────────────────────────────────────────────────────────── @@ -190,11 +209,13 @@ fn xtdb_valid_at_query() { #[test] fn xtdb_not_excludes_matching_entities() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:alice :person true] [:alice :banned true] [:bob :person true] [:carol :person true] [:carol :banned true] - ])"#) + ])"#, + ) .unwrap(); let unbanned = count_results( @@ -211,9 +232,11 @@ fn xtdb_not_excludes_matching_entities() { #[test] fn xtdb_count_aggregate() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:a :tag "rust"] [:b :tag "rust"] [:c :tag "go"] [:d :tag "rust"] - ])"#) + ])"#, + ) .unwrap(); match db @@ -238,11 +261,13 @@ fn xtdb_count_aggregate() { #[test] fn xtdb_recursive_ancestor_rule() { let db = Minigraf::in_memory().unwrap(); - db.execute(r#"(transact [ + db.execute( + r#"(transact [ [:alice :parent :bob] [:bob :parent :carol] [:carol :parent :dave] - ])"#) + ])"#, + ) .unwrap(); db.execute(r#"(rule [(ancestor ?x ?y) [?x :parent ?y]])"#) @@ -254,7 +279,10 @@ fn xtdb_recursive_ancestor_rule() { db.execute(r#"(query [:find ?anc :where (ancestor :alice ?anc)])"#) .unwrap(), ); - assert_eq!(ancestors_of_alice, 3, "alice has 3 ancestors: bob, carol, dave"); + assert_eq!( + ancestors_of_alice, 3, + "alice has 3 ancestors: bob, carol, dave" + ); } // ═════════════════════════════════════════════════════════════════════════════