|
| 1 | +/* |
| 2 | + * Tackler-NG 2026 |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +mod txns_extid { |
| 7 | + use indoc::formatdoc; |
| 8 | + use std::fmt::Write; |
| 9 | + use tackler_core::kernel::Settings; |
| 10 | + use tackler_core::parser; |
| 11 | + use tackler_rs::IndocUtils; |
| 12 | + |
| 13 | + const EXT_ID_01: &str = "ext-id #001"; |
| 14 | + const EXT_ID_02: &str = "ext-id #002"; |
| 15 | + const EXT_ID_03: &str = "ext-id #003"; |
| 16 | + |
| 17 | + #[rustfmt::skip] |
| 18 | + fn make_extids() -> String { |
| 19 | + formatdoc!( |
| 20 | + "2026-07-19 'txn01 |
| 21 | + | # ext-id: {EXT_ID_01} |
| 22 | + | e 1 |
| 23 | + | a |
| 24 | + | |
| 25 | + |2026-07-19 'txn02 |
| 26 | + | # ext-id: {EXT_ID_02} |
| 27 | + | e 1 |
| 28 | + | a |
| 29 | + | |
| 30 | + |2026-07-19 'txn03 |
| 31 | + | # ext-id: {EXT_ID_03} |
| 32 | + | e 1 |
| 33 | + | a |
| 34 | + |" |
| 35 | + ).strip_margin() |
| 36 | + } |
| 37 | + |
| 38 | + #[rustfmt::skip] |
| 39 | + fn dup_extid() -> String { |
| 40 | + formatdoc!( |
| 41 | + "2026-07-19 'txn04 |
| 42 | + | # ext-id: {EXT_ID_02} |
| 43 | + | e 1 |
| 44 | + | a |
| 45 | + |" |
| 46 | + ).strip_margin() |
| 47 | + } |
| 48 | + |
| 49 | + #[rustfmt::skip] |
| 50 | + fn make_dups_extid() -> String { |
| 51 | + let mut s = make_extids(); |
| 52 | + _ = writeln!(s); |
| 53 | + _ = writeln!(s, "{}", dup_extid()); |
| 54 | + s |
| 55 | + } |
| 56 | + |
| 57 | + #[test] |
| 58 | + // test: f3c3f4fb-2c58-47d8-82a6-82b04a752e2e |
| 59 | + // desc: try_from accepts duplicate ext-ids |
| 60 | + fn txns_try_from_accepts_dup_extid() { |
| 61 | + let txns = |
| 62 | + parser::string_to_txns(&mut make_dups_extid().as_str(), &mut Settings::default()); |
| 63 | + |
| 64 | + assert!(txns.is_ok()); |
| 65 | + } |
| 66 | + |
| 67 | + #[test] |
| 68 | + // test: c4905afd-ea7a-460f-8f0b-ab46803f63be |
| 69 | + // desc: try_from detects duplicate ext-ids |
| 70 | + fn txns_try_from_detects_dup_extid() { |
| 71 | + let txns = parser::string_to_txns( |
| 72 | + &mut make_dups_extid().as_str(), |
| 73 | + &mut Settings::default_extid(), |
| 74 | + ); |
| 75 | + |
| 76 | + let err_msg = txns.expect_err("test case went wonky").to_string(); |
| 77 | + |
| 78 | + assert!(err_msg.contains("Found 1 duplicate")); |
| 79 | + assert!(err_msg.contains("ext-id #002")); |
| 80 | + } |
| 81 | + |
| 82 | + #[test] |
| 83 | + // test: 843948ac-6d7a-402e-9fe3-931615fd9565 |
| 84 | + // desc: append accepts duplicate ext-ids |
| 85 | + fn txns_append_accepts_dup_extid() { |
| 86 | + let mut txns = parser::string_to_txns( |
| 87 | + &mut make_extids().as_str(), &mut Settings::default()).unwrap(/*:test:*/); |
| 88 | + |
| 89 | + let mut txns_dup = parser::string_to_txns( |
| 90 | + &mut dup_extid().as_str(), &mut Settings::default()).unwrap(/*:test:*/); |
| 91 | + |
| 92 | + let res = txns.append(&mut txns_dup); |
| 93 | + |
| 94 | + assert!(res.is_ok()); |
| 95 | + } |
| 96 | + |
| 97 | + #[test] |
| 98 | + // test: 1c8f8fb1-d96b-4661-8597-7ddda75194d5 |
| 99 | + // desc: append detects duplicate ext-ids |
| 100 | + fn txns_append_detects_dup_extid() { |
| 101 | + let mut txns = parser::string_to_txns( |
| 102 | + &mut make_extids().as_str(), &mut Settings::default_extid()).unwrap(/*:test:*/); |
| 103 | + |
| 104 | + let mut txns_dup = parser::string_to_txns( |
| 105 | + &mut dup_extid().as_str(), &mut Settings::default()).unwrap(/*:test:*/); |
| 106 | + |
| 107 | + let err = txns.append(&mut txns_dup); |
| 108 | + let err_msg = err.expect_err("test case went wonky").to_string(); |
| 109 | + |
| 110 | + assert!(err_msg.contains("Found 1 duplicate")); |
| 111 | + assert!(err_msg.contains("ext-id #002")); |
| 112 | + } |
| 113 | +} |
0 commit comments