Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_namex/tests/file.rs

2.1 KiB, 7 runs

created by r1870400018:525, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use oxedyne_fe2o3_namex::{
2 id::NamexId,
3 db::{
4 Entity,
5 MapKey,
6 Namex,
7 },
8};
9
10use oxedyne_fe2o3_core::prelude::*;
11
12use std::{
13 collections::BTreeMap,
14};
15
16pub fn test_file(filter: &'static str) -> Outcome<()> {
17
18 test_it!(filter, "Load and save 000", "all", "load", "save", {
19
20 let db = res!(Namex::<
21 BTreeMap<MapKey, Entity>,
22 BTreeMap<NamexId, Entity>,
23 >::load("./namex.jdat"));
24
25 test!("Successfully loaded namex file.");
26
27 res!(db.to_file(
28 res!(db.export_jdat()),
29 "./namex_echo.jdat",
30 ));
31
32 res!(db.to_file(
33 res!(db.export_json()),
34 "./namex_echo.json",
35 ));
36 });
37
38 test_it!(filter, "Lookup by canonical id 010", "all", "load", "lookup", {
39
40 let db = res!(Namex::<
41 BTreeMap<MapKey, Entity>,
42 BTreeMap<NamexId, Entity>,
43 >::load("./namex.jdat"));
44
45 // Ids are quoted in the registry exactly as `Display` renders them, so every id a
46 // caller holds as a string must resolve to an entity.
47 for (id_str, nam) in [
48 ("VybbHNWeNXeTqTrXj66TzZScbSTsEFVy0W79QnbroFA=", "SHA3_256"),
49 ("kCnQluCVX4v62XUObBIPJhg+VZaXjXHQOLoNDVrOZso=", "SHA-256"),
50 ] {
51 let id = res!(NamexId::try_from(id_str));
52 match db.by_id(&id) {
53 Some(entity) => if !entity.nams.iter().any(|n| n == nam) {
54 return Err(err!(
55 "Id {} resolved to names {:?}, expected it to include '{}'.",
56 id_str, entity.nams, nam;
57 Test, Invalid, Mismatch));
58 },
59 None => return Err(err!(
60 "Id {} is not present in the registry.", id_str;
61 Test, Invalid, Missing)),
62 }
63 // The canonical text form must survive a round trip through the id type.
64 if fmt!("{}", id) != id_str {
65 return Err(err!(
66 "Id {} does not render back to itself, got {}.", id_str, id;
67 Test, Invalid, Mismatch));
68 }
69 }
70 });
71
72 Ok(())
73}