From 149e6c8a4645ab32de4e52d4e7ea5bdd3d0fd4b3 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Mon, 22 Jan 2018 17:21:23 -0800 Subject: [PATCH] WIP: failing test for a harder problem. --- db/src/db.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/db/src/db.rs b/db/src/db.rs index d6fdfdb1..f43ef6a8 100644 --- a/db/src/db.rs +++ b/db/src/db.rs @@ -2308,4 +2308,41 @@ mod tests { r#"[[65536 :test/one 124 ?tx true] [?tx :db/txInstant ?ms ?tx true]]"#); } + + // TODO + /* + #[test] + fn test_cardinality_one_violation_new_entity() { + let mut conn = TestConn::default(); + + // Start by installing a few attributes. + assert_transact!(conn, r#"[ + [:db/add 111 :db/ident :test/one] + [:db/add 111 :db/valueType :db.type/long] + [:db/add 111 :db/cardinality :db.cardinality/one] + [:db/add 112 :db/ident :test/unique] + [:db/add 112 :db/index true] + [:db/add 112 :db/valueType :db.type/string] + [:db/add 112 :db/cardinality :db.cardinality/one] + [:db/add 112 :db/unique :db.unique/identity] + ]"#); + + // You can try to assert two values for the same entity and attribute, + // but only one will be transacted. + // This variant (see also `test_cardinality_one_violation_existing_entity`) + // is particularly tricky because the unique attribute is a new entity, + // and so the search will fail, two entids will be allocated, and then + // insert will fail. + let report = assert_transact!(conn, r#"[ + [:db/add "foo" :test/unique "x"] + [:db/add "foo" :test/one 123] + [:db/add "bar" :test/unique "x"] + [:db/add "bar" :test/one 124] + ]"#); + assert_matches!(conn.last_transaction(), + r#"[[998 :test/unique "x" ?tx true] + [998 :test/one 124 ?tx true] + [?tx :db/txInstant ?ms ?tx true]]"#); + } + */ }