Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broke integration tests into modules #679

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions tests/element_display.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#![cfg(feature = "experimental-reader")]
#![cfg(feature = "experimental-writer")]
use crate::ion_tests::contains_path;
use ion_rs::{Element, ElementWriter, IonResult, IonWriter, Sequence, TextWriterBuilder};
use std::fs::read;
use test_generator::test_resources;

mod ion_tests;

const TO_STRING_SKIP_LIST: &[&str] = &[
// These tests have shared symbol table imports in them, which the Reader does not
// yet support.
"ion-tests/iontestdata_1_0/good/subfieldVarUInt.ion",
"ion-tests/iontestdata_1_0/good/subfieldVarUInt15bit.ion",
"ion-tests/iontestdata_1_0/good/subfieldVarUInt16bit.ion",
"ion-tests/iontestdata_1_0/good/subfieldVarUInt32bit.ion",
// This test requires the reader to be able to read symbols whose ID is encoded
// with more than 8 bytes. Having a symbol table with more than 18 quintillion
// symbols is not very practical.
"ion-tests/iontestdata_1_0/good/typecodes/T7-large.10n",
"ion-tests/iontestdata_1_0/good/item1.10n",
"ion-tests/iontestdata_1_0/good/localSymbolTableImportZeroMaxId.ion",
"ion-tests/iontestdata_1_0/good/testfile35.ion",
// These files are encoded in utf16 and utf32; the reader currently assumes utf8.
"ion-tests/iontestdata_1_0/good/utf16.ion",
"ion-tests/iontestdata_1_0/good/utf32.ion",
];

#[test_resources("ion-tests/iontestdata_1_0/good/**/*.ion")]
#[test_resources("ion-tests/iontestdata_1_0/good/**/*.10n")]
fn test_to_string(file_name: &str) {
if contains_path(TO_STRING_SKIP_LIST, file_name) {
println!("IGNORING: {file_name}");
return;
}

let data = read(file_name).unwrap();
let result: IonResult<Sequence> = Element::read_all(data.as_slice());
let elements = result.unwrap_or_else(|e| {
panic!("Expected to be able to read Ion values for contents of file {file_name}: {e:?}")
});

for element in elements {
let mut buffer = Vec::with_capacity(2048);
let mut writer = TextWriterBuilder::default().build(&mut buffer).unwrap();
writer.write_element(&element).unwrap();
writer.flush().unwrap();
drop(writer);

let expected_string = std::str::from_utf8(buffer.as_slice()).unwrap().to_string();

assert_eq!(element.to_string(), expected_string);
}
}
82 changes: 82 additions & 0 deletions tests/element_ion_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#![cfg(feature = "experimental-reader")]
#![cfg(feature = "experimental-writer")]
use ion_rs::{Format, TextKind};
use test_generator::test_resources;

mod ion_tests;

#[cfg(test)]
mod native_element_tests {
use super::*;
use crate::ion_tests::{
bad, equivs, non_equivs, ElementApi, SkipList, ELEMENT_EQUIVS_SKIP_LIST,
ELEMENT_GLOBAL_SKIP_LIST, ELEMENT_ROUND_TRIP_SKIP_LIST,
};
use ion_rs::{IonResult, Reader, ReaderBuilder};

struct NativeElementApi;

impl ElementApi for NativeElementApi {
type ElementReader<'a> = Reader<'a>;

fn make_reader(data: &[u8]) -> IonResult<Reader<'_>> {
ReaderBuilder::default().build(data)
}

fn global_skip_list() -> SkipList {
ELEMENT_GLOBAL_SKIP_LIST
}

fn read_one_equivs_skip_list() -> SkipList {
&[]
}

fn round_trip_skip_list() -> SkipList {
ELEMENT_ROUND_TRIP_SKIP_LIST
}

fn equivs_skip_list() -> SkipList {
ELEMENT_EQUIVS_SKIP_LIST
}

fn non_equivs_skip_list() -> SkipList {
&[]
}
}

good_round_trip! {
use NativeElementApi;
fn binary_compact(Format::Binary, Format::Text(TextKind::Compact));
fn binary_lines(Format::Binary, Format::Text(TextKind::Lines));
fn binary_pretty(Format::Binary, Format::Text(TextKind::Pretty));
fn compact_binary(Format::Text(TextKind::Compact), Format::Binary);
fn compact_lines(Format::Text(TextKind::Compact), Format::Text(TextKind::Lines));
fn compact_pretty(Format::Text(TextKind::Compact), Format::Text(TextKind::Pretty));
fn lines_binary(Format::Text(TextKind::Lines), Format::Binary);
fn lines_compact(Format::Text(TextKind::Lines), Format::Text(TextKind::Compact));
fn lines_pretty(Format::Text(TextKind::Lines), Format::Text(TextKind::Pretty));
fn pretty_binary(Format::Text(TextKind::Pretty), Format::Binary);
fn pretty_compact(Format::Text(TextKind::Pretty), Format::Text(TextKind::Compact));
fn pretty_lines(Format::Text(TextKind::Pretty), Format::Text(TextKind::Lines));
}

#[test_resources("ion-tests/iontestdata_1_0/bad/**/*.ion")]
#[test_resources("ion-tests/iontestdata_1_0/bad/**/*.10n")]
fn native_bad(file_name: &str) {
bad(NativeElementApi, file_name)
}

#[test_resources("ion-tests/iontestdata_1_0/good/equivs/**/*.ion")]
#[test_resources("ion-tests/iontestdata_1_0/good/equivs/**/*.10n")]
fn native_equivs(file_name: &str) {
equivs(NativeElementApi, file_name)
}

#[test_resources("ion-tests/iontestdata_1_0/good/non-equivs/**/*.ion")]
// no binary files exist and the macro doesn't like empty globs...
// see frehberg/test-generator#12
//#[test_resources("ion-tests/iontestdata_1_0/good/non-equivs/**/*.10n")]
fn native_non_equivs(file_name: &str) {
non_equivs(NativeElementApi, file_name)
}
}
Loading
Loading