gedcom-core 0.0.2

GEDCOM is an acronym for GEnealogical Data COMmunication and it provides a flexible, uniform format for exchanging computerized genealogical data.
Documentation
// Copyright 2017-2026 Ahmed Charles <me@ahmedcharles.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![warn(absolute_paths_not_starting_with_crate)]
#![warn(ambiguous_negative_literals)]
#![warn(closure_returning_async_block)]
#![warn(deprecated_in_future)]
#![warn(deprecated_safe)]
#![warn(deref_into_dyn_supertrait)]
#![warn(edition_2024_expr_fragment_specifier)]
#![warn(elided_lifetimes_in_paths)]
#![warn(explicit_outlives_requirements)]
#![warn(ffi_unwind_calls)]
#![warn(if_let_rescope)]
#![warn(impl_trait_overcaptures)]
#![warn(impl_trait_redundant_captures)]
#![warn(keyword_idents)]
#![warn(let_underscore_drop)]
#![warn(macro_use_extern_crate)]
#![warn(meta_variable_misuse)]
#![warn(missing_copy_implementations)]
#![warn(missing_debug_implementations)]
#![warn(missing_docs)]
#![warn(missing_unsafe_on_extern)]
#![warn(non_ascii_idents)]
#![warn(redundant_imports)]
#![warn(redundant_lifetimes)]
#![warn(single_use_lifetimes)]
#![warn(tail_expr_drop_order)]
#![warn(trivial_casts)]
#![warn(trivial_numeric_casts)]
#![warn(unit_bindings)]
#![warn(unnameable_types)]
#![warn(unreachable_pub)]
#![warn(unsafe_attr_outside_unsafe)]
#![warn(unsafe_code)]
#![warn(unsafe_op_in_unsafe_fn)]
#![warn(unused)]
#![warn(unused_crate_dependencies)]
#![warn(unused_import_braces)]
#![warn(unused_lifetimes)]
#![warn(unused_qualifications)]
#![warn(unused_results)]
#![warn(variant_size_differences)]

//! Integration tests for GEDCOM.

use nom as _;
use nom_locate as _;
use serde as _;
use serde_json as _;
use smallvec as _;
use thiserror as _;

fn run_test(name: &str, text: &str) {
    let l = gedcom_core::data::lines(text).unwrap();
    let r = gedcom_core::data::records(text).unwrap();
    insta::with_settings!({
        prepend_module_to_snapshot => false,
        snapshot_path => "files"
    }, {
        let mut name_lines: String = name.into();
        name_lines.push_str("-lines");
        insta::assert_ron_snapshot!(name_lines, l);
        let mut name_records: String = name.into();
        name_records.push_str("-records");
        insta::assert_ron_snapshot!(name_records, r);
    });
}

// complete.ged          - 'complete tag file', notes in the file.
const COMPLETE: &str = include_str!("files/complete.ged");

#[test]
fn test_complete() {
    assert_eq!(63526, COMPLETE.len());
    run_test("complete", COMPLETE);
}

// sample555-utf8.ged    - GEDCOM 5.5.5 sample (UTF-8).
const SAMPLE_UTF8: &str = include_str!("files/sample555-utf8.ged");

#[test]
fn test_sample_utf8() {
    assert_eq!(1986, SAMPLE_UTF8.len());
    run_test("sample_utf8", SAMPLE_UTF8);
}

// sample555-utf16le.ged - GEDCOM 5.5.5 sample (UTF-16 Big Endian).
const SAMPLE_UTF16LE: &[u8] = include_bytes!("files/sample555-utf16le.ged");

#[test]
fn test_sample_utf16le() {
    assert_eq!(3972, SAMPLE_UTF16LE.len());
    let (enc, _) = encoding_rs::Encoding::for_bom(SAMPLE_UTF16LE).unwrap();
    let input = enc
        .decode_without_bom_handling_and_without_replacement(SAMPLE_UTF16LE)
        .unwrap();
    run_test("sample_utf16le", &input);
}

// sample555-utf16be.ged - GEDCOM 5.5.5 sample (UTF-16 Big Endian).
const SAMPLE_UTF16BE: &[u8] = include_bytes!("files/sample555-utf16be.ged");

#[test]
fn test_sample_utf16be() {
    assert_eq!(3972, SAMPLE_UTF16BE.len());
    let (enc, _) = encoding_rs::Encoding::for_bom(SAMPLE_UTF16BE).unwrap();
    let input = enc
        .decode_without_bom_handling_and_without_replacement(SAMPLE_UTF16BE)
        .unwrap();
    run_test("sample_utf16be", &input);
}

// remarr.ged            - Remarriage example GEDCOM file.
const REMARR: &str = include_str!("files/remarr.ged");

#[test]
fn test_remarr() {
    assert_eq!(1233, REMARR.len());
    run_test("remarr", REMARR);
}

// ssmarr.ged            - Same-sex marriage example GEDCOM file.
const SSMARR: &str = include_str!("files/ssmarr.ged");

#[test]
fn test_ssmarr() {
    assert_eq!(864, SSMARR.len());
    run_test("ssmarr", SSMARR);
}

// minimal555.ged        - The minimal GEDCOM 5.5.5 file.
const MINIMAL: &str = include_str!("files/minimal555.ged");

#[test]
fn test_minimal() {
    assert_eq!(132, MINIMAL.len());
    run_test("minimal", MINIMAL);
}

// married1200.ged       - One man with 1200 wives.
const MARRIED1200: &str = include_str!("files/married1200.ged");

#[test]
fn test_married1200() {
    assert_eq!(220057, MARRIED1200.len());
    run_test("married1200", MARRIED1200);
}

// children1200.ged      - One woman with 1200 children.
const CHILDREN1200: &str = include_str!("files/children1200.ged");

#[test]
fn test_children1200() {
    assert_eq!(169419, CHILDREN1200.len());
    run_test("children1200", CHILDREN1200);
}

// siblings1200.ged     - One man with 1200 wives, one child with each.
const SIBLINGS1200: &str = include_str!("files/siblings1200.ged");

#[test]
fn test_siblings1200() {
    assert_eq!(399500, SIBLINGS1200.len());
    run_test("siblings1200", SIBLINGS1200);
}

// long26cc.ged         - 26 individuals with increasingly longer names.
const LONG26CC: &str = include_str!("files/long26cc.ged");

#[test]
fn test_long26cc() {
    assert_eq!(9094, LONG26CC.len());
    run_test("long26cc", LONG26CC);
}