rd-helpdb 0.0.1

Reader for installed R package help databases (aliases, .rdx/.rdb, Meta/hsearch.rds), built on rd-rds
Documentation
//! Decodes the fake `.rdb` records shared with `rd-rds`'s fixture set
//! (a 4-byte big-endian uncompressed-size prefix followed by a raw zlib
//! stream, exactly the framing real `<pkg>.rdb` entries use) through
//! `rd_helpdb::decode_rdb_record` and checks the result is a parsed `Rd`
//! object.
//!
//! These files are copies of the generated artifacts from the repo-root
//! `tests/fixtures/data` (regenerated by `tests/fixtures/generate_fixtures.R`),
//! kept crate-local so this crate's tests work outside the workspace layout.

use std::{fs, path::PathBuf};

fn fixture_dir() -> PathBuf {
    PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/data")
}

#[test]
fn decodes_rdbentry_fixtures_as_rd_class() {
    for name in ["rd_minimal_v2", "rd_minimal_v3", "rd_arguments_v3"] {
        let path = fixture_dir().join(format!("{name}.rdbentry"));
        let bytes = fs::read(&path).unwrap_or_else(|err| panic!("read {}: {err}", path.display()));

        let root = rd_helpdb::decode_rdb_record(&bytes)
            .unwrap_or_else(|err| panic!("{name}: decode_rdb_record failed: {err}"));

        let class: Vec<String> = root
            .class()
            .unwrap_or_else(|| panic!("{name}: root has no class attribute"))
            .iter()
            .map(|value| {
                value
                    .as_str()
                    .unwrap_or_else(|| panic!("{name}: class value is NA"))
                    .unwrap_or_else(|err| panic!("{name}: class value decode error: {err}"))
                    .into_owned()
            })
            .collect();
        assert_eq!(class, vec!["Rd".to_string()], "{name}");
    }
}