use oxgraph_csr::{
CsrSnapshotIndex,
build::{GraphBuilder, export_csr_snapshot},
};
use oxgraph_layout_util::crc32c_append;
use oxgraph_snapshot::Snapshot;
const INBOUND_OFFSETS_KIND: u32 = 0x0205;
const INBOUND_TARGETS_KIND: u32 = 0x0209;
#[test]
#[ignore = "run manually to refresh proofs/tiny_dual.oxgtopo"]
fn write_tiny_dual_fixture() -> Result<(), Box<dyn std::error::Error>> {
let mut builder = GraphBuilder::<u32, u32>::new();
let a = builder.add_node()?;
let b = builder.add_node()?;
builder.add_edge(a, b)?;
let inbound = builder.freeze()?.transpose()?;
let csr_bytes = export_csr_snapshot(&inbound)?;
let csr = Snapshot::open(&csr_bytes)?;
let mut out = oxgraph_snapshot::SnapshotWriter::new(csr.section_count(), crc32c_append)?;
for section in csr.sections() {
let dest_kind = match section.kind() {
kind if kind == <u32 as CsrSnapshotIndex>::OFFSETS_KIND => INBOUND_OFFSETS_KIND,
kind if kind == <u32 as CsrSnapshotIndex>::TARGETS_KIND => INBOUND_TARGETS_KIND,
other => other,
};
let alignment = section.declared_alignment();
let alignment_log2 = if alignment <= 1 {
0
} else {
u8::try_from(alignment.trailing_zeros())?
};
out.section_bytes(
dest_kind,
section.version(),
alignment_log2,
section.bytes(),
)?;
}
let bytes = out.finish()?;
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/src/proofs/tiny_dual.oxgtopo");
std::fs::write(path, bytes)?;
Ok(())
}