From a6143705a5885bbd9425ffc6428369d012d4ec4e Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Fri, 10 May 2019 12:51:13 -0400 Subject: [PATCH 1/6] Starting fresh with Rust --- ci-rust | 7 +- spec/rust/Cargo.lock | 118 ++-------------------- spec/rust/Cargo.toml | 6 +- spec/rust/build.rs | 2 - spec/rust/test_expr_sizeof_type_0.rs | 14 --- spec/rust/test_expr_sizeof_type_1.rs | 15 --- spec/rust/test_expr_sizeof_value_0.rs | 18 ---- spec/rust/test_expr_sizeof_value_sized.rs | 18 ---- spec/rust/test_io_local_var.rs | 15 --- spec/rust/test_meta_tags.rs | 13 --- spec/rust/test_meta_xref.rs | 13 --- spec/rust/test_repeat_eos_bit.rs | 14 --- 12 files changed, 17 insertions(+), 236 deletions(-) delete mode 100644 spec/rust/test_expr_sizeof_type_0.rs delete mode 100644 spec/rust/test_expr_sizeof_type_1.rs delete mode 100644 spec/rust/test_expr_sizeof_value_0.rs delete mode 100644 spec/rust/test_expr_sizeof_value_sized.rs delete mode 100644 spec/rust/test_io_local_var.rs delete mode 100644 spec/rust/test_meta_tags.rs delete mode 100644 spec/rust/test_meta_xref.rs delete mode 100644 spec/rust/test_repeat_eos_bit.rs diff --git a/ci-rust b/ci-rust index 6afe5c4e7..cfa873b4f 100755 --- a/ci-rust +++ b/ci-rust @@ -1,12 +1,11 @@ #!/bin/sh - +set -eu . ./config mkdir -p "$TEST_OUT_DIR/rust" cd spec/rust -mkdir src +mkdir -p src touch src/lib.rs cargo build -cargo test-junit \ - --name "../../$TEST_OUT_DIR/rust/results.xml" +cargo junit --name "../../$TEST_OUT_DIR/rust/results.xml" diff --git a/spec/rust/Cargo.lock b/spec/rust/Cargo.lock index 31bdaab29..14b5457de 100644 --- a/spec/rust/Cargo.lock +++ b/spec/rust/Cargo.lock @@ -1,121 +1,25 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "byteorder" -version = "0.5.3" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "cc" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "encoding" -version = "0.2.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-korean 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-simpchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-japanese" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-korean" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-simpchinese" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-singlebyte" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-tradchinese" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding_index_tests" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "flate2" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "kaitai_struct" -version = "0.2.0" -source = "git+https://github.com/CWood1/kaitai_struct_rust_runtime#b5484246b52c57ad7e2cb66af7b37347289c058e" -dependencies = [ - "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "libc" -version = "0.2.40" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "miniz-sys" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" +name = "kaitai" +version = "0.1.0" +source = "git+https://github.com/bspeice/kaitai_rust#c108db095d80721bfcf212f5ccba45fdfa5a6ed6" dependencies = [ - "cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "rust" +name = "kaitai_test" version = "0.1.0" dependencies = [ - "kaitai_struct 0.2.0 (git+https://github.com/CWood1/kaitai_struct_rust_runtime)", + "kaitai 0.1.0 (git+https://github.com/bspeice/kaitai_rust)", ] [metadata] -"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "2b4911e4bdcb4100c7680e7e854ff38e23f1b34d4d9e079efae3da2801341ffc" -"checksum encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec" -"checksum encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91" -"checksum encoding-index-korean 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81" -"checksum encoding-index-simpchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7" -"checksum encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a" -"checksum encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18" -"checksum encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" -"checksum flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "e6234dd4468ae5d1e2dbb06fe2b058696fdc50a339c68a393aefbf00bc81e423" -"checksum kaitai_struct 0.2.0 (git+https://github.com/CWood1/kaitai_struct_rust_runtime)" = "" -"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" -"checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4" +"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" +"checksum kaitai 0.1.0 (git+https://github.com/bspeice/kaitai_rust)" = "" diff --git a/spec/rust/Cargo.toml b/spec/rust/Cargo.toml index e79b56875..3e91fb245 100644 --- a/spec/rust/Cargo.toml +++ b/spec/rust/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "rust" +name = "kaitai_test" version = "0.1.0" -authors = ["Connor Wood "] +authors = ["Connor Wood ", "Bradlee Speice"] build = "build.rs" [dependencies] -kaitai_struct = { git = "https://github.com/CWood1/kaitai_struct_rust_runtime" } +kaitai = { git = "https://github.com/bspeice/kaitai_rust" } diff --git a/spec/rust/build.rs b/spec/rust/build.rs index d629f0b37..58086586a 100644 --- a/spec/rust/build.rs +++ b/spec/rust/build.rs @@ -34,8 +34,6 @@ fn remove_existing(destination_path: &Path) -> io::Result<()> { fn copy_new(source_path: &Path, destination_path: &Path) -> io::Result<()> { let mut librs = fs::File::create(source_path.join("lib.rs"))?; - write!(librs, "extern crate kaitai_struct;")?; - for entry in fs::read_dir(source_path)? { let entry = entry?; let path = entry.path(); diff --git a/spec/rust/test_expr_sizeof_type_0.rs b/spec/rust/test_expr_sizeof_type_0.rs deleted file mode 100644 index 67cb1b5ce..000000000 --- a/spec/rust/test_expr_sizeof_type_0.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprSizeofType0; - -#[test] -fn test_expr_sizeof_type_0() { - if let Ok(r) = ExprSizeofType0::from_file("src/fixed_struct.bin") { - assert_eq!(r.sizeof_block, ((1 + 4) + 2)); - } -} diff --git a/spec/rust/test_expr_sizeof_type_1.rs b/spec/rust/test_expr_sizeof_type_1.rs deleted file mode 100644 index 9ab8e1f8c..000000000 --- a/spec/rust/test_expr_sizeof_type_1.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprSizeofType1; - -#[test] -fn test_expr_sizeof_type_1() { - if let Ok(r) = ExprSizeofType1::from_file("src/fixed_struct.bin") { - assert_eq!(r.sizeof_block, (((1 + 4) + 2) + 4)); - assert_eq!(r.sizeof_subblock, 4); - } -} diff --git a/spec/rust/test_expr_sizeof_value_0.rs b/spec/rust/test_expr_sizeof_value_0.rs deleted file mode 100644 index c51d563a7..000000000 --- a/spec/rust/test_expr_sizeof_value_0.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprSizeofValue0; - -#[test] -fn test_expr_sizeof_value_0() { - if let Ok(r) = ExprSizeofValue0::from_file("src/fixed_struct.bin") { - assert_eq!(r.self_sizeof, (((1 + 4) + 2) + 2)); - assert_eq!(r.sizeof_block, ((1 + 4) + 2)); - assert_eq!(r.sizeof_block_a, 1); - assert_eq!(r.sizeof_block_b, 4); - assert_eq!(r.sizeof_block_c, 2); - } -} diff --git a/spec/rust/test_expr_sizeof_value_sized.rs b/spec/rust/test_expr_sizeof_value_sized.rs deleted file mode 100644 index 50f5839d2..000000000 --- a/spec/rust/test_expr_sizeof_value_sized.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprSizeofValueSized; - -#[test] -fn test_expr_sizeof_value_sized() { - if let Ok(r) = ExprSizeofValueSized::from_file("src/fixed_struct.bin") { - assert_eq!(r.self_sizeof, (12 + 2)); - assert_eq!(r.sizeof_block, 12); - assert_eq!(r.sizeof_block_a, 1); - assert_eq!(r.sizeof_block_b, 4); - assert_eq!(r.sizeof_block_c, 2); - } -} diff --git a/spec/rust/test_io_local_var.rs b/spec/rust/test_io_local_var.rs deleted file mode 100644 index 3d861355c..000000000 --- a/spec/rust/test_io_local_var.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IoLocalVar; - -#[test] -fn test_io_local_var() { - if let Ok(r) = IoLocalVar::from_file("src/full256.bin") { - assert_eq!(r.skip, vec!([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13])); - assert_eq!(r.followup, 20); - } -} diff --git a/spec/rust/test_meta_tags.rs b/spec/rust/test_meta_tags.rs deleted file mode 100644 index 4978b9f09..000000000 --- a/spec/rust/test_meta_tags.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::MetaTags; - -#[test] -fn test_meta_tags() { - if let Ok(r) = MetaTags::from_file("src/fixed_struct.bin") { - } -} diff --git a/spec/rust/test_meta_xref.rs b/spec/rust/test_meta_xref.rs deleted file mode 100644 index 9f068b47a..000000000 --- a/spec/rust/test_meta_xref.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::MetaXref; - -#[test] -fn test_meta_xref() { - if let Ok(r) = MetaXref::from_file("src/fixed_struct.bin") { - } -} diff --git a/spec/rust/test_repeat_eos_bit.rs b/spec/rust/test_repeat_eos_bit.rs deleted file mode 100644 index a7518aade..000000000 --- a/spec/rust/test_repeat_eos_bit.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatEosBit; - -#[test] -fn test_repeat_eos_bit() { - if let Ok(r) = RepeatEosBit::from_file("src/enum_0.bin") { - assert_eq!(r.nibbles.len(), 16); - } -} From 2bc241ae129c3aaf5f8088aaf7fbc8483e8d72c6 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Fri, 10 May 2019 22:54:26 -0400 Subject: [PATCH 2/6] Get the tests running (and failing) We're working with a reduced spec set; some of the Rust codegen is failing, so those specs have been removed here. --- spec/rust/Cargo.toml | 1 + spec/rust/build.rs | 1 - spec/rust/tests/test_bcd_user_type_be.rs | 19 ------- spec/rust/tests/test_bcd_user_type_le.rs | 19 ------- spec/rust/tests/test_bits_byte_aligned.rs | 31 ++++++------ spec/rust/tests/test_bits_enum.rs | 15 ++++++ spec/rust/tests/test_bits_simple.rs | 41 ++++++++-------- spec/rust/tests/test_buffered_struct.rs | 20 -------- spec/rust/tests/test_bytes_pad_term.rs | 21 ++++---- spec/rust/tests/test_cast_nested.rs | 21 ++++---- spec/rust/tests/test_cast_to_imported.rs | 17 +++---- spec/rust/tests/test_cast_to_top.rs | 16 ------ spec/rust/tests/test_default_big_endian.rs | 15 +++--- .../test_default_endian_expr_inherited.rs | 43 ++++++++-------- .../tests/test_default_endian_expr_is_be.rs | 49 +++++++++---------- .../tests/test_default_endian_expr_is_le.rs | 37 +++++++------- spec/rust/tests/test_default_endian_mod.rs | 19 ++++--- spec/rust/tests/test_docstrings.rs | 13 +++-- spec/rust/tests/test_docstrings_docref.rs | 13 +++-- .../tests/test_docstrings_docref_multi.rs | 12 +++++ spec/rust/tests/test_enum_0.rs | 14 ++++++ spec/rust/tests/test_enum_1.rs | 14 ++++++ spec/rust/tests/test_enum_deep.rs | 14 ++++++ spec/rust/tests/test_enum_deep_literals.rs | 14 ++++++ spec/rust/tests/test_enum_fancy.rs | 14 ++++++ spec/rust/tests/test_enum_if.rs | 19 +++++++ spec/rust/tests/test_enum_negative.rs | 14 ++++++ spec/rust/tests/test_enum_of_value_inst.rs | 16 ++++++ spec/rust/tests/test_enum_to_i.rs | 17 +++++++ spec/rust/tests/test_expr_0.rs | 17 +++---- spec/rust/tests/test_expr_1.rs | 21 ++++---- spec/rust/tests/test_expr_2.rs | 30 ------------ spec/rust/tests/test_expr_3.rs | 37 +++++++------- spec/rust/tests/test_expr_array.rs | 43 ++++++++-------- spec/rust/tests/test_expr_bytes_cmp.rs | 33 ++++++------- spec/rust/tests/test_expr_enum.rs | 15 ++++++ spec/rust/tests/test_expr_io_pos.rs | 19 ------- spec/rust/tests/test_expr_mod.rs | 25 +++++----- spec/rust/tests/test_expr_sizeof_type_0.rs | 13 +++++ spec/rust/tests/test_expr_sizeof_type_1.rs | 14 ++++++ spec/rust/tests/test_expr_sizeof_value_0.rs | 17 +++++++ spec/rust/tests/test_fixed_contents.rs | 13 +++-- spec/rust/tests/test_fixed_struct.rs | 33 ------------- spec/rust/tests/test_float_to_i.rs | 29 ++++++----- spec/rust/tests/test_floating_points.rs | 20 ++++++++ spec/rust/tests/test_hello_world.rs | 15 +++--- spec/rust/tests/test_if_struct.rs | 27 +++++----- spec/rust/tests/test_if_values.rs | 25 +++++----- spec/rust/tests/test_imports0.rs | 15 ++++++ spec/rust/tests/test_imports_abs.rs | 14 ++++++ spec/rust/tests/test_index_sizes.rs | 27 +++++----- spec/rust/tests/test_index_to_param_eos.rs | 27 +++++----- spec/rust/tests/test_index_to_param_expr.rs | 27 +++++----- spec/rust/tests/test_index_to_param_until.rs | 27 +++++----- spec/rust/tests/test_instance_io_user.rs | 17 ------- spec/rust/tests/test_instance_std.rs | 14 ------ spec/rust/tests/test_instance_std_array.rs | 27 +++++----- spec/rust/tests/test_instance_user_array.rs | 23 --------- spec/rust/tests/test_integers.rs | 32 ++++++++++++ spec/rust/tests/test_js_signed_right_shift.rs | 17 +++---- spec/rust/tests/test_meta_tags.rs | 12 +++++ spec/rust/tests/test_meta_xref.rs | 13 +++-- spec/rust/tests/test_multiple_use.rs | 15 ------ spec/rust/tests/test_nav_parent.rs | 23 +++++---- spec/rust/tests/test_nav_parent2.rs | 33 ++++++------- spec/rust/tests/test_nav_parent3.rs | 33 ++++++------- spec/rust/tests/test_nav_parent_false.rs | 23 +++++---- spec/rust/tests/test_nav_parent_false2.rs | 15 +++--- spec/rust/tests/test_nav_parent_override.rs | 19 ++++--- spec/rust/tests/test_nav_parent_switch.rs | 19 ++++--- .../tests/test_nav_parent_vs_value_inst.rs | 15 +++--- spec/rust/tests/test_nav_root.rs | 23 +++++---- spec/rust/tests/test_nested_same_name.rs | 17 +++---- spec/rust/tests/test_nested_same_name2.rs | 18 ------- spec/rust/tests/test_nested_types.rs | 19 ++++--- spec/rust/tests/test_nested_types2.rs | 27 +++++----- spec/rust/tests/test_nested_types3.rs | 23 +++++---- spec/rust/tests/test_non_standard.rs | 15 +++--- spec/rust/tests/test_params_call_short.rs | 19 ++++--- spec/rust/tests/test_params_enum.rs | 14 ++++++ spec/rust/tests/test_params_pass_usertype.rs | 17 +++---- spec/rust/tests/test_position_abs.rs | 17 +++---- spec/rust/tests/test_position_in_seq.rs | 15 +++--- spec/rust/tests/test_position_to_end.rs | 15 ------ spec/rust/tests/test_process_coerce_bytes.rs | 21 ++++---- spec/rust/tests/test_process_coerce_switch.rs | 16 ------ .../tests/test_process_coerce_usertype1.rs | 17 ------- .../tests/test_process_coerce_usertype2.rs | 17 ------- spec/rust/tests/test_process_custom.rs | 19 ++++--- spec/rust/tests/test_process_rotate.rs | 19 ++++--- spec/rust/tests/test_process_to_user.rs | 14 ------ spec/rust/tests/test_process_xor4_const.rs | 17 +++---- spec/rust/tests/test_process_xor4_value.rs | 17 +++---- spec/rust/tests/test_process_xor_const.rs | 17 +++---- spec/rust/tests/test_process_xor_value.rs | 17 +++---- spec/rust/tests/test_repeat_eos_bit.rs | 13 +++++ spec/rust/tests/test_repeat_eos_struct.rs | 23 +++++---- spec/rust/tests/test_repeat_eos_u4.rs | 15 +++--- spec/rust/tests/test_repeat_n_struct.rs | 23 +++++---- spec/rust/tests/test_repeat_n_strz.rs | 17 +++---- spec/rust/tests/test_repeat_n_strz_double.rs | 19 ++++--- spec/rust/tests/test_repeat_until_complex.rs | 43 ++++++++-------- spec/rust/tests/test_repeat_until_s4.rs | 17 +++---- spec/rust/tests/test_repeat_until_sized.rs | 20 -------- spec/rust/tests/test_str_encodings.rs | 21 ++++---- spec/rust/tests/test_str_encodings_default.rs | 21 ++++---- spec/rust/tests/test_str_eos.rs | 15 +++--- spec/rust/tests/test_str_literals2.rs | 21 ++++---- spec/rust/tests/test_str_pad_term.rs | 21 ++++---- spec/rust/tests/test_str_pad_term_empty.rs | 21 ++++---- spec/rust/tests/test_switch_bytearray.rs | 31 ++++++------ spec/rust/tests/test_switch_integers.rs | 31 ++++++------ spec/rust/tests/test_switch_integers2.rs | 23 +++++---- spec/rust/tests/test_switch_manual_enum.rs | 21 ++++++++ spec/rust/tests/test_switch_manual_int.rs | 31 ++++++------ .../rust/tests/test_switch_manual_int_else.rs | 31 ++++++------ .../tests/test_switch_manual_int_size_else.rs | 23 --------- spec/rust/tests/test_switch_manual_str.rs | 31 ++++++------ .../rust/tests/test_switch_manual_str_else.rs | 31 ++++++------ spec/rust/tests/test_term_bytes.rs | 19 ++++--- spec/rust/tests/test_term_strz.rs | 19 ++++--- spec/rust/tests/test_ts_packet_header.rs | 19 +++++++ spec/rust/tests/test_type_int_unary_op.rs | 21 ++++---- spec/rust/tests/test_type_ternary.rs | 14 ------ spec/rust/tests/test_user_type.rs | 17 +++---- spec/rust/tests/test_zlib_with_header_78.rs | 15 +++--- 126 files changed, 1266 insertions(+), 1343 deletions(-) delete mode 100644 spec/rust/tests/test_bcd_user_type_be.rs delete mode 100644 spec/rust/tests/test_bcd_user_type_le.rs create mode 100644 spec/rust/tests/test_bits_enum.rs delete mode 100644 spec/rust/tests/test_buffered_struct.rs delete mode 100644 spec/rust/tests/test_cast_to_top.rs create mode 100644 spec/rust/tests/test_docstrings_docref_multi.rs create mode 100644 spec/rust/tests/test_enum_0.rs create mode 100644 spec/rust/tests/test_enum_1.rs create mode 100644 spec/rust/tests/test_enum_deep.rs create mode 100644 spec/rust/tests/test_enum_deep_literals.rs create mode 100644 spec/rust/tests/test_enum_fancy.rs create mode 100644 spec/rust/tests/test_enum_if.rs create mode 100644 spec/rust/tests/test_enum_negative.rs create mode 100644 spec/rust/tests/test_enum_of_value_inst.rs create mode 100644 spec/rust/tests/test_enum_to_i.rs delete mode 100644 spec/rust/tests/test_expr_2.rs create mode 100644 spec/rust/tests/test_expr_enum.rs delete mode 100644 spec/rust/tests/test_expr_io_pos.rs create mode 100644 spec/rust/tests/test_expr_sizeof_type_0.rs create mode 100644 spec/rust/tests/test_expr_sizeof_type_1.rs create mode 100644 spec/rust/tests/test_expr_sizeof_value_0.rs delete mode 100644 spec/rust/tests/test_fixed_struct.rs create mode 100644 spec/rust/tests/test_floating_points.rs create mode 100644 spec/rust/tests/test_imports0.rs create mode 100644 spec/rust/tests/test_imports_abs.rs delete mode 100644 spec/rust/tests/test_instance_io_user.rs delete mode 100644 spec/rust/tests/test_instance_std.rs delete mode 100644 spec/rust/tests/test_instance_user_array.rs create mode 100644 spec/rust/tests/test_integers.rs create mode 100644 spec/rust/tests/test_meta_tags.rs delete mode 100644 spec/rust/tests/test_multiple_use.rs delete mode 100644 spec/rust/tests/test_nested_same_name2.rs create mode 100644 spec/rust/tests/test_params_enum.rs delete mode 100644 spec/rust/tests/test_position_to_end.rs delete mode 100644 spec/rust/tests/test_process_coerce_switch.rs delete mode 100644 spec/rust/tests/test_process_coerce_usertype1.rs delete mode 100644 spec/rust/tests/test_process_coerce_usertype2.rs delete mode 100644 spec/rust/tests/test_process_to_user.rs create mode 100644 spec/rust/tests/test_repeat_eos_bit.rs delete mode 100644 spec/rust/tests/test_repeat_until_sized.rs create mode 100644 spec/rust/tests/test_switch_manual_enum.rs delete mode 100644 spec/rust/tests/test_switch_manual_int_size_else.rs create mode 100644 spec/rust/tests/test_ts_packet_header.rs delete mode 100644 spec/rust/tests/test_type_ternary.rs diff --git a/spec/rust/Cargo.toml b/spec/rust/Cargo.toml index 3e91fb245..5b6b6158e 100644 --- a/spec/rust/Cargo.toml +++ b/spec/rust/Cargo.toml @@ -3,6 +3,7 @@ name = "kaitai_test" version = "0.1.0" authors = ["Connor Wood ", "Bradlee Speice"] build = "build.rs" +edition = "2018" [dependencies] kaitai = { git = "https://github.com/bspeice/kaitai_rust" } diff --git a/spec/rust/build.rs b/spec/rust/build.rs index 58086586a..a8906b6ba 100644 --- a/spec/rust/build.rs +++ b/spec/rust/build.rs @@ -40,7 +40,6 @@ fn copy_new(source_path: &Path, destination_path: &Path) -> io::Result<()> { if let Some(file_name) = path.file_name() { fs::copy(path.clone(), destination_path.join(file_name))?; - write!(librs, "pub mod {};\n", path.file_stem().unwrap().to_str().unwrap())?; } diff --git a/spec/rust/tests/test_bcd_user_type_be.rs b/spec/rust/tests/test_bcd_user_type_be.rs deleted file mode 100644 index 640195c8b..000000000 --- a/spec/rust/tests/test_bcd_user_type_be.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BcdUserTypeBe; - -#[test] -fn test_bcd_user_type_be() { - if let Ok(r) = BcdUserTypeBe::from_file("src/bcd_user_type_be.bin") { - assert_eq!(r.ltr.as_int, 12345678); - assert_eq!(r.ltr.as_str, "12345678"); - assert_eq!(r.rtl.as_int, 87654321); - assert_eq!(r.rtl.as_str, "87654321"); - assert_eq!(r.leading_zero_ltr.as_int, 123456); - assert_eq!(r.leading_zero_ltr.as_str, "00123456"); - } -} diff --git a/spec/rust/tests/test_bcd_user_type_le.rs b/spec/rust/tests/test_bcd_user_type_le.rs deleted file mode 100644 index 9769abc1a..000000000 --- a/spec/rust/tests/test_bcd_user_type_le.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BcdUserTypeLe; - -#[test] -fn test_bcd_user_type_le() { - if let Ok(r) = BcdUserTypeLe::from_file("src/bcd_user_type_le.bin") { - assert_eq!(r.ltr.as_int, 12345678); - assert_eq!(r.ltr.as_str, "12345678"); - assert_eq!(r.rtl.as_int, 87654321); - assert_eq!(r.rtl.as_str, "87654321"); - assert_eq!(r.leading_zero_ltr.as_int, 123456); - assert_eq!(r.leading_zero_ltr.as_str, "00123456"); - } -} diff --git a/spec/rust/tests/test_bits_byte_aligned.rs b/spec/rust/tests/test_bits_byte_aligned.rs index 128edb632..312fa2170 100644 --- a/spec/rust/tests/test_bits_byte_aligned.rs +++ b/spec/rust/tests/test_bits_byte_aligned.rs @@ -1,22 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsByteAligned; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::bits_byte_aligned::BitsByteAligned; +use std::fs; #[test] fn test_bits_byte_aligned() { - if let Ok(r) = BitsByteAligned::from_file("src/fixed_struct.bin") { - assert_eq!(r.one, 20); - assert_eq!(r.byte_1, 65); - assert_eq!(r.two, 2); - assert_eq!(r.three, false); - assert_eq!(r.byte_2, 75); - assert_eq!(r.four, 2892); - assert_eq!(r.byte_3, vec!([0xff])); - assert_eq!(r.full_byte, 255); - assert_eq!(r.byte_4, 80); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = BitsByteAligned::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.one, 20); + // assert_eq!(r.byte_1, 65); + // assert_eq!(r.two, 2); + // assert_eq!(r.three, false); + // assert_eq!(r.byte_2, 75); + // assert_eq!(r.four, 2892); + // assert_eq!(r.byte_3, vec!([0xff])); + // assert_eq!(r.full_byte, 255); + // assert_eq!(r.byte_4, 80); } diff --git a/spec/rust/tests/test_bits_enum.rs b/spec/rust/tests/test_bits_enum.rs new file mode 100644 index 000000000..5493f9d16 --- /dev/null +++ b/spec/rust/tests/test_bits_enum.rs @@ -0,0 +1,15 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::bits_enum::BitsEnum; +use std::fs; + +#[test] +fn test_bits_enum() { + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = BitsEnum::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.one, animal::PLATYPUS); + // assert_eq!(r.two, animal::HORSE); + // assert_eq!(r.three, animal::CAT); +} diff --git a/spec/rust/tests/test_bits_simple.rs b/spec/rust/tests/test_bits_simple.rs index c3eb6a06c..95227dac9 100644 --- a/spec/rust/tests/test_bits_simple.rs +++ b/spec/rust/tests/test_bits_simple.rs @@ -1,27 +1,26 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsSimple; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::bits_simple::BitsSimple; +use std::fs; #[test] fn test_bits_simple() { - if let Ok(r) = BitsSimple::from_file("src/fixed_struct.bin") { - assert_eq!(r.byte_1, 80); - assert_eq!(r.byte_2, 65); - assert_eq!(r.bits_a, false); - assert_eq!(r.bits_b, 4); - assert_eq!(r.bits_c, 3); - assert_eq!(r.large_bits_1, 300); - assert_eq!(r.spacer, 5); - assert_eq!(r.large_bits_2, 1329); - assert_eq!(r.normal_s2, -1); - assert_eq!(r.byte_8_9_10, 5259587); - assert_eq!(r.byte_11_to_14, 1261262125); - assert_eq!(r.byte_15_to_19, 293220057087); - assert_eq!(r.byte_20_to_27, 18446744073709551615); - assert_eq!(r.test_if_b1, 123); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = BitsSimple::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.byte_1, 80); + // assert_eq!(r.byte_2, 65); + // assert_eq!(r.bits_a, false); + // assert_eq!(r.bits_b, 4); + // assert_eq!(r.bits_c, 3); + // assert_eq!(r.large_bits_1, 300); + // assert_eq!(r.spacer, 5); + // assert_eq!(r.large_bits_2, 1329); + // assert_eq!(r.normal_s2, -1); + // assert_eq!(r.byte_8_9_10, 5259587); + // assert_eq!(r.byte_11_to_14, 1261262125); + // assert_eq!(r.byte_15_to_19, 293220057087); + // assert_eq!(r.byte_20_to_27, 18446744073709551615); + // assert_eq!(r.test_if_b1, 123); } diff --git a/spec/rust/tests/test_buffered_struct.rs b/spec/rust/tests/test_buffered_struct.rs deleted file mode 100644 index 2b4a8d82e..000000000 --- a/spec/rust/tests/test_buffered_struct.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BufferedStruct; - -#[test] -fn test_buffered_struct() { - if let Ok(r) = BufferedStruct::from_file("src/buffered_struct.bin") { - assert_eq!(r.len1, 16); - assert_eq!(r.block1.number1, 66); - assert_eq!(r.block1.number2, 67); - assert_eq!(r.len2, 8); - assert_eq!(r.block2.number1, 68); - assert_eq!(r.block2.number2, 69); - assert_eq!(r.finisher, 238); - } -} diff --git a/spec/rust/tests/test_bytes_pad_term.rs b/spec/rust/tests/test_bytes_pad_term.rs index 87ac91cd8..44f433393 100644 --- a/spec/rust/tests/test_bytes_pad_term.rs +++ b/spec/rust/tests/test_bytes_pad_term.rs @@ -1,17 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BytesPadTerm; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::bytes_pad_term::BytesPadTerm; +use std::fs; #[test] fn test_bytes_pad_term() { - if let Ok(r) = BytesPadTerm::from_file("src/str_pad_term.bin") { - assert_eq!(r.str_pad, vec!([0x73, 0x74, 0x72, 0x31])); - assert_eq!(r.str_term, vec!([0x73, 0x74, 0x72, 0x32, 0x66, 0x6f, 0x6f])); - assert_eq!(r.str_term_and_pad, vec!([0x73, 0x74, 0x72, 0x2b, 0x2b, 0x2b, 0x33, 0x62, 0x61, 0x72, 0x2b, 0x2b, 0x2b])); - assert_eq!(r.str_term_include, vec!([0x73, 0x74, 0x72, 0x34, 0x62, 0x61, 0x7a, 0x40])); - } + let data = fs::read("src/str_pad_term.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = BytesPadTerm::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.str_pad, vec!([0x73, 0x74, 0x72, 0x31])); + // assert_eq!(r.str_term, vec!([0x73, 0x74, 0x72, 0x32, 0x66, 0x6f, 0x6f])); + // assert_eq!(r.str_term_and_pad, vec!([0x73, 0x74, 0x72, 0x2b, 0x2b, 0x2b, 0x33, 0x62, 0x61, 0x72, 0x2b, 0x2b, 0x2b])); + // assert_eq!(r.str_term_include, vec!([0x73, 0x74, 0x72, 0x34, 0x62, 0x61, 0x7a, 0x40])); } diff --git a/spec/rust/tests/test_cast_nested.rs b/spec/rust/tests/test_cast_nested.rs index 80a1d7566..7f91ae73a 100644 --- a/spec/rust/tests/test_cast_nested.rs +++ b/spec/rust/tests/test_cast_nested.rs @@ -1,17 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::CastNested; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::cast_nested::CastNested; +use std::fs; #[test] fn test_cast_nested() { - if let Ok(r) = CastNested::from_file("src/switch_opcodes.bin") { - assert_eq!(r.opcodes_0_str.value, "foobar"); - assert_eq!(r.opcodes_0_str_value, "foobar"); - assert_eq!(r.opcodes_1_int.value, 66); - assert_eq!(r.opcodes_1_int_value, 66); - } + let data = fs::read("src/switch_opcodes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = CastNested::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.opcodes_0_str.value, "foobar"); + // assert_eq!(r.opcodes_0_str_value, "foobar"); + // assert_eq!(r.opcodes_1_int.value, 66); + // assert_eq!(r.opcodes_1_int_value, 66); } diff --git a/spec/rust/tests/test_cast_to_imported.rs b/spec/rust/tests/test_cast_to_imported.rs index 896ee9be3..b17769ee3 100644 --- a/spec/rust/tests/test_cast_to_imported.rs +++ b/spec/rust/tests/test_cast_to_imported.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::CastToImported; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::cast_to_imported::CastToImported; +use std::fs; #[test] fn test_cast_to_imported() { - if let Ok(r) = CastToImported::from_file("src/fixed_struct.bin") { - assert_eq!(r.one.one, 80); - assert_eq!(r.one_casted.one, 80); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = CastToImported::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.one.one, 80); + // assert_eq!(r.one_casted.one, 80); } diff --git a/spec/rust/tests/test_cast_to_top.rs b/spec/rust/tests/test_cast_to_top.rs deleted file mode 100644 index 8c248dc84..000000000 --- a/spec/rust/tests/test_cast_to_top.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::CastToTop; - -#[test] -fn test_cast_to_top() { - if let Ok(r) = CastToTop::from_file("src/fixed_struct.bin") { - assert_eq!(r.code, 80); - assert_eq!(r.header.code, 65); - assert_eq!(r.header_casted.code, 65); - } -} diff --git a/spec/rust/tests/test_default_big_endian.rs b/spec/rust/tests/test_default_big_endian.rs index f5fc0ee75..c3fae9538 100644 --- a/spec/rust/tests/test_default_big_endian.rs +++ b/spec/rust/tests/test_default_big_endian.rs @@ -1,14 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultBigEndian; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::default_big_endian::DefaultBigEndian; +use std::fs; #[test] fn test_default_big_endian() { - if let Ok(r) = DefaultBigEndian::from_file("src/enum_0.bin") { - assert_eq!(r.one, 117440512); - } + let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = DefaultBigEndian::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.one, 117440512); } diff --git a/spec/rust/tests/test_default_endian_expr_inherited.rs b/spec/rust/tests/test_default_endian_expr_inherited.rs index f48bf523f..1e67114eb 100644 --- a/spec/rust/tests/test_default_endian_expr_inherited.rs +++ b/spec/rust/tests/test_default_endian_expr_inherited.rs @@ -1,28 +1,27 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultEndianExprInherited; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::default_endian_expr_inherited::DefaultEndianExprInherited; +use std::fs; #[test] fn test_default_endian_expr_inherited() { - if let Ok(r) = DefaultEndianExprInherited::from_file("src/endian_expr.bin") { - assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); - assert_eq!(r.docs[0].main.insides.some_int, 66); - assert_eq!(r.docs[0].main.insides.more.some_int1, 16896); - assert_eq!(r.docs[0].main.insides.more.some_int2, 66); - assert_eq!(r.docs[0].main.insides.more.some_inst, 66); - assert_eq!(r.docs[1].indicator, vec!([0x4d, 0x4d])); - assert_eq!(r.docs[1].main.insides.some_int, 66); - assert_eq!(r.docs[1].main.insides.more.some_int1, 66); - assert_eq!(r.docs[1].main.insides.more.some_int2, 16896); - assert_eq!(r.docs[1].main.insides.more.some_inst, 1107296256); - assert_eq!(r.docs[2].indicator, vec!([0x58, 0x58])); - assert_eq!(r.docs[2].main.insides.some_int, 66); - assert_eq!(r.docs[2].main.insides.more.some_int1, 66); - assert_eq!(r.docs[2].main.insides.more.some_int2, 16896); - assert_eq!(r.docs[2].main.insides.more.some_inst, 1107296256); - } + let data = fs::read("src/endian_expr.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = DefaultEndianExprInherited::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); + // assert_eq!(r.docs[0].main.insides.some_int, 66); + // assert_eq!(r.docs[0].main.insides.more.some_int1, 16896); + // assert_eq!(r.docs[0].main.insides.more.some_int2, 66); + // assert_eq!(r.docs[0].main.insides.more.some_inst, 66); + // assert_eq!(r.docs[1].indicator, vec!([0x4d, 0x4d])); + // assert_eq!(r.docs[1].main.insides.some_int, 66); + // assert_eq!(r.docs[1].main.insides.more.some_int1, 66); + // assert_eq!(r.docs[1].main.insides.more.some_int2, 16896); + // assert_eq!(r.docs[1].main.insides.more.some_inst, 1107296256); + // assert_eq!(r.docs[2].indicator, vec!([0x58, 0x58])); + // assert_eq!(r.docs[2].main.insides.some_int, 66); + // assert_eq!(r.docs[2].main.insides.more.some_int1, 66); + // assert_eq!(r.docs[2].main.insides.more.some_int2, 16896); + // assert_eq!(r.docs[2].main.insides.more.some_inst, 1107296256); } diff --git a/spec/rust/tests/test_default_endian_expr_is_be.rs b/spec/rust/tests/test_default_endian_expr_is_be.rs index 031394522..4d7f31fde 100644 --- a/spec/rust/tests/test_default_endian_expr_is_be.rs +++ b/spec/rust/tests/test_default_endian_expr_is_be.rs @@ -1,31 +1,30 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultEndianExprIsBe; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::default_endian_expr_is_be::DefaultEndianExprIsBe; +use std::fs; #[test] fn test_default_endian_expr_is_be() { - if let Ok(r) = DefaultEndianExprIsBe::from_file("src/endian_expr.bin") { - assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); - assert_eq!(r.docs[0].main.some_int, 66); - assert_eq!(r.docs[0].main.some_int_be, 66); - assert_eq!(r.docs[0].main.some_int_le, 66); - assert_eq!(r.docs[0].main.inst_int, 66); - assert_eq!(r.docs[0].main.inst_sub.foo, 66); - assert_eq!(r.docs[1].indicator, vec!([0x4d, 0x4d])); - assert_eq!(r.docs[1].main.some_int, 66); - assert_eq!(r.docs[1].main.some_int_be, 66); - assert_eq!(r.docs[1].main.some_int_le, 66); - assert_eq!(r.docs[1].main.inst_int, 1107296256); - assert_eq!(r.docs[1].main.inst_sub.foo, 1107296256); - assert_eq!(r.docs[2].indicator, vec!([0x58, 0x58])); - assert_eq!(r.docs[2].main.some_int, 1107296256); - assert_eq!(r.docs[2].main.some_int_be, 66); - assert_eq!(r.docs[2].main.some_int_le, 66); - assert_eq!(r.docs[2].main.inst_int, 66); - assert_eq!(r.docs[2].main.inst_sub.foo, 66); - } + let data = fs::read("src/endian_expr.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = DefaultEndianExprIsBe::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); + // assert_eq!(r.docs[0].main.some_int, 66); + // assert_eq!(r.docs[0].main.some_int_be, 66); + // assert_eq!(r.docs[0].main.some_int_le, 66); + // assert_eq!(r.docs[0].main.inst_int, 66); + // assert_eq!(r.docs[0].main.inst_sub.foo, 66); + // assert_eq!(r.docs[1].indicator, vec!([0x4d, 0x4d])); + // assert_eq!(r.docs[1].main.some_int, 66); + // assert_eq!(r.docs[1].main.some_int_be, 66); + // assert_eq!(r.docs[1].main.some_int_le, 66); + // assert_eq!(r.docs[1].main.inst_int, 1107296256); + // assert_eq!(r.docs[1].main.inst_sub.foo, 1107296256); + // assert_eq!(r.docs[2].indicator, vec!([0x58, 0x58])); + // assert_eq!(r.docs[2].main.some_int, 1107296256); + // assert_eq!(r.docs[2].main.some_int_be, 66); + // assert_eq!(r.docs[2].main.some_int_le, 66); + // assert_eq!(r.docs[2].main.inst_int, 66); + // assert_eq!(r.docs[2].main.inst_sub.foo, 66); } diff --git a/spec/rust/tests/test_default_endian_expr_is_le.rs b/spec/rust/tests/test_default_endian_expr_is_le.rs index 5172458be..6201fc1ad 100644 --- a/spec/rust/tests/test_default_endian_expr_is_le.rs +++ b/spec/rust/tests/test_default_endian_expr_is_le.rs @@ -1,25 +1,24 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultEndianExprIsLe; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::default_endian_expr_is_le::DefaultEndianExprIsLe; +use std::fs; #[test] fn test_default_endian_expr_is_le() { - if let Ok(r) = DefaultEndianExprIsLe::from_file("src/endian_expr.bin") { - assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); - assert_eq!(r.docs[0].main.some_int, 66); - assert_eq!(r.docs[0].main.some_int_be, 66); - assert_eq!(r.docs[0].main.some_int_le, 66); - assert_eq!(r.docs[1].indicator, vec!([0x4d, 0x4d])); - assert_eq!(r.docs[1].main.some_int, 66); - assert_eq!(r.docs[1].main.some_int_be, 66); - assert_eq!(r.docs[1].main.some_int_le, 66); - assert_eq!(r.docs[2].indicator, vec!([0x58, 0x58])); - assert_eq!(r.docs[2].main.some_int, 66); - assert_eq!(r.docs[2].main.some_int_be, 66); - assert_eq!(r.docs[2].main.some_int_le, 66); - } + let data = fs::read("src/endian_expr.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = DefaultEndianExprIsLe::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); + // assert_eq!(r.docs[0].main.some_int, 66); + // assert_eq!(r.docs[0].main.some_int_be, 66); + // assert_eq!(r.docs[0].main.some_int_le, 66); + // assert_eq!(r.docs[1].indicator, vec!([0x4d, 0x4d])); + // assert_eq!(r.docs[1].main.some_int, 66); + // assert_eq!(r.docs[1].main.some_int_be, 66); + // assert_eq!(r.docs[1].main.some_int_le, 66); + // assert_eq!(r.docs[2].indicator, vec!([0x58, 0x58])); + // assert_eq!(r.docs[2].main.some_int, 66); + // assert_eq!(r.docs[2].main.some_int_be, 66); + // assert_eq!(r.docs[2].main.some_int_le, 66); } diff --git a/spec/rust/tests/test_default_endian_mod.rs b/spec/rust/tests/test_default_endian_mod.rs index d8f21e85b..db410537e 100644 --- a/spec/rust/tests/test_default_endian_mod.rs +++ b/spec/rust/tests/test_default_endian_mod.rs @@ -1,16 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultEndianMod; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::default_endian_mod::DefaultEndianMod; +use std::fs; #[test] fn test_default_endian_mod() { - if let Ok(r) = DefaultEndianMod::from_file("src/fixed_struct.bin") { - assert_eq!(r.main.one, 1262698832); - assert_eq!(r.main.nest.two, -52947); - assert_eq!(r.main.nest_be.two, 1346454347); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = DefaultEndianMod::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.main.one, 1262698832); + // assert_eq!(r.main.nest.two, -52947); + // assert_eq!(r.main.nest_be.two, 1346454347); } diff --git a/spec/rust/tests/test_docstrings.rs b/spec/rust/tests/test_docstrings.rs index c71d39911..7ef44c56a 100644 --- a/spec/rust/tests/test_docstrings.rs +++ b/spec/rust/tests/test_docstrings.rs @@ -1,13 +1,12 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::Docstrings; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::docstrings::Docstrings; +use std::fs; #[test] fn test_docstrings() { - if let Ok(r) = Docstrings::from_file("src/fixed_struct.bin") { - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = Docstrings::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); } diff --git a/spec/rust/tests/test_docstrings_docref.rs b/spec/rust/tests/test_docstrings_docref.rs index 6a0603587..6442c43c4 100644 --- a/spec/rust/tests/test_docstrings_docref.rs +++ b/spec/rust/tests/test_docstrings_docref.rs @@ -1,13 +1,12 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DocstringsDocref; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::docstrings_docref::DocstringsDocref; +use std::fs; #[test] fn test_docstrings_docref() { - if let Ok(r) = DocstringsDocref::from_file("src/fixed_struct.bin") { - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = DocstringsDocref::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); } diff --git a/spec/rust/tests/test_docstrings_docref_multi.rs b/spec/rust/tests/test_docstrings_docref_multi.rs new file mode 100644 index 000000000..5e357dc56 --- /dev/null +++ b/spec/rust/tests/test_docstrings_docref_multi.rs @@ -0,0 +1,12 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::docstrings_docref_multi::DocstringsDocrefMulti; +use std::fs; + +#[test] +fn test_docstrings_docref_multi() { + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = DocstringsDocrefMulti::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); +} diff --git a/spec/rust/tests/test_enum_0.rs b/spec/rust/tests/test_enum_0.rs new file mode 100644 index 000000000..597a5d508 --- /dev/null +++ b/spec/rust/tests/test_enum_0.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::enum_0::Enum0; +use std::fs; + +#[test] +fn test_enum_0() { + let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = Enum0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.pet_1, animal::CAT); + // assert_eq!(r.pet_2, animal::CHICKEN); +} diff --git a/spec/rust/tests/test_enum_1.rs b/spec/rust/tests/test_enum_1.rs new file mode 100644 index 000000000..c76a71d4d --- /dev/null +++ b/spec/rust/tests/test_enum_1.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::enum_1::Enum1; +use std::fs; + +#[test] +fn test_enum_1() { + let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = Enum1::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.main.submain.pet_1, animal::CAT); + // assert_eq!(r.main.submain.pet_2, animal::CHICKEN); +} diff --git a/spec/rust/tests/test_enum_deep.rs b/spec/rust/tests/test_enum_deep.rs new file mode 100644 index 000000000..810185cf0 --- /dev/null +++ b/spec/rust/tests/test_enum_deep.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::enum_deep::EnumDeep; +use std::fs; + +#[test] +fn test_enum_deep() { + let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = EnumDeep::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.pet_1, animal::CAT); + // assert_eq!(r.pet_2, animal::HARE); +} diff --git a/spec/rust/tests/test_enum_deep_literals.rs b/spec/rust/tests/test_enum_deep_literals.rs new file mode 100644 index 000000000..0358250a1 --- /dev/null +++ b/spec/rust/tests/test_enum_deep_literals.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::enum_deep_literals::EnumDeepLiterals; +use std::fs; + +#[test] +fn test_enum_deep_literals() { + let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = EnumDeepLiterals::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.is_pet_1_ok, true); + // assert_eq!(r.is_pet_2_ok, true); +} diff --git a/spec/rust/tests/test_enum_fancy.rs b/spec/rust/tests/test_enum_fancy.rs new file mode 100644 index 000000000..3d4ea97f2 --- /dev/null +++ b/spec/rust/tests/test_enum_fancy.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::enum_fancy::EnumFancy; +use std::fs; + +#[test] +fn test_enum_fancy() { + let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = EnumFancy::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.pet_1, animal::CAT); + // assert_eq!(r.pet_2, animal::CHICKEN); +} diff --git a/spec/rust/tests/test_enum_if.rs b/spec/rust/tests/test_enum_if.rs new file mode 100644 index 000000000..19850bf08 --- /dev/null +++ b/spec/rust/tests/test_enum_if.rs @@ -0,0 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::enum_if::EnumIf; +use std::fs; + +#[test] +fn test_enum_if() { + let data = fs::read("src/if_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = EnumIf::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.op1.opcode, opcodes::A_STRING); + // assert_eq!(r.op1.arg_str.str, "foo"); + // assert_eq!(r.op2.opcode, opcodes::A_TUPLE); + // assert_eq!(r.op2.arg_tuple.num1, 66); + // assert_eq!(r.op2.arg_tuple.num2, 67); + // assert_eq!(r.op3.opcode, opcodes::A_STRING); + // assert_eq!(r.op3.arg_str.str, "bar"); +} diff --git a/spec/rust/tests/test_enum_negative.rs b/spec/rust/tests/test_enum_negative.rs new file mode 100644 index 000000000..3ada6528a --- /dev/null +++ b/spec/rust/tests/test_enum_negative.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::enum_negative::EnumNegative; +use std::fs; + +#[test] +fn test_enum_negative() { + let data = fs::read("src/enum_negative.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = EnumNegative::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.f1, constants::NEGATIVE_ONE); + // assert_eq!(r.f2, constants::POSITIVE_ONE); +} diff --git a/spec/rust/tests/test_enum_of_value_inst.rs b/spec/rust/tests/test_enum_of_value_inst.rs new file mode 100644 index 000000000..8d503d404 --- /dev/null +++ b/spec/rust/tests/test_enum_of_value_inst.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::enum_of_value_inst::EnumOfValueInst; +use std::fs; + +#[test] +fn test_enum_of_value_inst() { + let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = EnumOfValueInst::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.pet_1, animal::CAT); + // assert_eq!(r.pet_2, animal::CHICKEN); + // assert_eq!(r.pet_3, animal::DOG); + // assert_eq!(r.pet_4, animal::DOG); +} diff --git a/spec/rust/tests/test_enum_to_i.rs b/spec/rust/tests/test_enum_to_i.rs new file mode 100644 index 000000000..47b048f4b --- /dev/null +++ b/spec/rust/tests/test_enum_to_i.rs @@ -0,0 +1,17 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::enum_to_i::EnumToI; +use std::fs; + +#[test] +fn test_enum_to_i() { + let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = EnumToI::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.pet_1, animal::CAT); + // assert_eq!(r.pet_2, animal::CHICKEN); + // assert_eq!(r.pet_1_i, 7); + // assert_eq!(r.pet_1_mod, 32775); + // assert_eq!(r.one_lt_two, true); +} diff --git a/spec/rust/tests/test_expr_0.rs b/spec/rust/tests/test_expr_0.rs index 686cfdd53..a7a193ddc 100644 --- a/spec/rust/tests/test_expr_0.rs +++ b/spec/rust/tests/test_expr_0.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::Expr0; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_0::Expr0; +use std::fs; #[test] fn test_expr_0() { - if let Ok(r) = Expr0::from_file("src/str_encodings.bin") { - assert_eq!(r.must_be_f7, 247); - assert_eq!(r.must_be_abc123, "abc123"); - } + let data = fs::read("src/str_encodings.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = Expr0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.must_be_f7, 247); + // assert_eq!(r.must_be_abc123, "abc123"); } diff --git a/spec/rust/tests/test_expr_1.rs b/spec/rust/tests/test_expr_1.rs index 7b1377902..227fb061c 100644 --- a/spec/rust/tests/test_expr_1.rs +++ b/spec/rust/tests/test_expr_1.rs @@ -1,17 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::Expr1; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_1::Expr1; +use std::fs; #[test] fn test_expr_1() { - if let Ok(r) = Expr1::from_file("src/str_encodings.bin") { - assert_eq!(r.len_of_1, 10); - assert_eq!(r.len_of_1_mod, 8); - assert_eq!(r.str1, "Some ASC"); - assert_eq!(r.str1_len, 8); - } + let data = fs::read("src/str_encodings.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = Expr1::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.len_of_1, 10); + // assert_eq!(r.len_of_1_mod, 8); + // assert_eq!(r.str1, "Some ASC"); + // assert_eq!(r.str1_len, 8); } diff --git a/spec/rust/tests/test_expr_2.rs b/spec/rust/tests/test_expr_2.rs deleted file mode 100644 index eb7a2cb6a..000000000 --- a/spec/rust/tests/test_expr_2.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::Expr2; - -#[test] -fn test_expr_2() { - if let Ok(r) = Expr2::from_file("src/str_encodings.bin") { - assert_eq!(r.str1.len_orig, 10); - assert_eq!(r.str1.len_mod, 7); - assert_eq!(r.str1.str, "Some AS"); - assert_eq!(r.str1_len, 7); - assert_eq!(r.str1_len_mod, 7); - assert_eq!(r.str1_byte1, 73); - assert_eq!(r.str1_avg, 73); - assert_eq!(r.str1_char5, "e"); - assert_eq!(r.str1_tuple5.byte0, 101); - assert_eq!(r.str1_tuple5.byte0, 101); - assert_eq!(r.str1_tuple5.byte1, 32); - assert_eq!(r.str1_tuple5.byte2, 65); - assert_eq!(r.str1_tuple5.avg, 48); - assert_eq!(r.str2_tuple5.byte0, 101); - assert_eq!(r.str2_tuple5.byte1, 32); - assert_eq!(r.str2_tuple5.byte2, 65); - assert_eq!(r.str2_tuple5.avg, 48); - } -} diff --git a/spec/rust/tests/test_expr_3.rs b/spec/rust/tests/test_expr_3.rs index 9998e367a..d30eb3964 100644 --- a/spec/rust/tests/test_expr_3.rs +++ b/spec/rust/tests/test_expr_3.rs @@ -1,25 +1,24 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::Expr3; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_3::Expr3; +use std::fs; #[test] fn test_expr_3() { - if let Ok(r) = Expr3::from_file("src/fixed_struct.bin") { - assert_eq!(r.one, 80); - assert_eq!(r.two, "ACK"); - assert_eq!(r.three, "@ACK"); - assert_eq!(r.four, "_ACK_"); - assert_eq!(r.is_str_eq, true); - assert_eq!(r.is_str_ne, false); - assert_eq!(r.is_str_lt, true); - assert_eq!(r.is_str_gt, false); - assert_eq!(r.is_str_le, true); - assert_eq!(r.is_str_ge, false); - assert_eq!(r.is_str_lt2, true); - assert_eq!(r.test_not, true); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = Expr3::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.one, 80); + // assert_eq!(r.two, "ACK"); + // assert_eq!(r.three, "@ACK"); + // assert_eq!(r.four, "_ACK_"); + // assert_eq!(r.is_str_eq, true); + // assert_eq!(r.is_str_ne, false); + // assert_eq!(r.is_str_lt, true); + // assert_eq!(r.is_str_gt, false); + // assert_eq!(r.is_str_le, true); + // assert_eq!(r.is_str_ge, false); + // assert_eq!(r.is_str_lt2, true); + // assert_eq!(r.test_not, true); } diff --git a/spec/rust/tests/test_expr_array.rs b/spec/rust/tests/test_expr_array.rs index 21504b7d4..277270f50 100644 --- a/spec/rust/tests/test_expr_array.rs +++ b/spec/rust/tests/test_expr_array.rs @@ -1,28 +1,27 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprArray; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_array::ExprArray; +use std::fs; #[test] fn test_expr_array() { - if let Ok(r) = ExprArray::from_file("src/expr_array.bin") { - assert_eq!(r.aint_size, 4); - assert_eq!(r.aint_first, 7657765); - assert_eq!(r.aint_last, 16272640); - assert_eq!(r.aint_min, 49185); - assert_eq!(r.aint_max, 1123362332); - assert_eq!(r.afloat_size, 3); - assert_eq!(r.afloat_first, -2.6839530254859364E-121); - assert_eq!(r.afloat_last, -1.1103359815095273E-175); - assert_eq!(r.afloat_min, -8.754689149998834E+288); - assert_eq!(r.afloat_max, -1.1103359815095273E-175); - assert_eq!(r.astr_size, 3); - assert_eq!(r.astr_first, "foo"); - assert_eq!(r.astr_last, "baz"); - assert_eq!(r.astr_min, "bar"); - assert_eq!(r.astr_max, "foo"); - } + let data = fs::read("src/expr_array.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ExprArray::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.aint_size, 4); + // assert_eq!(r.aint_first, 7657765); + // assert_eq!(r.aint_last, 16272640); + // assert_eq!(r.aint_min, 49185); + // assert_eq!(r.aint_max, 1123362332); + // assert_eq!(r.afloat_size, 3); + // assert_eq!(r.afloat_first, -2.6839530254859364E-121); + // assert_eq!(r.afloat_last, -1.1103359815095273E-175); + // assert_eq!(r.afloat_min, -8.754689149998834E+288); + // assert_eq!(r.afloat_max, -1.1103359815095273E-175); + // assert_eq!(r.astr_size, 3); + // assert_eq!(r.astr_first, "foo"); + // assert_eq!(r.astr_last, "baz"); + // assert_eq!(r.astr_min, "bar"); + // assert_eq!(r.astr_max, "foo"); } diff --git a/spec/rust/tests/test_expr_bytes_cmp.rs b/spec/rust/tests/test_expr_bytes_cmp.rs index 58656b11c..2b45f9ff3 100644 --- a/spec/rust/tests/test_expr_bytes_cmp.rs +++ b/spec/rust/tests/test_expr_bytes_cmp.rs @@ -1,23 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprBytesCmp; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_bytes_cmp::ExprBytesCmp; +use std::fs; #[test] fn test_expr_bytes_cmp() { - if let Ok(r) = ExprBytesCmp::from_file("src/fixed_struct.bin") { - assert_eq!(r.one, vec!([0x50])); - assert_eq!(r.two, vec!([0x41, 0x43, 0x4b])); - assert_eq!(r.is_eq, true); - assert_eq!(r.is_ne, false); - assert_eq!(r.is_lt, true); - assert_eq!(r.is_gt, false); - assert_eq!(r.is_le, true); - assert_eq!(r.is_ge, false); - assert_eq!(r.is_lt2, false); - assert_eq!(r.is_gt2, true); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ExprBytesCmp::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.one, vec!([0x50])); + // assert_eq!(r.two, vec!([0x41, 0x43, 0x4b])); + // assert_eq!(r.is_eq, true); + // assert_eq!(r.is_ne, false); + // assert_eq!(r.is_lt, true); + // assert_eq!(r.is_gt, false); + // assert_eq!(r.is_le, true); + // assert_eq!(r.is_ge, false); + // assert_eq!(r.is_lt2, false); + // assert_eq!(r.is_gt2, true); } diff --git a/spec/rust/tests/test_expr_enum.rs b/spec/rust/tests/test_expr_enum.rs new file mode 100644 index 000000000..29e48d819 --- /dev/null +++ b/spec/rust/tests/test_expr_enum.rs @@ -0,0 +1,15 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_enum::ExprEnum; +use std::fs; + +#[test] +fn test_expr_enum() { + let data = fs::read("src/term_strz.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ExprEnum::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.const_dog, animal::DOG); + // assert_eq!(r.derived_boom, animal::BOOM); + // assert_eq!(r.derived_dog, animal::DOG); +} diff --git a/spec/rust/tests/test_expr_io_pos.rs b/spec/rust/tests/test_expr_io_pos.rs deleted file mode 100644 index f2410bae0..000000000 --- a/spec/rust/tests/test_expr_io_pos.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprIoPos; - -#[test] -fn test_expr_io_pos() { - if let Ok(r) = ExprIoPos::from_file("src/expr_io_pos.bin") { - assert_eq!(r.substream1.my_str, "CURIOSITY"); - assert_eq!(r.substream1.body, vec!([0x11, 0x22, 0x33, 0x44])); - assert_eq!(r.substream1.number, 66); - assert_eq!(r.substream2.my_str, "KILLED"); - assert_eq!(r.substream2.body, vec!([0x61, 0x20, 0x63, 0x61, 0x74])); - assert_eq!(r.substream2.number, 103); - } -} diff --git a/spec/rust/tests/test_expr_mod.rs b/spec/rust/tests/test_expr_mod.rs index 14001402e..32db60ed7 100644 --- a/spec/rust/tests/test_expr_mod.rs +++ b/spec/rust/tests/test_expr_mod.rs @@ -1,19 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprMod; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_mod::ExprMod; +use std::fs; #[test] fn test_expr_mod() { - if let Ok(r) = ExprMod::from_file("src/fixed_struct.bin") { - assert_eq!(r.int_u, 1262698832); - assert_eq!(r.int_s, -52947); - assert_eq!(r.mod_pos_const, 9); - assert_eq!(r.mod_neg_const, 4); - assert_eq!(r.mod_pos_seq, 5); - assert_eq!(r.mod_neg_seq, 2); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ExprMod::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.int_u, 1262698832); + // assert_eq!(r.int_s, -52947); + // assert_eq!(r.mod_pos_const, 9); + // assert_eq!(r.mod_neg_const, 4); + // assert_eq!(r.mod_pos_seq, 5); + // assert_eq!(r.mod_neg_seq, 2); } diff --git a/spec/rust/tests/test_expr_sizeof_type_0.rs b/spec/rust/tests/test_expr_sizeof_type_0.rs new file mode 100644 index 000000000..a41a4395f --- /dev/null +++ b/spec/rust/tests/test_expr_sizeof_type_0.rs @@ -0,0 +1,13 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_sizeof_type_0::ExprSizeofType0; +use std::fs; + +#[test] +fn test_expr_sizeof_type_0() { + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ExprSizeofType0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.sizeof_block, ((1 + 4) + 2)); +} diff --git a/spec/rust/tests/test_expr_sizeof_type_1.rs b/spec/rust/tests/test_expr_sizeof_type_1.rs new file mode 100644 index 000000000..9fa65796c --- /dev/null +++ b/spec/rust/tests/test_expr_sizeof_type_1.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_sizeof_type_1::ExprSizeofType1; +use std::fs; + +#[test] +fn test_expr_sizeof_type_1() { + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ExprSizeofType1::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.sizeof_block, (((1 + 4) + 2) + 4)); + // assert_eq!(r.sizeof_subblock, 4); +} diff --git a/spec/rust/tests/test_expr_sizeof_value_0.rs b/spec/rust/tests/test_expr_sizeof_value_0.rs new file mode 100644 index 000000000..d32033e06 --- /dev/null +++ b/spec/rust/tests/test_expr_sizeof_value_0.rs @@ -0,0 +1,17 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_sizeof_value_0::ExprSizeofValue0; +use std::fs; + +#[test] +fn test_expr_sizeof_value_0() { + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ExprSizeofValue0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.self_sizeof, (((1 + 4) + 2) + 2)); + // assert_eq!(r.sizeof_block, ((1 + 4) + 2)); + // assert_eq!(r.sizeof_block_a, 1); + // assert_eq!(r.sizeof_block_b, 4); + // assert_eq!(r.sizeof_block_c, 2); +} diff --git a/spec/rust/tests/test_fixed_contents.rs b/spec/rust/tests/test_fixed_contents.rs index fb0a425c0..04bc2a387 100644 --- a/spec/rust/tests/test_fixed_contents.rs +++ b/spec/rust/tests/test_fixed_contents.rs @@ -1,13 +1,12 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::FixedContents; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::fixed_contents::FixedContents; +use std::fs; #[test] fn test_fixed_contents() { - if let Ok(r) = FixedContents::from_file("src/fixed_struct.bin") { - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = FixedContents::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); } diff --git a/spec/rust/tests/test_fixed_struct.rs b/spec/rust/tests/test_fixed_struct.rs deleted file mode 100644 index a47a7e8d5..000000000 --- a/spec/rust/tests/test_fixed_struct.rs +++ /dev/null @@ -1,33 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::FixedStruct; - -#[test] -fn test_fixed_struct() { - if let Ok(r) = FixedStruct::from_file("src/fixed_struct.bin") { - assert_eq!(r.hdr.uint8, 255); - assert_eq!(r.hdr.uint16, 65535); - assert_eq!(r.hdr.uint32, 4294967295); - assert_eq!(r.hdr.uint64, 18446744073709551615); - assert_eq!(r.hdr.sint8, -1); - assert_eq!(r.hdr.sint16, -1); - assert_eq!(r.hdr.sint32, -1); - assert_eq!(r.hdr.sint64, -1); - assert_eq!(r.hdr.uint16le, 66); - assert_eq!(r.hdr.uint32le, 66); - assert_eq!(r.hdr.uint64le, 66); - assert_eq!(r.hdr.sint16le, -66); - assert_eq!(r.hdr.sint32le, -66); - assert_eq!(r.hdr.sint64le, -66); - assert_eq!(r.hdr.uint16be, 66); - assert_eq!(r.hdr.uint32be, 66); - assert_eq!(r.hdr.uint64be, 66); - assert_eq!(r.hdr.sint16be, -66); - assert_eq!(r.hdr.sint32be, -66); - assert_eq!(r.hdr.sint64be, -66); - } -} diff --git a/spec/rust/tests/test_float_to_i.rs b/spec/rust/tests/test_float_to_i.rs index 661d31f48..c6bfe3af1 100644 --- a/spec/rust/tests/test_float_to_i.rs +++ b/spec/rust/tests/test_float_to_i.rs @@ -1,21 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::FloatToI; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::float_to_i::FloatToI; +use std::fs; #[test] fn test_float_to_i() { - if let Ok(r) = FloatToI::from_file("src/floating_points.bin") { - assert_eq!(r.single_value, 0.5); - assert_eq!(r.double_value, 0.25); - assert_eq!(r.single_i, 0); - assert_eq!(r.double_i, 0); - assert_eq!(r.float1_i, 1); - assert_eq!(r.float2_i, 1); - assert_eq!(r.float3_i, 1); - assert_eq!(r.float4_i, -2); - } + let data = fs::read("src/floating_points.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = FloatToI::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.single_value, 0.5); + // assert_eq!(r.double_value, 0.25); + // assert_eq!(r.single_i, 0); + // assert_eq!(r.double_i, 0); + // assert_eq!(r.float1_i, 1); + // assert_eq!(r.float2_i, 1); + // assert_eq!(r.float3_i, 1); + // assert_eq!(r.float4_i, -2); } diff --git a/spec/rust/tests/test_floating_points.rs b/spec/rust/tests/test_floating_points.rs new file mode 100644 index 000000000..783e1925b --- /dev/null +++ b/spec/rust/tests/test_floating_points.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::floating_points::FloatingPoints; +use std::fs; + +#[test] +fn test_floating_points() { + let data = fs::read("src/floating_points.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = FloatingPoints::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.single_value, 0.5); + // assert_eq!(r.single_value_be, 0.5); + // assert_eq!(r.double_value, 0.25); + // assert_eq!(r.double_value_be, 0.25); + // assert_eq!(r.approximate_value, 1.2345); + // assert_eq!(r.single_value_plus_int, 1.5); + // assert_eq!(r.single_value_plus_float, 1.0); + // assert_eq!(r.double_value_plus_float, 0.3); +} diff --git a/spec/rust/tests/test_hello_world.rs b/spec/rust/tests/test_hello_world.rs index 6397cfb2a..4212250ae 100644 --- a/spec/rust/tests/test_hello_world.rs +++ b/spec/rust/tests/test_hello_world.rs @@ -1,14 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::HelloWorld; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::hello_world::HelloWorld; +use std::fs; #[test] fn test_hello_world() { - if let Ok(r) = HelloWorld::from_file("src/fixed_struct.bin") { - assert_eq!(r.one, 80); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = HelloWorld::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.one, 80); } diff --git a/spec/rust/tests/test_if_struct.rs b/spec/rust/tests/test_if_struct.rs index 475ef1e50..4bb955e89 100644 --- a/spec/rust/tests/test_if_struct.rs +++ b/spec/rust/tests/test_if_struct.rs @@ -1,20 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IfStruct; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::if_struct::IfStruct; +use std::fs; #[test] fn test_if_struct() { - if let Ok(r) = IfStruct::from_file("src/if_struct.bin") { - assert_eq!(r.op1.opcode, 83); - assert_eq!(r.op1.arg_str.str, "foo"); - assert_eq!(r.op2.opcode, 84); - assert_eq!(r.op2.arg_tuple.num1, 66); - assert_eq!(r.op2.arg_tuple.num2, 67); - assert_eq!(r.op3.opcode, 83); - assert_eq!(r.op3.arg_str.str, "bar"); - } + let data = fs::read("src/if_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = IfStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.op1.opcode, 83); + // assert_eq!(r.op1.arg_str.str, "foo"); + // assert_eq!(r.op2.opcode, 84); + // assert_eq!(r.op2.arg_tuple.num1, 66); + // assert_eq!(r.op2.arg_tuple.num2, 67); + // assert_eq!(r.op3.opcode, 83); + // assert_eq!(r.op3.arg_str.str, "bar"); } diff --git a/spec/rust/tests/test_if_values.rs b/spec/rust/tests/test_if_values.rs index a0ce3dab8..a63f270f7 100644 --- a/spec/rust/tests/test_if_values.rs +++ b/spec/rust/tests/test_if_values.rs @@ -1,19 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IfValues; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::if_values::IfValues; +use std::fs; #[test] fn test_if_values() { - if let Ok(r) = IfValues::from_file("src/fixed_struct.bin") { - assert_eq!(r.codes[0].opcode, 80); - assert_eq!(r.codes[0].half_opcode, 40); - assert_eq!(r.codes[1].opcode, 65); - assertNull(r.codes[1].half_opcode); - assert_eq!(r.codes[2].opcode, 67); - assertNull(r.codes[2].half_opcode); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = IfValues::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.codes[0].opcode, 80); + // assert_eq!(r.codes[0].half_opcode, 40); + // assert_eq!(r.codes[1].opcode, 65); + // nullAsset(r.codes[1].half_opcode); + // assert_eq!(r.codes[2].opcode, 67); + // nullAsset(r.codes[2].half_opcode); } diff --git a/spec/rust/tests/test_imports0.rs b/spec/rust/tests/test_imports0.rs new file mode 100644 index 000000000..f1f9b2ff6 --- /dev/null +++ b/spec/rust/tests/test_imports0.rs @@ -0,0 +1,15 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::imports0::Imports0; +use std::fs; + +#[test] +fn test_imports0() { + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = Imports0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.two, 80); + // assert_eq!(r.hw.one, 65); + // assert_eq!(r.hw_one, 65); +} diff --git a/spec/rust/tests/test_imports_abs.rs b/spec/rust/tests/test_imports_abs.rs new file mode 100644 index 000000000..a1e1bd82e --- /dev/null +++ b/spec/rust/tests/test_imports_abs.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::imports_abs::ImportsAbs; +use std::fs; + +#[test] +fn test_imports_abs() { + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ImportsAbs::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.len.value, 80); + // assert_eq!(r.body.len(), 80); +} diff --git a/spec/rust/tests/test_index_sizes.rs b/spec/rust/tests/test_index_sizes.rs index 8d9e033d3..9688dcc7d 100644 --- a/spec/rust/tests/test_index_sizes.rs +++ b/spec/rust/tests/test_index_sizes.rs @@ -1,20 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IndexSizes; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::index_sizes::IndexSizes; +use std::fs; #[test] fn test_index_sizes() { - if let Ok(r) = IndexSizes::from_file("src/index_sizes.bin") { - assert_eq!(r.qty, 3); - assert_eq!(r.sizes[0], 1); - assert_eq!(r.sizes[1], 8); - assert_eq!(r.sizes[2], 4); - assert_eq!(r.bufs[0], "A"); - assert_eq!(r.bufs[1], "BBBBBBBB"); - assert_eq!(r.bufs[2], "CCCC"); - } + let data = fs::read("src/index_sizes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = IndexSizes::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.qty, 3); + // assert_eq!(r.sizes[0], 1); + // assert_eq!(r.sizes[1], 8); + // assert_eq!(r.sizes[2], 4); + // assert_eq!(r.bufs[0], "A"); + // assert_eq!(r.bufs[1], "BBBBBBBB"); + // assert_eq!(r.bufs[2], "CCCC"); } diff --git a/spec/rust/tests/test_index_to_param_eos.rs b/spec/rust/tests/test_index_to_param_eos.rs index f727d6f72..918e64c0f 100644 --- a/spec/rust/tests/test_index_to_param_eos.rs +++ b/spec/rust/tests/test_index_to_param_eos.rs @@ -1,20 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IndexToParamEos; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::index_to_param_eos::IndexToParamEos; +use std::fs; #[test] fn test_index_to_param_eos() { - if let Ok(r) = IndexToParamEos::from_file("src/index_sizes.bin") { - assert_eq!(r.qty, 3); - assert_eq!(r.sizes[0], 1); - assert_eq!(r.sizes[1], 8); - assert_eq!(r.sizes[2], 4); - assert_eq!(r.blocks[0].buf, "A"); - assert_eq!(r.blocks[1].buf, "BBBBBBBB"); - assert_eq!(r.blocks[2].buf, "CCCC"); - } + let data = fs::read("src/index_sizes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = IndexToParamEos::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.qty, 3); + // assert_eq!(r.sizes[0], 1); + // assert_eq!(r.sizes[1], 8); + // assert_eq!(r.sizes[2], 4); + // assert_eq!(r.blocks[0].buf, "A"); + // assert_eq!(r.blocks[1].buf, "BBBBBBBB"); + // assert_eq!(r.blocks[2].buf, "CCCC"); } diff --git a/spec/rust/tests/test_index_to_param_expr.rs b/spec/rust/tests/test_index_to_param_expr.rs index 321f27012..c30c572b8 100644 --- a/spec/rust/tests/test_index_to_param_expr.rs +++ b/spec/rust/tests/test_index_to_param_expr.rs @@ -1,20 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IndexToParamExpr; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::index_to_param_expr::IndexToParamExpr; +use std::fs; #[test] fn test_index_to_param_expr() { - if let Ok(r) = IndexToParamExpr::from_file("src/index_sizes.bin") { - assert_eq!(r.qty, 3); - assert_eq!(r.sizes[0], 1); - assert_eq!(r.sizes[1], 8); - assert_eq!(r.sizes[2], 4); - assert_eq!(r.blocks[0].buf, "A"); - assert_eq!(r.blocks[1].buf, "BBBBBBBB"); - assert_eq!(r.blocks[2].buf, "CCCC"); - } + let data = fs::read("src/index_sizes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = IndexToParamExpr::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.qty, 3); + // assert_eq!(r.sizes[0], 1); + // assert_eq!(r.sizes[1], 8); + // assert_eq!(r.sizes[2], 4); + // assert_eq!(r.blocks[0].buf, "A"); + // assert_eq!(r.blocks[1].buf, "BBBBBBBB"); + // assert_eq!(r.blocks[2].buf, "CCCC"); } diff --git a/spec/rust/tests/test_index_to_param_until.rs b/spec/rust/tests/test_index_to_param_until.rs index 71d09ffbe..3a9ee7215 100644 --- a/spec/rust/tests/test_index_to_param_until.rs +++ b/spec/rust/tests/test_index_to_param_until.rs @@ -1,20 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IndexToParamUntil; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::index_to_param_until::IndexToParamUntil; +use std::fs; #[test] fn test_index_to_param_until() { - if let Ok(r) = IndexToParamUntil::from_file("src/index_sizes.bin") { - assert_eq!(r.qty, 3); - assert_eq!(r.sizes[0], 1); - assert_eq!(r.sizes[1], 8); - assert_eq!(r.sizes[2], 4); - assert_eq!(r.blocks[0].buf, "A"); - assert_eq!(r.blocks[1].buf, "BBBBBBBB"); - assert_eq!(r.blocks[2].buf, "CCCC"); - } + let data = fs::read("src/index_sizes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = IndexToParamUntil::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.qty, 3); + // assert_eq!(r.sizes[0], 1); + // assert_eq!(r.sizes[1], 8); + // assert_eq!(r.sizes[2], 4); + // assert_eq!(r.blocks[0].buf, "A"); + // assert_eq!(r.blocks[1].buf, "BBBBBBBB"); + // assert_eq!(r.blocks[2].buf, "CCCC"); } diff --git a/spec/rust/tests/test_instance_io_user.rs b/spec/rust/tests/test_instance_io_user.rs deleted file mode 100644 index c389a5d3b..000000000 --- a/spec/rust/tests/test_instance_io_user.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::InstanceIoUser; - -#[test] -fn test_instance_io_user() { - if let Ok(r) = InstanceIoUser::from_file("src/instance_io.bin") { - assert_eq!(r.qty_entries, 3); - assert_eq!(r.entries[0].name, "the"); - assert_eq!(r.entries[1].name, "rainy"); - assert_eq!(r.entries[2].name, "day it is"); - } -} diff --git a/spec/rust/tests/test_instance_std.rs b/spec/rust/tests/test_instance_std.rs deleted file mode 100644 index 0a798b75c..000000000 --- a/spec/rust/tests/test_instance_std.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::InstanceStd; - -#[test] -fn test_instance_std() { - if let Ok(r) = InstanceStd::from_file("src/str_encodings.bin") { - assert_eq!(r.header, "Some "); - } -} diff --git a/spec/rust/tests/test_instance_std_array.rs b/spec/rust/tests/test_instance_std_array.rs index 07df25cd1..9961daa03 100644 --- a/spec/rust/tests/test_instance_std_array.rs +++ b/spec/rust/tests/test_instance_std_array.rs @@ -1,20 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::InstanceStdArray; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::instance_std_array::InstanceStdArray; +use std::fs; #[test] fn test_instance_std_array() { - if let Ok(r) = InstanceStdArray::from_file("src/instance_std_array.bin") { - assert_eq!(r.ofs, 16); - assert_eq!(r.qty_entries, 3); - assert_eq!(r.entry_size, 4); - assert_eq!(r.entries.len(), 3); - assert_eq!(r.entries[0], vec!([0x11, 0x11, 0x11, 0x11])); - assert_eq!(r.entries[1], vec!([0x22, 0x22, 0x22, 0x22])); - assert_eq!(r.entries[2], vec!([0x33, 0x33, 0x33, 0x33])); - } + let data = fs::read("src/instance_std_array.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = InstanceStdArray::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.ofs, 16); + // assert_eq!(r.qty_entries, 3); + // assert_eq!(r.entry_size, 4); + // assert_eq!(r.entries.len(), 3); + // assert_eq!(r.entries[0], vec!([0x11, 0x11, 0x11, 0x11])); + // assert_eq!(r.entries[1], vec!([0x22, 0x22, 0x22, 0x22])); + // assert_eq!(r.entries[2], vec!([0x33, 0x33, 0x33, 0x33])); } diff --git a/spec/rust/tests/test_instance_user_array.rs b/spec/rust/tests/test_instance_user_array.rs deleted file mode 100644 index 3cbf3c76d..000000000 --- a/spec/rust/tests/test_instance_user_array.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::InstanceUserArray; - -#[test] -fn test_instance_user_array() { - if let Ok(r) = InstanceUserArray::from_file("src/instance_std_array.bin") { - assert_eq!(r.ofs, 16); - assert_eq!(r.qty_entries, 3); - assert_eq!(r.entry_size, 4); - assert_eq!(r.user_entries.len(), 3); - assert_eq!(r.user_entries[0].word1, 4369); - assert_eq!(r.user_entries[0].word2, 4369); - assert_eq!(r.user_entries[1].word1, 8738); - assert_eq!(r.user_entries[1].word2, 8738); - assert_eq!(r.user_entries[2].word1, 13107); - assert_eq!(r.user_entries[2].word2, 13107); - } -} diff --git a/spec/rust/tests/test_integers.rs b/spec/rust/tests/test_integers.rs new file mode 100644 index 000000000..c1def99c2 --- /dev/null +++ b/spec/rust/tests/test_integers.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::integers::Integers; +use std::fs; + +#[test] +fn test_integers() { + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = Integers::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.uint8, 255); + // assert_eq!(r.uint16, 65535); + // assert_eq!(r.uint32, 4294967295); + // assert_eq!(r.uint64, 18446744073709551615); + // assert_eq!(r.sint8, -1); + // assert_eq!(r.sint16, -1); + // assert_eq!(r.sint32, -1); + // assert_eq!(r.sint64, -1); + // assert_eq!(r.uint16le, 66); + // assert_eq!(r.uint32le, 66); + // assert_eq!(r.uint64le, 66); + // assert_eq!(r.sint16le, -66); + // assert_eq!(r.sint32le, -66); + // assert_eq!(r.sint64le, -66); + // assert_eq!(r.uint16be, 66); + // assert_eq!(r.uint32be, 66); + // assert_eq!(r.uint64be, 66); + // assert_eq!(r.sint16be, -66); + // assert_eq!(r.sint32be, -66); + // assert_eq!(r.sint64be, -66); +} diff --git a/spec/rust/tests/test_js_signed_right_shift.rs b/spec/rust/tests/test_js_signed_right_shift.rs index 305913aa5..112ff0137 100644 --- a/spec/rust/tests/test_js_signed_right_shift.rs +++ b/spec/rust/tests/test_js_signed_right_shift.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::JsSignedRightShift; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::js_signed_right_shift::JsSignedRightShift; +use std::fs; #[test] fn test_js_signed_right_shift() { - if let Ok(r) = JsSignedRightShift::from_file("src/fixed_struct.bin") { - assert_eq!(r.should_be_40000000, 1073741824); - assert_eq!(r.should_be_a00000, 10485760); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = JsSignedRightShift::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.should_be_40000000, 1073741824); + // assert_eq!(r.should_be_a00000, 10485760); } diff --git a/spec/rust/tests/test_meta_tags.rs b/spec/rust/tests/test_meta_tags.rs new file mode 100644 index 000000000..cfef90977 --- /dev/null +++ b/spec/rust/tests/test_meta_tags.rs @@ -0,0 +1,12 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::meta_tags::MetaTags; +use std::fs; + +#[test] +fn test_meta_tags() { + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = MetaTags::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); +} diff --git a/spec/rust/tests/test_meta_xref.rs b/spec/rust/tests/test_meta_xref.rs index 9f068b47a..055c31e89 100644 --- a/spec/rust/tests/test_meta_xref.rs +++ b/spec/rust/tests/test_meta_xref.rs @@ -1,13 +1,12 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::MetaXref; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::meta_xref::MetaXref; +use std::fs; #[test] fn test_meta_xref() { - if let Ok(r) = MetaXref::from_file("src/fixed_struct.bin") { - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = MetaXref::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); } diff --git a/spec/rust/tests/test_multiple_use.rs b/spec/rust/tests/test_multiple_use.rs deleted file mode 100644 index c66faece9..000000000 --- a/spec/rust/tests/test_multiple_use.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::MultipleUse; - -#[test] -fn test_multiple_use() { - if let Ok(r) = MultipleUse::from_file("src/position_abs.bin") { - assert_eq!(r.t1.first_use.value, 32); - assert_eq!(r.t2.second_use.value, 32); - } -} diff --git a/spec/rust/tests/test_nav_parent.rs b/spec/rust/tests/test_nav_parent.rs index c43fbd303..f08fe35d5 100644 --- a/spec/rust/tests/test_nav_parent.rs +++ b/spec/rust/tests/test_nav_parent.rs @@ -1,18 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParent; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nav_parent::NavParent; +use std::fs; #[test] fn test_nav_parent() { - if let Ok(r) = NavParent::from_file("src/nav.bin") { - assert_eq!(r.header.qty_entries, 2); - assert_eq!(r.header.filename_len, 8); - assert_eq!(r.index.entries.len(), 2); - assert_eq!(r.index.entries[0].filename, "FIRST___"); - assert_eq!(r.index.entries[1].filename, "SECOND__"); - } + let data = fs::read("src/nav.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NavParent::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.header.qty_entries, 2); + // assert_eq!(r.header.filename_len, 8); + // assert_eq!(r.index.entries.len(), 2); + // assert_eq!(r.index.entries[0].filename, "FIRST___"); + // assert_eq!(r.index.entries[1].filename, "SECOND__"); } diff --git a/spec/rust/tests/test_nav_parent2.rs b/spec/rust/tests/test_nav_parent2.rs index c2f6d256f..a4e5ada1d 100644 --- a/spec/rust/tests/test_nav_parent2.rs +++ b/spec/rust/tests/test_nav_parent2.rs @@ -1,23 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParent2; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nav_parent2::NavParent2; +use std::fs; #[test] fn test_nav_parent2() { - if let Ok(r) = NavParent2::from_file("src/nav_parent2.bin") { - assert_eq!(r.ofs_tags, 8); - assert_eq!(r.num_tags, 2); - assert_eq!(r.tags[0].name, "RAHC"); - assert_eq!(r.tags[0].ofs, 32); - assert_eq!(r.tags[0].num_items, 3); - assert_eq!(r.tags[0].tag_content.content, "foo"); - assert_eq!(r.tags[1].name, "RAHC"); - assert_eq!(r.tags[1].ofs, 35); - assert_eq!(r.tags[1].num_items, 6); - assert_eq!(r.tags[1].tag_content.content, "barbaz"); - } + let data = fs::read("src/nav_parent2.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NavParent2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.ofs_tags, 8); + // assert_eq!(r.num_tags, 2); + // assert_eq!(r.tags[0].name, "RAHC"); + // assert_eq!(r.tags[0].ofs, 32); + // assert_eq!(r.tags[0].num_items, 3); + // assert_eq!(r.tags[0].tag_content.content, "foo"); + // assert_eq!(r.tags[1].name, "RAHC"); + // assert_eq!(r.tags[1].ofs, 35); + // assert_eq!(r.tags[1].num_items, 6); + // assert_eq!(r.tags[1].tag_content.content, "barbaz"); } diff --git a/spec/rust/tests/test_nav_parent3.rs b/spec/rust/tests/test_nav_parent3.rs index cc5abd5b2..84e69f296 100644 --- a/spec/rust/tests/test_nav_parent3.rs +++ b/spec/rust/tests/test_nav_parent3.rs @@ -1,23 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParent3; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nav_parent3::NavParent3; +use std::fs; #[test] fn test_nav_parent3() { - if let Ok(r) = NavParent3::from_file("src/nav_parent2.bin") { - assert_eq!(r.ofs_tags, 8); - assert_eq!(r.num_tags, 2); - assert_eq!(r.tags[0].name, "RAHC"); - assert_eq!(r.tags[0].ofs, 32); - assert_eq!(r.tags[0].num_items, 3); - assert_eq!(r.tags[0].tag_content.content, "foo"); - assert_eq!(r.tags[1].name, "RAHC"); - assert_eq!(r.tags[1].ofs, 35); - assert_eq!(r.tags[1].num_items, 6); - assert_eq!(r.tags[1].tag_content.content, "barbaz"); - } + let data = fs::read("src/nav_parent2.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NavParent3::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.ofs_tags, 8); + // assert_eq!(r.num_tags, 2); + // assert_eq!(r.tags[0].name, "RAHC"); + // assert_eq!(r.tags[0].ofs, 32); + // assert_eq!(r.tags[0].num_items, 3); + // assert_eq!(r.tags[0].tag_content.content, "foo"); + // assert_eq!(r.tags[1].name, "RAHC"); + // assert_eq!(r.tags[1].ofs, 35); + // assert_eq!(r.tags[1].num_items, 6); + // assert_eq!(r.tags[1].tag_content.content, "barbaz"); } diff --git a/spec/rust/tests/test_nav_parent_false.rs b/spec/rust/tests/test_nav_parent_false.rs index f8e935120..0d24a6bcf 100644 --- a/spec/rust/tests/test_nav_parent_false.rs +++ b/spec/rust/tests/test_nav_parent_false.rs @@ -1,18 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParentFalse; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nav_parent_false::NavParentFalse; +use std::fs; #[test] fn test_nav_parent_false() { - if let Ok(r) = NavParentFalse::from_file("src/nav_parent_codes.bin") { - assert_eq!(r.child_size, 3); - assert_eq!(r.element_a.foo.code, 73); - assert_eq!(r.element_a.foo.more, vec!([0x31, 0x32, 0x33])); - assert_eq!(r.element_a.bar.foo.code, 66); - assert_eq!(r.element_b.foo.code, 98); - } + let data = fs::read("src/nav_parent_codes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NavParentFalse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.child_size, 3); + // assert_eq!(r.element_a.foo.code, 73); + // assert_eq!(r.element_a.foo.more, vec!([0x31, 0x32, 0x33])); + // assert_eq!(r.element_a.bar.foo.code, 66); + // assert_eq!(r.element_b.foo.code, 98); } diff --git a/spec/rust/tests/test_nav_parent_false2.rs b/spec/rust/tests/test_nav_parent_false2.rs index 868d60f24..7f5e0808a 100644 --- a/spec/rust/tests/test_nav_parent_false2.rs +++ b/spec/rust/tests/test_nav_parent_false2.rs @@ -1,14 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParentFalse2; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nav_parent_false2::NavParentFalse2; +use std::fs; #[test] fn test_nav_parent_false2() { - if let Ok(r) = NavParentFalse2::from_file("src/fixed_struct.bin") { - assert_eq!(r.parentless.foo, 80); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NavParentFalse2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.parentless.foo, 80); } diff --git a/spec/rust/tests/test_nav_parent_override.rs b/spec/rust/tests/test_nav_parent_override.rs index 2ebc78835..759cd2450 100644 --- a/spec/rust/tests/test_nav_parent_override.rs +++ b/spec/rust/tests/test_nav_parent_override.rs @@ -1,16 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParentOverride; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nav_parent_override::NavParentOverride; +use std::fs; #[test] fn test_nav_parent_override() { - if let Ok(r) = NavParentOverride::from_file("src/nav_parent_codes.bin") { - assert_eq!(r.child_size, 3); - assert_eq!(r.child_1.data, vec!([0x49, 0x31, 0x32])); - assert_eq!(r.mediator_2.child_2.data, vec!([0x33, 0x42, 0x62])); - } + let data = fs::read("src/nav_parent_codes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NavParentOverride::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.child_size, 3); + // assert_eq!(r.child_1.data, vec!([0x49, 0x31, 0x32])); + // assert_eq!(r.mediator_2.child_2.data, vec!([0x33, 0x42, 0x62])); } diff --git a/spec/rust/tests/test_nav_parent_switch.rs b/spec/rust/tests/test_nav_parent_switch.rs index b2373ef91..baeea14b3 100644 --- a/spec/rust/tests/test_nav_parent_switch.rs +++ b/spec/rust/tests/test_nav_parent_switch.rs @@ -1,16 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParentSwitch; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nav_parent_switch::NavParentSwitch; +use std::fs; #[test] fn test_nav_parent_switch() { - if let Ok(r) = NavParentSwitch::from_file("src/nav_parent_switch.bin") { - assert_eq!(r.category, 1); - assert_eq!(r.content.foo, 66); - assert_eq!(r.content.subelement.bar, 255); - } + let data = fs::read("src/nav_parent_switch.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NavParentSwitch::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.category, 1); + // assert_eq!(r.content.foo, 66); + // assert_eq!(r.content.subelement.bar, 255); } diff --git a/spec/rust/tests/test_nav_parent_vs_value_inst.rs b/spec/rust/tests/test_nav_parent_vs_value_inst.rs index 944464338..428b6a098 100644 --- a/spec/rust/tests/test_nav_parent_vs_value_inst.rs +++ b/spec/rust/tests/test_nav_parent_vs_value_inst.rs @@ -1,14 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParentVsValueInst; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nav_parent_vs_value_inst::NavParentVsValueInst; +use std::fs; #[test] fn test_nav_parent_vs_value_inst() { - if let Ok(r) = NavParentVsValueInst::from_file("src/term_strz.bin") { - assert_eq!(r.s1, "foo"); - } + let data = fs::read("src/term_strz.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NavParentVsValueInst::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.s1, "foo"); } diff --git a/spec/rust/tests/test_nav_root.rs b/spec/rust/tests/test_nav_root.rs index 1bf59f436..891957386 100644 --- a/spec/rust/tests/test_nav_root.rs +++ b/spec/rust/tests/test_nav_root.rs @@ -1,18 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavRoot; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nav_root::NavRoot; +use std::fs; #[test] fn test_nav_root() { - if let Ok(r) = NavRoot::from_file("src/nav.bin") { - assert_eq!(r.header.qty_entries, 2); - assert_eq!(r.header.filename_len, 8); - assert_eq!(r.index.entries.len(), 2); - assert_eq!(r.index.entries[0].filename, "FIRST___"); - assert_eq!(r.index.entries[1].filename, "SECOND__"); - } + let data = fs::read("src/nav.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NavRoot::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.header.qty_entries, 2); + // assert_eq!(r.header.filename_len, 8); + // assert_eq!(r.index.entries.len(), 2); + // assert_eq!(r.index.entries[0].filename, "FIRST___"); + // assert_eq!(r.index.entries[1].filename, "SECOND__"); } diff --git a/spec/rust/tests/test_nested_same_name.rs b/spec/rust/tests/test_nested_same_name.rs index ca73804cf..36e242b25 100644 --- a/spec/rust/tests/test_nested_same_name.rs +++ b/spec/rust/tests/test_nested_same_name.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NestedSameName; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nested_same_name::NestedSameName; +use std::fs; #[test] fn test_nested_same_name() { - if let Ok(r) = NestedSameName::from_file("src/repeat_n_struct.bin") { - assert_eq!(r.main_data.main_size, 2); - assert_eq!(r.main_data.foo.data, vec!([0x10, 0x0, 0x0, 0x0])); - } + let data = fs::read("src/repeat_n_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NestedSameName::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.main_data.main_size, 2); + // assert_eq!(r.main_data.foo.data, vec!([0x10, 0x0, 0x0, 0x0])); } diff --git a/spec/rust/tests/test_nested_same_name2.rs b/spec/rust/tests/test_nested_same_name2.rs deleted file mode 100644 index 1087cb851..000000000 --- a/spec/rust/tests/test_nested_same_name2.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NestedSameName2; - -#[test] -fn test_nested_same_name2() { - if let Ok(r) = NestedSameName2::from_file("src/nested_same_name2.bin") { - assert_eq!(r.version, 66); - assert_eq!(r.main_data.main_size, 2); - assert_eq!(r.main_data.foo.data1, vec!([0x11, 0x11, 0x11, 0x11])); - assert_eq!(r.dummy.dummy_size, 3); - assert_eq!(r.dummy.foo.data2, vec!([0x22, 0x22, 0x22, 0x22, 0x22, 0x22])); - } -} diff --git a/spec/rust/tests/test_nested_types.rs b/spec/rust/tests/test_nested_types.rs index 796b4dda8..0c077d7c4 100644 --- a/spec/rust/tests/test_nested_types.rs +++ b/spec/rust/tests/test_nested_types.rs @@ -1,16 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NestedTypes; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nested_types::NestedTypes; +use std::fs; #[test] fn test_nested_types() { - if let Ok(r) = NestedTypes::from_file("src/fixed_struct.bin") { - assert_eq!(r.one.typed_at_root.value_b, 80); - assert_eq!(r.one.typed_here.value_c, 65); - assert_eq!(r.two.value_b, 67); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NestedTypes::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.one.typed_at_root.value_b, 80); + // assert_eq!(r.one.typed_here.value_c, 65); + // assert_eq!(r.two.value_b, 67); } diff --git a/spec/rust/tests/test_nested_types2.rs b/spec/rust/tests/test_nested_types2.rs index ed295df76..3c1396779 100644 --- a/spec/rust/tests/test_nested_types2.rs +++ b/spec/rust/tests/test_nested_types2.rs @@ -1,20 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NestedTypes2; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nested_types2::NestedTypes2; +use std::fs; #[test] fn test_nested_types2() { - if let Ok(r) = NestedTypes2::from_file("src/fixed_struct.bin") { - assert_eq!(r.one.typed_at_root.value_b, 80); - assert_eq!(r.one.typed_here1.value_c, 65); - assert_eq!(r.one.typed_here1.typed_here.value_d, 67); - assert_eq!(r.one.typed_here1.typed_parent.value_cc, 75); - assert_eq!(r.one.typed_here1.typed_root.value_b, 45); - assert_eq!(r.one.typed_here2.value_cc, 49); - assert_eq!(r.two.value_b, -1); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NestedTypes2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.one.typed_at_root.value_b, 80); + // assert_eq!(r.one.typed_here1.value_c, 65); + // assert_eq!(r.one.typed_here1.typed_here.value_d, 67); + // assert_eq!(r.one.typed_here1.typed_parent.value_cc, 75); + // assert_eq!(r.one.typed_here1.typed_root.value_b, 45); + // assert_eq!(r.one.typed_here2.value_cc, 49); + // assert_eq!(r.two.value_b, -1); } diff --git a/spec/rust/tests/test_nested_types3.rs b/spec/rust/tests/test_nested_types3.rs index ee2fd8f97..1135c002a 100644 --- a/spec/rust/tests/test_nested_types3.rs +++ b/spec/rust/tests/test_nested_types3.rs @@ -1,18 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NestedTypes3; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nested_types3::NestedTypes3; +use std::fs; #[test] fn test_nested_types3() { - if let Ok(r) = NestedTypes3::from_file("src/fixed_struct.bin") { - assert_eq!(r.a_cc.value_cc, 80); - assert_eq!(r.a_c_d.value_d, 65); - assert_eq!(r.b.value_b, 67); - assert_eq!(r.b.a_cc.value_cc, 75); - assert_eq!(r.b.a_c_d.value_d, 45); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NestedTypes3::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.a_cc.value_cc, 80); + // assert_eq!(r.a_c_d.value_d, 65); + // assert_eq!(r.b.value_b, 67); + // assert_eq!(r.b.a_cc.value_cc, 75); + // assert_eq!(r.b.a_c_d.value_d, 45); } diff --git a/spec/rust/tests/test_non_standard.rs b/spec/rust/tests/test_non_standard.rs index c649b8283..781e053e1 100644 --- a/spec/rust/tests/test_non_standard.rs +++ b/spec/rust/tests/test_non_standard.rs @@ -1,14 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NonStandard; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::non_standard::NonStandard; +use std::fs; #[test] fn test_non_standard() { - if let Ok(r) = NonStandard::from_file("src/fixed_struct.bin") { - assert_eq!(r.foo, 80); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NonStandard::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.foo, 80); } diff --git a/spec/rust/tests/test_params_call_short.rs b/spec/rust/tests/test_params_call_short.rs index e979f2124..ab7664626 100644 --- a/spec/rust/tests/test_params_call_short.rs +++ b/spec/rust/tests/test_params_call_short.rs @@ -1,16 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ParamsCallShort; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::params_call_short::ParamsCallShort; +use std::fs; #[test] fn test_params_call_short() { - if let Ok(r) = ParamsCallShort::from_file("src/term_strz.bin") { - assert_eq!(r.buf1.body, "foo|b"); - assert_eq!(r.buf2.body, "ar|ba"); - assert_eq!(r.buf2.trailer, 122); - } + let data = fs::read("src/term_strz.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ParamsCallShort::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.buf1.body, "foo|b"); + // assert_eq!(r.buf2.body, "ar|ba"); + // assert_eq!(r.buf2.trailer, 122); } diff --git a/spec/rust/tests/test_params_enum.rs b/spec/rust/tests/test_params_enum.rs new file mode 100644 index 000000000..1b4a8c32e --- /dev/null +++ b/spec/rust/tests/test_params_enum.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::params_enum::ParamsEnum; +use std::fs; + +#[test] +fn test_params_enum() { + let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ParamsEnum::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.one, animal::CAT); + // assert_eq!(r.invoke_with_param.is_cat, true); +} diff --git a/spec/rust/tests/test_params_pass_usertype.rs b/spec/rust/tests/test_params_pass_usertype.rs index 619950a9f..89c019855 100644 --- a/spec/rust/tests/test_params_pass_usertype.rs +++ b/spec/rust/tests/test_params_pass_usertype.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ParamsPassUsertype; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::params_pass_usertype::ParamsPassUsertype; +use std::fs; #[test] fn test_params_pass_usertype() { - if let Ok(r) = ParamsPassUsertype::from_file("src/position_in_seq.bin") { - assert_eq!(r.first.foo, 1); - assert_eq!(r.one.buf, vec!([0x2])); - } + let data = fs::read("src/position_in_seq.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ParamsPassUsertype::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.first.foo, 1); + // assert_eq!(r.one.buf, vec!([0x2])); } diff --git a/spec/rust/tests/test_position_abs.rs b/spec/rust/tests/test_position_abs.rs index 27c477617..a9d5700ff 100644 --- a/spec/rust/tests/test_position_abs.rs +++ b/spec/rust/tests/test_position_abs.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::PositionAbs; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::position_abs::PositionAbs; +use std::fs; #[test] fn test_position_abs() { - if let Ok(r) = PositionAbs::from_file("src/position_abs.bin") { - assert_eq!(r.index_offset, 32); - assert_eq!(r.index.entry, "foo"); - } + let data = fs::read("src/position_abs.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = PositionAbs::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.index_offset, 32); + // assert_eq!(r.index.entry, "foo"); } diff --git a/spec/rust/tests/test_position_in_seq.rs b/spec/rust/tests/test_position_in_seq.rs index 31a69b08e..f11adbce7 100644 --- a/spec/rust/tests/test_position_in_seq.rs +++ b/spec/rust/tests/test_position_in_seq.rs @@ -1,14 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::PositionInSeq; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::position_in_seq::PositionInSeq; +use std::fs; #[test] fn test_position_in_seq() { - if let Ok(r) = PositionInSeq::from_file("src/position_in_seq.bin") { - assert_eq!(r.numbers, [(0 + 1), 2, 3]); - } + let data = fs::read("src/position_in_seq.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = PositionInSeq::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.numbers, [(0 + 1), 2, 3]); } diff --git a/spec/rust/tests/test_position_to_end.rs b/spec/rust/tests/test_position_to_end.rs deleted file mode 100644 index 97f5ddd06..000000000 --- a/spec/rust/tests/test_position_to_end.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::PositionToEnd; - -#[test] -fn test_position_to_end() { - if let Ok(r) = PositionToEnd::from_file("src/position_to_end.bin") { - assert_eq!(r.index.foo, 66); - assert_eq!(r.index.bar, 4660); - } -} diff --git a/spec/rust/tests/test_process_coerce_bytes.rs b/spec/rust/tests/test_process_coerce_bytes.rs index 3cc865f9f..3b7c551a5 100644 --- a/spec/rust/tests/test_process_coerce_bytes.rs +++ b/spec/rust/tests/test_process_coerce_bytes.rs @@ -1,17 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessCoerceBytes; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::process_coerce_bytes::ProcessCoerceBytes; +use std::fs; #[test] fn test_process_coerce_bytes() { - if let Ok(r) = ProcessCoerceBytes::from_file("src/process_coerce_bytes.bin") { - assert_eq!(r.records[0].flag, 0); - assert_eq!(r.records[0].buf, vec!([0x41, 0x41, 0x41, 0x41])); - assert_eq!(r.records[1].flag, 1); - assert_eq!(r.records[1].buf, vec!([0x42, 0x42, 0x42, 0x42])); - } + let data = fs::read("src/process_coerce_bytes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ProcessCoerceBytes::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.records[0].flag, 0); + // assert_eq!(r.records[0].buf, vec!([0x41, 0x41, 0x41, 0x41])); + // assert_eq!(r.records[1].flag, 1); + // assert_eq!(r.records[1].buf, vec!([0x42, 0x42, 0x42, 0x42])); } diff --git a/spec/rust/tests/test_process_coerce_switch.rs b/spec/rust/tests/test_process_coerce_switch.rs deleted file mode 100644 index 5373c7ad7..000000000 --- a/spec/rust/tests/test_process_coerce_switch.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessCoerceSwitch; - -#[test] -fn test_process_coerce_switch() { - if let Ok(r) = ProcessCoerceSwitch::from_file("src/process_coerce_switch.bin") { - assert_eq!(r.buf_type, 0); - assert_eq!(r.flag, 0); - assert_eq!(r.buf.bar, vec!([0x41, 0x41, 0x41, 0x41])); - } -} diff --git a/spec/rust/tests/test_process_coerce_usertype1.rs b/spec/rust/tests/test_process_coerce_usertype1.rs deleted file mode 100644 index e5b91114d..000000000 --- a/spec/rust/tests/test_process_coerce_usertype1.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessCoerceUsertype1; - -#[test] -fn test_process_coerce_usertype1() { - if let Ok(r) = ProcessCoerceUsertype1::from_file("src/process_coerce_bytes.bin") { - assert_eq!(r.records[0].flag, 0); - assert_eq!(r.records[0].buf.value, 1094795585); - assert_eq!(r.records[1].flag, 1); - assert_eq!(r.records[1].buf.value, 1111638594); - } -} diff --git a/spec/rust/tests/test_process_coerce_usertype2.rs b/spec/rust/tests/test_process_coerce_usertype2.rs deleted file mode 100644 index b0ecbd8cf..000000000 --- a/spec/rust/tests/test_process_coerce_usertype2.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessCoerceUsertype2; - -#[test] -fn test_process_coerce_usertype2() { - if let Ok(r) = ProcessCoerceUsertype2::from_file("src/process_coerce_bytes.bin") { - assert_eq!(r.records[0].flag, 0); - assert_eq!(r.records[0].buf.value, 1094795585); - assert_eq!(r.records[1].flag, 1); - assert_eq!(r.records[1].buf.value, 1111638594); - } -} diff --git a/spec/rust/tests/test_process_custom.rs b/spec/rust/tests/test_process_custom.rs index d07d106b2..7aefd0dec 100644 --- a/spec/rust/tests/test_process_custom.rs +++ b/spec/rust/tests/test_process_custom.rs @@ -1,16 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessCustom; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::process_custom::ProcessCustom; +use std::fs; #[test] fn test_process_custom() { - if let Ok(r) = ProcessCustom::from_file("src/process_rotate.bin") { - assert_eq!(r.buf1, vec!([0x10, 0xb3, 0x94, 0x94, 0xf4])); - assert_eq!(r.buf2, vec!([0x5f, 0xba, 0x7b, 0x93, 0x63, 0x23, 0x5f])); - assert_eq!(r.buf3, vec!([0x29, 0x33, 0xb1, 0x38, 0xb1])); - } + let data = fs::read("src/process_rotate.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ProcessCustom::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.buf1, vec!([0x10, 0xb3, 0x94, 0x94, 0xf4])); + // assert_eq!(r.buf2, vec!([0x5f, 0xba, 0x7b, 0x93, 0x63, 0x23, 0x5f])); + // assert_eq!(r.buf3, vec!([0x29, 0x33, 0xb1, 0x38, 0xb1])); } diff --git a/spec/rust/tests/test_process_rotate.rs b/spec/rust/tests/test_process_rotate.rs index 1ab694a8f..b2a974247 100644 --- a/spec/rust/tests/test_process_rotate.rs +++ b/spec/rust/tests/test_process_rotate.rs @@ -1,16 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessRotate; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::process_rotate::ProcessRotate; +use std::fs; #[test] fn test_process_rotate() { - if let Ok(r) = ProcessRotate::from_file("src/process_rotate.bin") { - assert_eq!(r.buf1, vec!([0x48, 0x65, 0x6c, 0x6c, 0x6f])); - assert_eq!(r.buf2, vec!([0x57, 0x6f, 0x72, 0x6c, 0x64])); - assert_eq!(r.buf3, vec!([0x54, 0x68, 0x65, 0x72, 0x65])); - } + let data = fs::read("src/process_rotate.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ProcessRotate::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.buf1, vec!([0x48, 0x65, 0x6c, 0x6c, 0x6f])); + // assert_eq!(r.buf2, vec!([0x57, 0x6f, 0x72, 0x6c, 0x64])); + // assert_eq!(r.buf3, vec!([0x54, 0x68, 0x65, 0x72, 0x65])); } diff --git a/spec/rust/tests/test_process_to_user.rs b/spec/rust/tests/test_process_to_user.rs deleted file mode 100644 index 35fe9f85c..000000000 --- a/spec/rust/tests/test_process_to_user.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessToUser; - -#[test] -fn test_process_to_user() { - if let Ok(r) = ProcessToUser::from_file("src/process_rotate.bin") { - assert_eq!(r.buf1.str, "Hello"); - } -} diff --git a/spec/rust/tests/test_process_xor4_const.rs b/spec/rust/tests/test_process_xor4_const.rs index cb41dcc7f..dcf3fc299 100644 --- a/spec/rust/tests/test_process_xor4_const.rs +++ b/spec/rust/tests/test_process_xor4_const.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessXor4Const; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::process_xor4_const::ProcessXor4Const; +use std::fs; #[test] fn test_process_xor4_const() { - if let Ok(r) = ProcessXor4Const::from_file("src/process_xor_4.bin") { - assert_eq!(r.key, vec!([0xec, 0xbb, 0xa3, 0x14])); - assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); - } + let data = fs::read("src/process_xor_4.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ProcessXor4Const::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.key, vec!([0xec, 0xbb, 0xa3, 0x14])); + // assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); } diff --git a/spec/rust/tests/test_process_xor4_value.rs b/spec/rust/tests/test_process_xor4_value.rs index deff2c110..14f9a78e9 100644 --- a/spec/rust/tests/test_process_xor4_value.rs +++ b/spec/rust/tests/test_process_xor4_value.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessXor4Value; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::process_xor4_value::ProcessXor4Value; +use std::fs; #[test] fn test_process_xor4_value() { - if let Ok(r) = ProcessXor4Value::from_file("src/process_xor_4.bin") { - assert_eq!(r.key, vec!([0xec, 0xbb, 0xa3, 0x14])); - assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); - } + let data = fs::read("src/process_xor_4.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ProcessXor4Value::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.key, vec!([0xec, 0xbb, 0xa3, 0x14])); + // assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); } diff --git a/spec/rust/tests/test_process_xor_const.rs b/spec/rust/tests/test_process_xor_const.rs index 268c1e802..9b9bc5b65 100644 --- a/spec/rust/tests/test_process_xor_const.rs +++ b/spec/rust/tests/test_process_xor_const.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessXorConst; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::process_xor_const::ProcessXorConst; +use std::fs; #[test] fn test_process_xor_const() { - if let Ok(r) = ProcessXorConst::from_file("src/process_xor_1.bin") { - assert_eq!(r.key, 255); - assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); - } + let data = fs::read("src/process_xor_1.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ProcessXorConst::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.key, 255); + // assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); } diff --git a/spec/rust/tests/test_process_xor_value.rs b/spec/rust/tests/test_process_xor_value.rs index e0a266145..961a21503 100644 --- a/spec/rust/tests/test_process_xor_value.rs +++ b/spec/rust/tests/test_process_xor_value.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessXorValue; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::process_xor_value::ProcessXorValue; +use std::fs; #[test] fn test_process_xor_value() { - if let Ok(r) = ProcessXorValue::from_file("src/process_xor_1.bin") { - assert_eq!(r.key, 255); - assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); - } + let data = fs::read("src/process_xor_1.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ProcessXorValue::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.key, 255); + // assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); } diff --git a/spec/rust/tests/test_repeat_eos_bit.rs b/spec/rust/tests/test_repeat_eos_bit.rs new file mode 100644 index 000000000..4c70df2d9 --- /dev/null +++ b/spec/rust/tests/test_repeat_eos_bit.rs @@ -0,0 +1,13 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::repeat_eos_bit::RepeatEosBit; +use std::fs; + +#[test] +fn test_repeat_eos_bit() { + let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = RepeatEosBit::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.nibbles.len(), 16); +} diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs index 2eca3a73c..566c6a2d9 100644 --- a/spec/rust/tests/test_repeat_eos_struct.rs +++ b/spec/rust/tests/test_repeat_eos_struct.rs @@ -1,18 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatEosStruct; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::repeat_eos_struct::RepeatEosStruct; +use std::fs; #[test] fn test_repeat_eos_struct() { - if let Ok(r) = RepeatEosStruct::from_file("src/repeat_eos_struct.bin") { - assert_eq!(r.chunks.len(), 2); - assert_eq!(r.chunks[0].offset, 0); - assert_eq!(r.chunks[0].len, 66); - assert_eq!(r.chunks[1].offset, 66); - assert_eq!(r.chunks[1].len, 2069); - } + let data = fs::read("src/repeat_eos_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = RepeatEosStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.chunks.len(), 2); + // assert_eq!(r.chunks[0].offset, 0); + // assert_eq!(r.chunks[0].len, 66); + // assert_eq!(r.chunks[1].offset, 66); + // assert_eq!(r.chunks[1].len, 2069); } diff --git a/spec/rust/tests/test_repeat_eos_u4.rs b/spec/rust/tests/test_repeat_eos_u4.rs index 74f5d24cf..a0892f066 100644 --- a/spec/rust/tests/test_repeat_eos_u4.rs +++ b/spec/rust/tests/test_repeat_eos_u4.rs @@ -1,14 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatEosU4; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::repeat_eos_u4::RepeatEosU4; +use std::fs; #[test] fn test_repeat_eos_u4() { - if let Ok(r) = RepeatEosU4::from_file("src/repeat_eos_struct.bin") { - assert_eq!(r.numbers, [0, 66, 66, 2069]); - } + let data = fs::read("src/repeat_eos_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = RepeatEosU4::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.numbers, [0, 66, 66, 2069]); } diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs index 802fb7497..624725d15 100644 --- a/spec/rust/tests/test_repeat_n_struct.rs +++ b/spec/rust/tests/test_repeat_n_struct.rs @@ -1,18 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatNStruct; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::repeat_n_struct::RepeatNStruct; +use std::fs; #[test] fn test_repeat_n_struct() { - if let Ok(r) = RepeatNStruct::from_file("src/repeat_n_struct.bin") { - assert_eq!(r.chunks.len(), 2); - assert_eq!(r.chunks[0].offset, 16); - assert_eq!(r.chunks[0].len, 8312); - assert_eq!(r.chunks[1].offset, 8328); - assert_eq!(r.chunks[1].len, 15); - } + let data = fs::read("src/repeat_n_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = RepeatNStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.chunks.len(), 2); + // assert_eq!(r.chunks[0].offset, 16); + // assert_eq!(r.chunks[0].len, 8312); + // assert_eq!(r.chunks[1].offset, 8328); + // assert_eq!(r.chunks[1].len, 15); } diff --git a/spec/rust/tests/test_repeat_n_strz.rs b/spec/rust/tests/test_repeat_n_strz.rs index 87c87b8d4..073fdcda7 100644 --- a/spec/rust/tests/test_repeat_n_strz.rs +++ b/spec/rust/tests/test_repeat_n_strz.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatNStrz; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::repeat_n_strz::RepeatNStrz; +use std::fs; #[test] fn test_repeat_n_strz() { - if let Ok(r) = RepeatNStrz::from_file("src/repeat_n_strz.bin") { - assert_eq!(r.qty, 2); - assert_eq!(r.lines, ["foo", "bar"]); - } + let data = fs::read("src/repeat_n_strz.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = RepeatNStrz::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.qty, 2); + // assert_eq!(r.lines, ["foo", "bar"]); } diff --git a/spec/rust/tests/test_repeat_n_strz_double.rs b/spec/rust/tests/test_repeat_n_strz_double.rs index 0286318ab..7b0b68c11 100644 --- a/spec/rust/tests/test_repeat_n_strz_double.rs +++ b/spec/rust/tests/test_repeat_n_strz_double.rs @@ -1,16 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatNStrzDouble; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::repeat_n_strz_double::RepeatNStrzDouble; +use std::fs; #[test] fn test_repeat_n_strz_double() { - if let Ok(r) = RepeatNStrzDouble::from_file("src/repeat_n_strz.bin") { - assert_eq!(r.qty, 2); - assert_eq!(r.lines1, ["foo"]); - assert_eq!(r.lines2, ["bar"]); - } + let data = fs::read("src/repeat_n_strz.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = RepeatNStrzDouble::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.qty, 2); + // assert_eq!(r.lines1, ["foo"]); + // assert_eq!(r.lines2, ["bar"]); } diff --git a/spec/rust/tests/test_repeat_until_complex.rs b/spec/rust/tests/test_repeat_until_complex.rs index 158fc16b9..cdaea6d1f 100644 --- a/spec/rust/tests/test_repeat_until_complex.rs +++ b/spec/rust/tests/test_repeat_until_complex.rs @@ -1,28 +1,27 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatUntilComplex; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::repeat_until_complex::RepeatUntilComplex; +use std::fs; #[test] fn test_repeat_until_complex() { - if let Ok(r) = RepeatUntilComplex::from_file("src/repeat_until_complex.bin") { - assert_eq!(r.first.len(), 3); - assert_eq!(r.first[0].count, 4); - assert_eq!(r.first[0].values, [(0 + 1), 2, 3, 4]); - assert_eq!(r.first[1].count, 2); - assert_eq!(r.first[1].values, [(0 + 1), 2]); - assert_eq!(r.first[2].count, 0); - assert_eq!(r.second.len(), 4); - assert_eq!(r.second[0].count, 6); - assert_eq!(r.second[0].values, [(0 + 1), 2, 3, 4, 5, 6]); - assert_eq!(r.second[1].count, 3); - assert_eq!(r.second[1].values, [(0 + 1), 2, 3]); - assert_eq!(r.second[2].count, 4); - assert_eq!(r.second[2].values, [(0 + 1), 2, 3, 4]); - assert_eq!(r.second[3].count, 0); - assert_eq!(r.third, [(0 + 102), 111, 111, 98, 97, 114, 0]); - } + let data = fs::read("src/repeat_until_complex.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = RepeatUntilComplex::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.first.len(), 3); + // assert_eq!(r.first[0].count, 4); + // assert_eq!(r.first[0].values, [(0 + 1), 2, 3, 4]); + // assert_eq!(r.first[1].count, 2); + // assert_eq!(r.first[1].values, [(0 + 1), 2]); + // assert_eq!(r.first[2].count, 0); + // assert_eq!(r.second.len(), 4); + // assert_eq!(r.second[0].count, 6); + // assert_eq!(r.second[0].values, [(0 + 1), 2, 3, 4, 5, 6]); + // assert_eq!(r.second[1].count, 3); + // assert_eq!(r.second[1].values, [(0 + 1), 2, 3]); + // assert_eq!(r.second[2].count, 4); + // assert_eq!(r.second[2].values, [(0 + 1), 2, 3, 4]); + // assert_eq!(r.second[3].count, 0); + // assert_eq!(r.third, [(0 + 102), 111, 111, 98, 97, 114, 0]); } diff --git a/spec/rust/tests/test_repeat_until_s4.rs b/spec/rust/tests/test_repeat_until_s4.rs index 2fe282b51..554a2f93b 100644 --- a/spec/rust/tests/test_repeat_until_s4.rs +++ b/spec/rust/tests/test_repeat_until_s4.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatUntilS4; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::repeat_until_s4::RepeatUntilS4; +use std::fs; #[test] fn test_repeat_until_s4() { - if let Ok(r) = RepeatUntilS4::from_file("src/repeat_until_s4.bin") { - assert_eq!(r.entries, [66, 4919, -251658241, -1]); - assert_eq!(r.afterall, "foobar"); - } + let data = fs::read("src/repeat_until_s4.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = RepeatUntilS4::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.entries, [66, 4919, -251658241, -1]); + // assert_eq!(r.afterall, "foobar"); } diff --git a/spec/rust/tests/test_repeat_until_sized.rs b/spec/rust/tests/test_repeat_until_sized.rs deleted file mode 100644 index 3d23c1efc..000000000 --- a/spec/rust/tests/test_repeat_until_sized.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatUntilSized; - -#[test] -fn test_repeat_until_sized() { - if let Ok(r) = RepeatUntilSized::from_file("src/repeat_until_process.bin") { - assert_eq!(r.records.len(), 3); - assert_eq!(r.records[0].marker, 232); - assert_eq!(r.records[0].body, 2863311546); - assert_eq!(r.records[1].marker, 250); - assert_eq!(r.records[1].body, 2863315102); - assert_eq!(r.records[2].marker, 170); - assert_eq!(r.records[2].body, 1431655765); - } -} diff --git a/spec/rust/tests/test_str_encodings.rs b/spec/rust/tests/test_str_encodings.rs index 7759fd83f..52908f856 100644 --- a/spec/rust/tests/test_str_encodings.rs +++ b/spec/rust/tests/test_str_encodings.rs @@ -1,17 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrEncodings; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::str_encodings::StrEncodings; +use std::fs; #[test] fn test_str_encodings() { - if let Ok(r) = StrEncodings::from_file("src/str_encodings.bin") { - assert_eq!(r.str1, "Some ASCII"); - assert_eq!(r.str2, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.str3, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.str4, "\u{2591}\u{2592}\u{2593}"); - } + let data = fs::read("src/str_encodings.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = StrEncodings::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.str1, "Some ASCII"); + // assert_eq!(r.str2, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + // assert_eq!(r.str3, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + // assert_eq!(r.str4, "\u{2591}\u{2592}\u{2593}"); } diff --git a/spec/rust/tests/test_str_encodings_default.rs b/spec/rust/tests/test_str_encodings_default.rs index e2cdd782a..c9e325fa8 100644 --- a/spec/rust/tests/test_str_encodings_default.rs +++ b/spec/rust/tests/test_str_encodings_default.rs @@ -1,17 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrEncodingsDefault; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::str_encodings_default::StrEncodingsDefault; +use std::fs; #[test] fn test_str_encodings_default() { - if let Ok(r) = StrEncodingsDefault::from_file("src/str_encodings.bin") { - assert_eq!(r.str1, "Some ASCII"); - assert_eq!(r.rest.str2, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.rest.str3, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.rest.str4, "\u{2591}\u{2592}\u{2593}"); - } + let data = fs::read("src/str_encodings.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = StrEncodingsDefault::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.str1, "Some ASCII"); + // assert_eq!(r.rest.str2, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + // assert_eq!(r.rest.str3, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + // assert_eq!(r.rest.str4, "\u{2591}\u{2592}\u{2593}"); } diff --git a/spec/rust/tests/test_str_eos.rs b/spec/rust/tests/test_str_eos.rs index dda25ba85..6be8c2f6e 100644 --- a/spec/rust/tests/test_str_eos.rs +++ b/spec/rust/tests/test_str_eos.rs @@ -1,14 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrEos; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::str_eos::StrEos; +use std::fs; #[test] fn test_str_eos() { - if let Ok(r) = StrEos::from_file("src/term_strz.bin") { - assert_eq!(r.str, "foo|bar|baz@"); - } + let data = fs::read("src/term_strz.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = StrEos::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.str, "foo|bar|baz@"); } diff --git a/spec/rust/tests/test_str_literals2.rs b/spec/rust/tests/test_str_literals2.rs index 95c5148a8..0a76cbd66 100644 --- a/spec/rust/tests/test_str_literals2.rs +++ b/spec/rust/tests/test_str_literals2.rs @@ -1,17 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrLiterals2; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::str_literals2::StrLiterals2; +use std::fs; #[test] fn test_str_literals2() { - if let Ok(r) = StrLiterals2::from_file("src/fixed_struct.bin") { - assert_eq!(r.dollar1, "$foo"); - assert_eq!(r.dollar2, "${foo}"); - assert_eq!(r.hash, "#{foo}"); - assert_eq!(r.at_sign, "@foo"); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = StrLiterals2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.dollar1, "$foo"); + // assert_eq!(r.dollar2, "${foo}"); + // assert_eq!(r.hash, "#{foo}"); + // assert_eq!(r.at_sign, "@foo"); } diff --git a/spec/rust/tests/test_str_pad_term.rs b/spec/rust/tests/test_str_pad_term.rs index 8b953fd98..86602dbe8 100644 --- a/spec/rust/tests/test_str_pad_term.rs +++ b/spec/rust/tests/test_str_pad_term.rs @@ -1,17 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrPadTerm; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::str_pad_term::StrPadTerm; +use std::fs; #[test] fn test_str_pad_term() { - if let Ok(r) = StrPadTerm::from_file("src/str_pad_term.bin") { - assert_eq!(r.str_pad, "str1"); - assert_eq!(r.str_term, "str2foo"); - assert_eq!(r.str_term_and_pad, "str+++3bar+++"); - assert_eq!(r.str_term_include, "str4baz@"); - } + let data = fs::read("src/str_pad_term.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = StrPadTerm::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.str_pad, "str1"); + // assert_eq!(r.str_term, "str2foo"); + // assert_eq!(r.str_term_and_pad, "str+++3bar+++"); + // assert_eq!(r.str_term_include, "str4baz@"); } diff --git a/spec/rust/tests/test_str_pad_term_empty.rs b/spec/rust/tests/test_str_pad_term_empty.rs index 72ef1bd5c..f27912c86 100644 --- a/spec/rust/tests/test_str_pad_term_empty.rs +++ b/spec/rust/tests/test_str_pad_term_empty.rs @@ -1,17 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrPadTermEmpty; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::str_pad_term_empty::StrPadTermEmpty; +use std::fs; #[test] fn test_str_pad_term_empty() { - if let Ok(r) = StrPadTermEmpty::from_file("src/str_pad_term_empty.bin") { - assert_eq!(r.str_pad, ""); - assert_eq!(r.str_term, ""); - assert_eq!(r.str_term_and_pad, ""); - assert_eq!(r.str_term_include, "@"); - } + let data = fs::read("src/str_pad_term_empty.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = StrPadTermEmpty::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.str_pad, ""); + // assert_eq!(r.str_term, ""); + // assert_eq!(r.str_term_and_pad, ""); + // assert_eq!(r.str_term_include, "@"); } diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs index 427692a69..cb1c17f17 100644 --- a/spec/rust/tests/test_switch_bytearray.rs +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -1,22 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchBytearray; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::switch_bytearray::SwitchBytearray; +use std::fs; #[test] fn test_switch_bytearray() { - if let Ok(r) = SwitchBytearray::from_file("src/switch_opcodes.bin") { - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, vec!([0x53])); - assert_eq!(r.opcodes[0].body.value, "foobar"); - assert_eq!(r.opcodes[1].code, vec!([0x49])); - assert_eq!(r.opcodes[1].body.value, 66); - assert_eq!(r.opcodes[2].code, vec!([0x49])); - assert_eq!(r.opcodes[2].body.value, 55); - assert_eq!(r.opcodes[3].code, vec!([0x53])); - assert_eq!(r.opcodes[3].body.value, ""); - } + let data = fs::read("src/switch_opcodes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = SwitchBytearray::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.opcodes.len(), 4); + // assert_eq!(r.opcodes[0].code, vec!([0x53])); + // assert_eq!(r.opcodes[0].body.value, "foobar"); + // assert_eq!(r.opcodes[1].code, vec!([0x49])); + // assert_eq!(r.opcodes[1].body.value, 66); + // assert_eq!(r.opcodes[2].code, vec!([0x49])); + // assert_eq!(r.opcodes[2].body.value, 55); + // assert_eq!(r.opcodes[3].code, vec!([0x53])); + // assert_eq!(r.opcodes[3].body.value, ""); } diff --git a/spec/rust/tests/test_switch_integers.rs b/spec/rust/tests/test_switch_integers.rs index f873b3bda..c3c1b26a6 100644 --- a/spec/rust/tests/test_switch_integers.rs +++ b/spec/rust/tests/test_switch_integers.rs @@ -1,22 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchIntegers; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::switch_integers::SwitchIntegers; +use std::fs; #[test] fn test_switch_integers() { - if let Ok(r) = SwitchIntegers::from_file("src/switch_integers.bin") { - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, 1); - assert_eq!(r.opcodes[0].body, 7); - assert_eq!(r.opcodes[1].code, 2); - assert_eq!(r.opcodes[1].body, 16448); - assert_eq!(r.opcodes[2].code, 4); - assert_eq!(r.opcodes[2].body, 4919); - assert_eq!(r.opcodes[3].code, 8); - assert_eq!(r.opcodes[3].body, 4919); - } + let data = fs::read("src/switch_integers.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = SwitchIntegers::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.opcodes.len(), 4); + // assert_eq!(r.opcodes[0].code, 1); + // assert_eq!(r.opcodes[0].body, 7); + // assert_eq!(r.opcodes[1].code, 2); + // assert_eq!(r.opcodes[1].body, 16448); + // assert_eq!(r.opcodes[2].code, 4); + // assert_eq!(r.opcodes[2].body, 4919); + // assert_eq!(r.opcodes[3].code, 8); + // assert_eq!(r.opcodes[3].body, 4919); } diff --git a/spec/rust/tests/test_switch_integers2.rs b/spec/rust/tests/test_switch_integers2.rs index 6e7872a2f..74e1a20a8 100644 --- a/spec/rust/tests/test_switch_integers2.rs +++ b/spec/rust/tests/test_switch_integers2.rs @@ -1,18 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchIntegers2; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::switch_integers2::SwitchIntegers2; +use std::fs; #[test] fn test_switch_integers2() { - if let Ok(r) = SwitchIntegers2::from_file("src/switch_integers.bin") { - assert_eq!(r.code, 1); - assert_eq!(r.len, 7); - assert_eq!(r.ham, vec!([0x2, 0x40, 0x40, 0x4, 0x37, 0x13, 0x0])); - assert_eq!(r.padding, 0); - assert_eq!(r.len_mod_str, "13"); - } + let data = fs::read("src/switch_integers.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = SwitchIntegers2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.code, 1); + // assert_eq!(r.len, 7); + // assert_eq!(r.ham, vec!([0x2, 0x40, 0x40, 0x4, 0x37, 0x13, 0x0])); + // assert_eq!(r.padding, 0); + // assert_eq!(r.len_mod_str, "13"); } diff --git a/spec/rust/tests/test_switch_manual_enum.rs b/spec/rust/tests/test_switch_manual_enum.rs new file mode 100644 index 000000000..a11f22c32 --- /dev/null +++ b/spec/rust/tests/test_switch_manual_enum.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::switch_manual_enum::SwitchManualEnum; +use std::fs; + +#[test] +fn test_switch_manual_enum() { + let data = fs::read("src/switch_opcodes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = SwitchManualEnum::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.opcodes.len(), 4); + // assert_eq!(r.opcodes[0].code, code_enum::STRVAL); + // assert_eq!(r.opcodes[0].body.value, "foobar"); + // assert_eq!(r.opcodes[1].code, code_enum::INTVAL); + // assert_eq!(r.opcodes[1].body.value, 66); + // assert_eq!(r.opcodes[2].code, code_enum::INTVAL); + // assert_eq!(r.opcodes[2].body.value, 55); + // assert_eq!(r.opcodes[3].code, code_enum::STRVAL); + // assert_eq!(r.opcodes[3].body.value, ""); +} diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs index 776a6b1b2..6bd855715 100644 --- a/spec/rust/tests/test_switch_manual_int.rs +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -1,22 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualInt; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::switch_manual_int::SwitchManualInt; +use std::fs; #[test] fn test_switch_manual_int() { - if let Ok(r) = SwitchManualInt::from_file("src/switch_opcodes.bin") { - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, 83); - assert_eq!(r.opcodes[0].body.value, "foobar"); - assert_eq!(r.opcodes[1].code, 73); - assert_eq!(r.opcodes[1].body.value, 66); - assert_eq!(r.opcodes[2].code, 73); - assert_eq!(r.opcodes[2].body.value, 55); - assert_eq!(r.opcodes[3].code, 83); - assert_eq!(r.opcodes[3].body.value, ""); - } + let data = fs::read("src/switch_opcodes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = SwitchManualInt::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.opcodes.len(), 4); + // assert_eq!(r.opcodes[0].code, 83); + // assert_eq!(r.opcodes[0].body.value, "foobar"); + // assert_eq!(r.opcodes[1].code, 73); + // assert_eq!(r.opcodes[1].body.value, 66); + // assert_eq!(r.opcodes[2].code, 73); + // assert_eq!(r.opcodes[2].body.value, 55); + // assert_eq!(r.opcodes[3].code, 83); + // assert_eq!(r.opcodes[3].body.value, ""); } diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs index cae8cfba0..c0aaf60a3 100644 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -1,22 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualIntElse; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::switch_manual_int_else::SwitchManualIntElse; +use std::fs; #[test] fn test_switch_manual_int_else() { - if let Ok(r) = SwitchManualIntElse::from_file("src/switch_opcodes2.bin") { - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, 83); - assert_eq!(r.opcodes[0].body.value, "foo"); - assert_eq!(r.opcodes[1].code, 88); - assert_eq!(r.opcodes[1].body.filler, 66); - assert_eq!(r.opcodes[2].code, 89); - assert_eq!(r.opcodes[2].body.filler, 51966); - assert_eq!(r.opcodes[3].code, 73); - assert_eq!(r.opcodes[3].body.value, 7); - } + let data = fs::read("src/switch_opcodes2.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = SwitchManualIntElse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.opcodes.len(), 4); + // assert_eq!(r.opcodes[0].code, 83); + // assert_eq!(r.opcodes[0].body.value, "foo"); + // assert_eq!(r.opcodes[1].code, 88); + // assert_eq!(r.opcodes[1].body.filler, 66); + // assert_eq!(r.opcodes[2].code, 89); + // assert_eq!(r.opcodes[2].body.filler, 51966); + // assert_eq!(r.opcodes[3].code, 73); + // assert_eq!(r.opcodes[3].body.value, 7); } diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs deleted file mode 100644 index 91e53241c..000000000 --- a/spec/rust/tests/test_switch_manual_int_size_else.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualIntSizeElse; - -#[test] -fn test_switch_manual_int_size_else() { - if let Ok(r) = SwitchManualIntSizeElse::from_file("src/switch_tlv.bin") { - assert_eq!(r.chunks.len(), 4); - assert_eq!(r.chunks[0].code, 17); - assert_eq!(r.chunks[0].body.title, "Stuff"); - assert_eq!(r.chunks[0].body.author, "Me"); - assert_eq!(r.chunks[1].code, 34); - assert_eq!(r.chunks[1].body.entries, ["AAAA", "BBBB", "CCCC"]); - assert_eq!(r.chunks[2].code, 51); - assert_eq!(r.chunks[2].body.rest, vec!([0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80])); - assert_eq!(r.chunks[3].code, 255); - assert_eq!(r.chunks[3].body.rest, vec!([])); - } -} diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs index 16b2eb92e..4433bd50d 100644 --- a/spec/rust/tests/test_switch_manual_str.rs +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -1,22 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualStr; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::switch_manual_str::SwitchManualStr; +use std::fs; #[test] fn test_switch_manual_str() { - if let Ok(r) = SwitchManualStr::from_file("src/switch_opcodes.bin") { - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, "S"); - assert_eq!(r.opcodes[0].body.value, "foobar"); - assert_eq!(r.opcodes[1].code, "I"); - assert_eq!(r.opcodes[1].body.value, 66); - assert_eq!(r.opcodes[2].code, "I"); - assert_eq!(r.opcodes[2].body.value, 55); - assert_eq!(r.opcodes[3].code, "S"); - assert_eq!(r.opcodes[3].body.value, ""); - } + let data = fs::read("src/switch_opcodes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = SwitchManualStr::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.opcodes.len(), 4); + // assert_eq!(r.opcodes[0].code, "S"); + // assert_eq!(r.opcodes[0].body.value, "foobar"); + // assert_eq!(r.opcodes[1].code, "I"); + // assert_eq!(r.opcodes[1].body.value, 66); + // assert_eq!(r.opcodes[2].code, "I"); + // assert_eq!(r.opcodes[2].body.value, 55); + // assert_eq!(r.opcodes[3].code, "S"); + // assert_eq!(r.opcodes[3].body.value, ""); } diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs index c27d75a23..c476f1b7a 100644 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -1,22 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualStrElse; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::switch_manual_str_else::SwitchManualStrElse; +use std::fs; #[test] fn test_switch_manual_str_else() { - if let Ok(r) = SwitchManualStrElse::from_file("src/switch_opcodes2.bin") { - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, "S"); - assert_eq!(r.opcodes[0].body.value, "foo"); - assert_eq!(r.opcodes[1].code, "X"); - assert_eq!(r.opcodes[1].body.filler, 66); - assert_eq!(r.opcodes[2].code, "Y"); - assert_eq!(r.opcodes[2].body.filler, 51966); - assert_eq!(r.opcodes[3].code, "I"); - assert_eq!(r.opcodes[3].body.value, 7); - } + let data = fs::read("src/switch_opcodes2.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = SwitchManualStrElse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.opcodes.len(), 4); + // assert_eq!(r.opcodes[0].code, "S"); + // assert_eq!(r.opcodes[0].body.value, "foo"); + // assert_eq!(r.opcodes[1].code, "X"); + // assert_eq!(r.opcodes[1].body.filler, 66); + // assert_eq!(r.opcodes[2].code, "Y"); + // assert_eq!(r.opcodes[2].body.filler, 51966); + // assert_eq!(r.opcodes[3].code, "I"); + // assert_eq!(r.opcodes[3].body.value, 7); } diff --git a/spec/rust/tests/test_term_bytes.rs b/spec/rust/tests/test_term_bytes.rs index 23375a5fa..8b5ef76cc 100644 --- a/spec/rust/tests/test_term_bytes.rs +++ b/spec/rust/tests/test_term_bytes.rs @@ -1,16 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::TermBytes; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::term_bytes::TermBytes; +use std::fs; #[test] fn test_term_bytes() { - if let Ok(r) = TermBytes::from_file("src/term_strz.bin") { - assert_eq!(r.s1, vec!([0x66, 0x6f, 0x6f])); - assert_eq!(r.s2, vec!([0x62, 0x61, 0x72])); - assert_eq!(r.s3, vec!([0x7c, 0x62, 0x61, 0x7a, 0x40])); - } + let data = fs::read("src/term_strz.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = TermBytes::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.s1, vec!([0x66, 0x6f, 0x6f])); + // assert_eq!(r.s2, vec!([0x62, 0x61, 0x72])); + // assert_eq!(r.s3, vec!([0x7c, 0x62, 0x61, 0x7a, 0x40])); } diff --git a/spec/rust/tests/test_term_strz.rs b/spec/rust/tests/test_term_strz.rs index c40bce5cd..26155888e 100644 --- a/spec/rust/tests/test_term_strz.rs +++ b/spec/rust/tests/test_term_strz.rs @@ -1,16 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::TermStrz; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::term_strz::TermStrz; +use std::fs; #[test] fn test_term_strz() { - if let Ok(r) = TermStrz::from_file("src/term_strz.bin") { - assert_eq!(r.s1, "foo"); - assert_eq!(r.s2, "bar"); - assert_eq!(r.s3, "|baz@"); - } + let data = fs::read("src/term_strz.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = TermStrz::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.s1, "foo"); + // assert_eq!(r.s2, "bar"); + // assert_eq!(r.s3, "|baz@"); } diff --git a/spec/rust/tests/test_ts_packet_header.rs b/spec/rust/tests/test_ts_packet_header.rs new file mode 100644 index 000000000..c4ba0128f --- /dev/null +++ b/spec/rust/tests/test_ts_packet_header.rs @@ -0,0 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::ts_packet_header::TsPacketHeader; +use std::fs; + +#[test] +fn test_ts_packet_header() { + let data = fs::read("src/ts_packet.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = TsPacketHeader::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.sync_byte, 71); + // assert_eq!(r.transport_error_indicator, false); + // assert_eq!(r.payload_unit_start_indicator, false); + // assert_eq!(r.transport_priority, true); + // assert_eq!(r.pid, 33); + // assert_eq!(r.transport_scrambling_control, 0); + // assert_eq!(r.adaptation_field_control, adaptation_field_control_enum::PAYLOAD_ONLY); +} diff --git a/spec/rust/tests/test_type_int_unary_op.rs b/spec/rust/tests/test_type_int_unary_op.rs index cdc32dfe2..fcef4e400 100644 --- a/spec/rust/tests/test_type_int_unary_op.rs +++ b/spec/rust/tests/test_type_int_unary_op.rs @@ -1,17 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::TypeIntUnaryOp; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::type_int_unary_op::TypeIntUnaryOp; +use std::fs; #[test] fn test_type_int_unary_op() { - if let Ok(r) = TypeIntUnaryOp::from_file("src/fixed_struct.bin") { - assert_eq!(r.value_s2, 16720); - assert_eq!(r.value_s8, 4706543082108963651); - assert_eq!(r.unary_s2, -16720); - assert_eq!(r.unary_s8, -4706543082108963651); - } + let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = TypeIntUnaryOp::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.value_s2, 16720); + // assert_eq!(r.value_s8, 4706543082108963651); + // assert_eq!(r.unary_s2, -16720); + // assert_eq!(r.unary_s8, -4706543082108963651); } diff --git a/spec/rust/tests/test_type_ternary.rs b/spec/rust/tests/test_type_ternary.rs deleted file mode 100644 index 6e2412116..000000000 --- a/spec/rust/tests/test_type_ternary.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::TypeTernary; - -#[test] -fn test_type_ternary() { - if let Ok(r) = TypeTernary::from_file("src/term_strz.bin") { - assert_eq!(r.dif.value, 101); - } -} diff --git a/spec/rust/tests/test_user_type.rs b/spec/rust/tests/test_user_type.rs index 358ec2130..677be5e77 100644 --- a/spec/rust/tests/test_user_type.rs +++ b/spec/rust/tests/test_user_type.rs @@ -1,15 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::UserType; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::user_type::UserType; +use std::fs; #[test] fn test_user_type() { - if let Ok(r) = UserType::from_file("src/repeat_until_s4.bin") { - assert_eq!(r.one.width, 66); - assert_eq!(r.one.height, 4919); - } + let data = fs::read("src/repeat_until_s4.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = UserType::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.one.width, 66); + // assert_eq!(r.one.height, 4919); } diff --git a/spec/rust/tests/test_zlib_with_header_78.rs b/spec/rust/tests/test_zlib_with_header_78.rs index 8001b37bf..17556c384 100644 --- a/spec/rust/tests/test_zlib_with_header_78.rs +++ b/spec/rust/tests/test_zlib_with_header_78.rs @@ -1,14 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ZlibWithHeader78; +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::zlib_with_header_78::ZlibWithHeader78; +use std::fs; #[test] fn test_zlib_with_header_78() { - if let Ok(r) = ZlibWithHeader78::from_file("src/zlib_with_header_78.bin") { - assert_eq!(r.data, vec!([0x61, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72])); - } + let data = fs::read("src/zlib_with_header_78.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ZlibWithHeader78::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.data, vec!([0x61, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72])); } From 823c161da1dcff1cf998a5c930c43b27aed70d4b Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 13 May 2019 11:29:38 -0400 Subject: [PATCH 3/6] Get test infrastructure working All tests generate and pass, but aren't actually testing anything at the moment. --- ci-rust | 12 +++-- spec/rust/Cargo.toml | 1 - spec/rust/build.rs | 49 ------------------- spec/rust/tests/test_bcd_user_type_be.rs | 18 +++++++ spec/rust/tests/test_bcd_user_type_le.rs | 18 +++++++ spec/rust/tests/test_bits_byte_aligned.rs | 2 +- spec/rust/tests/test_bits_enum.rs | 2 +- spec/rust/tests/test_bits_simple.rs | 2 +- spec/rust/tests/test_buffered_struct.rs | 19 +++++++ spec/rust/tests/test_bytes_pad_term.rs | 2 +- spec/rust/tests/test_cast_nested.rs | 2 +- spec/rust/tests/test_cast_to_imported.rs | 2 +- spec/rust/tests/test_cast_to_top.rs | 15 ++++++ spec/rust/tests/test_default_big_endian.rs | 2 +- .../test_default_endian_expr_inherited.rs | 2 +- .../tests/test_default_endian_expr_is_be.rs | 2 +- .../tests/test_default_endian_expr_is_le.rs | 2 +- spec/rust/tests/test_default_endian_mod.rs | 2 +- spec/rust/tests/test_docstrings.rs | 2 +- spec/rust/tests/test_docstrings_docref.rs | 2 +- .../tests/test_docstrings_docref_multi.rs | 2 +- spec/rust/tests/test_enum_0.rs | 2 +- spec/rust/tests/test_enum_1.rs | 2 +- spec/rust/tests/test_enum_deep.rs | 2 +- spec/rust/tests/test_enum_deep_literals.rs | 2 +- spec/rust/tests/test_enum_fancy.rs | 2 +- spec/rust/tests/test_enum_if.rs | 2 +- spec/rust/tests/test_enum_negative.rs | 2 +- spec/rust/tests/test_enum_of_value_inst.rs | 2 +- spec/rust/tests/test_enum_to_i.rs | 2 +- spec/rust/tests/test_expr_0.rs | 2 +- spec/rust/tests/test_expr_1.rs | 2 +- spec/rust/tests/test_expr_2.rs | 29 +++++++++++ spec/rust/tests/test_expr_3.rs | 2 +- spec/rust/tests/test_expr_array.rs | 2 +- spec/rust/tests/test_expr_bytes_cmp.rs | 2 +- spec/rust/tests/test_expr_enum.rs | 2 +- spec/rust/tests/test_expr_io_pos.rs | 18 +++++++ spec/rust/tests/test_expr_mod.rs | 2 +- spec/rust/tests/test_expr_sizeof_type_0.rs | 2 +- spec/rust/tests/test_expr_sizeof_type_1.rs | 2 +- spec/rust/tests/test_expr_sizeof_value_0.rs | 2 +- .../tests/test_expr_sizeof_value_sized.rs | 17 +++++++ spec/rust/tests/test_fixed_contents.rs | 2 +- spec/rust/tests/test_fixed_struct.rs | 32 ++++++++++++ spec/rust/tests/test_float_to_i.rs | 2 +- spec/rust/tests/test_floating_points.rs | 2 +- spec/rust/tests/test_hello_world.rs | 2 +- spec/rust/tests/test_if_instances.rs | 13 +++++ spec/rust/tests/test_if_struct.rs | 2 +- spec/rust/tests/test_if_values.rs | 2 +- spec/rust/tests/test_imports0.rs | 2 +- spec/rust/tests/test_imports_abs.rs | 2 +- spec/rust/tests/test_index_sizes.rs | 2 +- spec/rust/tests/test_index_to_param_eos.rs | 2 +- spec/rust/tests/test_index_to_param_expr.rs | 2 +- spec/rust/tests/test_index_to_param_until.rs | 2 +- spec/rust/tests/test_instance_io_user.rs | 16 ++++++ spec/rust/tests/test_instance_std.rs | 13 +++++ spec/rust/tests/test_instance_std_array.rs | 2 +- spec/rust/tests/test_instance_user_array.rs | 22 +++++++++ spec/rust/tests/test_integers.rs | 2 +- spec/rust/tests/test_io_local_var.rs | 14 ++++++ spec/rust/tests/test_js_signed_right_shift.rs | 2 +- spec/rust/tests/test_meta_tags.rs | 2 +- spec/rust/tests/test_meta_xref.rs | 2 +- spec/rust/tests/test_multiple_use.rs | 14 ++++++ spec/rust/tests/test_nav_parent.rs | 2 +- spec/rust/tests/test_nav_parent2.rs | 2 +- spec/rust/tests/test_nav_parent3.rs | 2 +- spec/rust/tests/test_nav_parent_false.rs | 2 +- spec/rust/tests/test_nav_parent_false2.rs | 2 +- spec/rust/tests/test_nav_parent_override.rs | 2 +- spec/rust/tests/test_nav_parent_switch.rs | 2 +- .../tests/test_nav_parent_vs_value_inst.rs | 2 +- spec/rust/tests/test_nav_root.rs | 2 +- spec/rust/tests/test_nested_same_name.rs | 2 +- spec/rust/tests/test_nested_same_name2.rs | 17 +++++++ spec/rust/tests/test_nested_types.rs | 2 +- spec/rust/tests/test_nested_types2.rs | 2 +- spec/rust/tests/test_nested_types3.rs | 2 +- spec/rust/tests/test_non_standard.rs | 2 +- spec/rust/tests/test_params_call_short.rs | 2 +- spec/rust/tests/test_params_enum.rs | 2 +- spec/rust/tests/test_params_pass_usertype.rs | 2 +- spec/rust/tests/test_position_abs.rs | 2 +- spec/rust/tests/test_position_in_seq.rs | 2 +- spec/rust/tests/test_position_to_end.rs | 14 ++++++ spec/rust/tests/test_process_coerce_bytes.rs | 2 +- spec/rust/tests/test_process_coerce_switch.rs | 15 ++++++ .../tests/test_process_coerce_usertype1.rs | 16 ++++++ .../tests/test_process_coerce_usertype2.rs | 16 ++++++ spec/rust/tests/test_process_custom.rs | 2 +- spec/rust/tests/test_process_rotate.rs | 2 +- spec/rust/tests/test_process_to_user.rs | 13 +++++ spec/rust/tests/test_process_xor4_const.rs | 2 +- spec/rust/tests/test_process_xor4_value.rs | 2 +- spec/rust/tests/test_process_xor_const.rs | 2 +- spec/rust/tests/test_process_xor_value.rs | 2 +- spec/rust/tests/test_recursive_one.rs | 16 ++++++ spec/rust/tests/test_repeat_eos_bit.rs | 2 +- spec/rust/tests/test_repeat_eos_struct.rs | 2 +- spec/rust/tests/test_repeat_eos_u4.rs | 2 +- spec/rust/tests/test_repeat_n_struct.rs | 2 +- spec/rust/tests/test_repeat_n_strz.rs | 2 +- spec/rust/tests/test_repeat_n_strz_double.rs | 2 +- spec/rust/tests/test_repeat_until_complex.rs | 2 +- spec/rust/tests/test_repeat_until_s4.rs | 2 +- spec/rust/tests/test_repeat_until_sized.rs | 19 +++++++ spec/rust/tests/test_str_encodings.rs | 2 +- spec/rust/tests/test_str_encodings_default.rs | 2 +- spec/rust/tests/test_str_eos.rs | 2 +- spec/rust/tests/test_str_literals2.rs | 2 +- spec/rust/tests/test_str_pad_term.rs | 2 +- spec/rust/tests/test_str_pad_term_empty.rs | 2 +- spec/rust/tests/test_switch_bytearray.rs | 2 +- spec/rust/tests/test_switch_integers.rs | 2 +- spec/rust/tests/test_switch_integers2.rs | 2 +- spec/rust/tests/test_switch_manual_enum.rs | 2 +- spec/rust/tests/test_switch_manual_int.rs | 2 +- .../rust/tests/test_switch_manual_int_else.rs | 2 +- .../tests/test_switch_manual_int_size_else.rs | 22 +++++++++ spec/rust/tests/test_switch_manual_str.rs | 2 +- .../rust/tests/test_switch_manual_str_else.rs | 2 +- spec/rust/tests/test_term_bytes.rs | 2 +- spec/rust/tests/test_term_strz.rs | 2 +- spec/rust/tests/test_ts_packet_header.rs | 2 +- spec/rust/tests/test_type_int_unary_op.rs | 2 +- spec/rust/tests/test_type_ternary.rs | 13 +++++ spec/rust/tests/test_user_type.rs | 2 +- spec/rust/tests/test_zlib_with_header_78.rs | 2 +- 131 files changed, 531 insertions(+), 158 deletions(-) delete mode 100644 spec/rust/build.rs create mode 100644 spec/rust/tests/test_bcd_user_type_be.rs create mode 100644 spec/rust/tests/test_bcd_user_type_le.rs create mode 100644 spec/rust/tests/test_buffered_struct.rs create mode 100644 spec/rust/tests/test_cast_to_top.rs create mode 100644 spec/rust/tests/test_expr_2.rs create mode 100644 spec/rust/tests/test_expr_io_pos.rs create mode 100644 spec/rust/tests/test_expr_sizeof_value_sized.rs create mode 100644 spec/rust/tests/test_fixed_struct.rs create mode 100644 spec/rust/tests/test_if_instances.rs create mode 100644 spec/rust/tests/test_instance_io_user.rs create mode 100644 spec/rust/tests/test_instance_std.rs create mode 100644 spec/rust/tests/test_instance_user_array.rs create mode 100644 spec/rust/tests/test_io_local_var.rs create mode 100644 spec/rust/tests/test_multiple_use.rs create mode 100644 spec/rust/tests/test_nested_same_name2.rs create mode 100644 spec/rust/tests/test_position_to_end.rs create mode 100644 spec/rust/tests/test_process_coerce_switch.rs create mode 100644 spec/rust/tests/test_process_coerce_usertype1.rs create mode 100644 spec/rust/tests/test_process_coerce_usertype2.rs create mode 100644 spec/rust/tests/test_process_to_user.rs create mode 100644 spec/rust/tests/test_recursive_one.rs create mode 100644 spec/rust/tests/test_repeat_until_sized.rs create mode 100644 spec/rust/tests/test_switch_manual_int_size_else.rs create mode 100644 spec/rust/tests/test_type_ternary.rs diff --git a/ci-rust b/ci-rust index cfa873b4f..0bcb65c81 100755 --- a/ci-rust +++ b/ci-rust @@ -4,8 +4,12 @@ set -eu mkdir -p "$TEST_OUT_DIR/rust" -cd spec/rust -mkdir -p src -touch src/lib.rs -cargo build +rm -r "spec/rust/src" +mkdir -p "spec/rust/src/" +for rs in $(ls "$FORMATS_COMPILED_DIR/rust/"); do + cp "$FORMATS_COMPILED_DIR/rust/$rs" "spec/rust/src" + mod_name="$(echo "$rs" | cut -d'.' -f1)" + echo "pub mod $mod_name;" >> "spec/rust/src/lib.rs" +done + cargo junit --name "../../$TEST_OUT_DIR/rust/results.xml" diff --git a/spec/rust/Cargo.toml b/spec/rust/Cargo.toml index 5b6b6158e..c41a9f750 100644 --- a/spec/rust/Cargo.toml +++ b/spec/rust/Cargo.toml @@ -2,7 +2,6 @@ name = "kaitai_test" version = "0.1.0" authors = ["Connor Wood ", "Bradlee Speice"] -build = "build.rs" edition = "2018" [dependencies] diff --git a/spec/rust/build.rs b/spec/rust/build.rs deleted file mode 100644 index a8906b6ba..000000000 --- a/spec/rust/build.rs +++ /dev/null @@ -1,49 +0,0 @@ -use std::{ - io::{ - self, - prelude::* - }, - fs, - path::Path -}; - -fn main() { - let source_path = Path::new("../../compiled/rust"); - let destination_path = Path::new("./src"); - - remove_existing(destination_path).unwrap_or_else(|e| { - println!("Unable to remove existing files under test: {}", e.to_string()); - }); - - copy_new(source_path, destination_path).unwrap_or_else(|e| { - println!("Unable to copy new files under test: {}", e.to_string()); - }); -} - -fn remove_existing(destination_path: &Path) -> io::Result<()> { - for entry in fs::read_dir(destination_path)? { - let entry = entry?; - let path = entry.path(); - - fs::remove_file(path)?; - } - - Ok(()) -} - -fn copy_new(source_path: &Path, destination_path: &Path) -> io::Result<()> { - let mut librs = fs::File::create(source_path.join("lib.rs"))?; - - for entry in fs::read_dir(source_path)? { - let entry = entry?; - let path = entry.path(); - - if let Some(file_name) = path.file_name() { - fs::copy(path.clone(), destination_path.join(file_name))?; - write!(librs, "pub mod {};\n", - path.file_stem().unwrap().to_str().unwrap())?; - } - } - - Ok(()) -} diff --git a/spec/rust/tests/test_bcd_user_type_be.rs b/spec/rust/tests/test_bcd_user_type_be.rs new file mode 100644 index 000000000..6d85d58e8 --- /dev/null +++ b/spec/rust/tests/test_bcd_user_type_be.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::bcd_user_type_be::BcdUserTypeBe; +use std::fs; + +#[test] +fn test_bcd_user_type_be() { + let data = fs::read("../../src/bcd_user_type_be.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = BcdUserTypeBe::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.ltr.as_int, 12345678); + // assert_eq!(r.ltr.as_str, "12345678"); + // assert_eq!(r.rtl.as_int, 87654321); + // assert_eq!(r.rtl.as_str, "87654321"); + // assert_eq!(r.leading_zero_ltr.as_int, 123456); + // assert_eq!(r.leading_zero_ltr.as_str, "00123456"); +} diff --git a/spec/rust/tests/test_bcd_user_type_le.rs b/spec/rust/tests/test_bcd_user_type_le.rs new file mode 100644 index 000000000..cee6e1575 --- /dev/null +++ b/spec/rust/tests/test_bcd_user_type_le.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::bcd_user_type_le::BcdUserTypeLe; +use std::fs; + +#[test] +fn test_bcd_user_type_le() { + let data = fs::read("../../src/bcd_user_type_le.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = BcdUserTypeLe::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.ltr.as_int, 12345678); + // assert_eq!(r.ltr.as_str, "12345678"); + // assert_eq!(r.rtl.as_int, 87654321); + // assert_eq!(r.rtl.as_str, "87654321"); + // assert_eq!(r.leading_zero_ltr.as_int, 123456); + // assert_eq!(r.leading_zero_ltr.as_str, "00123456"); +} diff --git a/spec/rust/tests/test_bits_byte_aligned.rs b/spec/rust/tests/test_bits_byte_aligned.rs index 312fa2170..e13314821 100644 --- a/spec/rust/tests/test_bits_byte_aligned.rs +++ b/spec/rust/tests/test_bits_byte_aligned.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_bits_byte_aligned() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = BitsByteAligned::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.one, 20); diff --git a/spec/rust/tests/test_bits_enum.rs b/spec/rust/tests/test_bits_enum.rs index 5493f9d16..333f2d404 100644 --- a/spec/rust/tests/test_bits_enum.rs +++ b/spec/rust/tests/test_bits_enum.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_bits_enum() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = BitsEnum::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.one, animal::PLATYPUS); diff --git a/spec/rust/tests/test_bits_simple.rs b/spec/rust/tests/test_bits_simple.rs index 95227dac9..12bebc6b5 100644 --- a/spec/rust/tests/test_bits_simple.rs +++ b/spec/rust/tests/test_bits_simple.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_bits_simple() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = BitsSimple::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.byte_1, 80); diff --git a/spec/rust/tests/test_buffered_struct.rs b/spec/rust/tests/test_buffered_struct.rs new file mode 100644 index 000000000..bc224b560 --- /dev/null +++ b/spec/rust/tests/test_buffered_struct.rs @@ -0,0 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::buffered_struct::BufferedStruct; +use std::fs; + +#[test] +fn test_buffered_struct() { + let data = fs::read("../../src/buffered_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = BufferedStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.len1, 16); + // assert_eq!(r.block1.number1, 66); + // assert_eq!(r.block1.number2, 67); + // assert_eq!(r.len2, 8); + // assert_eq!(r.block2.number1, 68); + // assert_eq!(r.block2.number2, 69); + // assert_eq!(r.finisher, 238); +} diff --git a/spec/rust/tests/test_bytes_pad_term.rs b/spec/rust/tests/test_bytes_pad_term.rs index 44f433393..a45f0df92 100644 --- a/spec/rust/tests/test_bytes_pad_term.rs +++ b/spec/rust/tests/test_bytes_pad_term.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_bytes_pad_term() { - let data = fs::read("src/str_pad_term.bin").expect("Unable to read data."); + let data = fs::read("../../src/str_pad_term.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = BytesPadTerm::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.str_pad, vec!([0x73, 0x74, 0x72, 0x31])); diff --git a/spec/rust/tests/test_cast_nested.rs b/spec/rust/tests/test_cast_nested.rs index 7f91ae73a..6d59aa86f 100644 --- a/spec/rust/tests/test_cast_nested.rs +++ b/spec/rust/tests/test_cast_nested.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_cast_nested() { - let data = fs::read("src/switch_opcodes.bin").expect("Unable to read data."); + let data = fs::read("../../src/switch_opcodes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = CastNested::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.opcodes_0_str.value, "foobar"); diff --git a/spec/rust/tests/test_cast_to_imported.rs b/spec/rust/tests/test_cast_to_imported.rs index b17769ee3..c0b55622c 100644 --- a/spec/rust/tests/test_cast_to_imported.rs +++ b/spec/rust/tests/test_cast_to_imported.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_cast_to_imported() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = CastToImported::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.one.one, 80); diff --git a/spec/rust/tests/test_cast_to_top.rs b/spec/rust/tests/test_cast_to_top.rs new file mode 100644 index 000000000..7a4d4f3b8 --- /dev/null +++ b/spec/rust/tests/test_cast_to_top.rs @@ -0,0 +1,15 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::cast_to_top::CastToTop; +use std::fs; + +#[test] +fn test_cast_to_top() { + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = CastToTop::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.code, 80); + // assert_eq!(r.header.code, 65); + // assert_eq!(r.header_casted.code, 65); +} diff --git a/spec/rust/tests/test_default_big_endian.rs b/spec/rust/tests/test_default_big_endian.rs index c3fae9538..160780cda 100644 --- a/spec/rust/tests/test_default_big_endian.rs +++ b/spec/rust/tests/test_default_big_endian.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_default_big_endian() { - let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = DefaultBigEndian::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.one, 117440512); diff --git a/spec/rust/tests/test_default_endian_expr_inherited.rs b/spec/rust/tests/test_default_endian_expr_inherited.rs index 1e67114eb..15993266a 100644 --- a/spec/rust/tests/test_default_endian_expr_inherited.rs +++ b/spec/rust/tests/test_default_endian_expr_inherited.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_default_endian_expr_inherited() { - let data = fs::read("src/endian_expr.bin").expect("Unable to read data."); + let data = fs::read("../../src/endian_expr.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = DefaultEndianExprInherited::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); diff --git a/spec/rust/tests/test_default_endian_expr_is_be.rs b/spec/rust/tests/test_default_endian_expr_is_be.rs index 4d7f31fde..b7465684d 100644 --- a/spec/rust/tests/test_default_endian_expr_is_be.rs +++ b/spec/rust/tests/test_default_endian_expr_is_be.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_default_endian_expr_is_be() { - let data = fs::read("src/endian_expr.bin").expect("Unable to read data."); + let data = fs::read("../../src/endian_expr.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = DefaultEndianExprIsBe::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); diff --git a/spec/rust/tests/test_default_endian_expr_is_le.rs b/spec/rust/tests/test_default_endian_expr_is_le.rs index 6201fc1ad..ee21fb530 100644 --- a/spec/rust/tests/test_default_endian_expr_is_le.rs +++ b/spec/rust/tests/test_default_endian_expr_is_le.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_default_endian_expr_is_le() { - let data = fs::read("src/endian_expr.bin").expect("Unable to read data."); + let data = fs::read("../../src/endian_expr.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = DefaultEndianExprIsLe::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); diff --git a/spec/rust/tests/test_default_endian_mod.rs b/spec/rust/tests/test_default_endian_mod.rs index db410537e..33b01c285 100644 --- a/spec/rust/tests/test_default_endian_mod.rs +++ b/spec/rust/tests/test_default_endian_mod.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_default_endian_mod() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = DefaultEndianMod::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.main.one, 1262698832); diff --git a/spec/rust/tests/test_docstrings.rs b/spec/rust/tests/test_docstrings.rs index 7ef44c56a..9ec3e6cd8 100644 --- a/spec/rust/tests/test_docstrings.rs +++ b/spec/rust/tests/test_docstrings.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_docstrings() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = Docstrings::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); } diff --git a/spec/rust/tests/test_docstrings_docref.rs b/spec/rust/tests/test_docstrings_docref.rs index 6442c43c4..dac79007e 100644 --- a/spec/rust/tests/test_docstrings_docref.rs +++ b/spec/rust/tests/test_docstrings_docref.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_docstrings_docref() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = DocstringsDocref::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); } diff --git a/spec/rust/tests/test_docstrings_docref_multi.rs b/spec/rust/tests/test_docstrings_docref_multi.rs index 5e357dc56..fac750220 100644 --- a/spec/rust/tests/test_docstrings_docref_multi.rs +++ b/spec/rust/tests/test_docstrings_docref_multi.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_docstrings_docref_multi() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = DocstringsDocrefMulti::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); } diff --git a/spec/rust/tests/test_enum_0.rs b/spec/rust/tests/test_enum_0.rs index 597a5d508..9789a6b81 100644 --- a/spec/rust/tests/test_enum_0.rs +++ b/spec/rust/tests/test_enum_0.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_enum_0() { - let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = Enum0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.pet_1, animal::CAT); diff --git a/spec/rust/tests/test_enum_1.rs b/spec/rust/tests/test_enum_1.rs index c76a71d4d..65c999216 100644 --- a/spec/rust/tests/test_enum_1.rs +++ b/spec/rust/tests/test_enum_1.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_enum_1() { - let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = Enum1::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.main.submain.pet_1, animal::CAT); diff --git a/spec/rust/tests/test_enum_deep.rs b/spec/rust/tests/test_enum_deep.rs index 810185cf0..3388e3df9 100644 --- a/spec/rust/tests/test_enum_deep.rs +++ b/spec/rust/tests/test_enum_deep.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_enum_deep() { - let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = EnumDeep::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.pet_1, animal::CAT); diff --git a/spec/rust/tests/test_enum_deep_literals.rs b/spec/rust/tests/test_enum_deep_literals.rs index 0358250a1..9adbe1b51 100644 --- a/spec/rust/tests/test_enum_deep_literals.rs +++ b/spec/rust/tests/test_enum_deep_literals.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_enum_deep_literals() { - let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = EnumDeepLiterals::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.is_pet_1_ok, true); diff --git a/spec/rust/tests/test_enum_fancy.rs b/spec/rust/tests/test_enum_fancy.rs index 3d4ea97f2..976da00e0 100644 --- a/spec/rust/tests/test_enum_fancy.rs +++ b/spec/rust/tests/test_enum_fancy.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_enum_fancy() { - let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = EnumFancy::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.pet_1, animal::CAT); diff --git a/spec/rust/tests/test_enum_if.rs b/spec/rust/tests/test_enum_if.rs index 19850bf08..a3327f652 100644 --- a/spec/rust/tests/test_enum_if.rs +++ b/spec/rust/tests/test_enum_if.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_enum_if() { - let data = fs::read("src/if_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/if_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = EnumIf::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.op1.opcode, opcodes::A_STRING); diff --git a/spec/rust/tests/test_enum_negative.rs b/spec/rust/tests/test_enum_negative.rs index 3ada6528a..4f8efe078 100644 --- a/spec/rust/tests/test_enum_negative.rs +++ b/spec/rust/tests/test_enum_negative.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_enum_negative() { - let data = fs::read("src/enum_negative.bin").expect("Unable to read data."); + let data = fs::read("../../src/enum_negative.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = EnumNegative::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.f1, constants::NEGATIVE_ONE); diff --git a/spec/rust/tests/test_enum_of_value_inst.rs b/spec/rust/tests/test_enum_of_value_inst.rs index 8d503d404..b0f6dd8ed 100644 --- a/spec/rust/tests/test_enum_of_value_inst.rs +++ b/spec/rust/tests/test_enum_of_value_inst.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_enum_of_value_inst() { - let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = EnumOfValueInst::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.pet_1, animal::CAT); diff --git a/spec/rust/tests/test_enum_to_i.rs b/spec/rust/tests/test_enum_to_i.rs index 47b048f4b..663ba13e6 100644 --- a/spec/rust/tests/test_enum_to_i.rs +++ b/spec/rust/tests/test_enum_to_i.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_enum_to_i() { - let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = EnumToI::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.pet_1, animal::CAT); diff --git a/spec/rust/tests/test_expr_0.rs b/spec/rust/tests/test_expr_0.rs index a7a193ddc..5c75d2498 100644 --- a/spec/rust/tests/test_expr_0.rs +++ b/spec/rust/tests/test_expr_0.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_expr_0() { - let data = fs::read("src/str_encodings.bin").expect("Unable to read data."); + let data = fs::read("../../src/str_encodings.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = Expr0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.must_be_f7, 247); diff --git a/spec/rust/tests/test_expr_1.rs b/spec/rust/tests/test_expr_1.rs index 227fb061c..6a402f1e2 100644 --- a/spec/rust/tests/test_expr_1.rs +++ b/spec/rust/tests/test_expr_1.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_expr_1() { - let data = fs::read("src/str_encodings.bin").expect("Unable to read data."); + let data = fs::read("../../src/str_encodings.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = Expr1::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.len_of_1, 10); diff --git a/spec/rust/tests/test_expr_2.rs b/spec/rust/tests/test_expr_2.rs new file mode 100644 index 000000000..efa6b787d --- /dev/null +++ b/spec/rust/tests/test_expr_2.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_2::Expr2; +use std::fs; + +#[test] +fn test_expr_2() { + let data = fs::read("../../src/str_encodings.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = Expr2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.str1.len_orig, 10); + // assert_eq!(r.str1.len_mod, 7); + // assert_eq!(r.str1.str, "Some AS"); + // assert_eq!(r.str1_len, 7); + // assert_eq!(r.str1_len_mod, 7); + // assert_eq!(r.str1_byte1, 73); + // assert_eq!(r.str1_avg, 73); + // assert_eq!(r.str1_char5, "e"); + // assert_eq!(r.str1_tuple5.byte0, 101); + // assert_eq!(r.str1_tuple5.byte0, 101); + // assert_eq!(r.str1_tuple5.byte1, 32); + // assert_eq!(r.str1_tuple5.byte2, 65); + // assert_eq!(r.str1_tuple5.avg, 48); + // assert_eq!(r.str2_tuple5.byte0, 101); + // assert_eq!(r.str2_tuple5.byte1, 32); + // assert_eq!(r.str2_tuple5.byte2, 65); + // assert_eq!(r.str2_tuple5.avg, 48); +} diff --git a/spec/rust/tests/test_expr_3.rs b/spec/rust/tests/test_expr_3.rs index d30eb3964..1312c69dc 100644 --- a/spec/rust/tests/test_expr_3.rs +++ b/spec/rust/tests/test_expr_3.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_expr_3() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = Expr3::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.one, 80); diff --git a/spec/rust/tests/test_expr_array.rs b/spec/rust/tests/test_expr_array.rs index 277270f50..de38146c3 100644 --- a/spec/rust/tests/test_expr_array.rs +++ b/spec/rust/tests/test_expr_array.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_expr_array() { - let data = fs::read("src/expr_array.bin").expect("Unable to read data."); + let data = fs::read("../../src/expr_array.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ExprArray::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.aint_size, 4); diff --git a/spec/rust/tests/test_expr_bytes_cmp.rs b/spec/rust/tests/test_expr_bytes_cmp.rs index 2b45f9ff3..1c37e8ee6 100644 --- a/spec/rust/tests/test_expr_bytes_cmp.rs +++ b/spec/rust/tests/test_expr_bytes_cmp.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_expr_bytes_cmp() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ExprBytesCmp::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.one, vec!([0x50])); diff --git a/spec/rust/tests/test_expr_enum.rs b/spec/rust/tests/test_expr_enum.rs index 29e48d819..9f1525858 100644 --- a/spec/rust/tests/test_expr_enum.rs +++ b/spec/rust/tests/test_expr_enum.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_expr_enum() { - let data = fs::read("src/term_strz.bin").expect("Unable to read data."); + let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ExprEnum::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.const_dog, animal::DOG); diff --git a/spec/rust/tests/test_expr_io_pos.rs b/spec/rust/tests/test_expr_io_pos.rs new file mode 100644 index 000000000..688ae12a8 --- /dev/null +++ b/spec/rust/tests/test_expr_io_pos.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_io_pos::ExprIoPos; +use std::fs; + +#[test] +fn test_expr_io_pos() { + let data = fs::read("../../src/expr_io_pos.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ExprIoPos::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.substream1.my_str, "CURIOSITY"); + // assert_eq!(r.substream1.body, vec!([0x11, 0x22, 0x33, 0x44])); + // assert_eq!(r.substream1.number, 66); + // assert_eq!(r.substream2.my_str, "KILLED"); + // assert_eq!(r.substream2.body, vec!([0x61, 0x20, 0x63, 0x61, 0x74])); + // assert_eq!(r.substream2.number, 103); +} diff --git a/spec/rust/tests/test_expr_mod.rs b/spec/rust/tests/test_expr_mod.rs index 32db60ed7..3185a2197 100644 --- a/spec/rust/tests/test_expr_mod.rs +++ b/spec/rust/tests/test_expr_mod.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_expr_mod() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ExprMod::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.int_u, 1262698832); diff --git a/spec/rust/tests/test_expr_sizeof_type_0.rs b/spec/rust/tests/test_expr_sizeof_type_0.rs index a41a4395f..a64f146e1 100644 --- a/spec/rust/tests/test_expr_sizeof_type_0.rs +++ b/spec/rust/tests/test_expr_sizeof_type_0.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_expr_sizeof_type_0() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ExprSizeofType0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.sizeof_block, ((1 + 4) + 2)); diff --git a/spec/rust/tests/test_expr_sizeof_type_1.rs b/spec/rust/tests/test_expr_sizeof_type_1.rs index 9fa65796c..e504a0293 100644 --- a/spec/rust/tests/test_expr_sizeof_type_1.rs +++ b/spec/rust/tests/test_expr_sizeof_type_1.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_expr_sizeof_type_1() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ExprSizeofType1::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.sizeof_block, (((1 + 4) + 2) + 4)); diff --git a/spec/rust/tests/test_expr_sizeof_value_0.rs b/spec/rust/tests/test_expr_sizeof_value_0.rs index d32033e06..8b426910a 100644 --- a/spec/rust/tests/test_expr_sizeof_value_0.rs +++ b/spec/rust/tests/test_expr_sizeof_value_0.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_expr_sizeof_value_0() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ExprSizeofValue0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.self_sizeof, (((1 + 4) + 2) + 2)); diff --git a/spec/rust/tests/test_expr_sizeof_value_sized.rs b/spec/rust/tests/test_expr_sizeof_value_sized.rs new file mode 100644 index 000000000..44f060677 --- /dev/null +++ b/spec/rust/tests/test_expr_sizeof_value_sized.rs @@ -0,0 +1,17 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::expr_sizeof_value_sized::ExprSizeofValueSized; +use std::fs; + +#[test] +fn test_expr_sizeof_value_sized() { + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ExprSizeofValueSized::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.self_sizeof, (12 + 2)); + // assert_eq!(r.sizeof_block, 12); + // assert_eq!(r.sizeof_block_a, 1); + // assert_eq!(r.sizeof_block_b, 4); + // assert_eq!(r.sizeof_block_c, 2); +} diff --git a/spec/rust/tests/test_fixed_contents.rs b/spec/rust/tests/test_fixed_contents.rs index 04bc2a387..a3657b847 100644 --- a/spec/rust/tests/test_fixed_contents.rs +++ b/spec/rust/tests/test_fixed_contents.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_fixed_contents() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = FixedContents::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); } diff --git a/spec/rust/tests/test_fixed_struct.rs b/spec/rust/tests/test_fixed_struct.rs new file mode 100644 index 000000000..d982f39af --- /dev/null +++ b/spec/rust/tests/test_fixed_struct.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::fixed_struct::FixedStruct; +use std::fs; + +#[test] +fn test_fixed_struct() { + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = FixedStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.hdr.uint8, 255); + // assert_eq!(r.hdr.uint16, 65535); + // assert_eq!(r.hdr.uint32, 4294967295); + // assert_eq!(r.hdr.uint64, 18446744073709551615); + // assert_eq!(r.hdr.sint8, -1); + // assert_eq!(r.hdr.sint16, -1); + // assert_eq!(r.hdr.sint32, -1); + // assert_eq!(r.hdr.sint64, -1); + // assert_eq!(r.hdr.uint16le, 66); + // assert_eq!(r.hdr.uint32le, 66); + // assert_eq!(r.hdr.uint64le, 66); + // assert_eq!(r.hdr.sint16le, -66); + // assert_eq!(r.hdr.sint32le, -66); + // assert_eq!(r.hdr.sint64le, -66); + // assert_eq!(r.hdr.uint16be, 66); + // assert_eq!(r.hdr.uint32be, 66); + // assert_eq!(r.hdr.uint64be, 66); + // assert_eq!(r.hdr.sint16be, -66); + // assert_eq!(r.hdr.sint32be, -66); + // assert_eq!(r.hdr.sint64be, -66); +} diff --git a/spec/rust/tests/test_float_to_i.rs b/spec/rust/tests/test_float_to_i.rs index c6bfe3af1..72ea81bd2 100644 --- a/spec/rust/tests/test_float_to_i.rs +++ b/spec/rust/tests/test_float_to_i.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_float_to_i() { - let data = fs::read("src/floating_points.bin").expect("Unable to read data."); + let data = fs::read("../../src/floating_points.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = FloatToI::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.single_value, 0.5); diff --git a/spec/rust/tests/test_floating_points.rs b/spec/rust/tests/test_floating_points.rs index 783e1925b..f159122c7 100644 --- a/spec/rust/tests/test_floating_points.rs +++ b/spec/rust/tests/test_floating_points.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_floating_points() { - let data = fs::read("src/floating_points.bin").expect("Unable to read data."); + let data = fs::read("../../src/floating_points.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = FloatingPoints::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.single_value, 0.5); diff --git a/spec/rust/tests/test_hello_world.rs b/spec/rust/tests/test_hello_world.rs index 4212250ae..a1448d2b6 100644 --- a/spec/rust/tests/test_hello_world.rs +++ b/spec/rust/tests/test_hello_world.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_hello_world() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = HelloWorld::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.one, 80); diff --git a/spec/rust/tests/test_if_instances.rs b/spec/rust/tests/test_if_instances.rs new file mode 100644 index 000000000..978a09cee --- /dev/null +++ b/spec/rust/tests/test_if_instances.rs @@ -0,0 +1,13 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::if_instances::IfInstances; +use std::fs; + +#[test] +fn test_if_instances() { + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = IfInstances::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // nullAsset(r.never_happens); +} diff --git a/spec/rust/tests/test_if_struct.rs b/spec/rust/tests/test_if_struct.rs index 4bb955e89..a17a8a389 100644 --- a/spec/rust/tests/test_if_struct.rs +++ b/spec/rust/tests/test_if_struct.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_if_struct() { - let data = fs::read("src/if_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/if_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = IfStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.op1.opcode, 83); diff --git a/spec/rust/tests/test_if_values.rs b/spec/rust/tests/test_if_values.rs index a63f270f7..23ffb26fb 100644 --- a/spec/rust/tests/test_if_values.rs +++ b/spec/rust/tests/test_if_values.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_if_values() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = IfValues::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.codes[0].opcode, 80); diff --git a/spec/rust/tests/test_imports0.rs b/spec/rust/tests/test_imports0.rs index f1f9b2ff6..0c3140de7 100644 --- a/spec/rust/tests/test_imports0.rs +++ b/spec/rust/tests/test_imports0.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_imports0() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = Imports0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.two, 80); diff --git a/spec/rust/tests/test_imports_abs.rs b/spec/rust/tests/test_imports_abs.rs index a1e1bd82e..2fd835f70 100644 --- a/spec/rust/tests/test_imports_abs.rs +++ b/spec/rust/tests/test_imports_abs.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_imports_abs() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ImportsAbs::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.len.value, 80); diff --git a/spec/rust/tests/test_index_sizes.rs b/spec/rust/tests/test_index_sizes.rs index 9688dcc7d..d32fff22b 100644 --- a/spec/rust/tests/test_index_sizes.rs +++ b/spec/rust/tests/test_index_sizes.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_index_sizes() { - let data = fs::read("src/index_sizes.bin").expect("Unable to read data."); + let data = fs::read("../../src/index_sizes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = IndexSizes::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.qty, 3); diff --git a/spec/rust/tests/test_index_to_param_eos.rs b/spec/rust/tests/test_index_to_param_eos.rs index 918e64c0f..ac7cd7590 100644 --- a/spec/rust/tests/test_index_to_param_eos.rs +++ b/spec/rust/tests/test_index_to_param_eos.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_index_to_param_eos() { - let data = fs::read("src/index_sizes.bin").expect("Unable to read data."); + let data = fs::read("../../src/index_sizes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = IndexToParamEos::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.qty, 3); diff --git a/spec/rust/tests/test_index_to_param_expr.rs b/spec/rust/tests/test_index_to_param_expr.rs index c30c572b8..50b23ecb1 100644 --- a/spec/rust/tests/test_index_to_param_expr.rs +++ b/spec/rust/tests/test_index_to_param_expr.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_index_to_param_expr() { - let data = fs::read("src/index_sizes.bin").expect("Unable to read data."); + let data = fs::read("../../src/index_sizes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = IndexToParamExpr::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.qty, 3); diff --git a/spec/rust/tests/test_index_to_param_until.rs b/spec/rust/tests/test_index_to_param_until.rs index 3a9ee7215..e1336bde2 100644 --- a/spec/rust/tests/test_index_to_param_until.rs +++ b/spec/rust/tests/test_index_to_param_until.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_index_to_param_until() { - let data = fs::read("src/index_sizes.bin").expect("Unable to read data."); + let data = fs::read("../../src/index_sizes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = IndexToParamUntil::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.qty, 3); diff --git a/spec/rust/tests/test_instance_io_user.rs b/spec/rust/tests/test_instance_io_user.rs new file mode 100644 index 000000000..507581751 --- /dev/null +++ b/spec/rust/tests/test_instance_io_user.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::instance_io_user::InstanceIoUser; +use std::fs; + +#[test] +fn test_instance_io_user() { + let data = fs::read("../../src/instance_io.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = InstanceIoUser::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.qty_entries, 3); + // assert_eq!(r.entries[0].name, "the"); + // assert_eq!(r.entries[1].name, "rainy"); + // assert_eq!(r.entries[2].name, "day it is"); +} diff --git a/spec/rust/tests/test_instance_std.rs b/spec/rust/tests/test_instance_std.rs new file mode 100644 index 000000000..d4c135ce3 --- /dev/null +++ b/spec/rust/tests/test_instance_std.rs @@ -0,0 +1,13 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::instance_std::InstanceStd; +use std::fs; + +#[test] +fn test_instance_std() { + let data = fs::read("../../src/str_encodings.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = InstanceStd::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.header, "Some "); +} diff --git a/spec/rust/tests/test_instance_std_array.rs b/spec/rust/tests/test_instance_std_array.rs index 9961daa03..7ac5a9652 100644 --- a/spec/rust/tests/test_instance_std_array.rs +++ b/spec/rust/tests/test_instance_std_array.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_instance_std_array() { - let data = fs::read("src/instance_std_array.bin").expect("Unable to read data."); + let data = fs::read("../../src/instance_std_array.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = InstanceStdArray::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.ofs, 16); diff --git a/spec/rust/tests/test_instance_user_array.rs b/spec/rust/tests/test_instance_user_array.rs new file mode 100644 index 000000000..28e8d46be --- /dev/null +++ b/spec/rust/tests/test_instance_user_array.rs @@ -0,0 +1,22 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::instance_user_array::InstanceUserArray; +use std::fs; + +#[test] +fn test_instance_user_array() { + let data = fs::read("../../src/instance_std_array.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = InstanceUserArray::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.ofs, 16); + // assert_eq!(r.qty_entries, 3); + // assert_eq!(r.entry_size, 4); + // assert_eq!(r.user_entries.len(), 3); + // assert_eq!(r.user_entries[0].word1, 4369); + // assert_eq!(r.user_entries[0].word2, 4369); + // assert_eq!(r.user_entries[1].word1, 8738); + // assert_eq!(r.user_entries[1].word2, 8738); + // assert_eq!(r.user_entries[2].word1, 13107); + // assert_eq!(r.user_entries[2].word2, 13107); +} diff --git a/spec/rust/tests/test_integers.rs b/spec/rust/tests/test_integers.rs index c1def99c2..3ade78b99 100644 --- a/spec/rust/tests/test_integers.rs +++ b/spec/rust/tests/test_integers.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_integers() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = Integers::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.uint8, 255); diff --git a/spec/rust/tests/test_io_local_var.rs b/spec/rust/tests/test_io_local_var.rs new file mode 100644 index 000000000..152474f96 --- /dev/null +++ b/spec/rust/tests/test_io_local_var.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::io_local_var::IoLocalVar; +use std::fs; + +#[test] +fn test_io_local_var() { + let data = fs::read("../../src/full256.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = IoLocalVar::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.skip, vec!([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13])); + // assert_eq!(r.followup, 20); +} diff --git a/spec/rust/tests/test_js_signed_right_shift.rs b/spec/rust/tests/test_js_signed_right_shift.rs index 112ff0137..afe37a77d 100644 --- a/spec/rust/tests/test_js_signed_right_shift.rs +++ b/spec/rust/tests/test_js_signed_right_shift.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_js_signed_right_shift() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = JsSignedRightShift::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.should_be_40000000, 1073741824); diff --git a/spec/rust/tests/test_meta_tags.rs b/spec/rust/tests/test_meta_tags.rs index cfef90977..428bf3542 100644 --- a/spec/rust/tests/test_meta_tags.rs +++ b/spec/rust/tests/test_meta_tags.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_meta_tags() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = MetaTags::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); } diff --git a/spec/rust/tests/test_meta_xref.rs b/spec/rust/tests/test_meta_xref.rs index 055c31e89..77f826885 100644 --- a/spec/rust/tests/test_meta_xref.rs +++ b/spec/rust/tests/test_meta_xref.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_meta_xref() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = MetaXref::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); } diff --git a/spec/rust/tests/test_multiple_use.rs b/spec/rust/tests/test_multiple_use.rs new file mode 100644 index 000000000..4c38ff192 --- /dev/null +++ b/spec/rust/tests/test_multiple_use.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::multiple_use::MultipleUse; +use std::fs; + +#[test] +fn test_multiple_use() { + let data = fs::read("../../src/position_abs.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = MultipleUse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.t1.first_use.value, 32); + // assert_eq!(r.t2.second_use.value, 32); +} diff --git a/spec/rust/tests/test_nav_parent.rs b/spec/rust/tests/test_nav_parent.rs index f08fe35d5..a3abe1ddb 100644 --- a/spec/rust/tests/test_nav_parent.rs +++ b/spec/rust/tests/test_nav_parent.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nav_parent() { - let data = fs::read("src/nav.bin").expect("Unable to read data."); + let data = fs::read("../../src/nav.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NavParent::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.header.qty_entries, 2); diff --git a/spec/rust/tests/test_nav_parent2.rs b/spec/rust/tests/test_nav_parent2.rs index a4e5ada1d..ef824bfcd 100644 --- a/spec/rust/tests/test_nav_parent2.rs +++ b/spec/rust/tests/test_nav_parent2.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nav_parent2() { - let data = fs::read("src/nav_parent2.bin").expect("Unable to read data."); + let data = fs::read("../../src/nav_parent2.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NavParent2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.ofs_tags, 8); diff --git a/spec/rust/tests/test_nav_parent3.rs b/spec/rust/tests/test_nav_parent3.rs index 84e69f296..803a59041 100644 --- a/spec/rust/tests/test_nav_parent3.rs +++ b/spec/rust/tests/test_nav_parent3.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nav_parent3() { - let data = fs::read("src/nav_parent2.bin").expect("Unable to read data."); + let data = fs::read("../../src/nav_parent2.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NavParent3::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.ofs_tags, 8); diff --git a/spec/rust/tests/test_nav_parent_false.rs b/spec/rust/tests/test_nav_parent_false.rs index 0d24a6bcf..3be9fc658 100644 --- a/spec/rust/tests/test_nav_parent_false.rs +++ b/spec/rust/tests/test_nav_parent_false.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nav_parent_false() { - let data = fs::read("src/nav_parent_codes.bin").expect("Unable to read data."); + let data = fs::read("../../src/nav_parent_codes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NavParentFalse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.child_size, 3); diff --git a/spec/rust/tests/test_nav_parent_false2.rs b/spec/rust/tests/test_nav_parent_false2.rs index 7f5e0808a..17a37a5ac 100644 --- a/spec/rust/tests/test_nav_parent_false2.rs +++ b/spec/rust/tests/test_nav_parent_false2.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nav_parent_false2() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NavParentFalse2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.parentless.foo, 80); diff --git a/spec/rust/tests/test_nav_parent_override.rs b/spec/rust/tests/test_nav_parent_override.rs index 759cd2450..ae098c224 100644 --- a/spec/rust/tests/test_nav_parent_override.rs +++ b/spec/rust/tests/test_nav_parent_override.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nav_parent_override() { - let data = fs::read("src/nav_parent_codes.bin").expect("Unable to read data."); + let data = fs::read("../../src/nav_parent_codes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NavParentOverride::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.child_size, 3); diff --git a/spec/rust/tests/test_nav_parent_switch.rs b/spec/rust/tests/test_nav_parent_switch.rs index baeea14b3..b51912862 100644 --- a/spec/rust/tests/test_nav_parent_switch.rs +++ b/spec/rust/tests/test_nav_parent_switch.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nav_parent_switch() { - let data = fs::read("src/nav_parent_switch.bin").expect("Unable to read data."); + let data = fs::read("../../src/nav_parent_switch.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NavParentSwitch::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.category, 1); diff --git a/spec/rust/tests/test_nav_parent_vs_value_inst.rs b/spec/rust/tests/test_nav_parent_vs_value_inst.rs index 428b6a098..7f0965017 100644 --- a/spec/rust/tests/test_nav_parent_vs_value_inst.rs +++ b/spec/rust/tests/test_nav_parent_vs_value_inst.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nav_parent_vs_value_inst() { - let data = fs::read("src/term_strz.bin").expect("Unable to read data."); + let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NavParentVsValueInst::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.s1, "foo"); diff --git a/spec/rust/tests/test_nav_root.rs b/spec/rust/tests/test_nav_root.rs index 891957386..a4574586e 100644 --- a/spec/rust/tests/test_nav_root.rs +++ b/spec/rust/tests/test_nav_root.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nav_root() { - let data = fs::read("src/nav.bin").expect("Unable to read data."); + let data = fs::read("../../src/nav.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NavRoot::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.header.qty_entries, 2); diff --git a/spec/rust/tests/test_nested_same_name.rs b/spec/rust/tests/test_nested_same_name.rs index 36e242b25..249f25774 100644 --- a/spec/rust/tests/test_nested_same_name.rs +++ b/spec/rust/tests/test_nested_same_name.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nested_same_name() { - let data = fs::read("src/repeat_n_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/repeat_n_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NestedSameName::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.main_data.main_size, 2); diff --git a/spec/rust/tests/test_nested_same_name2.rs b/spec/rust/tests/test_nested_same_name2.rs new file mode 100644 index 000000000..8bc88dd45 --- /dev/null +++ b/spec/rust/tests/test_nested_same_name2.rs @@ -0,0 +1,17 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::nested_same_name2::NestedSameName2; +use std::fs; + +#[test] +fn test_nested_same_name2() { + let data = fs::read("../../src/nested_same_name2.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = NestedSameName2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.version, 66); + // assert_eq!(r.main_data.main_size, 2); + // assert_eq!(r.main_data.foo.data1, vec!([0x11, 0x11, 0x11, 0x11])); + // assert_eq!(r.dummy.dummy_size, 3); + // assert_eq!(r.dummy.foo.data2, vec!([0x22, 0x22, 0x22, 0x22, 0x22, 0x22])); +} diff --git a/spec/rust/tests/test_nested_types.rs b/spec/rust/tests/test_nested_types.rs index 0c077d7c4..2cdf7fed4 100644 --- a/spec/rust/tests/test_nested_types.rs +++ b/spec/rust/tests/test_nested_types.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nested_types() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NestedTypes::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.one.typed_at_root.value_b, 80); diff --git a/spec/rust/tests/test_nested_types2.rs b/spec/rust/tests/test_nested_types2.rs index 3c1396779..bf9e62dc5 100644 --- a/spec/rust/tests/test_nested_types2.rs +++ b/spec/rust/tests/test_nested_types2.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nested_types2() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NestedTypes2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.one.typed_at_root.value_b, 80); diff --git a/spec/rust/tests/test_nested_types3.rs b/spec/rust/tests/test_nested_types3.rs index 1135c002a..ba1f11819 100644 --- a/spec/rust/tests/test_nested_types3.rs +++ b/spec/rust/tests/test_nested_types3.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_nested_types3() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NestedTypes3::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.a_cc.value_cc, 80); diff --git a/spec/rust/tests/test_non_standard.rs b/spec/rust/tests/test_non_standard.rs index 781e053e1..9a8757350 100644 --- a/spec/rust/tests/test_non_standard.rs +++ b/spec/rust/tests/test_non_standard.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_non_standard() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = NonStandard::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.foo, 80); diff --git a/spec/rust/tests/test_params_call_short.rs b/spec/rust/tests/test_params_call_short.rs index ab7664626..903e339bb 100644 --- a/spec/rust/tests/test_params_call_short.rs +++ b/spec/rust/tests/test_params_call_short.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_params_call_short() { - let data = fs::read("src/term_strz.bin").expect("Unable to read data."); + let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ParamsCallShort::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.buf1.body, "foo|b"); diff --git a/spec/rust/tests/test_params_enum.rs b/spec/rust/tests/test_params_enum.rs index 1b4a8c32e..b127a7139 100644 --- a/spec/rust/tests/test_params_enum.rs +++ b/spec/rust/tests/test_params_enum.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_params_enum() { - let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ParamsEnum::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.one, animal::CAT); diff --git a/spec/rust/tests/test_params_pass_usertype.rs b/spec/rust/tests/test_params_pass_usertype.rs index 89c019855..0b50f6ad7 100644 --- a/spec/rust/tests/test_params_pass_usertype.rs +++ b/spec/rust/tests/test_params_pass_usertype.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_params_pass_usertype() { - let data = fs::read("src/position_in_seq.bin").expect("Unable to read data."); + let data = fs::read("../../src/position_in_seq.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ParamsPassUsertype::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.first.foo, 1); diff --git a/spec/rust/tests/test_position_abs.rs b/spec/rust/tests/test_position_abs.rs index a9d5700ff..18a7b5ee9 100644 --- a/spec/rust/tests/test_position_abs.rs +++ b/spec/rust/tests/test_position_abs.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_position_abs() { - let data = fs::read("src/position_abs.bin").expect("Unable to read data."); + let data = fs::read("../../src/position_abs.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = PositionAbs::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.index_offset, 32); diff --git a/spec/rust/tests/test_position_in_seq.rs b/spec/rust/tests/test_position_in_seq.rs index f11adbce7..807a3799b 100644 --- a/spec/rust/tests/test_position_in_seq.rs +++ b/spec/rust/tests/test_position_in_seq.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_position_in_seq() { - let data = fs::read("src/position_in_seq.bin").expect("Unable to read data."); + let data = fs::read("../../src/position_in_seq.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = PositionInSeq::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.numbers, [(0 + 1), 2, 3]); diff --git a/spec/rust/tests/test_position_to_end.rs b/spec/rust/tests/test_position_to_end.rs new file mode 100644 index 000000000..3ed8d21ff --- /dev/null +++ b/spec/rust/tests/test_position_to_end.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::position_to_end::PositionToEnd; +use std::fs; + +#[test] +fn test_position_to_end() { + let data = fs::read("../../src/position_to_end.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = PositionToEnd::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.index.foo, 66); + // assert_eq!(r.index.bar, 4660); +} diff --git a/spec/rust/tests/test_process_coerce_bytes.rs b/spec/rust/tests/test_process_coerce_bytes.rs index 3b7c551a5..739de7b26 100644 --- a/spec/rust/tests/test_process_coerce_bytes.rs +++ b/spec/rust/tests/test_process_coerce_bytes.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_process_coerce_bytes() { - let data = fs::read("src/process_coerce_bytes.bin").expect("Unable to read data."); + let data = fs::read("../../src/process_coerce_bytes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ProcessCoerceBytes::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.records[0].flag, 0); diff --git a/spec/rust/tests/test_process_coerce_switch.rs b/spec/rust/tests/test_process_coerce_switch.rs new file mode 100644 index 000000000..eb1eb7efc --- /dev/null +++ b/spec/rust/tests/test_process_coerce_switch.rs @@ -0,0 +1,15 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::process_coerce_switch::ProcessCoerceSwitch; +use std::fs; + +#[test] +fn test_process_coerce_switch() { + let data = fs::read("../../src/process_coerce_switch.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ProcessCoerceSwitch::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.buf_type, 0); + // assert_eq!(r.flag, 0); + // assert_eq!(r.buf.bar, vec!([0x41, 0x41, 0x41, 0x41])); +} diff --git a/spec/rust/tests/test_process_coerce_usertype1.rs b/spec/rust/tests/test_process_coerce_usertype1.rs new file mode 100644 index 000000000..d1838384e --- /dev/null +++ b/spec/rust/tests/test_process_coerce_usertype1.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::process_coerce_usertype1::ProcessCoerceUsertype1; +use std::fs; + +#[test] +fn test_process_coerce_usertype1() { + let data = fs::read("../../src/process_coerce_bytes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ProcessCoerceUsertype1::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.records[0].flag, 0); + // assert_eq!(r.records[0].buf.value, 1094795585); + // assert_eq!(r.records[1].flag, 1); + // assert_eq!(r.records[1].buf.value, 1111638594); +} diff --git a/spec/rust/tests/test_process_coerce_usertype2.rs b/spec/rust/tests/test_process_coerce_usertype2.rs new file mode 100644 index 000000000..f1e07ffde --- /dev/null +++ b/spec/rust/tests/test_process_coerce_usertype2.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::process_coerce_usertype2::ProcessCoerceUsertype2; +use std::fs; + +#[test] +fn test_process_coerce_usertype2() { + let data = fs::read("../../src/process_coerce_bytes.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ProcessCoerceUsertype2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.records[0].flag, 0); + // assert_eq!(r.records[0].buf.value, 1094795585); + // assert_eq!(r.records[1].flag, 1); + // assert_eq!(r.records[1].buf.value, 1111638594); +} diff --git a/spec/rust/tests/test_process_custom.rs b/spec/rust/tests/test_process_custom.rs index 7aefd0dec..67b976714 100644 --- a/spec/rust/tests/test_process_custom.rs +++ b/spec/rust/tests/test_process_custom.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_process_custom() { - let data = fs::read("src/process_rotate.bin").expect("Unable to read data."); + let data = fs::read("../../src/process_rotate.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ProcessCustom::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.buf1, vec!([0x10, 0xb3, 0x94, 0x94, 0xf4])); diff --git a/spec/rust/tests/test_process_rotate.rs b/spec/rust/tests/test_process_rotate.rs index b2a974247..320c2077f 100644 --- a/spec/rust/tests/test_process_rotate.rs +++ b/spec/rust/tests/test_process_rotate.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_process_rotate() { - let data = fs::read("src/process_rotate.bin").expect("Unable to read data."); + let data = fs::read("../../src/process_rotate.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ProcessRotate::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.buf1, vec!([0x48, 0x65, 0x6c, 0x6c, 0x6f])); diff --git a/spec/rust/tests/test_process_to_user.rs b/spec/rust/tests/test_process_to_user.rs new file mode 100644 index 000000000..cb2ca1d0b --- /dev/null +++ b/spec/rust/tests/test_process_to_user.rs @@ -0,0 +1,13 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::process_to_user::ProcessToUser; +use std::fs; + +#[test] +fn test_process_to_user() { + let data = fs::read("../../src/process_rotate.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = ProcessToUser::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.buf1.str, "Hello"); +} diff --git a/spec/rust/tests/test_process_xor4_const.rs b/spec/rust/tests/test_process_xor4_const.rs index dcf3fc299..acf00037c 100644 --- a/spec/rust/tests/test_process_xor4_const.rs +++ b/spec/rust/tests/test_process_xor4_const.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_process_xor4_const() { - let data = fs::read("src/process_xor_4.bin").expect("Unable to read data."); + let data = fs::read("../../src/process_xor_4.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ProcessXor4Const::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.key, vec!([0xec, 0xbb, 0xa3, 0x14])); diff --git a/spec/rust/tests/test_process_xor4_value.rs b/spec/rust/tests/test_process_xor4_value.rs index 14f9a78e9..b237625f9 100644 --- a/spec/rust/tests/test_process_xor4_value.rs +++ b/spec/rust/tests/test_process_xor4_value.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_process_xor4_value() { - let data = fs::read("src/process_xor_4.bin").expect("Unable to read data."); + let data = fs::read("../../src/process_xor_4.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ProcessXor4Value::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.key, vec!([0xec, 0xbb, 0xa3, 0x14])); diff --git a/spec/rust/tests/test_process_xor_const.rs b/spec/rust/tests/test_process_xor_const.rs index 9b9bc5b65..695c5170d 100644 --- a/spec/rust/tests/test_process_xor_const.rs +++ b/spec/rust/tests/test_process_xor_const.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_process_xor_const() { - let data = fs::read("src/process_xor_1.bin").expect("Unable to read data."); + let data = fs::read("../../src/process_xor_1.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ProcessXorConst::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.key, 255); diff --git a/spec/rust/tests/test_process_xor_value.rs b/spec/rust/tests/test_process_xor_value.rs index 961a21503..d3ba80bb8 100644 --- a/spec/rust/tests/test_process_xor_value.rs +++ b/spec/rust/tests/test_process_xor_value.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_process_xor_value() { - let data = fs::read("src/process_xor_1.bin").expect("Unable to read data."); + let data = fs::read("../../src/process_xor_1.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ProcessXorValue::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.key, 255); diff --git a/spec/rust/tests/test_recursive_one.rs b/spec/rust/tests/test_recursive_one.rs new file mode 100644 index 000000000..d15d63331 --- /dev/null +++ b/spec/rust/tests/test_recursive_one.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::recursive_one::RecursiveOne; +use std::fs; + +#[test] +fn test_recursive_one() { + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = RecursiveOne::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.one, 80); + // assert_eq!(r.next.one, 65); + // assert_eq!(r.next.next.one, 67); + // assert_eq!(r.next.next.next.finisher, 11595); +} diff --git a/spec/rust/tests/test_repeat_eos_bit.rs b/spec/rust/tests/test_repeat_eos_bit.rs index 4c70df2d9..6779501a8 100644 --- a/spec/rust/tests/test_repeat_eos_bit.rs +++ b/spec/rust/tests/test_repeat_eos_bit.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_repeat_eos_bit() { - let data = fs::read("src/enum_0.bin").expect("Unable to read data."); + let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = RepeatEosBit::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.nibbles.len(), 16); diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs index 566c6a2d9..40075511c 100644 --- a/spec/rust/tests/test_repeat_eos_struct.rs +++ b/spec/rust/tests/test_repeat_eos_struct.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_repeat_eos_struct() { - let data = fs::read("src/repeat_eos_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/repeat_eos_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = RepeatEosStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.chunks.len(), 2); diff --git a/spec/rust/tests/test_repeat_eos_u4.rs b/spec/rust/tests/test_repeat_eos_u4.rs index a0892f066..a41b62960 100644 --- a/spec/rust/tests/test_repeat_eos_u4.rs +++ b/spec/rust/tests/test_repeat_eos_u4.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_repeat_eos_u4() { - let data = fs::read("src/repeat_eos_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/repeat_eos_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = RepeatEosU4::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.numbers, [0, 66, 66, 2069]); diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs index 624725d15..1ca273dee 100644 --- a/spec/rust/tests/test_repeat_n_struct.rs +++ b/spec/rust/tests/test_repeat_n_struct.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_repeat_n_struct() { - let data = fs::read("src/repeat_n_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/repeat_n_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = RepeatNStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.chunks.len(), 2); diff --git a/spec/rust/tests/test_repeat_n_strz.rs b/spec/rust/tests/test_repeat_n_strz.rs index 073fdcda7..2347f4009 100644 --- a/spec/rust/tests/test_repeat_n_strz.rs +++ b/spec/rust/tests/test_repeat_n_strz.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_repeat_n_strz() { - let data = fs::read("src/repeat_n_strz.bin").expect("Unable to read data."); + let data = fs::read("../../src/repeat_n_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = RepeatNStrz::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.qty, 2); diff --git a/spec/rust/tests/test_repeat_n_strz_double.rs b/spec/rust/tests/test_repeat_n_strz_double.rs index 7b0b68c11..ae1bcc5ba 100644 --- a/spec/rust/tests/test_repeat_n_strz_double.rs +++ b/spec/rust/tests/test_repeat_n_strz_double.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_repeat_n_strz_double() { - let data = fs::read("src/repeat_n_strz.bin").expect("Unable to read data."); + let data = fs::read("../../src/repeat_n_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = RepeatNStrzDouble::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.qty, 2); diff --git a/spec/rust/tests/test_repeat_until_complex.rs b/spec/rust/tests/test_repeat_until_complex.rs index cdaea6d1f..9a71c8e10 100644 --- a/spec/rust/tests/test_repeat_until_complex.rs +++ b/spec/rust/tests/test_repeat_until_complex.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_repeat_until_complex() { - let data = fs::read("src/repeat_until_complex.bin").expect("Unable to read data."); + let data = fs::read("../../src/repeat_until_complex.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = RepeatUntilComplex::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.first.len(), 3); diff --git a/spec/rust/tests/test_repeat_until_s4.rs b/spec/rust/tests/test_repeat_until_s4.rs index 554a2f93b..43230a62f 100644 --- a/spec/rust/tests/test_repeat_until_s4.rs +++ b/spec/rust/tests/test_repeat_until_s4.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_repeat_until_s4() { - let data = fs::read("src/repeat_until_s4.bin").expect("Unable to read data."); + let data = fs::read("../../src/repeat_until_s4.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = RepeatUntilS4::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.entries, [66, 4919, -251658241, -1]); diff --git a/spec/rust/tests/test_repeat_until_sized.rs b/spec/rust/tests/test_repeat_until_sized.rs new file mode 100644 index 000000000..c87f2e31b --- /dev/null +++ b/spec/rust/tests/test_repeat_until_sized.rs @@ -0,0 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::repeat_until_sized::RepeatUntilSized; +use std::fs; + +#[test] +fn test_repeat_until_sized() { + let data = fs::read("../../src/repeat_until_process.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = RepeatUntilSized::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.records.len(), 3); + // assert_eq!(r.records[0].marker, 232); + // assert_eq!(r.records[0].body, 2863311546); + // assert_eq!(r.records[1].marker, 250); + // assert_eq!(r.records[1].body, 2863315102); + // assert_eq!(r.records[2].marker, 170); + // assert_eq!(r.records[2].body, 1431655765); +} diff --git a/spec/rust/tests/test_str_encodings.rs b/spec/rust/tests/test_str_encodings.rs index 52908f856..445266821 100644 --- a/spec/rust/tests/test_str_encodings.rs +++ b/spec/rust/tests/test_str_encodings.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_str_encodings() { - let data = fs::read("src/str_encodings.bin").expect("Unable to read data."); + let data = fs::read("../../src/str_encodings.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = StrEncodings::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.str1, "Some ASCII"); diff --git a/spec/rust/tests/test_str_encodings_default.rs b/spec/rust/tests/test_str_encodings_default.rs index c9e325fa8..d79d164ae 100644 --- a/spec/rust/tests/test_str_encodings_default.rs +++ b/spec/rust/tests/test_str_encodings_default.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_str_encodings_default() { - let data = fs::read("src/str_encodings.bin").expect("Unable to read data."); + let data = fs::read("../../src/str_encodings.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = StrEncodingsDefault::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.str1, "Some ASCII"); diff --git a/spec/rust/tests/test_str_eos.rs b/spec/rust/tests/test_str_eos.rs index 6be8c2f6e..cb576b396 100644 --- a/spec/rust/tests/test_str_eos.rs +++ b/spec/rust/tests/test_str_eos.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_str_eos() { - let data = fs::read("src/term_strz.bin").expect("Unable to read data."); + let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = StrEos::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.str, "foo|bar|baz@"); diff --git a/spec/rust/tests/test_str_literals2.rs b/spec/rust/tests/test_str_literals2.rs index 0a76cbd66..6aa34afce 100644 --- a/spec/rust/tests/test_str_literals2.rs +++ b/spec/rust/tests/test_str_literals2.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_str_literals2() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = StrLiterals2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.dollar1, "$foo"); diff --git a/spec/rust/tests/test_str_pad_term.rs b/spec/rust/tests/test_str_pad_term.rs index 86602dbe8..cdc1ac72f 100644 --- a/spec/rust/tests/test_str_pad_term.rs +++ b/spec/rust/tests/test_str_pad_term.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_str_pad_term() { - let data = fs::read("src/str_pad_term.bin").expect("Unable to read data."); + let data = fs::read("../../src/str_pad_term.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = StrPadTerm::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.str_pad, "str1"); diff --git a/spec/rust/tests/test_str_pad_term_empty.rs b/spec/rust/tests/test_str_pad_term_empty.rs index f27912c86..141749141 100644 --- a/spec/rust/tests/test_str_pad_term_empty.rs +++ b/spec/rust/tests/test_str_pad_term_empty.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_str_pad_term_empty() { - let data = fs::read("src/str_pad_term_empty.bin").expect("Unable to read data."); + let data = fs::read("../../src/str_pad_term_empty.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = StrPadTermEmpty::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.str_pad, ""); diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs index cb1c17f17..c10721ceb 100644 --- a/spec/rust/tests/test_switch_bytearray.rs +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_switch_bytearray() { - let data = fs::read("src/switch_opcodes.bin").expect("Unable to read data."); + let data = fs::read("../../src/switch_opcodes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = SwitchBytearray::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.opcodes.len(), 4); diff --git a/spec/rust/tests/test_switch_integers.rs b/spec/rust/tests/test_switch_integers.rs index c3c1b26a6..4ee5ffa11 100644 --- a/spec/rust/tests/test_switch_integers.rs +++ b/spec/rust/tests/test_switch_integers.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_switch_integers() { - let data = fs::read("src/switch_integers.bin").expect("Unable to read data."); + let data = fs::read("../../src/switch_integers.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = SwitchIntegers::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.opcodes.len(), 4); diff --git a/spec/rust/tests/test_switch_integers2.rs b/spec/rust/tests/test_switch_integers2.rs index 74e1a20a8..dfee01af6 100644 --- a/spec/rust/tests/test_switch_integers2.rs +++ b/spec/rust/tests/test_switch_integers2.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_switch_integers2() { - let data = fs::read("src/switch_integers.bin").expect("Unable to read data."); + let data = fs::read("../../src/switch_integers.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = SwitchIntegers2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.code, 1); diff --git a/spec/rust/tests/test_switch_manual_enum.rs b/spec/rust/tests/test_switch_manual_enum.rs index a11f22c32..a7019d645 100644 --- a/spec/rust/tests/test_switch_manual_enum.rs +++ b/spec/rust/tests/test_switch_manual_enum.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_switch_manual_enum() { - let data = fs::read("src/switch_opcodes.bin").expect("Unable to read data."); + let data = fs::read("../../src/switch_opcodes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = SwitchManualEnum::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.opcodes.len(), 4); diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs index 6bd855715..db6afa695 100644 --- a/spec/rust/tests/test_switch_manual_int.rs +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_switch_manual_int() { - let data = fs::read("src/switch_opcodes.bin").expect("Unable to read data."); + let data = fs::read("../../src/switch_opcodes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = SwitchManualInt::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.opcodes.len(), 4); diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs index c0aaf60a3..38e7f46b2 100644 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_switch_manual_int_else() { - let data = fs::read("src/switch_opcodes2.bin").expect("Unable to read data."); + let data = fs::read("../../src/switch_opcodes2.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = SwitchManualIntElse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.opcodes.len(), 4); diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs new file mode 100644 index 000000000..88854a504 --- /dev/null +++ b/spec/rust/tests/test_switch_manual_int_size_else.rs @@ -0,0 +1,22 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::switch_manual_int_size_else::SwitchManualIntSizeElse; +use std::fs; + +#[test] +fn test_switch_manual_int_size_else() { + let data = fs::read("../../src/switch_tlv.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = SwitchManualIntSizeElse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.chunks.len(), 4); + // assert_eq!(r.chunks[0].code, 17); + // assert_eq!(r.chunks[0].body.title, "Stuff"); + // assert_eq!(r.chunks[0].body.author, "Me"); + // assert_eq!(r.chunks[1].code, 34); + // assert_eq!(r.chunks[1].body.entries, ["AAAA", "BBBB", "CCCC"]); + // assert_eq!(r.chunks[2].code, 51); + // assert_eq!(r.chunks[2].body.rest, vec!([0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80])); + // assert_eq!(r.chunks[3].code, 255); + // assert_eq!(r.chunks[3].body.rest, vec!([])); +} diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs index 4433bd50d..24f7d9571 100644 --- a/spec/rust/tests/test_switch_manual_str.rs +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_switch_manual_str() { - let data = fs::read("src/switch_opcodes.bin").expect("Unable to read data."); + let data = fs::read("../../src/switch_opcodes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = SwitchManualStr::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.opcodes.len(), 4); diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs index c476f1b7a..23ee34449 100644 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_switch_manual_str_else() { - let data = fs::read("src/switch_opcodes2.bin").expect("Unable to read data."); + let data = fs::read("../../src/switch_opcodes2.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = SwitchManualStrElse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.opcodes.len(), 4); diff --git a/spec/rust/tests/test_term_bytes.rs b/spec/rust/tests/test_term_bytes.rs index 8b5ef76cc..558788d06 100644 --- a/spec/rust/tests/test_term_bytes.rs +++ b/spec/rust/tests/test_term_bytes.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_term_bytes() { - let data = fs::read("src/term_strz.bin").expect("Unable to read data."); + let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = TermBytes::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.s1, vec!([0x66, 0x6f, 0x6f])); diff --git a/spec/rust/tests/test_term_strz.rs b/spec/rust/tests/test_term_strz.rs index 26155888e..0fbe3f7a5 100644 --- a/spec/rust/tests/test_term_strz.rs +++ b/spec/rust/tests/test_term_strz.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_term_strz() { - let data = fs::read("src/term_strz.bin").expect("Unable to read data."); + let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = TermStrz::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.s1, "foo"); diff --git a/spec/rust/tests/test_ts_packet_header.rs b/spec/rust/tests/test_ts_packet_header.rs index c4ba0128f..a1f474f84 100644 --- a/spec/rust/tests/test_ts_packet_header.rs +++ b/spec/rust/tests/test_ts_packet_header.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_ts_packet_header() { - let data = fs::read("src/ts_packet.bin").expect("Unable to read data."); + let data = fs::read("../../src/ts_packet.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = TsPacketHeader::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.sync_byte, 71); diff --git a/spec/rust/tests/test_type_int_unary_op.rs b/spec/rust/tests/test_type_int_unary_op.rs index fcef4e400..71900f1ad 100644 --- a/spec/rust/tests/test_type_int_unary_op.rs +++ b/spec/rust/tests/test_type_int_unary_op.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_type_int_unary_op() { - let data = fs::read("src/fixed_struct.bin").expect("Unable to read data."); + let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = TypeIntUnaryOp::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.value_s2, 16720); diff --git a/spec/rust/tests/test_type_ternary.rs b/spec/rust/tests/test_type_ternary.rs new file mode 100644 index 000000000..1d099db5e --- /dev/null +++ b/spec/rust/tests/test_type_ternary.rs @@ -0,0 +1,13 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::type_ternary::TypeTernary; +use std::fs; + +#[test] +fn test_type_ternary() { + let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let r = TypeTernary::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + // assert_eq!(r.dif.value, 101); +} diff --git a/spec/rust/tests/test_user_type.rs b/spec/rust/tests/test_user_type.rs index 677be5e77..37d5e13f0 100644 --- a/spec/rust/tests/test_user_type.rs +++ b/spec/rust/tests/test_user_type.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_user_type() { - let data = fs::read("src/repeat_until_s4.bin").expect("Unable to read data."); + let data = fs::read("../../src/repeat_until_s4.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = UserType::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.one.width, 66); diff --git a/spec/rust/tests/test_zlib_with_header_78.rs b/spec/rust/tests/test_zlib_with_header_78.rs index 17556c384..c46f32d3d 100644 --- a/spec/rust/tests/test_zlib_with_header_78.rs +++ b/spec/rust/tests/test_zlib_with_header_78.rs @@ -6,7 +6,7 @@ use std::fs; #[test] fn test_zlib_with_header_78() { - let data = fs::read("src/zlib_with_header_78.bin").expect("Unable to read data."); + let data = fs::read("../../src/zlib_with_header_78.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); let r = ZlibWithHeader78::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); // assert_eq!(r.data, vec!([0x61, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72])); From 172088e405b47fb502a57175335f8837999b883f Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 13 May 2019 11:32:50 -0400 Subject: [PATCH 4/6] Commit the translator fixes --- .../specgenerators/RustSG.scala | 68 +++++++++---------- 1 file changed, 31 insertions(+), 37 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 560f93c76..537ede41c 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -1,66 +1,60 @@ package io.kaitai.struct.testtranslator.specgenerators -import _root_.io.kaitai.struct.{ClassTypeProvider, RuntimeConfig} -import _root_.io.kaitai.struct.datatype.DataType -import _root_.io.kaitai.struct.datatype.DataType._ -import _root_.io.kaitai.struct.exprlang.Ast -import _root_.io.kaitai.struct.languages.RustCompiler import _root_.io.kaitai.struct.testtranslator.{Main, TestAssert, TestSpec} -import _root_.io.kaitai.struct.translators.RustTranslator - -class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(spec) { - val className = RustCompiler.type2class(spec.id) +import io.kaitai.struct.datatype.DataType +import io.kaitai.struct.exprlang.Ast +import io.kaitai.struct.{ClassTypeProvider, RuntimeConfig} +import io.kaitai.struct.languages.RustCompiler +import io.kaitai.struct.translators.RustTranslator + +class RustSG(spec: TestSpec, provider: ClassTypeProvider) + extends BaseGenerator(spec) { + val className: String = RustCompiler.type2class(spec.id) val translator = new RustTranslator(provider, RuntimeConfig()) - override def fileName(name: String): String = s"test_$name.rs" + override def fileName(name: String): String = s"tests/test_$name.rs" override def header(): Unit = { - out.puts("extern crate kaitai_struct;") - out.puts(s"extern crate rust;") - out.puts - - out.puts("use kaitai_struct::KaitaiStruct;") - out.puts(s"use rust::$className;") + out.puts("use kaitai::{BytesReader, KStruct, KStructUnit};") + out.puts(s"use kaitai_test::${spec.id}::$className;") + out.puts(s"use std::fs;") out.puts out.puts("#[test]") out.puts(s"fn test_${spec.id}() {") out.inc - out.puts("if let Ok(r) = " + className + "::from_file(\"src/" + spec.data + "\") {") - out.inc + out.puts("let data = fs::read(\"../../src/" + spec.data + "\").expect(\"Unable to read data.\");") + out.puts(s"let reader = BytesReader::new(&data[..]);") + out.puts(s"let r = $className::default().read(&reader, None, KStructUnit::parent_stack()).unwrap();") } override def footer(): Unit = { out.dec out.puts("}") - out.dec - out.puts("}") - } - - override def simpleAssert(check: TestAssert): Unit = { - val actStr = translateAct(check.actual) - val expStr = translator.translate(check.expected) - out.puts(s"assert_eq!($actStr, $expStr);") } override def nullAssert(actual: Ast.expr): Unit = { val actStr = translateAct(actual) - out.puts(s"assertNull($actStr);") - // TODO: Figure out what's meant to happen here + out.puts(s"// nullAsset($actStr);") } - override def trueArrayAssert(check: TestAssert, elType: DataType, elts: Seq[Ast.expr]): Unit = { - simpleAssert(check) // FIXME - } + def translateAct(x: Ast.expr): String = + translator.translate(x).replace("self." + Main.INIT_OBJ_NAME, "r") - override def indentStr: String = " " + override def trueArrayAssert(check: TestAssert, + elType: DataType, + elts: Seq[Ast.expr]): Unit = { + simpleAssert(check) + } - override def results: String = { - "// " + AUTOGEN_COMMENT + "\n\n" + - out.result + override def simpleAssert(check: TestAssert): Unit = { + val actStr = translateAct(check.actual) + val expStr = translator.translate(check.expected) + out.puts(s"// assert_eq!($actStr, $expStr);") } - def translateAct(x: Ast.expr) = - translator.translate(x).replace("self." + Main.INIT_OBJ_NAME, "r") + override def indentStr: String = " " + + override def results: String = "// " + AUTOGEN_COMMENT + "\n\n" + out.result } From 924c2e6c07d297bac0c3a059d4281b3be2bbb948 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Fri, 17 May 2019 09:51:04 -0400 Subject: [PATCH 5/6] Enable asserts for basic behavior --- ci-rust | 2 +- spec/rust/tests/test_bcd_user_type_be.rs | 17 ++-- spec/rust/tests/test_bcd_user_type_le.rs | 17 ++-- spec/rust/tests/test_bits_byte_aligned.rs | 23 ++--- spec/rust/tests/test_bits_enum.rs | 11 ++- spec/rust/tests/test_bits_simple.rs | 33 ++++--- spec/rust/tests/test_buffered_struct.rs | 19 ++-- spec/rust/tests/test_bytes_pad_term.rs | 13 +-- spec/rust/tests/test_cast_nested.rs | 13 +-- spec/rust/tests/test_cast_to_imported.rs | 9 +- spec/rust/tests/test_cast_to_top.rs | 11 ++- spec/rust/tests/test_default_big_endian.rs | 7 +- .../test_default_endian_expr_inherited.rs | 35 +++---- .../tests/test_default_endian_expr_is_be.rs | 41 ++++---- .../tests/test_default_endian_expr_is_le.rs | 29 +++--- spec/rust/tests/test_default_endian_mod.rs | 11 ++- spec/rust/tests/test_docstrings.rs | 5 +- spec/rust/tests/test_docstrings_docref.rs | 5 +- .../tests/test_docstrings_docref_multi.rs | 5 +- spec/rust/tests/test_enum_0.rs | 9 +- spec/rust/tests/test_enum_1.rs | 9 +- spec/rust/tests/test_enum_deep.rs | 9 +- spec/rust/tests/test_enum_deep_literals.rs | 9 +- spec/rust/tests/test_enum_fancy.rs | 9 +- spec/rust/tests/test_enum_if.rs | 19 ++-- spec/rust/tests/test_enum_invalid.rs | 15 +++ spec/rust/tests/test_enum_negative.rs | 9 +- spec/rust/tests/test_enum_of_value_inst.rs | 13 +-- spec/rust/tests/test_enum_to_i.rs | 15 +-- spec/rust/tests/test_expr_0.rs | 9 +- spec/rust/tests/test_expr_1.rs | 13 +-- spec/rust/tests/test_expr_2.rs | 39 ++++---- spec/rust/tests/test_expr_3.rs | 29 +++--- spec/rust/tests/test_expr_array.rs | 35 +++---- spec/rust/tests/test_expr_bytes_cmp.rs | 25 ++--- spec/rust/tests/test_expr_enum.rs | 11 ++- spec/rust/tests/test_expr_io_pos.rs | 17 ++-- spec/rust/tests/test_expr_mod.rs | 17 ++-- spec/rust/tests/test_expr_sizeof_type_0.rs | 7 +- spec/rust/tests/test_expr_sizeof_type_1.rs | 9 +- spec/rust/tests/test_expr_sizeof_value_0.rs | 15 +-- .../tests/test_expr_sizeof_value_sized.rs | 15 +-- spec/rust/tests/test_fixed_contents.rs | 5 +- spec/rust/tests/test_fixed_struct.rs | 45 ++++----- spec/rust/tests/test_float_to_i.rs | 21 ++-- spec/rust/tests/test_floating_points.rs | 21 ++-- spec/rust/tests/test_hello_world.rs | 7 +- spec/rust/tests/test_if_instances.rs | 5 +- spec/rust/tests/test_if_struct.rs | 19 ++-- spec/rust/tests/test_if_values.rs | 13 +-- spec/rust/tests/test_imports0.rs | 11 ++- spec/rust/tests/test_imports_abs.rs | 9 +- spec/rust/tests/test_index_sizes.rs | 19 ++-- spec/rust/tests/test_index_to_param_eos.rs | 19 ++-- spec/rust/tests/test_index_to_param_expr.rs | 19 ++-- spec/rust/tests/test_index_to_param_until.rs | 19 ++-- spec/rust/tests/test_instance_io_user.rs | 13 +-- spec/rust/tests/test_instance_std.rs | 7 +- spec/rust/tests/test_instance_std_array.rs | 19 ++-- spec/rust/tests/test_instance_user_array.rs | 25 ++--- spec/rust/tests/test_integers.rs | 45 ++++----- spec/rust/tests/test_io_local_var.rs | 9 +- spec/rust/tests/test_js_signed_right_shift.rs | 9 +- spec/rust/tests/test_meta_tags.rs | 5 +- spec/rust/tests/test_meta_xref.rs | 5 +- spec/rust/tests/test_multiple_use.rs | 9 +- spec/rust/tests/test_nav_parent.rs | 15 +-- spec/rust/tests/test_nav_parent2.rs | 25 ++--- spec/rust/tests/test_nav_parent3.rs | 25 ++--- spec/rust/tests/test_nav_parent_false.rs | 15 +-- spec/rust/tests/test_nav_parent_false2.rs | 7 +- spec/rust/tests/test_nav_parent_override.rs | 11 ++- spec/rust/tests/test_nav_parent_switch.rs | 11 ++- .../tests/test_nav_parent_vs_value_inst.rs | 7 +- spec/rust/tests/test_nav_root.rs | 15 +-- spec/rust/tests/test_nested_same_name.rs | 9 +- spec/rust/tests/test_nested_same_name2.rs | 15 +-- spec/rust/tests/test_nested_types.rs | 11 ++- spec/rust/tests/test_nested_types2.rs | 19 ++-- spec/rust/tests/test_nested_types3.rs | 15 +-- spec/rust/tests/test_non_standard.rs | 7 +- spec/rust/tests/test_params_call_short.rs | 11 ++- spec/rust/tests/test_params_enum.rs | 9 +- spec/rust/tests/test_params_pass_usertype.rs | 9 +- spec/rust/tests/test_position_abs.rs | 9 +- spec/rust/tests/test_position_in_seq.rs | 7 +- spec/rust/tests/test_position_to_end.rs | 9 +- spec/rust/tests/test_process_coerce_bytes.rs | 13 +-- spec/rust/tests/test_process_coerce_switch.rs | 15 --- .../tests/test_process_coerce_usertype1.rs | 13 +-- .../tests/test_process_coerce_usertype2.rs | 13 +-- spec/rust/tests/test_process_custom.rs | 11 ++- spec/rust/tests/test_process_rotate.rs | 11 ++- spec/rust/tests/test_process_to_user.rs | 7 +- spec/rust/tests/test_process_xor4_const.rs | 9 +- spec/rust/tests/test_process_xor4_value.rs | 9 +- spec/rust/tests/test_process_xor_const.rs | 9 +- spec/rust/tests/test_process_xor_value.rs | 9 +- spec/rust/tests/test_recursive_one.rs | 13 +-- spec/rust/tests/test_repeat_eos_bit.rs | 7 +- spec/rust/tests/test_repeat_eos_struct.rs | 15 +-- spec/rust/tests/test_repeat_eos_u4.rs | 7 +- spec/rust/tests/test_repeat_n_struct.rs | 15 +-- spec/rust/tests/test_repeat_n_strz.rs | 9 +- spec/rust/tests/test_repeat_n_strz_double.rs | 11 ++- spec/rust/tests/test_repeat_until_complex.rs | 35 +++---- spec/rust/tests/test_repeat_until_s4.rs | 9 +- spec/rust/tests/test_repeat_until_sized.rs | 19 ++-- spec/rust/tests/test_str_encodings.rs | 16 --- spec/rust/tests/test_str_encodings_default.rs | 16 --- spec/rust/tests/test_str_eos.rs | 7 +- spec/rust/tests/test_str_literals2.rs | 13 +-- spec/rust/tests/test_str_pad_term.rs | 13 +-- spec/rust/tests/test_str_pad_term_empty.rs | 13 +-- spec/rust/tests/test_switch_bytearray.rs | 23 ++--- spec/rust/tests/test_switch_integers.rs | 23 ++--- spec/rust/tests/test_switch_integers2.rs | 15 +-- spec/rust/tests/test_switch_manual_enum.rs | 23 ++--- spec/rust/tests/test_switch_manual_int.rs | 23 ++--- .../rust/tests/test_switch_manual_int_else.rs | 23 ++--- .../tests/test_switch_manual_int_size_else.rs | 25 ++--- spec/rust/tests/test_switch_manual_str.rs | 23 ++--- .../rust/tests/test_switch_manual_str_else.rs | 23 ++--- spec/rust/tests/test_term_bytes.rs | 11 ++- spec/rust/tests/test_term_strz.rs | 11 ++- spec/rust/tests/test_ts_packet_header.rs | 19 ++-- spec/rust/tests/test_type_int_unary_op.rs | 13 +-- spec/rust/tests/test_type_ternary.rs | 7 +- spec/rust/tests/test_user_type.rs | 9 +- spec/rust/tests/test_zlib_with_header_78.rs | 7 +- .../specgenerators/RustSG.scala | 98 ++++++++++++++++--- 131 files changed, 1090 insertions(+), 925 deletions(-) create mode 100644 spec/rust/tests/test_enum_invalid.rs delete mode 100644 spec/rust/tests/test_process_coerce_switch.rs delete mode 100644 spec/rust/tests/test_str_encodings.rs delete mode 100644 spec/rust/tests/test_str_encodings_default.rs diff --git a/ci-rust b/ci-rust index 0bcb65c81..a7bda0545 100755 --- a/ci-rust +++ b/ci-rust @@ -4,7 +4,7 @@ set -eu mkdir -p "$TEST_OUT_DIR/rust" -rm -r "spec/rust/src" +rm -rf "spec/rust/src" mkdir -p "spec/rust/src/" for rs in $(ls "$FORMATS_COMPILED_DIR/rust/"); do cp "$FORMATS_COMPILED_DIR/rust/$rs" "spec/rust/src" diff --git a/spec/rust/tests/test_bcd_user_type_be.rs b/spec/rust/tests/test_bcd_user_type_be.rs index 6d85d58e8..d336146b0 100644 --- a/spec/rust/tests/test_bcd_user_type_be.rs +++ b/spec/rust/tests/test_bcd_user_type_be.rs @@ -1,18 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::bcd_user_type_be::BcdUserTypeBe; +use kaitai_test::bcd_user_type_be::*; use std::fs; #[test] fn test_bcd_user_type_be() { let data = fs::read("../../src/bcd_user_type_be.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = BcdUserTypeBe::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.ltr.as_int, 12345678); - // assert_eq!(r.ltr.as_str, "12345678"); - // assert_eq!(r.rtl.as_int, 87654321); - // assert_eq!(r.rtl.as_str, "87654321"); - // assert_eq!(r.leading_zero_ltr.as_int, 123456); - // assert_eq!(r.leading_zero_ltr.as_str, "00123456"); + let mut r = BcdUserTypeBe::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(ltr)),identifier(as_int)), IntNum(12345678)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(ltr)),identifier(as_str)), Str(12345678)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(rtl)),identifier(as_int)), IntNum(87654321)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(rtl)),identifier(as_str)), Str(87654321)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(leading_zero_ltr)),identifier(as_int)), IntNum(123456)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(leading_zero_ltr)),identifier(as_str)), Str(00123456)) } diff --git a/spec/rust/tests/test_bcd_user_type_le.rs b/spec/rust/tests/test_bcd_user_type_le.rs index cee6e1575..9dad1e810 100644 --- a/spec/rust/tests/test_bcd_user_type_le.rs +++ b/spec/rust/tests/test_bcd_user_type_le.rs @@ -1,18 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::bcd_user_type_le::BcdUserTypeLe; +use kaitai_test::bcd_user_type_le::*; use std::fs; #[test] fn test_bcd_user_type_le() { let data = fs::read("../../src/bcd_user_type_le.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = BcdUserTypeLe::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.ltr.as_int, 12345678); - // assert_eq!(r.ltr.as_str, "12345678"); - // assert_eq!(r.rtl.as_int, 87654321); - // assert_eq!(r.rtl.as_str, "87654321"); - // assert_eq!(r.leading_zero_ltr.as_int, 123456); - // assert_eq!(r.leading_zero_ltr.as_str, "00123456"); + let mut r = BcdUserTypeLe::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(ltr)),identifier(as_int)), IntNum(12345678)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(ltr)),identifier(as_str)), Str(12345678)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(rtl)),identifier(as_int)), IntNum(87654321)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(rtl)),identifier(as_str)), Str(87654321)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(leading_zero_ltr)),identifier(as_int)), IntNum(123456)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(leading_zero_ltr)),identifier(as_str)), Str(00123456)) } diff --git a/spec/rust/tests/test_bits_byte_aligned.rs b/spec/rust/tests/test_bits_byte_aligned.rs index e13314821..85544ad8b 100644 --- a/spec/rust/tests/test_bits_byte_aligned.rs +++ b/spec/rust/tests/test_bits_byte_aligned.rs @@ -1,21 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::bits_byte_aligned::BitsByteAligned; +use kaitai_test::bits_byte_aligned::*; use std::fs; #[test] fn test_bits_byte_aligned() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = BitsByteAligned::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.one, 20); - // assert_eq!(r.byte_1, 65); - // assert_eq!(r.two, 2); - // assert_eq!(r.three, false); - // assert_eq!(r.byte_2, 75); - // assert_eq!(r.four, 2892); - // assert_eq!(r.byte_3, vec!([0xff])); - // assert_eq!(r.full_byte, 255); - // assert_eq!(r.byte_4, 80); + let mut r = BitsByteAligned::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.one, 20); + assert_eq!(r.byte_1, 65); + assert_eq!(r.two, 2); + assert_eq!(r.three, false); + assert_eq!(r.byte_2, 75); + assert_eq!(r.four, 2892); + assert_eq!(r.byte_3, &[0xff]); + assert_eq!(r.full_byte, 255); + assert_eq!(r.byte_4, 80); } diff --git a/spec/rust/tests/test_bits_enum.rs b/spec/rust/tests/test_bits_enum.rs index 333f2d404..3d80fb639 100644 --- a/spec/rust/tests/test_bits_enum.rs +++ b/spec/rust/tests/test_bits_enum.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::bits_enum::BitsEnum; +use kaitai_test::bits_enum::*; use std::fs; #[test] fn test_bits_enum() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = BitsEnum::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.one, animal::PLATYPUS); - // assert_eq!(r.two, animal::HORSE); - // assert_eq!(r.three, animal::CAT); + let mut r = BitsEnum::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(one)), EnumByLabel(identifier(animal),identifier(platypus),typeId(false,ArrayBuffer(bits_enum),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(two)), EnumByLabel(identifier(animal),identifier(horse),typeId(false,ArrayBuffer(bits_enum),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(three)), EnumByLabel(identifier(animal),identifier(cat),typeId(false,ArrayBuffer(bits_enum),false))) } diff --git a/spec/rust/tests/test_bits_simple.rs b/spec/rust/tests/test_bits_simple.rs index 12bebc6b5..621297c1d 100644 --- a/spec/rust/tests/test_bits_simple.rs +++ b/spec/rust/tests/test_bits_simple.rs @@ -1,26 +1,27 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::bits_simple::BitsSimple; +use kaitai_test::bits_simple::*; use std::fs; #[test] fn test_bits_simple() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = BitsSimple::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.byte_1, 80); - // assert_eq!(r.byte_2, 65); - // assert_eq!(r.bits_a, false); - // assert_eq!(r.bits_b, 4); - // assert_eq!(r.bits_c, 3); - // assert_eq!(r.large_bits_1, 300); - // assert_eq!(r.spacer, 5); - // assert_eq!(r.large_bits_2, 1329); - // assert_eq!(r.normal_s2, -1); - // assert_eq!(r.byte_8_9_10, 5259587); - // assert_eq!(r.byte_11_to_14, 1261262125); - // assert_eq!(r.byte_15_to_19, 293220057087); - // assert_eq!(r.byte_20_to_27, 18446744073709551615); - // assert_eq!(r.test_if_b1, 123); + let mut r = BitsSimple::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.byte_1, 80); + assert_eq!(r.byte_2, 65); + assert_eq!(r.bits_a, false); + assert_eq!(r.bits_b, 4); + assert_eq!(r.bits_c, 3); + assert_eq!(r.large_bits_1, 300); + assert_eq!(r.spacer, 5); + assert_eq!(r.large_bits_2, 1329); + assert_eq!(r.normal_s2, -1); + assert_eq!(r.byte_8_9_10, 5259587); + assert_eq!(r.byte_11_to_14, 1261262125); + assert_eq!(r.byte_15_to_19, 293220057087); + assert_eq!(r.byte_20_to_27, 18446744073709551615); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(test_if_b1)), IntNum(123)) } diff --git a/spec/rust/tests/test_buffered_struct.rs b/spec/rust/tests/test_buffered_struct.rs index bc224b560..e9f3a021f 100644 --- a/spec/rust/tests/test_buffered_struct.rs +++ b/spec/rust/tests/test_buffered_struct.rs @@ -1,19 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::buffered_struct::BufferedStruct; +use kaitai_test::buffered_struct::*; use std::fs; #[test] fn test_buffered_struct() { let data = fs::read("../../src/buffered_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = BufferedStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.len1, 16); - // assert_eq!(r.block1.number1, 66); - // assert_eq!(r.block1.number2, 67); - // assert_eq!(r.len2, 8); - // assert_eq!(r.block2.number1, 68); - // assert_eq!(r.block2.number2, 69); - // assert_eq!(r.finisher, 238); + let mut r = BufferedStruct::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.len1, 16); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(block1)),identifier(number1)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(block1)),identifier(number2)), IntNum(67)) + assert_eq!(r.len2, 8); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(block2)),identifier(number1)), IntNum(68)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(block2)),identifier(number2)), IntNum(69)) + assert_eq!(r.finisher, 238); } diff --git a/spec/rust/tests/test_bytes_pad_term.rs b/spec/rust/tests/test_bytes_pad_term.rs index a45f0df92..522f57323 100644 --- a/spec/rust/tests/test_bytes_pad_term.rs +++ b/spec/rust/tests/test_bytes_pad_term.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::bytes_pad_term::BytesPadTerm; +use kaitai_test::bytes_pad_term::*; use std::fs; #[test] fn test_bytes_pad_term() { let data = fs::read("../../src/str_pad_term.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = BytesPadTerm::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.str_pad, vec!([0x73, 0x74, 0x72, 0x31])); - // assert_eq!(r.str_term, vec!([0x73, 0x74, 0x72, 0x32, 0x66, 0x6f, 0x6f])); - // assert_eq!(r.str_term_and_pad, vec!([0x73, 0x74, 0x72, 0x2b, 0x2b, 0x2b, 0x33, 0x62, 0x61, 0x72, 0x2b, 0x2b, 0x2b])); - // assert_eq!(r.str_term_include, vec!([0x73, 0x74, 0x72, 0x34, 0x62, 0x61, 0x7a, 0x40])); + let mut r = BytesPadTerm::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.str_pad, &[0x73, 0x74, 0x72, 0x31]); + assert_eq!(r.str_term, &[0x73, 0x74, 0x72, 0x32, 0x66, 0x6f, 0x6f]); + assert_eq!(r.str_term_and_pad, &[0x73, 0x74, 0x72, 0x2b, 0x2b, 0x2b, 0x33, 0x62, 0x61, 0x72, 0x2b, 0x2b, 0x2b]); + assert_eq!(r.str_term_include, &[0x73, 0x74, 0x72, 0x34, 0x62, 0x61, 0x7a, 0x40]); } diff --git a/spec/rust/tests/test_cast_nested.rs b/spec/rust/tests/test_cast_nested.rs index 6d59aa86f..84845d4b6 100644 --- a/spec/rust/tests/test_cast_nested.rs +++ b/spec/rust/tests/test_cast_nested.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::cast_nested::CastNested; +use kaitai_test::cast_nested::*; use std::fs; #[test] fn test_cast_nested() { let data = fs::read("../../src/switch_opcodes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = CastNested::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.opcodes_0_str.value, "foobar"); - // assert_eq!(r.opcodes_0_str_value, "foobar"); - // assert_eq!(r.opcodes_1_int.value, 66); - // assert_eq!(r.opcodes_1_int_value, 66); + let mut r = CastNested::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(opcodes_0_str)),identifier(value)), Str(foobar)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(opcodes_0_str_value)), Str(foobar)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(opcodes_1_int)),identifier(value)), IntNum(66)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(opcodes_1_int_value)), IntNum(66)) } diff --git a/spec/rust/tests/test_cast_to_imported.rs b/spec/rust/tests/test_cast_to_imported.rs index c0b55622c..e3380e8cc 100644 --- a/spec/rust/tests/test_cast_to_imported.rs +++ b/spec/rust/tests/test_cast_to_imported.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::cast_to_imported::CastToImported; +use kaitai_test::cast_to_imported::*; use std::fs; #[test] fn test_cast_to_imported() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = CastToImported::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.one.one, 80); - // assert_eq!(r.one_casted.one, 80); + let mut r = CastToImported::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one)),identifier(one)), IntNum(80)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one_casted)),identifier(one)), IntNum(80)) } diff --git a/spec/rust/tests/test_cast_to_top.rs b/spec/rust/tests/test_cast_to_top.rs index 7a4d4f3b8..107baef40 100644 --- a/spec/rust/tests/test_cast_to_top.rs +++ b/spec/rust/tests/test_cast_to_top.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::cast_to_top::CastToTop; +use kaitai_test::cast_to_top::*; use std::fs; #[test] fn test_cast_to_top() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = CastToTop::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.code, 80); - // assert_eq!(r.header.code, 65); - // assert_eq!(r.header_casted.code, 65); + let mut r = CastToTop::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.code, 80); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(header)),identifier(code)), IntNum(65)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(header_casted)),identifier(code)), IntNum(65)) } diff --git a/spec/rust/tests/test_default_big_endian.rs b/spec/rust/tests/test_default_big_endian.rs index 160780cda..db2d6bd2e 100644 --- a/spec/rust/tests/test_default_big_endian.rs +++ b/spec/rust/tests/test_default_big_endian.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::default_big_endian::DefaultBigEndian; +use kaitai_test::default_big_endian::*; use std::fs; #[test] fn test_default_big_endian() { let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = DefaultBigEndian::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.one, 117440512); + let mut r = DefaultBigEndian::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.one, 117440512); } diff --git a/spec/rust/tests/test_default_endian_expr_inherited.rs b/spec/rust/tests/test_default_endian_expr_inherited.rs index 15993266a..808430a09 100644 --- a/spec/rust/tests/test_default_endian_expr_inherited.rs +++ b/spec/rust/tests/test_default_endian_expr_inherited.rs @@ -1,27 +1,28 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::default_endian_expr_inherited::DefaultEndianExprInherited; +use kaitai_test::default_endian_expr_inherited::*; use std::fs; #[test] fn test_default_endian_expr_inherited() { let data = fs::read("../../src/endian_expr.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = DefaultEndianExprInherited::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); - // assert_eq!(r.docs[0].main.insides.some_int, 66); - // assert_eq!(r.docs[0].main.insides.more.some_int1, 16896); - // assert_eq!(r.docs[0].main.insides.more.some_int2, 66); - // assert_eq!(r.docs[0].main.insides.more.some_inst, 66); - // assert_eq!(r.docs[1].indicator, vec!([0x4d, 0x4d])); - // assert_eq!(r.docs[1].main.insides.some_int, 66); - // assert_eq!(r.docs[1].main.insides.more.some_int1, 66); - // assert_eq!(r.docs[1].main.insides.more.some_int2, 16896); - // assert_eq!(r.docs[1].main.insides.more.some_inst, 1107296256); - // assert_eq!(r.docs[2].indicator, vec!([0x58, 0x58])); - // assert_eq!(r.docs[2].main.insides.some_int, 66); - // assert_eq!(r.docs[2].main.insides.more.some_int1, 66); - // assert_eq!(r.docs[2].main.insides.more.some_int2, 16896); - // assert_eq!(r.docs[2].main.insides.more.some_inst, 1107296256); + let mut r = DefaultEndianExprInherited::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(indicator)), List(ArrayBuffer(IntNum(73), IntNum(73)))) + // assert_eq!(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(main)),identifier(insides)),identifier(some_int)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(main)),identifier(insides)),identifier(more)),identifier(some_int1)), IntNum(16896)) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(main)),identifier(insides)),identifier(more)),identifier(some_int2)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(main)),identifier(insides)),identifier(more)),identifier(some_inst)), IntNum(66)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(indicator)), List(ArrayBuffer(IntNum(77), IntNum(77)))) + // assert_eq!(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(main)),identifier(insides)),identifier(some_int)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(main)),identifier(insides)),identifier(more)),identifier(some_int1)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(main)),identifier(insides)),identifier(more)),identifier(some_int2)), IntNum(16896)) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(main)),identifier(insides)),identifier(more)),identifier(some_inst)), IntNum(1107296256)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(indicator)), List(ArrayBuffer(IntNum(88), IntNum(88)))) + // assert_eq!(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(main)),identifier(insides)),identifier(some_int)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(main)),identifier(insides)),identifier(more)),identifier(some_int1)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(main)),identifier(insides)),identifier(more)),identifier(some_int2)), IntNum(16896)) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(main)),identifier(insides)),identifier(more)),identifier(some_inst)), IntNum(1107296256)) } diff --git a/spec/rust/tests/test_default_endian_expr_is_be.rs b/spec/rust/tests/test_default_endian_expr_is_be.rs index b7465684d..6d6e258e8 100644 --- a/spec/rust/tests/test_default_endian_expr_is_be.rs +++ b/spec/rust/tests/test_default_endian_expr_is_be.rs @@ -1,30 +1,31 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::default_endian_expr_is_be::DefaultEndianExprIsBe; +use kaitai_test::default_endian_expr_is_be::*; use std::fs; #[test] fn test_default_endian_expr_is_be() { let data = fs::read("../../src/endian_expr.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = DefaultEndianExprIsBe::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); - // assert_eq!(r.docs[0].main.some_int, 66); - // assert_eq!(r.docs[0].main.some_int_be, 66); - // assert_eq!(r.docs[0].main.some_int_le, 66); - // assert_eq!(r.docs[0].main.inst_int, 66); - // assert_eq!(r.docs[0].main.inst_sub.foo, 66); - // assert_eq!(r.docs[1].indicator, vec!([0x4d, 0x4d])); - // assert_eq!(r.docs[1].main.some_int, 66); - // assert_eq!(r.docs[1].main.some_int_be, 66); - // assert_eq!(r.docs[1].main.some_int_le, 66); - // assert_eq!(r.docs[1].main.inst_int, 1107296256); - // assert_eq!(r.docs[1].main.inst_sub.foo, 1107296256); - // assert_eq!(r.docs[2].indicator, vec!([0x58, 0x58])); - // assert_eq!(r.docs[2].main.some_int, 1107296256); - // assert_eq!(r.docs[2].main.some_int_be, 66); - // assert_eq!(r.docs[2].main.some_int_le, 66); - // assert_eq!(r.docs[2].main.inst_int, 66); - // assert_eq!(r.docs[2].main.inst_sub.foo, 66); + let mut r = DefaultEndianExprIsBe::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(indicator)), List(ArrayBuffer(IntNum(73), IntNum(73)))) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(main)),identifier(some_int)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(main)),identifier(some_int_be)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(main)),identifier(some_int_le)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(main)),identifier(inst_int)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(main)),identifier(inst_sub)),identifier(foo)), IntNum(66)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(indicator)), List(ArrayBuffer(IntNum(77), IntNum(77)))) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(main)),identifier(some_int)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(main)),identifier(some_int_be)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(main)),identifier(some_int_le)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(main)),identifier(inst_int)), IntNum(1107296256)) + // assert_eq!(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(main)),identifier(inst_sub)),identifier(foo)), IntNum(1107296256)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(indicator)), List(ArrayBuffer(IntNum(88), IntNum(88)))) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(main)),identifier(some_int)), IntNum(1107296256)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(main)),identifier(some_int_be)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(main)),identifier(some_int_le)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(main)),identifier(inst_int)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(main)),identifier(inst_sub)),identifier(foo)), IntNum(66)) } diff --git a/spec/rust/tests/test_default_endian_expr_is_le.rs b/spec/rust/tests/test_default_endian_expr_is_le.rs index ee21fb530..18ff4f5a7 100644 --- a/spec/rust/tests/test_default_endian_expr_is_le.rs +++ b/spec/rust/tests/test_default_endian_expr_is_le.rs @@ -1,24 +1,25 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::default_endian_expr_is_le::DefaultEndianExprIsLe; +use kaitai_test::default_endian_expr_is_le::*; use std::fs; #[test] fn test_default_endian_expr_is_le() { let data = fs::read("../../src/endian_expr.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = DefaultEndianExprIsLe::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); - // assert_eq!(r.docs[0].main.some_int, 66); - // assert_eq!(r.docs[0].main.some_int_be, 66); - // assert_eq!(r.docs[0].main.some_int_le, 66); - // assert_eq!(r.docs[1].indicator, vec!([0x4d, 0x4d])); - // assert_eq!(r.docs[1].main.some_int, 66); - // assert_eq!(r.docs[1].main.some_int_be, 66); - // assert_eq!(r.docs[1].main.some_int_le, 66); - // assert_eq!(r.docs[2].indicator, vec!([0x58, 0x58])); - // assert_eq!(r.docs[2].main.some_int, 66); - // assert_eq!(r.docs[2].main.some_int_be, 66); - // assert_eq!(r.docs[2].main.some_int_le, 66); + let mut r = DefaultEndianExprIsLe::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(indicator)), List(ArrayBuffer(IntNum(73), IntNum(73)))) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(main)),identifier(some_int)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(main)),identifier(some_int_be)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(0)),identifier(main)),identifier(some_int_le)), IntNum(66)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(indicator)), List(ArrayBuffer(IntNum(77), IntNum(77)))) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(main)),identifier(some_int)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(main)),identifier(some_int_be)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(1)),identifier(main)),identifier(some_int_le)), IntNum(66)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(indicator)), List(ArrayBuffer(IntNum(88), IntNum(88)))) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(main)),identifier(some_int)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(main)),identifier(some_int_be)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(docs)),IntNum(2)),identifier(main)),identifier(some_int_le)), IntNum(66)) } diff --git a/spec/rust/tests/test_default_endian_mod.rs b/spec/rust/tests/test_default_endian_mod.rs index 33b01c285..0491abccf 100644 --- a/spec/rust/tests/test_default_endian_mod.rs +++ b/spec/rust/tests/test_default_endian_mod.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::default_endian_mod::DefaultEndianMod; +use kaitai_test::default_endian_mod::*; use std::fs; #[test] fn test_default_endian_mod() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = DefaultEndianMod::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.main.one, 1262698832); - // assert_eq!(r.main.nest.two, -52947); - // assert_eq!(r.main.nest_be.two, 1346454347); + let mut r = DefaultEndianMod::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(main)),identifier(one)), IntNum(1262698832)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(main)),identifier(nest)),identifier(two)), UnaryOp(Minus,IntNum(52947))) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(main)),identifier(nest_be)),identifier(two)), IntNum(1346454347)) } diff --git a/spec/rust/tests/test_docstrings.rs b/spec/rust/tests/test_docstrings.rs index 9ec3e6cd8..4487b6243 100644 --- a/spec/rust/tests/test_docstrings.rs +++ b/spec/rust/tests/test_docstrings.rs @@ -1,12 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::docstrings::Docstrings; +use kaitai_test::docstrings::*; use std::fs; #[test] fn test_docstrings() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = Docstrings::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + let mut r = Docstrings::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); } diff --git a/spec/rust/tests/test_docstrings_docref.rs b/spec/rust/tests/test_docstrings_docref.rs index dac79007e..079ea5054 100644 --- a/spec/rust/tests/test_docstrings_docref.rs +++ b/spec/rust/tests/test_docstrings_docref.rs @@ -1,12 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::docstrings_docref::DocstringsDocref; +use kaitai_test::docstrings_docref::*; use std::fs; #[test] fn test_docstrings_docref() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = DocstringsDocref::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + let mut r = DocstringsDocref::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); } diff --git a/spec/rust/tests/test_docstrings_docref_multi.rs b/spec/rust/tests/test_docstrings_docref_multi.rs index fac750220..b230d3b91 100644 --- a/spec/rust/tests/test_docstrings_docref_multi.rs +++ b/spec/rust/tests/test_docstrings_docref_multi.rs @@ -1,12 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::docstrings_docref_multi::DocstringsDocrefMulti; +use kaitai_test::docstrings_docref_multi::*; use std::fs; #[test] fn test_docstrings_docref_multi() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = DocstringsDocrefMulti::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + let mut r = DocstringsDocrefMulti::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); } diff --git a/spec/rust/tests/test_enum_0.rs b/spec/rust/tests/test_enum_0.rs index 9789a6b81..8292c0d50 100644 --- a/spec/rust/tests/test_enum_0.rs +++ b/spec/rust/tests/test_enum_0.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::enum_0::Enum0; +use kaitai_test::enum_0::*; use std::fs; #[test] fn test_enum_0() { let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = Enum0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.pet_1, animal::CAT); - // assert_eq!(r.pet_2, animal::CHICKEN); + let mut r = Enum0::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_1)), EnumByLabel(identifier(animal),identifier(cat),typeId(false,ArrayBuffer(enum_0),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_2)), EnumByLabel(identifier(animal),identifier(chicken),typeId(false,ArrayBuffer(enum_0),false))) } diff --git a/spec/rust/tests/test_enum_1.rs b/spec/rust/tests/test_enum_1.rs index 65c999216..67b442448 100644 --- a/spec/rust/tests/test_enum_1.rs +++ b/spec/rust/tests/test_enum_1.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::enum_1::Enum1; +use kaitai_test::enum_1::*; use std::fs; #[test] fn test_enum_1() { let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = Enum1::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.main.submain.pet_1, animal::CAT); - // assert_eq!(r.main.submain.pet_2, animal::CHICKEN); + let mut r = Enum1::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(main)),identifier(submain)),identifier(pet_1)), EnumByLabel(identifier(animal),identifier(cat),typeId(false,ArrayBuffer(enum_1, main_obj),false))) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(main)),identifier(submain)),identifier(pet_2)), EnumByLabel(identifier(animal),identifier(chicken),typeId(false,ArrayBuffer(enum_1, main_obj),false))) } diff --git a/spec/rust/tests/test_enum_deep.rs b/spec/rust/tests/test_enum_deep.rs index 3388e3df9..783fd9f5a 100644 --- a/spec/rust/tests/test_enum_deep.rs +++ b/spec/rust/tests/test_enum_deep.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::enum_deep::EnumDeep; +use kaitai_test::enum_deep::*; use std::fs; #[test] fn test_enum_deep() { let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = EnumDeep::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.pet_1, animal::CAT); - // assert_eq!(r.pet_2, animal::HARE); + let mut r = EnumDeep::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_1)), EnumByLabel(identifier(animal),identifier(cat),typeId(false,ArrayBuffer(enum_deep, container1),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_2)), EnumByLabel(identifier(animal),identifier(hare),typeId(false,ArrayBuffer(enum_deep, container1, container2),false))) } diff --git a/spec/rust/tests/test_enum_deep_literals.rs b/spec/rust/tests/test_enum_deep_literals.rs index 9adbe1b51..38158ba78 100644 --- a/spec/rust/tests/test_enum_deep_literals.rs +++ b/spec/rust/tests/test_enum_deep_literals.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::enum_deep_literals::EnumDeepLiterals; +use kaitai_test::enum_deep_literals::*; use std::fs; #[test] fn test_enum_deep_literals() { let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = EnumDeepLiterals::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.is_pet_1_ok, true); - // assert_eq!(r.is_pet_2_ok, true); + let mut r = EnumDeepLiterals::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_pet_1_ok)), Bool(true)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_pet_2_ok)), Bool(true)) } diff --git a/spec/rust/tests/test_enum_fancy.rs b/spec/rust/tests/test_enum_fancy.rs index 976da00e0..29fa588cc 100644 --- a/spec/rust/tests/test_enum_fancy.rs +++ b/spec/rust/tests/test_enum_fancy.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::enum_fancy::EnumFancy; +use kaitai_test::enum_fancy::*; use std::fs; #[test] fn test_enum_fancy() { let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = EnumFancy::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.pet_1, animal::CAT); - // assert_eq!(r.pet_2, animal::CHICKEN); + let mut r = EnumFancy::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_1)), EnumByLabel(identifier(animal),identifier(cat),typeId(false,ArrayBuffer(enum_fancy),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_2)), EnumByLabel(identifier(animal),identifier(chicken),typeId(false,ArrayBuffer(enum_fancy),false))) } diff --git a/spec/rust/tests/test_enum_if.rs b/spec/rust/tests/test_enum_if.rs index a3327f652..3cd6b7228 100644 --- a/spec/rust/tests/test_enum_if.rs +++ b/spec/rust/tests/test_enum_if.rs @@ -1,19 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::enum_if::EnumIf; +use kaitai_test::enum_if::*; use std::fs; #[test] fn test_enum_if() { let data = fs::read("../../src/if_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = EnumIf::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.op1.opcode, opcodes::A_STRING); - // assert_eq!(r.op1.arg_str.str, "foo"); - // assert_eq!(r.op2.opcode, opcodes::A_TUPLE); - // assert_eq!(r.op2.arg_tuple.num1, 66); - // assert_eq!(r.op2.arg_tuple.num2, 67); - // assert_eq!(r.op3.opcode, opcodes::A_STRING); - // assert_eq!(r.op3.arg_str.str, "bar"); + let mut r = EnumIf::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op1)),identifier(opcode)), EnumByLabel(identifier(opcodes),identifier(a_string),typeId(false,ArrayBuffer(enum_if),false))) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op1)),identifier(arg_str)),identifier(str)), Str(foo)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op2)),identifier(opcode)), EnumByLabel(identifier(opcodes),identifier(a_tuple),typeId(false,ArrayBuffer(enum_if),false))) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op2)),identifier(arg_tuple)),identifier(num1)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op2)),identifier(arg_tuple)),identifier(num2)), IntNum(67)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op3)),identifier(opcode)), EnumByLabel(identifier(opcodes),identifier(a_string),typeId(false,ArrayBuffer(enum_if),false))) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op3)),identifier(arg_str)),identifier(str)), Str(bar)) } diff --git a/spec/rust/tests/test_enum_invalid.rs b/spec/rust/tests/test_enum_invalid.rs new file mode 100644 index 000000000..0eefe8c70 --- /dev/null +++ b/spec/rust/tests/test_enum_invalid.rs @@ -0,0 +1,15 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use kaitai::{BytesReader, KStruct, KStructUnit}; +use kaitai_test::enum_invalid::*; +use std::fs; + +#[test] +fn test_enum_invalid() { + let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); + let reader = BytesReader::new(&data[..]); + let mut r = EnumInvalid::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_1)), EnumByLabel(identifier(animal),identifier(dog),typeId(false,List(),false))) + // nullAsset(r.pet_2); +} diff --git a/spec/rust/tests/test_enum_negative.rs b/spec/rust/tests/test_enum_negative.rs index 4f8efe078..38ef4dc7c 100644 --- a/spec/rust/tests/test_enum_negative.rs +++ b/spec/rust/tests/test_enum_negative.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::enum_negative::EnumNegative; +use kaitai_test::enum_negative::*; use std::fs; #[test] fn test_enum_negative() { let data = fs::read("../../src/enum_negative.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = EnumNegative::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.f1, constants::NEGATIVE_ONE); - // assert_eq!(r.f2, constants::POSITIVE_ONE); + let mut r = EnumNegative::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(f1)), EnumByLabel(identifier(constants),identifier(negative_one),typeId(false,ArrayBuffer(enum_negative),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(f2)), EnumByLabel(identifier(constants),identifier(positive_one),typeId(false,ArrayBuffer(enum_negative),false))) } diff --git a/spec/rust/tests/test_enum_of_value_inst.rs b/spec/rust/tests/test_enum_of_value_inst.rs index b0f6dd8ed..aa5fe526d 100644 --- a/spec/rust/tests/test_enum_of_value_inst.rs +++ b/spec/rust/tests/test_enum_of_value_inst.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::enum_of_value_inst::EnumOfValueInst; +use kaitai_test::enum_of_value_inst::*; use std::fs; #[test] fn test_enum_of_value_inst() { let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = EnumOfValueInst::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.pet_1, animal::CAT); - // assert_eq!(r.pet_2, animal::CHICKEN); - // assert_eq!(r.pet_3, animal::DOG); - // assert_eq!(r.pet_4, animal::DOG); + let mut r = EnumOfValueInst::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_1)), EnumByLabel(identifier(animal),identifier(cat),typeId(false,ArrayBuffer(enum_of_value_inst),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_2)), EnumByLabel(identifier(animal),identifier(chicken),typeId(false,ArrayBuffer(enum_of_value_inst),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_3)), EnumByLabel(identifier(animal),identifier(dog),typeId(false,ArrayBuffer(enum_of_value_inst),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_4)), EnumByLabel(identifier(animal),identifier(dog),typeId(false,ArrayBuffer(enum_of_value_inst),false))) } diff --git a/spec/rust/tests/test_enum_to_i.rs b/spec/rust/tests/test_enum_to_i.rs index 663ba13e6..517f863cc 100644 --- a/spec/rust/tests/test_enum_to_i.rs +++ b/spec/rust/tests/test_enum_to_i.rs @@ -1,17 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::enum_to_i::EnumToI; +use kaitai_test::enum_to_i::*; use std::fs; #[test] fn test_enum_to_i() { let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = EnumToI::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.pet_1, animal::CAT); - // assert_eq!(r.pet_2, animal::CHICKEN); - // assert_eq!(r.pet_1_i, 7); - // assert_eq!(r.pet_1_mod, 32775); - // assert_eq!(r.one_lt_two, true); + let mut r = EnumToI::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_1)), EnumByLabel(identifier(animal),identifier(cat),typeId(false,ArrayBuffer(enum_to_i),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_2)), EnumByLabel(identifier(animal),identifier(chicken),typeId(false,ArrayBuffer(enum_to_i),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_1_i)), IntNum(7)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(pet_1_mod)), IntNum(32775)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(one_lt_two)), Bool(true)) } diff --git a/spec/rust/tests/test_expr_0.rs b/spec/rust/tests/test_expr_0.rs index 5c75d2498..b4e60efa6 100644 --- a/spec/rust/tests/test_expr_0.rs +++ b/spec/rust/tests/test_expr_0.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_0::Expr0; +use kaitai_test::expr_0::*; use std::fs; #[test] fn test_expr_0() { let data = fs::read("../../src/str_encodings.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = Expr0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.must_be_f7, 247); - // assert_eq!(r.must_be_abc123, "abc123"); + let mut r = Expr0::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(must_be_f7)), IntNum(247)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(must_be_abc123)), Str(abc123)) } diff --git a/spec/rust/tests/test_expr_1.rs b/spec/rust/tests/test_expr_1.rs index 6a402f1e2..03d9a0252 100644 --- a/spec/rust/tests/test_expr_1.rs +++ b/spec/rust/tests/test_expr_1.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_1::Expr1; +use kaitai_test::expr_1::*; use std::fs; #[test] fn test_expr_1() { let data = fs::read("../../src/str_encodings.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = Expr1::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.len_of_1, 10); - // assert_eq!(r.len_of_1_mod, 8); - // assert_eq!(r.str1, "Some ASC"); - // assert_eq!(r.str1_len, 8); + let mut r = Expr1::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.len_of_1, 10); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(len_of_1_mod)), IntNum(8)) + assert_eq!(r.str1, "Some ASC"); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(str1_len)), IntNum(8)) } diff --git a/spec/rust/tests/test_expr_2.rs b/spec/rust/tests/test_expr_2.rs index efa6b787d..7ec22e089 100644 --- a/spec/rust/tests/test_expr_2.rs +++ b/spec/rust/tests/test_expr_2.rs @@ -1,29 +1,30 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_2::Expr2; +use kaitai_test::expr_2::*; use std::fs; #[test] fn test_expr_2() { let data = fs::read("../../src/str_encodings.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = Expr2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.str1.len_orig, 10); - // assert_eq!(r.str1.len_mod, 7); - // assert_eq!(r.str1.str, "Some AS"); - // assert_eq!(r.str1_len, 7); - // assert_eq!(r.str1_len_mod, 7); - // assert_eq!(r.str1_byte1, 73); - // assert_eq!(r.str1_avg, 73); - // assert_eq!(r.str1_char5, "e"); - // assert_eq!(r.str1_tuple5.byte0, 101); - // assert_eq!(r.str1_tuple5.byte0, 101); - // assert_eq!(r.str1_tuple5.byte1, 32); - // assert_eq!(r.str1_tuple5.byte2, 65); - // assert_eq!(r.str1_tuple5.avg, 48); - // assert_eq!(r.str2_tuple5.byte0, 101); - // assert_eq!(r.str2_tuple5.byte1, 32); - // assert_eq!(r.str2_tuple5.byte2, 65); - // assert_eq!(r.str2_tuple5.avg, 48); + let mut r = Expr2::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(str1)),identifier(len_orig)), IntNum(10)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(str1)),identifier(len_mod)), IntNum(7)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(str1)),identifier(str)), Str(Some AS)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(str1_len)), IntNum(7)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(str1_len_mod)), IntNum(7)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(str1_byte1)), IntNum(73)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(str1_avg)), IntNum(73)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(str1_char5)), Str(e)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(str1_tuple5)),identifier(byte0)), IntNum(101)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(str1_tuple5)),identifier(byte0)), IntNum(101)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(str1_tuple5)),identifier(byte1)), IntNum(32)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(str1_tuple5)),identifier(byte2)), IntNum(65)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(str1_tuple5)),identifier(avg)), IntNum(48)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(str2_tuple5)),identifier(byte0)), IntNum(101)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(str2_tuple5)),identifier(byte1)), IntNum(32)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(str2_tuple5)),identifier(byte2)), IntNum(65)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(str2_tuple5)),identifier(avg)), IntNum(48)) } diff --git a/spec/rust/tests/test_expr_3.rs b/spec/rust/tests/test_expr_3.rs index 1312c69dc..2dc0c09c7 100644 --- a/spec/rust/tests/test_expr_3.rs +++ b/spec/rust/tests/test_expr_3.rs @@ -1,24 +1,25 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_3::Expr3; +use kaitai_test::expr_3::*; use std::fs; #[test] fn test_expr_3() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = Expr3::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.one, 80); - // assert_eq!(r.two, "ACK"); - // assert_eq!(r.three, "@ACK"); - // assert_eq!(r.four, "_ACK_"); - // assert_eq!(r.is_str_eq, true); - // assert_eq!(r.is_str_ne, false); - // assert_eq!(r.is_str_lt, true); - // assert_eq!(r.is_str_gt, false); - // assert_eq!(r.is_str_le, true); - // assert_eq!(r.is_str_ge, false); - // assert_eq!(r.is_str_lt2, true); - // assert_eq!(r.test_not, true); + let mut r = Expr3::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.one, 80); + assert_eq!(r.two, "ACK"); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(three)), Str(@ACK)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(four)), Str(_ACK_)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_str_eq)), Bool(true)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_str_ne)), Bool(false)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_str_lt)), Bool(true)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_str_gt)), Bool(false)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_str_le)), Bool(true)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_str_ge)), Bool(false)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_str_lt2)), Bool(true)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(test_not)), Bool(true)) } diff --git a/spec/rust/tests/test_expr_array.rs b/spec/rust/tests/test_expr_array.rs index de38146c3..1ab3d71b6 100644 --- a/spec/rust/tests/test_expr_array.rs +++ b/spec/rust/tests/test_expr_array.rs @@ -1,27 +1,28 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_array::ExprArray; +use kaitai_test::expr_array::*; use std::fs; #[test] fn test_expr_array() { let data = fs::read("../../src/expr_array.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ExprArray::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.aint_size, 4); - // assert_eq!(r.aint_first, 7657765); - // assert_eq!(r.aint_last, 16272640); - // assert_eq!(r.aint_min, 49185); - // assert_eq!(r.aint_max, 1123362332); - // assert_eq!(r.afloat_size, 3); - // assert_eq!(r.afloat_first, -2.6839530254859364E-121); - // assert_eq!(r.afloat_last, -1.1103359815095273E-175); - // assert_eq!(r.afloat_min, -8.754689149998834E+288); - // assert_eq!(r.afloat_max, -1.1103359815095273E-175); - // assert_eq!(r.astr_size, 3); - // assert_eq!(r.astr_first, "foo"); - // assert_eq!(r.astr_last, "baz"); - // assert_eq!(r.astr_min, "bar"); - // assert_eq!(r.astr_max, "foo"); + let mut r = ExprArray::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(aint_size)), IntNum(4)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(aint_first)), IntNum(7657765)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(aint_last)), IntNum(16272640)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(aint_min)), IntNum(49185)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(aint_max)), IntNum(1123362332)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(afloat_size)), IntNum(3)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(afloat_first)), UnaryOp(Minus,FloatNum(2.6839530254859364E-121))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(afloat_last)), UnaryOp(Minus,FloatNum(1.1103359815095273E-175))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(afloat_min)), UnaryOp(Minus,FloatNum(8.754689149998834E+288))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(afloat_max)), UnaryOp(Minus,FloatNum(1.1103359815095273E-175))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(astr_size)), IntNum(3)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(astr_first)), Str(foo)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(astr_last)), Str(baz)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(astr_min)), Str(bar)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(astr_max)), Str(foo)) } diff --git a/spec/rust/tests/test_expr_bytes_cmp.rs b/spec/rust/tests/test_expr_bytes_cmp.rs index 1c37e8ee6..80e8dadf8 100644 --- a/spec/rust/tests/test_expr_bytes_cmp.rs +++ b/spec/rust/tests/test_expr_bytes_cmp.rs @@ -1,22 +1,23 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_bytes_cmp::ExprBytesCmp; +use kaitai_test::expr_bytes_cmp::*; use std::fs; #[test] fn test_expr_bytes_cmp() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ExprBytesCmp::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.one, vec!([0x50])); - // assert_eq!(r.two, vec!([0x41, 0x43, 0x4b])); - // assert_eq!(r.is_eq, true); - // assert_eq!(r.is_ne, false); - // assert_eq!(r.is_lt, true); - // assert_eq!(r.is_gt, false); - // assert_eq!(r.is_le, true); - // assert_eq!(r.is_ge, false); - // assert_eq!(r.is_lt2, false); - // assert_eq!(r.is_gt2, true); + let mut r = ExprBytesCmp::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.one, &[0x50]); + assert_eq!(r.two, &[0x41, 0x43, 0x4b]); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_eq)), Bool(true)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_ne)), Bool(false)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_lt)), Bool(true)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_gt)), Bool(false)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_le)), Bool(true)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_ge)), Bool(false)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_lt2)), Bool(false)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(is_gt2)), Bool(true)) } diff --git a/spec/rust/tests/test_expr_enum.rs b/spec/rust/tests/test_expr_enum.rs index 9f1525858..f496b93cd 100644 --- a/spec/rust/tests/test_expr_enum.rs +++ b/spec/rust/tests/test_expr_enum.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_enum::ExprEnum; +use kaitai_test::expr_enum::*; use std::fs; #[test] fn test_expr_enum() { let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ExprEnum::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.const_dog, animal::DOG); - // assert_eq!(r.derived_boom, animal::BOOM); - // assert_eq!(r.derived_dog, animal::DOG); + let mut r = ExprEnum::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(const_dog)), EnumByLabel(identifier(animal),identifier(dog),typeId(false,ArrayBuffer(expr_enum),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(derived_boom)), EnumByLabel(identifier(animal),identifier(boom),typeId(false,ArrayBuffer(expr_enum),false))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(derived_dog)), EnumByLabel(identifier(animal),identifier(dog),typeId(false,ArrayBuffer(expr_enum),false))) } diff --git a/spec/rust/tests/test_expr_io_pos.rs b/spec/rust/tests/test_expr_io_pos.rs index 688ae12a8..4ff9c2432 100644 --- a/spec/rust/tests/test_expr_io_pos.rs +++ b/spec/rust/tests/test_expr_io_pos.rs @@ -1,18 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_io_pos::ExprIoPos; +use kaitai_test::expr_io_pos::*; use std::fs; #[test] fn test_expr_io_pos() { let data = fs::read("../../src/expr_io_pos.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ExprIoPos::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.substream1.my_str, "CURIOSITY"); - // assert_eq!(r.substream1.body, vec!([0x11, 0x22, 0x33, 0x44])); - // assert_eq!(r.substream1.number, 66); - // assert_eq!(r.substream2.my_str, "KILLED"); - // assert_eq!(r.substream2.body, vec!([0x61, 0x20, 0x63, 0x61, 0x74])); - // assert_eq!(r.substream2.number, 103); + let mut r = ExprIoPos::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(substream1)),identifier(my_str)), Str(CURIOSITY)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(substream1)),identifier(body)), List(ArrayBuffer(IntNum(17), IntNum(34), IntNum(51), IntNum(68)))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(substream1)),identifier(number)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(substream2)),identifier(my_str)), Str(KILLED)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(substream2)),identifier(body)), List(ArrayBuffer(IntNum(97), IntNum(32), IntNum(99), IntNum(97), IntNum(116)))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(substream2)),identifier(number)), IntNum(103)) } diff --git a/spec/rust/tests/test_expr_mod.rs b/spec/rust/tests/test_expr_mod.rs index 3185a2197..35ea3d58a 100644 --- a/spec/rust/tests/test_expr_mod.rs +++ b/spec/rust/tests/test_expr_mod.rs @@ -1,18 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_mod::ExprMod; +use kaitai_test::expr_mod::*; use std::fs; #[test] fn test_expr_mod() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ExprMod::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.int_u, 1262698832); - // assert_eq!(r.int_s, -52947); - // assert_eq!(r.mod_pos_const, 9); - // assert_eq!(r.mod_neg_const, 4); - // assert_eq!(r.mod_pos_seq, 5); - // assert_eq!(r.mod_neg_seq, 2); + let mut r = ExprMod::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.int_u, 1262698832); + assert_eq!(r.int_s, -52947); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(mod_pos_const)), IntNum(9)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(mod_neg_const)), IntNum(4)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(mod_pos_seq)), IntNum(5)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(mod_neg_seq)), IntNum(2)) } diff --git a/spec/rust/tests/test_expr_sizeof_type_0.rs b/spec/rust/tests/test_expr_sizeof_type_0.rs index a64f146e1..f5fecb538 100644 --- a/spec/rust/tests/test_expr_sizeof_type_0.rs +++ b/spec/rust/tests/test_expr_sizeof_type_0.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_sizeof_type_0::ExprSizeofType0; +use kaitai_test::expr_sizeof_type_0::*; use std::fs; #[test] fn test_expr_sizeof_type_0() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ExprSizeofType0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.sizeof_block, ((1 + 4) + 2)); + let mut r = ExprSizeofType0::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(sizeof_block)), BinOp(BinOp(IntNum(1),Add,IntNum(4)),Add,IntNum(2))) } diff --git a/spec/rust/tests/test_expr_sizeof_type_1.rs b/spec/rust/tests/test_expr_sizeof_type_1.rs index e504a0293..44f5e2b51 100644 --- a/spec/rust/tests/test_expr_sizeof_type_1.rs +++ b/spec/rust/tests/test_expr_sizeof_type_1.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_sizeof_type_1::ExprSizeofType1; +use kaitai_test::expr_sizeof_type_1::*; use std::fs; #[test] fn test_expr_sizeof_type_1() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ExprSizeofType1::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.sizeof_block, (((1 + 4) + 2) + 4)); - // assert_eq!(r.sizeof_subblock, 4); + let mut r = ExprSizeofType1::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(sizeof_block)), BinOp(BinOp(BinOp(IntNum(1),Add,IntNum(4)),Add,IntNum(2)),Add,IntNum(4))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(sizeof_subblock)), IntNum(4)) } diff --git a/spec/rust/tests/test_expr_sizeof_value_0.rs b/spec/rust/tests/test_expr_sizeof_value_0.rs index 8b426910a..91cc27bab 100644 --- a/spec/rust/tests/test_expr_sizeof_value_0.rs +++ b/spec/rust/tests/test_expr_sizeof_value_0.rs @@ -1,17 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_sizeof_value_0::ExprSizeofValue0; +use kaitai_test::expr_sizeof_value_0::*; use std::fs; #[test] fn test_expr_sizeof_value_0() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ExprSizeofValue0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.self_sizeof, (((1 + 4) + 2) + 2)); - // assert_eq!(r.sizeof_block, ((1 + 4) + 2)); - // assert_eq!(r.sizeof_block_a, 1); - // assert_eq!(r.sizeof_block_b, 4); - // assert_eq!(r.sizeof_block_c, 2); + let mut r = ExprSizeofValue0::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(self_sizeof)), BinOp(BinOp(BinOp(IntNum(1),Add,IntNum(4)),Add,IntNum(2)),Add,IntNum(2))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(sizeof_block)), BinOp(BinOp(IntNum(1),Add,IntNum(4)),Add,IntNum(2))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(sizeof_block_a)), IntNum(1)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(sizeof_block_b)), IntNum(4)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(sizeof_block_c)), IntNum(2)) } diff --git a/spec/rust/tests/test_expr_sizeof_value_sized.rs b/spec/rust/tests/test_expr_sizeof_value_sized.rs index 44f060677..508047501 100644 --- a/spec/rust/tests/test_expr_sizeof_value_sized.rs +++ b/spec/rust/tests/test_expr_sizeof_value_sized.rs @@ -1,17 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::expr_sizeof_value_sized::ExprSizeofValueSized; +use kaitai_test::expr_sizeof_value_sized::*; use std::fs; #[test] fn test_expr_sizeof_value_sized() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ExprSizeofValueSized::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.self_sizeof, (12 + 2)); - // assert_eq!(r.sizeof_block, 12); - // assert_eq!(r.sizeof_block_a, 1); - // assert_eq!(r.sizeof_block_b, 4); - // assert_eq!(r.sizeof_block_c, 2); + let mut r = ExprSizeofValueSized::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(self_sizeof)), BinOp(IntNum(12),Add,IntNum(2))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(sizeof_block)), IntNum(12)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(sizeof_block_a)), IntNum(1)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(sizeof_block_b)), IntNum(4)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(sizeof_block_c)), IntNum(2)) } diff --git a/spec/rust/tests/test_fixed_contents.rs b/spec/rust/tests/test_fixed_contents.rs index a3657b847..c926f149d 100644 --- a/spec/rust/tests/test_fixed_contents.rs +++ b/spec/rust/tests/test_fixed_contents.rs @@ -1,12 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::fixed_contents::FixedContents; +use kaitai_test::fixed_contents::*; use std::fs; #[test] fn test_fixed_contents() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = FixedContents::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + let mut r = FixedContents::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); } diff --git a/spec/rust/tests/test_fixed_struct.rs b/spec/rust/tests/test_fixed_struct.rs index d982f39af..5a32d691b 100644 --- a/spec/rust/tests/test_fixed_struct.rs +++ b/spec/rust/tests/test_fixed_struct.rs @@ -1,32 +1,33 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::fixed_struct::FixedStruct; +use kaitai_test::fixed_struct::*; use std::fs; #[test] fn test_fixed_struct() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = FixedStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.hdr.uint8, 255); - // assert_eq!(r.hdr.uint16, 65535); - // assert_eq!(r.hdr.uint32, 4294967295); - // assert_eq!(r.hdr.uint64, 18446744073709551615); - // assert_eq!(r.hdr.sint8, -1); - // assert_eq!(r.hdr.sint16, -1); - // assert_eq!(r.hdr.sint32, -1); - // assert_eq!(r.hdr.sint64, -1); - // assert_eq!(r.hdr.uint16le, 66); - // assert_eq!(r.hdr.uint32le, 66); - // assert_eq!(r.hdr.uint64le, 66); - // assert_eq!(r.hdr.sint16le, -66); - // assert_eq!(r.hdr.sint32le, -66); - // assert_eq!(r.hdr.sint64le, -66); - // assert_eq!(r.hdr.uint16be, 66); - // assert_eq!(r.hdr.uint32be, 66); - // assert_eq!(r.hdr.uint64be, 66); - // assert_eq!(r.hdr.sint16be, -66); - // assert_eq!(r.hdr.sint32be, -66); - // assert_eq!(r.hdr.sint64be, -66); + let mut r = FixedStruct::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(uint8)), IntNum(255)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(uint16)), IntNum(65535)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(uint32)), IntNum(4294967295)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(uint64)), IntNum(18446744073709551615)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(sint8)), UnaryOp(Minus,IntNum(1))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(sint16)), UnaryOp(Minus,IntNum(1))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(sint32)), UnaryOp(Minus,IntNum(1))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(sint64)), UnaryOp(Minus,IntNum(1))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(uint16le)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(uint32le)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(uint64le)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(sint16le)), UnaryOp(Minus,IntNum(66))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(sint32le)), UnaryOp(Minus,IntNum(66))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(sint64le)), UnaryOp(Minus,IntNum(66))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(uint16be)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(uint32be)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(uint64be)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(sint16be)), UnaryOp(Minus,IntNum(66))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(sint32be)), UnaryOp(Minus,IntNum(66))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hdr)),identifier(sint64be)), UnaryOp(Minus,IntNum(66))) } diff --git a/spec/rust/tests/test_float_to_i.rs b/spec/rust/tests/test_float_to_i.rs index 72ea81bd2..85a610c4e 100644 --- a/spec/rust/tests/test_float_to_i.rs +++ b/spec/rust/tests/test_float_to_i.rs @@ -1,20 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::float_to_i::FloatToI; +use kaitai_test::float_to_i::*; use std::fs; #[test] fn test_float_to_i() { let data = fs::read("../../src/floating_points.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = FloatToI::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.single_value, 0.5); - // assert_eq!(r.double_value, 0.25); - // assert_eq!(r.single_i, 0); - // assert_eq!(r.double_i, 0); - // assert_eq!(r.float1_i, 1); - // assert_eq!(r.float2_i, 1); - // assert_eq!(r.float3_i, 1); - // assert_eq!(r.float4_i, -2); + let mut r = FloatToI::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.single_value, 0.5); + assert_eq!(r.double_value, 0.25); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(single_i)), IntNum(0)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(double_i)), IntNum(0)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(float1_i)), IntNum(1)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(float2_i)), IntNum(1)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(float3_i)), IntNum(1)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(float4_i)), UnaryOp(Minus,IntNum(2))) } diff --git a/spec/rust/tests/test_floating_points.rs b/spec/rust/tests/test_floating_points.rs index f159122c7..541bc3a04 100644 --- a/spec/rust/tests/test_floating_points.rs +++ b/spec/rust/tests/test_floating_points.rs @@ -1,20 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::floating_points::FloatingPoints; +use kaitai_test::floating_points::*; use std::fs; #[test] fn test_floating_points() { let data = fs::read("../../src/floating_points.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = FloatingPoints::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.single_value, 0.5); - // assert_eq!(r.single_value_be, 0.5); - // assert_eq!(r.double_value, 0.25); - // assert_eq!(r.double_value_be, 0.25); - // assert_eq!(r.approximate_value, 1.2345); - // assert_eq!(r.single_value_plus_int, 1.5); - // assert_eq!(r.single_value_plus_float, 1.0); - // assert_eq!(r.double_value_plus_float, 0.3); + let mut r = FloatingPoints::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.single_value, 0.5); + assert_eq!(r.single_value_be, 0.5); + assert_eq!(r.double_value, 0.25); + assert_eq!(r.double_value_be, 0.25); + assert_eq!(r.approximate_value, 1.2345); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(single_value_plus_int)), FloatNum(1.5)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(single_value_plus_float)), FloatNum(1.0)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(double_value_plus_float)), FloatNum(0.3)) } diff --git a/spec/rust/tests/test_hello_world.rs b/spec/rust/tests/test_hello_world.rs index a1448d2b6..81fcc939e 100644 --- a/spec/rust/tests/test_hello_world.rs +++ b/spec/rust/tests/test_hello_world.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::hello_world::HelloWorld; +use kaitai_test::hello_world::*; use std::fs; #[test] fn test_hello_world() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = HelloWorld::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.one, 80); + let mut r = HelloWorld::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.one, 80); } diff --git a/spec/rust/tests/test_if_instances.rs b/spec/rust/tests/test_if_instances.rs index 978a09cee..167f7213f 100644 --- a/spec/rust/tests/test_if_instances.rs +++ b/spec/rust/tests/test_if_instances.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::if_instances::IfInstances; +use kaitai_test::if_instances::*; use std::fs; #[test] fn test_if_instances() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = IfInstances::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + let mut r = IfInstances::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); // nullAsset(r.never_happens); } diff --git a/spec/rust/tests/test_if_struct.rs b/spec/rust/tests/test_if_struct.rs index a17a8a389..5ab4d1b0c 100644 --- a/spec/rust/tests/test_if_struct.rs +++ b/spec/rust/tests/test_if_struct.rs @@ -1,19 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::if_struct::IfStruct; +use kaitai_test::if_struct::*; use std::fs; #[test] fn test_if_struct() { let data = fs::read("../../src/if_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = IfStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.op1.opcode, 83); - // assert_eq!(r.op1.arg_str.str, "foo"); - // assert_eq!(r.op2.opcode, 84); - // assert_eq!(r.op2.arg_tuple.num1, 66); - // assert_eq!(r.op2.arg_tuple.num2, 67); - // assert_eq!(r.op3.opcode, 83); - // assert_eq!(r.op3.arg_str.str, "bar"); + let mut r = IfStruct::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op1)),identifier(opcode)), IntNum(83)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op1)),identifier(arg_str)),identifier(str)), Str(foo)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op2)),identifier(opcode)), IntNum(84)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op2)),identifier(arg_tuple)),identifier(num1)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op2)),identifier(arg_tuple)),identifier(num2)), IntNum(67)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op3)),identifier(opcode)), IntNum(83)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(op3)),identifier(arg_str)),identifier(str)), Str(bar)) } diff --git a/spec/rust/tests/test_if_values.rs b/spec/rust/tests/test_if_values.rs index 23ffb26fb..e886195cf 100644 --- a/spec/rust/tests/test_if_values.rs +++ b/spec/rust/tests/test_if_values.rs @@ -1,18 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::if_values::IfValues; +use kaitai_test::if_values::*; use std::fs; #[test] fn test_if_values() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = IfValues::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.codes[0].opcode, 80); - // assert_eq!(r.codes[0].half_opcode, 40); - // assert_eq!(r.codes[1].opcode, 65); + let mut r = IfValues::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(codes)),IntNum(0)),identifier(opcode)), IntNum(80)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(codes)),IntNum(0)),identifier(half_opcode)), IntNum(40)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(codes)),IntNum(1)),identifier(opcode)), IntNum(65)) // nullAsset(r.codes[1].half_opcode); - // assert_eq!(r.codes[2].opcode, 67); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(codes)),IntNum(2)),identifier(opcode)), IntNum(67)) // nullAsset(r.codes[2].half_opcode); } diff --git a/spec/rust/tests/test_imports0.rs b/spec/rust/tests/test_imports0.rs index 0c3140de7..14292d0e6 100644 --- a/spec/rust/tests/test_imports0.rs +++ b/spec/rust/tests/test_imports0.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::imports0::Imports0; +use kaitai_test::imports0::*; use std::fs; #[test] fn test_imports0() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = Imports0::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.two, 80); - // assert_eq!(r.hw.one, 65); - // assert_eq!(r.hw_one, 65); + let mut r = Imports0::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.two, 80); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(hw)),identifier(one)), IntNum(65)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(hw_one)), IntNum(65)) } diff --git a/spec/rust/tests/test_imports_abs.rs b/spec/rust/tests/test_imports_abs.rs index 2fd835f70..aef0f8eaf 100644 --- a/spec/rust/tests/test_imports_abs.rs +++ b/spec/rust/tests/test_imports_abs.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::imports_abs::ImportsAbs; +use kaitai_test::imports_abs::*; use std::fs; #[test] fn test_imports_abs() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ImportsAbs::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.len.value, 80); - // assert_eq!(r.body.len(), 80); + let mut r = ImportsAbs::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(len)),identifier(value)), IntNum(80)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(body)),identifier(length)), IntNum(80)) } diff --git a/spec/rust/tests/test_index_sizes.rs b/spec/rust/tests/test_index_sizes.rs index d32fff22b..a6fa0178d 100644 --- a/spec/rust/tests/test_index_sizes.rs +++ b/spec/rust/tests/test_index_sizes.rs @@ -1,19 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::index_sizes::IndexSizes; +use kaitai_test::index_sizes::*; use std::fs; #[test] fn test_index_sizes() { let data = fs::read("../../src/index_sizes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = IndexSizes::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.qty, 3); - // assert_eq!(r.sizes[0], 1); - // assert_eq!(r.sizes[1], 8); - // assert_eq!(r.sizes[2], 4); - // assert_eq!(r.bufs[0], "A"); - // assert_eq!(r.bufs[1], "BBBBBBBB"); - // assert_eq!(r.bufs[2], "CCCC"); + let mut r = IndexSizes::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.qty, 3); + assert_eq!(r.sizes[0], 1); + assert_eq!(r.sizes[1], 8); + assert_eq!(r.sizes[2], 4); + assert_eq!(r.bufs[0], "A"); + assert_eq!(r.bufs[1], "BBBBBBBB"); + assert_eq!(r.bufs[2], "CCCC"); } diff --git a/spec/rust/tests/test_index_to_param_eos.rs b/spec/rust/tests/test_index_to_param_eos.rs index ac7cd7590..475f491d5 100644 --- a/spec/rust/tests/test_index_to_param_eos.rs +++ b/spec/rust/tests/test_index_to_param_eos.rs @@ -1,19 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::index_to_param_eos::IndexToParamEos; +use kaitai_test::index_to_param_eos::*; use std::fs; #[test] fn test_index_to_param_eos() { let data = fs::read("../../src/index_sizes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = IndexToParamEos::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.qty, 3); - // assert_eq!(r.sizes[0], 1); - // assert_eq!(r.sizes[1], 8); - // assert_eq!(r.sizes[2], 4); - // assert_eq!(r.blocks[0].buf, "A"); - // assert_eq!(r.blocks[1].buf, "BBBBBBBB"); - // assert_eq!(r.blocks[2].buf, "CCCC"); + let mut r = IndexToParamEos::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.qty, 3); + assert_eq!(r.sizes[0], 1); + assert_eq!(r.sizes[1], 8); + assert_eq!(r.sizes[2], 4); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(blocks)),IntNum(0)),identifier(buf)), Str(A)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(blocks)),IntNum(1)),identifier(buf)), Str(BBBBBBBB)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(blocks)),IntNum(2)),identifier(buf)), Str(CCCC)) } diff --git a/spec/rust/tests/test_index_to_param_expr.rs b/spec/rust/tests/test_index_to_param_expr.rs index 50b23ecb1..0dbaf38f9 100644 --- a/spec/rust/tests/test_index_to_param_expr.rs +++ b/spec/rust/tests/test_index_to_param_expr.rs @@ -1,19 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::index_to_param_expr::IndexToParamExpr; +use kaitai_test::index_to_param_expr::*; use std::fs; #[test] fn test_index_to_param_expr() { let data = fs::read("../../src/index_sizes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = IndexToParamExpr::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.qty, 3); - // assert_eq!(r.sizes[0], 1); - // assert_eq!(r.sizes[1], 8); - // assert_eq!(r.sizes[2], 4); - // assert_eq!(r.blocks[0].buf, "A"); - // assert_eq!(r.blocks[1].buf, "BBBBBBBB"); - // assert_eq!(r.blocks[2].buf, "CCCC"); + let mut r = IndexToParamExpr::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.qty, 3); + assert_eq!(r.sizes[0], 1); + assert_eq!(r.sizes[1], 8); + assert_eq!(r.sizes[2], 4); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(blocks)),IntNum(0)),identifier(buf)), Str(A)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(blocks)),IntNum(1)),identifier(buf)), Str(BBBBBBBB)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(blocks)),IntNum(2)),identifier(buf)), Str(CCCC)) } diff --git a/spec/rust/tests/test_index_to_param_until.rs b/spec/rust/tests/test_index_to_param_until.rs index e1336bde2..ce1c46f81 100644 --- a/spec/rust/tests/test_index_to_param_until.rs +++ b/spec/rust/tests/test_index_to_param_until.rs @@ -1,19 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::index_to_param_until::IndexToParamUntil; +use kaitai_test::index_to_param_until::*; use std::fs; #[test] fn test_index_to_param_until() { let data = fs::read("../../src/index_sizes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = IndexToParamUntil::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.qty, 3); - // assert_eq!(r.sizes[0], 1); - // assert_eq!(r.sizes[1], 8); - // assert_eq!(r.sizes[2], 4); - // assert_eq!(r.blocks[0].buf, "A"); - // assert_eq!(r.blocks[1].buf, "BBBBBBBB"); - // assert_eq!(r.blocks[2].buf, "CCCC"); + let mut r = IndexToParamUntil::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.qty, 3); + assert_eq!(r.sizes[0], 1); + assert_eq!(r.sizes[1], 8); + assert_eq!(r.sizes[2], 4); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(blocks)),IntNum(0)),identifier(buf)), Str(A)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(blocks)),IntNum(1)),identifier(buf)), Str(BBBBBBBB)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(blocks)),IntNum(2)),identifier(buf)), Str(CCCC)) } diff --git a/spec/rust/tests/test_instance_io_user.rs b/spec/rust/tests/test_instance_io_user.rs index 507581751..7b12699c9 100644 --- a/spec/rust/tests/test_instance_io_user.rs +++ b/spec/rust/tests/test_instance_io_user.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::instance_io_user::InstanceIoUser; +use kaitai_test::instance_io_user::*; use std::fs; #[test] fn test_instance_io_user() { let data = fs::read("../../src/instance_io.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = InstanceIoUser::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.qty_entries, 3); - // assert_eq!(r.entries[0].name, "the"); - // assert_eq!(r.entries[1].name, "rainy"); - // assert_eq!(r.entries[2].name, "day it is"); + let mut r = InstanceIoUser::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.qty_entries, 3); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(entries)),IntNum(0)),identifier(name)), Str(the)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(entries)),IntNum(1)),identifier(name)), Str(rainy)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(entries)),IntNum(2)),identifier(name)), Str(day it is)) } diff --git a/spec/rust/tests/test_instance_std.rs b/spec/rust/tests/test_instance_std.rs index d4c135ce3..2f1a39c39 100644 --- a/spec/rust/tests/test_instance_std.rs +++ b/spec/rust/tests/test_instance_std.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::instance_std::InstanceStd; +use kaitai_test::instance_std::*; use std::fs; #[test] fn test_instance_std() { let data = fs::read("../../src/str_encodings.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = InstanceStd::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.header, "Some "); + let mut r = InstanceStd::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(header)), Str(Some )) } diff --git a/spec/rust/tests/test_instance_std_array.rs b/spec/rust/tests/test_instance_std_array.rs index 7ac5a9652..134dc6f28 100644 --- a/spec/rust/tests/test_instance_std_array.rs +++ b/spec/rust/tests/test_instance_std_array.rs @@ -1,19 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::instance_std_array::InstanceStdArray; +use kaitai_test::instance_std_array::*; use std::fs; #[test] fn test_instance_std_array() { let data = fs::read("../../src/instance_std_array.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = InstanceStdArray::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.ofs, 16); - // assert_eq!(r.qty_entries, 3); - // assert_eq!(r.entry_size, 4); - // assert_eq!(r.entries.len(), 3); - // assert_eq!(r.entries[0], vec!([0x11, 0x11, 0x11, 0x11])); - // assert_eq!(r.entries[1], vec!([0x22, 0x22, 0x22, 0x22])); - // assert_eq!(r.entries[2], vec!([0x33, 0x33, 0x33, 0x33])); + let mut r = InstanceStdArray::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.ofs, 16); + assert_eq!(r.qty_entries, 3); + assert_eq!(r.entry_size, 4); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(entries)),identifier(size)), IntNum(3)) + assert_eq!(r.entries[0], &[0x11, 0x11, 0x11, 0x11]); + assert_eq!(r.entries[1], &[0x22, 0x22, 0x22, 0x22]); + assert_eq!(r.entries[2], &[0x33, 0x33, 0x33, 0x33]); } diff --git a/spec/rust/tests/test_instance_user_array.rs b/spec/rust/tests/test_instance_user_array.rs index 28e8d46be..34ce6a3b3 100644 --- a/spec/rust/tests/test_instance_user_array.rs +++ b/spec/rust/tests/test_instance_user_array.rs @@ -1,22 +1,23 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::instance_user_array::InstanceUserArray; +use kaitai_test::instance_user_array::*; use std::fs; #[test] fn test_instance_user_array() { let data = fs::read("../../src/instance_std_array.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = InstanceUserArray::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.ofs, 16); - // assert_eq!(r.qty_entries, 3); - // assert_eq!(r.entry_size, 4); - // assert_eq!(r.user_entries.len(), 3); - // assert_eq!(r.user_entries[0].word1, 4369); - // assert_eq!(r.user_entries[0].word2, 4369); - // assert_eq!(r.user_entries[1].word1, 8738); - // assert_eq!(r.user_entries[1].word2, 8738); - // assert_eq!(r.user_entries[2].word1, 13107); - // assert_eq!(r.user_entries[2].word2, 13107); + let mut r = InstanceUserArray::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.ofs, 16); + assert_eq!(r.qty_entries, 3); + assert_eq!(r.entry_size, 4); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(user_entries)),identifier(size)), IntNum(3)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(user_entries)),IntNum(0)),identifier(word1)), IntNum(4369)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(user_entries)),IntNum(0)),identifier(word2)), IntNum(4369)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(user_entries)),IntNum(1)),identifier(word1)), IntNum(8738)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(user_entries)),IntNum(1)),identifier(word2)), IntNum(8738)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(user_entries)),IntNum(2)),identifier(word1)), IntNum(13107)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(user_entries)),IntNum(2)),identifier(word2)), IntNum(13107)) } diff --git a/spec/rust/tests/test_integers.rs b/spec/rust/tests/test_integers.rs index 3ade78b99..20d9e873a 100644 --- a/spec/rust/tests/test_integers.rs +++ b/spec/rust/tests/test_integers.rs @@ -1,32 +1,33 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::integers::Integers; +use kaitai_test::integers::*; use std::fs; #[test] fn test_integers() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = Integers::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.uint8, 255); - // assert_eq!(r.uint16, 65535); - // assert_eq!(r.uint32, 4294967295); - // assert_eq!(r.uint64, 18446744073709551615); - // assert_eq!(r.sint8, -1); - // assert_eq!(r.sint16, -1); - // assert_eq!(r.sint32, -1); - // assert_eq!(r.sint64, -1); - // assert_eq!(r.uint16le, 66); - // assert_eq!(r.uint32le, 66); - // assert_eq!(r.uint64le, 66); - // assert_eq!(r.sint16le, -66); - // assert_eq!(r.sint32le, -66); - // assert_eq!(r.sint64le, -66); - // assert_eq!(r.uint16be, 66); - // assert_eq!(r.uint32be, 66); - // assert_eq!(r.uint64be, 66); - // assert_eq!(r.sint16be, -66); - // assert_eq!(r.sint32be, -66); - // assert_eq!(r.sint64be, -66); + let mut r = Integers::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.uint8, 255); + assert_eq!(r.uint16, 65535); + assert_eq!(r.uint32, 4294967295); + assert_eq!(r.uint64, 18446744073709551615); + assert_eq!(r.sint8, -1); + assert_eq!(r.sint16, -1); + assert_eq!(r.sint32, -1); + assert_eq!(r.sint64, -1); + assert_eq!(r.uint16le, 66); + assert_eq!(r.uint32le, 66); + assert_eq!(r.uint64le, 66); + assert_eq!(r.sint16le, -66); + assert_eq!(r.sint32le, -66); + assert_eq!(r.sint64le, -66); + assert_eq!(r.uint16be, 66); + assert_eq!(r.uint32be, 66); + assert_eq!(r.uint64be, 66); + assert_eq!(r.sint16be, -66); + assert_eq!(r.sint32be, -66); + assert_eq!(r.sint64be, -66); } diff --git a/spec/rust/tests/test_io_local_var.rs b/spec/rust/tests/test_io_local_var.rs index 152474f96..cc696f029 100644 --- a/spec/rust/tests/test_io_local_var.rs +++ b/spec/rust/tests/test_io_local_var.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::io_local_var::IoLocalVar; +use kaitai_test::io_local_var::*; use std::fs; #[test] fn test_io_local_var() { let data = fs::read("../../src/full256.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = IoLocalVar::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.skip, vec!([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13])); - // assert_eq!(r.followup, 20); + let mut r = IoLocalVar::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.skip, &[0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13]); + assert_eq!(r.followup, 20); } diff --git a/spec/rust/tests/test_js_signed_right_shift.rs b/spec/rust/tests/test_js_signed_right_shift.rs index afe37a77d..f9a9d3156 100644 --- a/spec/rust/tests/test_js_signed_right_shift.rs +++ b/spec/rust/tests/test_js_signed_right_shift.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::js_signed_right_shift::JsSignedRightShift; +use kaitai_test::js_signed_right_shift::*; use std::fs; #[test] fn test_js_signed_right_shift() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = JsSignedRightShift::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.should_be_40000000, 1073741824); - // assert_eq!(r.should_be_a00000, 10485760); + let mut r = JsSignedRightShift::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(should_be_40000000)), IntNum(1073741824)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(should_be_a00000)), IntNum(10485760)) } diff --git a/spec/rust/tests/test_meta_tags.rs b/spec/rust/tests/test_meta_tags.rs index 428bf3542..0950def3a 100644 --- a/spec/rust/tests/test_meta_tags.rs +++ b/spec/rust/tests/test_meta_tags.rs @@ -1,12 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::meta_tags::MetaTags; +use kaitai_test::meta_tags::*; use std::fs; #[test] fn test_meta_tags() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = MetaTags::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + let mut r = MetaTags::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); } diff --git a/spec/rust/tests/test_meta_xref.rs b/spec/rust/tests/test_meta_xref.rs index 77f826885..23ccff685 100644 --- a/spec/rust/tests/test_meta_xref.rs +++ b/spec/rust/tests/test_meta_xref.rs @@ -1,12 +1,13 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::meta_xref::MetaXref; +use kaitai_test::meta_xref::*; use std::fs; #[test] fn test_meta_xref() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = MetaXref::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); + let mut r = MetaXref::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); } diff --git a/spec/rust/tests/test_multiple_use.rs b/spec/rust/tests/test_multiple_use.rs index 4c38ff192..c2690e59c 100644 --- a/spec/rust/tests/test_multiple_use.rs +++ b/spec/rust/tests/test_multiple_use.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::multiple_use::MultipleUse; +use kaitai_test::multiple_use::*; use std::fs; #[test] fn test_multiple_use() { let data = fs::read("../../src/position_abs.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = MultipleUse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.t1.first_use.value, 32); - // assert_eq!(r.t2.second_use.value, 32); + let mut r = MultipleUse::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(t1)),identifier(first_use)),identifier(value)), IntNum(32)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(t2)),identifier(second_use)),identifier(value)), IntNum(32)) } diff --git a/spec/rust/tests/test_nav_parent.rs b/spec/rust/tests/test_nav_parent.rs index a3abe1ddb..6822a6fd5 100644 --- a/spec/rust/tests/test_nav_parent.rs +++ b/spec/rust/tests/test_nav_parent.rs @@ -1,17 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nav_parent::NavParent; +use kaitai_test::nav_parent::*; use std::fs; #[test] fn test_nav_parent() { let data = fs::read("../../src/nav.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NavParent::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.header.qty_entries, 2); - // assert_eq!(r.header.filename_len, 8); - // assert_eq!(r.index.entries.len(), 2); - // assert_eq!(r.index.entries[0].filename, "FIRST___"); - // assert_eq!(r.index.entries[1].filename, "SECOND__"); + let mut r = NavParent::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(header)),identifier(qty_entries)), IntNum(2)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(header)),identifier(filename_len)), IntNum(8)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(index)),identifier(entries)),identifier(size)), IntNum(2)) + // assert_eq!(Attribute(Subscript(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(index)),identifier(entries)),IntNum(0)),identifier(filename)), Str(FIRST___)) + // assert_eq!(Attribute(Subscript(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(index)),identifier(entries)),IntNum(1)),identifier(filename)), Str(SECOND__)) } diff --git a/spec/rust/tests/test_nav_parent2.rs b/spec/rust/tests/test_nav_parent2.rs index ef824bfcd..3c975a528 100644 --- a/spec/rust/tests/test_nav_parent2.rs +++ b/spec/rust/tests/test_nav_parent2.rs @@ -1,22 +1,23 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nav_parent2::NavParent2; +use kaitai_test::nav_parent2::*; use std::fs; #[test] fn test_nav_parent2() { let data = fs::read("../../src/nav_parent2.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NavParent2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.ofs_tags, 8); - // assert_eq!(r.num_tags, 2); - // assert_eq!(r.tags[0].name, "RAHC"); - // assert_eq!(r.tags[0].ofs, 32); - // assert_eq!(r.tags[0].num_items, 3); - // assert_eq!(r.tags[0].tag_content.content, "foo"); - // assert_eq!(r.tags[1].name, "RAHC"); - // assert_eq!(r.tags[1].ofs, 35); - // assert_eq!(r.tags[1].num_items, 6); - // assert_eq!(r.tags[1].tag_content.content, "barbaz"); + let mut r = NavParent2::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.ofs_tags, 8); + assert_eq!(r.num_tags, 2); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(0)),identifier(name)), Str(RAHC)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(0)),identifier(ofs)), IntNum(32)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(0)),identifier(num_items)), IntNum(3)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(0)),identifier(tag_content)),identifier(content)), Str(foo)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(1)),identifier(name)), Str(RAHC)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(1)),identifier(ofs)), IntNum(35)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(1)),identifier(num_items)), IntNum(6)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(1)),identifier(tag_content)),identifier(content)), Str(barbaz)) } diff --git a/spec/rust/tests/test_nav_parent3.rs b/spec/rust/tests/test_nav_parent3.rs index 803a59041..55b4fcd42 100644 --- a/spec/rust/tests/test_nav_parent3.rs +++ b/spec/rust/tests/test_nav_parent3.rs @@ -1,22 +1,23 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nav_parent3::NavParent3; +use kaitai_test::nav_parent3::*; use std::fs; #[test] fn test_nav_parent3() { let data = fs::read("../../src/nav_parent2.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NavParent3::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.ofs_tags, 8); - // assert_eq!(r.num_tags, 2); - // assert_eq!(r.tags[0].name, "RAHC"); - // assert_eq!(r.tags[0].ofs, 32); - // assert_eq!(r.tags[0].num_items, 3); - // assert_eq!(r.tags[0].tag_content.content, "foo"); - // assert_eq!(r.tags[1].name, "RAHC"); - // assert_eq!(r.tags[1].ofs, 35); - // assert_eq!(r.tags[1].num_items, 6); - // assert_eq!(r.tags[1].tag_content.content, "barbaz"); + let mut r = NavParent3::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.ofs_tags, 8); + assert_eq!(r.num_tags, 2); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(0)),identifier(name)), Str(RAHC)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(0)),identifier(ofs)), IntNum(32)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(0)),identifier(num_items)), IntNum(3)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(0)),identifier(tag_content)),identifier(content)), Str(foo)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(1)),identifier(name)), Str(RAHC)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(1)),identifier(ofs)), IntNum(35)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(1)),identifier(num_items)), IntNum(6)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(tags)),IntNum(1)),identifier(tag_content)),identifier(content)), Str(barbaz)) } diff --git a/spec/rust/tests/test_nav_parent_false.rs b/spec/rust/tests/test_nav_parent_false.rs index 3be9fc658..6cb0e6293 100644 --- a/spec/rust/tests/test_nav_parent_false.rs +++ b/spec/rust/tests/test_nav_parent_false.rs @@ -1,17 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nav_parent_false::NavParentFalse; +use kaitai_test::nav_parent_false::*; use std::fs; #[test] fn test_nav_parent_false() { let data = fs::read("../../src/nav_parent_codes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NavParentFalse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.child_size, 3); - // assert_eq!(r.element_a.foo.code, 73); - // assert_eq!(r.element_a.foo.more, vec!([0x31, 0x32, 0x33])); - // assert_eq!(r.element_a.bar.foo.code, 66); - // assert_eq!(r.element_b.foo.code, 98); + let mut r = NavParentFalse::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.child_size, 3); + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(element_a)),identifier(foo)),identifier(code)), IntNum(73)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(element_a)),identifier(foo)),identifier(more)), List(ArrayBuffer(IntNum(49), IntNum(50), IntNum(51)))) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(element_a)),identifier(bar)),identifier(foo)),identifier(code)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(element_b)),identifier(foo)),identifier(code)), IntNum(98)) } diff --git a/spec/rust/tests/test_nav_parent_false2.rs b/spec/rust/tests/test_nav_parent_false2.rs index 17a37a5ac..68ed5ce2a 100644 --- a/spec/rust/tests/test_nav_parent_false2.rs +++ b/spec/rust/tests/test_nav_parent_false2.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nav_parent_false2::NavParentFalse2; +use kaitai_test::nav_parent_false2::*; use std::fs; #[test] fn test_nav_parent_false2() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NavParentFalse2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.parentless.foo, 80); + let mut r = NavParentFalse2::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(parentless)),identifier(foo)), IntNum(80)) } diff --git a/spec/rust/tests/test_nav_parent_override.rs b/spec/rust/tests/test_nav_parent_override.rs index ae098c224..b254ec1f1 100644 --- a/spec/rust/tests/test_nav_parent_override.rs +++ b/spec/rust/tests/test_nav_parent_override.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nav_parent_override::NavParentOverride; +use kaitai_test::nav_parent_override::*; use std::fs; #[test] fn test_nav_parent_override() { let data = fs::read("../../src/nav_parent_codes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NavParentOverride::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.child_size, 3); - // assert_eq!(r.child_1.data, vec!([0x49, 0x31, 0x32])); - // assert_eq!(r.mediator_2.child_2.data, vec!([0x33, 0x42, 0x62])); + let mut r = NavParentOverride::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.child_size, 3); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(child_1)),identifier(data)), List(ArrayBuffer(IntNum(73), IntNum(49), IntNum(50)))) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(mediator_2)),identifier(child_2)),identifier(data)), List(ArrayBuffer(IntNum(51), IntNum(66), IntNum(98)))) } diff --git a/spec/rust/tests/test_nav_parent_switch.rs b/spec/rust/tests/test_nav_parent_switch.rs index b51912862..adcfe2489 100644 --- a/spec/rust/tests/test_nav_parent_switch.rs +++ b/spec/rust/tests/test_nav_parent_switch.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nav_parent_switch::NavParentSwitch; +use kaitai_test::nav_parent_switch::*; use std::fs; #[test] fn test_nav_parent_switch() { let data = fs::read("../../src/nav_parent_switch.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NavParentSwitch::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.category, 1); - // assert_eq!(r.content.foo, 66); - // assert_eq!(r.content.subelement.bar, 255); + let mut r = NavParentSwitch::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.category, 1); + // assert_eq!(Attribute(CastToType(Attribute(Name(identifier(q1w2e3)),identifier(content)),typeId(false,ArrayBuffer(nav_parent_switch, element_1),false)),identifier(foo)), IntNum(66)) + // assert_eq!(Attribute(Attribute(CastToType(Attribute(Name(identifier(q1w2e3)),identifier(content)),typeId(false,ArrayBuffer(nav_parent_switch, element_1),false)),identifier(subelement)),identifier(bar)), IntNum(255)) } diff --git a/spec/rust/tests/test_nav_parent_vs_value_inst.rs b/spec/rust/tests/test_nav_parent_vs_value_inst.rs index 7f0965017..4efa07ee6 100644 --- a/spec/rust/tests/test_nav_parent_vs_value_inst.rs +++ b/spec/rust/tests/test_nav_parent_vs_value_inst.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nav_parent_vs_value_inst::NavParentVsValueInst; +use kaitai_test::nav_parent_vs_value_inst::*; use std::fs; #[test] fn test_nav_parent_vs_value_inst() { let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NavParentVsValueInst::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.s1, "foo"); + let mut r = NavParentVsValueInst::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.s1, "foo"); } diff --git a/spec/rust/tests/test_nav_root.rs b/spec/rust/tests/test_nav_root.rs index a4574586e..0cfd5e779 100644 --- a/spec/rust/tests/test_nav_root.rs +++ b/spec/rust/tests/test_nav_root.rs @@ -1,17 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nav_root::NavRoot; +use kaitai_test::nav_root::*; use std::fs; #[test] fn test_nav_root() { let data = fs::read("../../src/nav.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NavRoot::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.header.qty_entries, 2); - // assert_eq!(r.header.filename_len, 8); - // assert_eq!(r.index.entries.len(), 2); - // assert_eq!(r.index.entries[0].filename, "FIRST___"); - // assert_eq!(r.index.entries[1].filename, "SECOND__"); + let mut r = NavRoot::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(header)),identifier(qty_entries)), IntNum(2)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(header)),identifier(filename_len)), IntNum(8)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(index)),identifier(entries)),identifier(size)), IntNum(2)) + // assert_eq!(Attribute(Subscript(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(index)),identifier(entries)),IntNum(0)),identifier(filename)), Str(FIRST___)) + // assert_eq!(Attribute(Subscript(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(index)),identifier(entries)),IntNum(1)),identifier(filename)), Str(SECOND__)) } diff --git a/spec/rust/tests/test_nested_same_name.rs b/spec/rust/tests/test_nested_same_name.rs index 249f25774..25e84288b 100644 --- a/spec/rust/tests/test_nested_same_name.rs +++ b/spec/rust/tests/test_nested_same_name.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nested_same_name::NestedSameName; +use kaitai_test::nested_same_name::*; use std::fs; #[test] fn test_nested_same_name() { let data = fs::read("../../src/repeat_n_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NestedSameName::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.main_data.main_size, 2); - // assert_eq!(r.main_data.foo.data, vec!([0x10, 0x0, 0x0, 0x0])); + let mut r = NestedSameName::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(main_data)),identifier(main_size)), IntNum(2)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(main_data)),identifier(foo)),identifier(data)), List(ArrayBuffer(IntNum(16), IntNum(0), IntNum(0), IntNum(0)))) } diff --git a/spec/rust/tests/test_nested_same_name2.rs b/spec/rust/tests/test_nested_same_name2.rs index 8bc88dd45..662082d1a 100644 --- a/spec/rust/tests/test_nested_same_name2.rs +++ b/spec/rust/tests/test_nested_same_name2.rs @@ -1,17 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nested_same_name2::NestedSameName2; +use kaitai_test::nested_same_name2::*; use std::fs; #[test] fn test_nested_same_name2() { let data = fs::read("../../src/nested_same_name2.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NestedSameName2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.version, 66); - // assert_eq!(r.main_data.main_size, 2); - // assert_eq!(r.main_data.foo.data1, vec!([0x11, 0x11, 0x11, 0x11])); - // assert_eq!(r.dummy.dummy_size, 3); - // assert_eq!(r.dummy.foo.data2, vec!([0x22, 0x22, 0x22, 0x22, 0x22, 0x22])); + let mut r = NestedSameName2::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.version, 66); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(main_data)),identifier(main_size)), IntNum(2)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(main_data)),identifier(foo)),identifier(data1)), List(ArrayBuffer(IntNum(17), IntNum(17), IntNum(17), IntNum(17)))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(dummy)),identifier(dummy_size)), IntNum(3)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(dummy)),identifier(foo)),identifier(data2)), List(ArrayBuffer(IntNum(34), IntNum(34), IntNum(34), IntNum(34), IntNum(34), IntNum(34)))) } diff --git a/spec/rust/tests/test_nested_types.rs b/spec/rust/tests/test_nested_types.rs index 2cdf7fed4..a45a12e3d 100644 --- a/spec/rust/tests/test_nested_types.rs +++ b/spec/rust/tests/test_nested_types.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nested_types::NestedTypes; +use kaitai_test::nested_types::*; use std::fs; #[test] fn test_nested_types() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NestedTypes::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.one.typed_at_root.value_b, 80); - // assert_eq!(r.one.typed_here.value_c, 65); - // assert_eq!(r.two.value_b, 67); + let mut r = NestedTypes::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one)),identifier(typed_at_root)),identifier(value_b)), IntNum(80)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one)),identifier(typed_here)),identifier(value_c)), IntNum(65)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(two)),identifier(value_b)), IntNum(67)) } diff --git a/spec/rust/tests/test_nested_types2.rs b/spec/rust/tests/test_nested_types2.rs index bf9e62dc5..e4a5f7800 100644 --- a/spec/rust/tests/test_nested_types2.rs +++ b/spec/rust/tests/test_nested_types2.rs @@ -1,19 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nested_types2::NestedTypes2; +use kaitai_test::nested_types2::*; use std::fs; #[test] fn test_nested_types2() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NestedTypes2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.one.typed_at_root.value_b, 80); - // assert_eq!(r.one.typed_here1.value_c, 65); - // assert_eq!(r.one.typed_here1.typed_here.value_d, 67); - // assert_eq!(r.one.typed_here1.typed_parent.value_cc, 75); - // assert_eq!(r.one.typed_here1.typed_root.value_b, 45); - // assert_eq!(r.one.typed_here2.value_cc, 49); - // assert_eq!(r.two.value_b, -1); + let mut r = NestedTypes2::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one)),identifier(typed_at_root)),identifier(value_b)), IntNum(80)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one)),identifier(typed_here1)),identifier(value_c)), IntNum(65)) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one)),identifier(typed_here1)),identifier(typed_here)),identifier(value_d)), IntNum(67)) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one)),identifier(typed_here1)),identifier(typed_parent)),identifier(value_cc)), IntNum(75)) + // assert_eq!(Attribute(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one)),identifier(typed_here1)),identifier(typed_root)),identifier(value_b)), IntNum(45)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one)),identifier(typed_here2)),identifier(value_cc)), IntNum(49)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(two)),identifier(value_b)), UnaryOp(Minus,IntNum(1))) } diff --git a/spec/rust/tests/test_nested_types3.rs b/spec/rust/tests/test_nested_types3.rs index ba1f11819..505192470 100644 --- a/spec/rust/tests/test_nested_types3.rs +++ b/spec/rust/tests/test_nested_types3.rs @@ -1,17 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::nested_types3::NestedTypes3; +use kaitai_test::nested_types3::*; use std::fs; #[test] fn test_nested_types3() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NestedTypes3::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.a_cc.value_cc, 80); - // assert_eq!(r.a_c_d.value_d, 65); - // assert_eq!(r.b.value_b, 67); - // assert_eq!(r.b.a_cc.value_cc, 75); - // assert_eq!(r.b.a_c_d.value_d, 45); + let mut r = NestedTypes3::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(a_cc)),identifier(value_cc)), IntNum(80)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(a_c_d)),identifier(value_d)), IntNum(65)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(b)),identifier(value_b)), IntNum(67)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(b)),identifier(a_cc)),identifier(value_cc)), IntNum(75)) + // assert_eq!(Attribute(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(b)),identifier(a_c_d)),identifier(value_d)), IntNum(45)) } diff --git a/spec/rust/tests/test_non_standard.rs b/spec/rust/tests/test_non_standard.rs index 9a8757350..d3a82c8f6 100644 --- a/spec/rust/tests/test_non_standard.rs +++ b/spec/rust/tests/test_non_standard.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::non_standard::NonStandard; +use kaitai_test::non_standard::*; use std::fs; #[test] fn test_non_standard() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = NonStandard::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.foo, 80); + let mut r = NonStandard::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.foo, 80); } diff --git a/spec/rust/tests/test_params_call_short.rs b/spec/rust/tests/test_params_call_short.rs index 903e339bb..1ffc8d4b7 100644 --- a/spec/rust/tests/test_params_call_short.rs +++ b/spec/rust/tests/test_params_call_short.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::params_call_short::ParamsCallShort; +use kaitai_test::params_call_short::*; use std::fs; #[test] fn test_params_call_short() { let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ParamsCallShort::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.buf1.body, "foo|b"); - // assert_eq!(r.buf2.body, "ar|ba"); - // assert_eq!(r.buf2.trailer, 122); + let mut r = ParamsCallShort::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(buf1)),identifier(body)), Str(foo|b)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(buf2)),identifier(body)), Str(ar|ba)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(buf2)),identifier(trailer)), IntNum(122)) } diff --git a/spec/rust/tests/test_params_enum.rs b/spec/rust/tests/test_params_enum.rs index b127a7139..f8d809ed4 100644 --- a/spec/rust/tests/test_params_enum.rs +++ b/spec/rust/tests/test_params_enum.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::params_enum::ParamsEnum; +use kaitai_test::params_enum::*; use std::fs; #[test] fn test_params_enum() { let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ParamsEnum::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.one, animal::CAT); - // assert_eq!(r.invoke_with_param.is_cat, true); + let mut r = ParamsEnum::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(one)), EnumByLabel(identifier(animal),identifier(cat),typeId(false,ArrayBuffer(params_enum),false))) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(invoke_with_param)),identifier(is_cat)), Bool(true)) } diff --git a/spec/rust/tests/test_params_pass_usertype.rs b/spec/rust/tests/test_params_pass_usertype.rs index 0b50f6ad7..ecbcbd16f 100644 --- a/spec/rust/tests/test_params_pass_usertype.rs +++ b/spec/rust/tests/test_params_pass_usertype.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::params_pass_usertype::ParamsPassUsertype; +use kaitai_test::params_pass_usertype::*; use std::fs; #[test] fn test_params_pass_usertype() { let data = fs::read("../../src/position_in_seq.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ParamsPassUsertype::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.first.foo, 1); - // assert_eq!(r.one.buf, vec!([0x2])); + let mut r = ParamsPassUsertype::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(first)),identifier(foo)), IntNum(1)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one)),identifier(buf)), List(ArrayBuffer(IntNum(2)))) } diff --git a/spec/rust/tests/test_position_abs.rs b/spec/rust/tests/test_position_abs.rs index 18a7b5ee9..adc7203d5 100644 --- a/spec/rust/tests/test_position_abs.rs +++ b/spec/rust/tests/test_position_abs.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::position_abs::PositionAbs; +use kaitai_test::position_abs::*; use std::fs; #[test] fn test_position_abs() { let data = fs::read("../../src/position_abs.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = PositionAbs::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.index_offset, 32); - // assert_eq!(r.index.entry, "foo"); + let mut r = PositionAbs::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.index_offset, 32); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(index)),identifier(entry)), Str(foo)) } diff --git a/spec/rust/tests/test_position_in_seq.rs b/spec/rust/tests/test_position_in_seq.rs index 807a3799b..6e779bf51 100644 --- a/spec/rust/tests/test_position_in_seq.rs +++ b/spec/rust/tests/test_position_in_seq.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::position_in_seq::PositionInSeq; +use kaitai_test::position_in_seq::*; use std::fs; #[test] fn test_position_in_seq() { let data = fs::read("../../src/position_in_seq.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = PositionInSeq::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.numbers, [(0 + 1), 2, 3]); + let mut r = PositionInSeq::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.numbers, [(0 + 1), 2, 3]); } diff --git a/spec/rust/tests/test_position_to_end.rs b/spec/rust/tests/test_position_to_end.rs index 3ed8d21ff..47a3ba686 100644 --- a/spec/rust/tests/test_position_to_end.rs +++ b/spec/rust/tests/test_position_to_end.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::position_to_end::PositionToEnd; +use kaitai_test::position_to_end::*; use std::fs; #[test] fn test_position_to_end() { let data = fs::read("../../src/position_to_end.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = PositionToEnd::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.index.foo, 66); - // assert_eq!(r.index.bar, 4660); + let mut r = PositionToEnd::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(index)),identifier(foo)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(index)),identifier(bar)), IntNum(4660)) } diff --git a/spec/rust/tests/test_process_coerce_bytes.rs b/spec/rust/tests/test_process_coerce_bytes.rs index 739de7b26..e8d326383 100644 --- a/spec/rust/tests/test_process_coerce_bytes.rs +++ b/spec/rust/tests/test_process_coerce_bytes.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::process_coerce_bytes::ProcessCoerceBytes; +use kaitai_test::process_coerce_bytes::*; use std::fs; #[test] fn test_process_coerce_bytes() { let data = fs::read("../../src/process_coerce_bytes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ProcessCoerceBytes::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.records[0].flag, 0); - // assert_eq!(r.records[0].buf, vec!([0x41, 0x41, 0x41, 0x41])); - // assert_eq!(r.records[1].flag, 1); - // assert_eq!(r.records[1].buf, vec!([0x42, 0x42, 0x42, 0x42])); + let mut r = ProcessCoerceBytes::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(0)),identifier(flag)), IntNum(0)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(0)),identifier(buf)), List(ArrayBuffer(IntNum(65), IntNum(65), IntNum(65), IntNum(65)))) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(1)),identifier(flag)), IntNum(1)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(1)),identifier(buf)), List(ArrayBuffer(IntNum(66), IntNum(66), IntNum(66), IntNum(66)))) } diff --git a/spec/rust/tests/test_process_coerce_switch.rs b/spec/rust/tests/test_process_coerce_switch.rs deleted file mode 100644 index eb1eb7efc..000000000 --- a/spec/rust/tests/test_process_coerce_switch.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::process_coerce_switch::ProcessCoerceSwitch; -use std::fs; - -#[test] -fn test_process_coerce_switch() { - let data = fs::read("../../src/process_coerce_switch.bin").expect("Unable to read data."); - let reader = BytesReader::new(&data[..]); - let r = ProcessCoerceSwitch::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.buf_type, 0); - // assert_eq!(r.flag, 0); - // assert_eq!(r.buf.bar, vec!([0x41, 0x41, 0x41, 0x41])); -} diff --git a/spec/rust/tests/test_process_coerce_usertype1.rs b/spec/rust/tests/test_process_coerce_usertype1.rs index d1838384e..8b3d50852 100644 --- a/spec/rust/tests/test_process_coerce_usertype1.rs +++ b/spec/rust/tests/test_process_coerce_usertype1.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::process_coerce_usertype1::ProcessCoerceUsertype1; +use kaitai_test::process_coerce_usertype1::*; use std::fs; #[test] fn test_process_coerce_usertype1() { let data = fs::read("../../src/process_coerce_bytes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ProcessCoerceUsertype1::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.records[0].flag, 0); - // assert_eq!(r.records[0].buf.value, 1094795585); - // assert_eq!(r.records[1].flag, 1); - // assert_eq!(r.records[1].buf.value, 1111638594); + let mut r = ProcessCoerceUsertype1::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(0)),identifier(flag)), IntNum(0)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(0)),identifier(buf)),identifier(value)), IntNum(1094795585)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(1)),identifier(flag)), IntNum(1)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(1)),identifier(buf)),identifier(value)), IntNum(1111638594)) } diff --git a/spec/rust/tests/test_process_coerce_usertype2.rs b/spec/rust/tests/test_process_coerce_usertype2.rs index f1e07ffde..b763ccee4 100644 --- a/spec/rust/tests/test_process_coerce_usertype2.rs +++ b/spec/rust/tests/test_process_coerce_usertype2.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::process_coerce_usertype2::ProcessCoerceUsertype2; +use kaitai_test::process_coerce_usertype2::*; use std::fs; #[test] fn test_process_coerce_usertype2() { let data = fs::read("../../src/process_coerce_bytes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ProcessCoerceUsertype2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.records[0].flag, 0); - // assert_eq!(r.records[0].buf.value, 1094795585); - // assert_eq!(r.records[1].flag, 1); - // assert_eq!(r.records[1].buf.value, 1111638594); + let mut r = ProcessCoerceUsertype2::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(0)),identifier(flag)), IntNum(0)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(0)),identifier(buf)),identifier(value)), IntNum(1094795585)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(1)),identifier(flag)), IntNum(1)) + // assert_eq!(Attribute(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(1)),identifier(buf)),identifier(value)), IntNum(1111638594)) } diff --git a/spec/rust/tests/test_process_custom.rs b/spec/rust/tests/test_process_custom.rs index 67b976714..f7411b083 100644 --- a/spec/rust/tests/test_process_custom.rs +++ b/spec/rust/tests/test_process_custom.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::process_custom::ProcessCustom; +use kaitai_test::process_custom::*; use std::fs; #[test] fn test_process_custom() { let data = fs::read("../../src/process_rotate.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ProcessCustom::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.buf1, vec!([0x10, 0xb3, 0x94, 0x94, 0xf4])); - // assert_eq!(r.buf2, vec!([0x5f, 0xba, 0x7b, 0x93, 0x63, 0x23, 0x5f])); - // assert_eq!(r.buf3, vec!([0x29, 0x33, 0xb1, 0x38, 0xb1])); + let mut r = ProcessCustom::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.buf1, &[0x10, 0xb3, 0x94, 0x94, 0xf4]); + assert_eq!(r.buf2, &[0x5f, 0xba, 0x7b, 0x93, 0x63, 0x23, 0x5f]); + assert_eq!(r.buf3, &[0x29, 0x33, 0xb1, 0x38, 0xb1]); } diff --git a/spec/rust/tests/test_process_rotate.rs b/spec/rust/tests/test_process_rotate.rs index 320c2077f..e4d02b5b6 100644 --- a/spec/rust/tests/test_process_rotate.rs +++ b/spec/rust/tests/test_process_rotate.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::process_rotate::ProcessRotate; +use kaitai_test::process_rotate::*; use std::fs; #[test] fn test_process_rotate() { let data = fs::read("../../src/process_rotate.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ProcessRotate::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.buf1, vec!([0x48, 0x65, 0x6c, 0x6c, 0x6f])); - // assert_eq!(r.buf2, vec!([0x57, 0x6f, 0x72, 0x6c, 0x64])); - // assert_eq!(r.buf3, vec!([0x54, 0x68, 0x65, 0x72, 0x65])); + let mut r = ProcessRotate::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.buf1, &[0x48, 0x65, 0x6c, 0x6c, 0x6f]); + assert_eq!(r.buf2, &[0x57, 0x6f, 0x72, 0x6c, 0x64]); + assert_eq!(r.buf3, &[0x54, 0x68, 0x65, 0x72, 0x65]); } diff --git a/spec/rust/tests/test_process_to_user.rs b/spec/rust/tests/test_process_to_user.rs index cb2ca1d0b..d52b87ddf 100644 --- a/spec/rust/tests/test_process_to_user.rs +++ b/spec/rust/tests/test_process_to_user.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::process_to_user::ProcessToUser; +use kaitai_test::process_to_user::*; use std::fs; #[test] fn test_process_to_user() { let data = fs::read("../../src/process_rotate.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ProcessToUser::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.buf1.str, "Hello"); + let mut r = ProcessToUser::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(buf1)),identifier(str)), Str(Hello)) } diff --git a/spec/rust/tests/test_process_xor4_const.rs b/spec/rust/tests/test_process_xor4_const.rs index acf00037c..fa258ffba 100644 --- a/spec/rust/tests/test_process_xor4_const.rs +++ b/spec/rust/tests/test_process_xor4_const.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::process_xor4_const::ProcessXor4Const; +use kaitai_test::process_xor4_const::*; use std::fs; #[test] fn test_process_xor4_const() { let data = fs::read("../../src/process_xor_4.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ProcessXor4Const::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.key, vec!([0xec, 0xbb, 0xa3, 0x14])); - // assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); + let mut r = ProcessXor4Const::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.key, &[0xec, 0xbb, 0xa3, 0x14]); + assert_eq!(r.buf, &[0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72]); } diff --git a/spec/rust/tests/test_process_xor4_value.rs b/spec/rust/tests/test_process_xor4_value.rs index b237625f9..6c8294f16 100644 --- a/spec/rust/tests/test_process_xor4_value.rs +++ b/spec/rust/tests/test_process_xor4_value.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::process_xor4_value::ProcessXor4Value; +use kaitai_test::process_xor4_value::*; use std::fs; #[test] fn test_process_xor4_value() { let data = fs::read("../../src/process_xor_4.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ProcessXor4Value::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.key, vec!([0xec, 0xbb, 0xa3, 0x14])); - // assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); + let mut r = ProcessXor4Value::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.key, &[0xec, 0xbb, 0xa3, 0x14]); + assert_eq!(r.buf, &[0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72]); } diff --git a/spec/rust/tests/test_process_xor_const.rs b/spec/rust/tests/test_process_xor_const.rs index 695c5170d..10165b70f 100644 --- a/spec/rust/tests/test_process_xor_const.rs +++ b/spec/rust/tests/test_process_xor_const.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::process_xor_const::ProcessXorConst; +use kaitai_test::process_xor_const::*; use std::fs; #[test] fn test_process_xor_const() { let data = fs::read("../../src/process_xor_1.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ProcessXorConst::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.key, 255); - // assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); + let mut r = ProcessXorConst::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.key, 255); + assert_eq!(r.buf, &[0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72]); } diff --git a/spec/rust/tests/test_process_xor_value.rs b/spec/rust/tests/test_process_xor_value.rs index d3ba80bb8..8fcade3b4 100644 --- a/spec/rust/tests/test_process_xor_value.rs +++ b/spec/rust/tests/test_process_xor_value.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::process_xor_value::ProcessXorValue; +use kaitai_test::process_xor_value::*; use std::fs; #[test] fn test_process_xor_value() { let data = fs::read("../../src/process_xor_1.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ProcessXorValue::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.key, 255); - // assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); + let mut r = ProcessXorValue::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.key, 255); + assert_eq!(r.buf, &[0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72]); } diff --git a/spec/rust/tests/test_recursive_one.rs b/spec/rust/tests/test_recursive_one.rs index d15d63331..625d52c74 100644 --- a/spec/rust/tests/test_recursive_one.rs +++ b/spec/rust/tests/test_recursive_one.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::recursive_one::RecursiveOne; +use kaitai_test::recursive_one::*; use std::fs; #[test] fn test_recursive_one() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = RecursiveOne::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.one, 80); - // assert_eq!(r.next.one, 65); - // assert_eq!(r.next.next.one, 67); - // assert_eq!(r.next.next.next.finisher, 11595); + let mut r = RecursiveOne::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.one, 80); + // assert_eq!(Attribute(CastToType(Attribute(Name(identifier(q1w2e3)),identifier(next)),typeId(false,ArrayBuffer(recursive_one),false)),identifier(one)), IntNum(65)) + // assert_eq!(Attribute(CastToType(Attribute(CastToType(Attribute(Name(identifier(q1w2e3)),identifier(next)),typeId(false,ArrayBuffer(recursive_one),false)),identifier(next)),typeId(false,ArrayBuffer(recursive_one),false)),identifier(one)), IntNum(67)) + // assert_eq!(Attribute(CastToType(Attribute(CastToType(Attribute(CastToType(Attribute(Name(identifier(q1w2e3)),identifier(next)),typeId(false,ArrayBuffer(recursive_one),false)),identifier(next)),typeId(false,ArrayBuffer(recursive_one),false)),identifier(next)),typeId(false,ArrayBuffer(recursive_one, fini),false)),identifier(finisher)), IntNum(11595)) } diff --git a/spec/rust/tests/test_repeat_eos_bit.rs b/spec/rust/tests/test_repeat_eos_bit.rs index 6779501a8..3427a7188 100644 --- a/spec/rust/tests/test_repeat_eos_bit.rs +++ b/spec/rust/tests/test_repeat_eos_bit.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::repeat_eos_bit::RepeatEosBit; +use kaitai_test::repeat_eos_bit::*; use std::fs; #[test] fn test_repeat_eos_bit() { let data = fs::read("../../src/enum_0.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = RepeatEosBit::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.nibbles.len(), 16); + let mut r = RepeatEosBit::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(nibbles)),identifier(size)), IntNum(16)) } diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs index 40075511c..55cd8e5fc 100644 --- a/spec/rust/tests/test_repeat_eos_struct.rs +++ b/spec/rust/tests/test_repeat_eos_struct.rs @@ -1,17 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::repeat_eos_struct::RepeatEosStruct; +use kaitai_test::repeat_eos_struct::*; use std::fs; #[test] fn test_repeat_eos_struct() { let data = fs::read("../../src/repeat_eos_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = RepeatEosStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.chunks.len(), 2); - // assert_eq!(r.chunks[0].offset, 0); - // assert_eq!(r.chunks[0].len, 66); - // assert_eq!(r.chunks[1].offset, 66); - // assert_eq!(r.chunks[1].len, 2069); + let mut r = RepeatEosStruct::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),identifier(size)), IntNum(2)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(0)),identifier(offset)), IntNum(0)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(0)),identifier(len)), IntNum(66)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(1)),identifier(offset)), IntNum(66)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(1)),identifier(len)), IntNum(2069)) } diff --git a/spec/rust/tests/test_repeat_eos_u4.rs b/spec/rust/tests/test_repeat_eos_u4.rs index a41b62960..d8589ce68 100644 --- a/spec/rust/tests/test_repeat_eos_u4.rs +++ b/spec/rust/tests/test_repeat_eos_u4.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::repeat_eos_u4::RepeatEosU4; +use kaitai_test::repeat_eos_u4::*; use std::fs; #[test] fn test_repeat_eos_u4() { let data = fs::read("../../src/repeat_eos_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = RepeatEosU4::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.numbers, [0, 66, 66, 2069]); + let mut r = RepeatEosU4::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.numbers, [0, 66, 66, 2069]); } diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs index 1ca273dee..2e500b388 100644 --- a/spec/rust/tests/test_repeat_n_struct.rs +++ b/spec/rust/tests/test_repeat_n_struct.rs @@ -1,17 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::repeat_n_struct::RepeatNStruct; +use kaitai_test::repeat_n_struct::*; use std::fs; #[test] fn test_repeat_n_struct() { let data = fs::read("../../src/repeat_n_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = RepeatNStruct::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.chunks.len(), 2); - // assert_eq!(r.chunks[0].offset, 16); - // assert_eq!(r.chunks[0].len, 8312); - // assert_eq!(r.chunks[1].offset, 8328); - // assert_eq!(r.chunks[1].len, 15); + let mut r = RepeatNStruct::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),identifier(size)), IntNum(2)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(0)),identifier(offset)), IntNum(16)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(0)),identifier(len)), IntNum(8312)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(1)),identifier(offset)), IntNum(8328)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(1)),identifier(len)), IntNum(15)) } diff --git a/spec/rust/tests/test_repeat_n_strz.rs b/spec/rust/tests/test_repeat_n_strz.rs index 2347f4009..c8717578e 100644 --- a/spec/rust/tests/test_repeat_n_strz.rs +++ b/spec/rust/tests/test_repeat_n_strz.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::repeat_n_strz::RepeatNStrz; +use kaitai_test::repeat_n_strz::*; use std::fs; #[test] fn test_repeat_n_strz() { let data = fs::read("../../src/repeat_n_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = RepeatNStrz::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.qty, 2); - // assert_eq!(r.lines, ["foo", "bar"]); + let mut r = RepeatNStrz::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.qty, 2); + assert_eq!(r.lines, ["foo", "bar"]); } diff --git a/spec/rust/tests/test_repeat_n_strz_double.rs b/spec/rust/tests/test_repeat_n_strz_double.rs index ae1bcc5ba..45bfc0169 100644 --- a/spec/rust/tests/test_repeat_n_strz_double.rs +++ b/spec/rust/tests/test_repeat_n_strz_double.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::repeat_n_strz_double::RepeatNStrzDouble; +use kaitai_test::repeat_n_strz_double::*; use std::fs; #[test] fn test_repeat_n_strz_double() { let data = fs::read("../../src/repeat_n_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = RepeatNStrzDouble::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.qty, 2); - // assert_eq!(r.lines1, ["foo"]); - // assert_eq!(r.lines2, ["bar"]); + let mut r = RepeatNStrzDouble::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.qty, 2); + assert_eq!(r.lines1, ["foo"]); + assert_eq!(r.lines2, ["bar"]); } diff --git a/spec/rust/tests/test_repeat_until_complex.rs b/spec/rust/tests/test_repeat_until_complex.rs index 9a71c8e10..06fee6025 100644 --- a/spec/rust/tests/test_repeat_until_complex.rs +++ b/spec/rust/tests/test_repeat_until_complex.rs @@ -1,27 +1,28 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::repeat_until_complex::RepeatUntilComplex; +use kaitai_test::repeat_until_complex::*; use std::fs; #[test] fn test_repeat_until_complex() { let data = fs::read("../../src/repeat_until_complex.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = RepeatUntilComplex::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.first.len(), 3); - // assert_eq!(r.first[0].count, 4); - // assert_eq!(r.first[0].values, [(0 + 1), 2, 3, 4]); - // assert_eq!(r.first[1].count, 2); - // assert_eq!(r.first[1].values, [(0 + 1), 2]); - // assert_eq!(r.first[2].count, 0); - // assert_eq!(r.second.len(), 4); - // assert_eq!(r.second[0].count, 6); - // assert_eq!(r.second[0].values, [(0 + 1), 2, 3, 4, 5, 6]); - // assert_eq!(r.second[1].count, 3); - // assert_eq!(r.second[1].values, [(0 + 1), 2, 3]); - // assert_eq!(r.second[2].count, 4); - // assert_eq!(r.second[2].values, [(0 + 1), 2, 3, 4]); - // assert_eq!(r.second[3].count, 0); - // assert_eq!(r.third, [(0 + 102), 111, 111, 98, 97, 114, 0]); + let mut r = RepeatUntilComplex::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(first)),identifier(size)), IntNum(3)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(first)),IntNum(0)),identifier(count)), IntNum(4)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(first)),IntNum(0)),identifier(values)), List(ArrayBuffer(BinOp(IntNum(0),Add,IntNum(1)), IntNum(2), IntNum(3), IntNum(4)))) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(first)),IntNum(1)),identifier(count)), IntNum(2)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(first)),IntNum(1)),identifier(values)), List(ArrayBuffer(BinOp(IntNum(0),Add,IntNum(1)), IntNum(2)))) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(first)),IntNum(2)),identifier(count)), IntNum(0)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(second)),identifier(size)), IntNum(4)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(second)),IntNum(0)),identifier(count)), IntNum(6)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(second)),IntNum(0)),identifier(values)), List(ArrayBuffer(BinOp(IntNum(0),Add,IntNum(1)), IntNum(2), IntNum(3), IntNum(4), IntNum(5), IntNum(6)))) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(second)),IntNum(1)),identifier(count)), IntNum(3)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(second)),IntNum(1)),identifier(values)), List(ArrayBuffer(BinOp(IntNum(0),Add,IntNum(1)), IntNum(2), IntNum(3)))) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(second)),IntNum(2)),identifier(count)), IntNum(4)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(second)),IntNum(2)),identifier(values)), List(ArrayBuffer(BinOp(IntNum(0),Add,IntNum(1)), IntNum(2), IntNum(3), IntNum(4)))) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(second)),IntNum(3)),identifier(count)), IntNum(0)) + assert_eq!(r.third, [(0 + 102), 111, 111, 98, 97, 114, 0]); } diff --git a/spec/rust/tests/test_repeat_until_s4.rs b/spec/rust/tests/test_repeat_until_s4.rs index 43230a62f..ee41050b3 100644 --- a/spec/rust/tests/test_repeat_until_s4.rs +++ b/spec/rust/tests/test_repeat_until_s4.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::repeat_until_s4::RepeatUntilS4; +use kaitai_test::repeat_until_s4::*; use std::fs; #[test] fn test_repeat_until_s4() { let data = fs::read("../../src/repeat_until_s4.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = RepeatUntilS4::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.entries, [66, 4919, -251658241, -1]); - // assert_eq!(r.afterall, "foobar"); + let mut r = RepeatUntilS4::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.entries, [66, 4919, -251658241, -1]); + assert_eq!(r.afterall, "foobar"); } diff --git a/spec/rust/tests/test_repeat_until_sized.rs b/spec/rust/tests/test_repeat_until_sized.rs index c87f2e31b..5010c479e 100644 --- a/spec/rust/tests/test_repeat_until_sized.rs +++ b/spec/rust/tests/test_repeat_until_sized.rs @@ -1,19 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::repeat_until_sized::RepeatUntilSized; +use kaitai_test::repeat_until_sized::*; use std::fs; #[test] fn test_repeat_until_sized() { let data = fs::read("../../src/repeat_until_process.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = RepeatUntilSized::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.records.len(), 3); - // assert_eq!(r.records[0].marker, 232); - // assert_eq!(r.records[0].body, 2863311546); - // assert_eq!(r.records[1].marker, 250); - // assert_eq!(r.records[1].body, 2863315102); - // assert_eq!(r.records[2].marker, 170); - // assert_eq!(r.records[2].body, 1431655765); + let mut r = RepeatUntilSized::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(records)),identifier(size)), IntNum(3)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(0)),identifier(marker)), IntNum(232)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(0)),identifier(body)), IntNum(2863311546)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(1)),identifier(marker)), IntNum(250)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(1)),identifier(body)), IntNum(2863315102)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(2)),identifier(marker)), IntNum(170)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(records)),IntNum(2)),identifier(body)), IntNum(1431655765)) } diff --git a/spec/rust/tests/test_str_encodings.rs b/spec/rust/tests/test_str_encodings.rs deleted file mode 100644 index 445266821..000000000 --- a/spec/rust/tests/test_str_encodings.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::str_encodings::StrEncodings; -use std::fs; - -#[test] -fn test_str_encodings() { - let data = fs::read("../../src/str_encodings.bin").expect("Unable to read data."); - let reader = BytesReader::new(&data[..]); - let r = StrEncodings::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.str1, "Some ASCII"); - // assert_eq!(r.str2, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - // assert_eq!(r.str3, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - // assert_eq!(r.str4, "\u{2591}\u{2592}\u{2593}"); -} diff --git a/spec/rust/tests/test_str_encodings_default.rs b/spec/rust/tests/test_str_encodings_default.rs deleted file mode 100644 index d79d164ae..000000000 --- a/spec/rust/tests/test_str_encodings_default.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::str_encodings_default::StrEncodingsDefault; -use std::fs; - -#[test] -fn test_str_encodings_default() { - let data = fs::read("../../src/str_encodings.bin").expect("Unable to read data."); - let reader = BytesReader::new(&data[..]); - let r = StrEncodingsDefault::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.str1, "Some ASCII"); - // assert_eq!(r.rest.str2, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - // assert_eq!(r.rest.str3, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - // assert_eq!(r.rest.str4, "\u{2591}\u{2592}\u{2593}"); -} diff --git a/spec/rust/tests/test_str_eos.rs b/spec/rust/tests/test_str_eos.rs index cb576b396..0d0a14f15 100644 --- a/spec/rust/tests/test_str_eos.rs +++ b/spec/rust/tests/test_str_eos.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::str_eos::StrEos; +use kaitai_test::str_eos::*; use std::fs; #[test] fn test_str_eos() { let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = StrEos::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.str, "foo|bar|baz@"); + let mut r = StrEos::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.str, "foo|bar|baz@"); } diff --git a/spec/rust/tests/test_str_literals2.rs b/spec/rust/tests/test_str_literals2.rs index 6aa34afce..2532cb59c 100644 --- a/spec/rust/tests/test_str_literals2.rs +++ b/spec/rust/tests/test_str_literals2.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::str_literals2::StrLiterals2; +use kaitai_test::str_literals2::*; use std::fs; #[test] fn test_str_literals2() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = StrLiterals2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.dollar1, "$foo"); - // assert_eq!(r.dollar2, "${foo}"); - // assert_eq!(r.hash, "#{foo}"); - // assert_eq!(r.at_sign, "@foo"); + let mut r = StrLiterals2::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(dollar1)), Str($foo)) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(dollar2)), Str(${foo})) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(hash)), Str(#{foo})) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(at_sign)), Str(@foo)) } diff --git a/spec/rust/tests/test_str_pad_term.rs b/spec/rust/tests/test_str_pad_term.rs index cdc1ac72f..34225e920 100644 --- a/spec/rust/tests/test_str_pad_term.rs +++ b/spec/rust/tests/test_str_pad_term.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::str_pad_term::StrPadTerm; +use kaitai_test::str_pad_term::*; use std::fs; #[test] fn test_str_pad_term() { let data = fs::read("../../src/str_pad_term.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = StrPadTerm::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.str_pad, "str1"); - // assert_eq!(r.str_term, "str2foo"); - // assert_eq!(r.str_term_and_pad, "str+++3bar+++"); - // assert_eq!(r.str_term_include, "str4baz@"); + let mut r = StrPadTerm::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.str_pad, "str1"); + assert_eq!(r.str_term, "str2foo"); + assert_eq!(r.str_term_and_pad, "str+++3bar+++"); + assert_eq!(r.str_term_include, "str4baz@"); } diff --git a/spec/rust/tests/test_str_pad_term_empty.rs b/spec/rust/tests/test_str_pad_term_empty.rs index 141749141..f8db40310 100644 --- a/spec/rust/tests/test_str_pad_term_empty.rs +++ b/spec/rust/tests/test_str_pad_term_empty.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::str_pad_term_empty::StrPadTermEmpty; +use kaitai_test::str_pad_term_empty::*; use std::fs; #[test] fn test_str_pad_term_empty() { let data = fs::read("../../src/str_pad_term_empty.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = StrPadTermEmpty::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.str_pad, ""); - // assert_eq!(r.str_term, ""); - // assert_eq!(r.str_term_and_pad, ""); - // assert_eq!(r.str_term_include, "@"); + let mut r = StrPadTermEmpty::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.str_pad, ""); + assert_eq!(r.str_term, ""); + assert_eq!(r.str_term_and_pad, ""); + assert_eq!(r.str_term_include, "@"); } diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs index c10721ceb..7627fc69d 100644 --- a/spec/rust/tests/test_switch_bytearray.rs +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -1,21 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::switch_bytearray::SwitchBytearray; +use kaitai_test::switch_bytearray::*; use std::fs; #[test] fn test_switch_bytearray() { let data = fs::read("../../src/switch_opcodes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = SwitchBytearray::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.opcodes.len(), 4); - // assert_eq!(r.opcodes[0].code, vec!([0x53])); - // assert_eq!(r.opcodes[0].body.value, "foobar"); - // assert_eq!(r.opcodes[1].code, vec!([0x49])); - // assert_eq!(r.opcodes[1].body.value, 66); - // assert_eq!(r.opcodes[2].code, vec!([0x49])); - // assert_eq!(r.opcodes[2].body.value, 55); - // assert_eq!(r.opcodes[3].code, vec!([0x53])); - // assert_eq!(r.opcodes[3].body.value, ""); + let mut r = SwitchBytearray::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),identifier(size)), IntNum(4)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(code)), List(ArrayBuffer(IntNum(83)))) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(body)),typeId(false,ArrayBuffer(switch_bytearray, opcode, strval),false)),identifier(value)), Str(foobar)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(code)), List(ArrayBuffer(IntNum(73)))) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(body)),typeId(false,ArrayBuffer(switch_bytearray, opcode, intval),false)),identifier(value)), IntNum(66)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(code)), List(ArrayBuffer(IntNum(73)))) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(body)),typeId(false,ArrayBuffer(switch_bytearray, opcode, intval),false)),identifier(value)), IntNum(55)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(code)), List(ArrayBuffer(IntNum(83)))) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(body)),typeId(false,ArrayBuffer(switch_bytearray, opcode, strval),false)),identifier(value)), Str()) } diff --git a/spec/rust/tests/test_switch_integers.rs b/spec/rust/tests/test_switch_integers.rs index 4ee5ffa11..20e3017c8 100644 --- a/spec/rust/tests/test_switch_integers.rs +++ b/spec/rust/tests/test_switch_integers.rs @@ -1,21 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::switch_integers::SwitchIntegers; +use kaitai_test::switch_integers::*; use std::fs; #[test] fn test_switch_integers() { let data = fs::read("../../src/switch_integers.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = SwitchIntegers::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.opcodes.len(), 4); - // assert_eq!(r.opcodes[0].code, 1); - // assert_eq!(r.opcodes[0].body, 7); - // assert_eq!(r.opcodes[1].code, 2); - // assert_eq!(r.opcodes[1].body, 16448); - // assert_eq!(r.opcodes[2].code, 4); - // assert_eq!(r.opcodes[2].body, 4919); - // assert_eq!(r.opcodes[3].code, 8); - // assert_eq!(r.opcodes[3].body, 4919); + let mut r = SwitchIntegers::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),identifier(size)), IntNum(4)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(code)), IntNum(1)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(body)), IntNum(7)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(code)), IntNum(2)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(body)), IntNum(16448)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(code)), IntNum(4)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(body)), IntNum(4919)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(code)), IntNum(8)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(body)), IntNum(4919)) } diff --git a/spec/rust/tests/test_switch_integers2.rs b/spec/rust/tests/test_switch_integers2.rs index dfee01af6..182fb6ce1 100644 --- a/spec/rust/tests/test_switch_integers2.rs +++ b/spec/rust/tests/test_switch_integers2.rs @@ -1,17 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::switch_integers2::SwitchIntegers2; +use kaitai_test::switch_integers2::*; use std::fs; #[test] fn test_switch_integers2() { let data = fs::read("../../src/switch_integers.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = SwitchIntegers2::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.code, 1); - // assert_eq!(r.len, 7); - // assert_eq!(r.ham, vec!([0x2, 0x40, 0x40, 0x4, 0x37, 0x13, 0x0])); - // assert_eq!(r.padding, 0); - // assert_eq!(r.len_mod_str, "13"); + let mut r = SwitchIntegers2::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.code, 1); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(len)), IntNum(7)) + assert_eq!(r.ham, &[0x2, 0x40, 0x40, 0x4, 0x37, 0x13, 0x0]); + assert_eq!(r.padding, 0); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(len_mod_str)), Str(13)) } diff --git a/spec/rust/tests/test_switch_manual_enum.rs b/spec/rust/tests/test_switch_manual_enum.rs index a7019d645..2bf0921a8 100644 --- a/spec/rust/tests/test_switch_manual_enum.rs +++ b/spec/rust/tests/test_switch_manual_enum.rs @@ -1,21 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::switch_manual_enum::SwitchManualEnum; +use kaitai_test::switch_manual_enum::*; use std::fs; #[test] fn test_switch_manual_enum() { let data = fs::read("../../src/switch_opcodes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = SwitchManualEnum::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.opcodes.len(), 4); - // assert_eq!(r.opcodes[0].code, code_enum::STRVAL); - // assert_eq!(r.opcodes[0].body.value, "foobar"); - // assert_eq!(r.opcodes[1].code, code_enum::INTVAL); - // assert_eq!(r.opcodes[1].body.value, 66); - // assert_eq!(r.opcodes[2].code, code_enum::INTVAL); - // assert_eq!(r.opcodes[2].body.value, 55); - // assert_eq!(r.opcodes[3].code, code_enum::STRVAL); - // assert_eq!(r.opcodes[3].body.value, ""); + let mut r = SwitchManualEnum::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),identifier(size)), IntNum(4)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(code)), EnumByLabel(identifier(code_enum),identifier(strval),typeId(false,ArrayBuffer(switch_manual_enum, opcode),false))) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_enum, opcode, strval),false)),identifier(value)), Str(foobar)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(code)), EnumByLabel(identifier(code_enum),identifier(intval),typeId(false,ArrayBuffer(switch_manual_enum, opcode),false))) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_enum, opcode, intval),false)),identifier(value)), IntNum(66)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(code)), EnumByLabel(identifier(code_enum),identifier(intval),typeId(false,ArrayBuffer(switch_manual_enum, opcode),false))) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_enum, opcode, intval),false)),identifier(value)), IntNum(55)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(code)), EnumByLabel(identifier(code_enum),identifier(strval),typeId(false,ArrayBuffer(switch_manual_enum, opcode),false))) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_enum, opcode, strval),false)),identifier(value)), Str()) } diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs index db6afa695..2d26b3c29 100644 --- a/spec/rust/tests/test_switch_manual_int.rs +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -1,21 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::switch_manual_int::SwitchManualInt; +use kaitai_test::switch_manual_int::*; use std::fs; #[test] fn test_switch_manual_int() { let data = fs::read("../../src/switch_opcodes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = SwitchManualInt::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.opcodes.len(), 4); - // assert_eq!(r.opcodes[0].code, 83); - // assert_eq!(r.opcodes[0].body.value, "foobar"); - // assert_eq!(r.opcodes[1].code, 73); - // assert_eq!(r.opcodes[1].body.value, 66); - // assert_eq!(r.opcodes[2].code, 73); - // assert_eq!(r.opcodes[2].body.value, 55); - // assert_eq!(r.opcodes[3].code, 83); - // assert_eq!(r.opcodes[3].body.value, ""); + let mut r = SwitchManualInt::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),identifier(size)), IntNum(4)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(code)), IntNum(83)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int, opcode, strval),false)),identifier(value)), Str(foobar)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(code)), IntNum(73)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int, opcode, intval),false)),identifier(value)), IntNum(66)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(code)), IntNum(73)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int, opcode, intval),false)),identifier(value)), IntNum(55)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(code)), IntNum(83)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int, opcode, strval),false)),identifier(value)), Str()) } diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs index 38e7f46b2..1a51c610d 100644 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -1,21 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::switch_manual_int_else::SwitchManualIntElse; +use kaitai_test::switch_manual_int_else::*; use std::fs; #[test] fn test_switch_manual_int_else() { let data = fs::read("../../src/switch_opcodes2.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = SwitchManualIntElse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.opcodes.len(), 4); - // assert_eq!(r.opcodes[0].code, 83); - // assert_eq!(r.opcodes[0].body.value, "foo"); - // assert_eq!(r.opcodes[1].code, 88); - // assert_eq!(r.opcodes[1].body.filler, 66); - // assert_eq!(r.opcodes[2].code, 89); - // assert_eq!(r.opcodes[2].body.filler, 51966); - // assert_eq!(r.opcodes[3].code, 73); - // assert_eq!(r.opcodes[3].body.value, 7); + let mut r = SwitchManualIntElse::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),identifier(size)), IntNum(4)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(code)), IntNum(83)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int_else, opcode, strval),false)),identifier(value)), Str(foo)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(code)), IntNum(88)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int_else, opcode, noneval),false)),identifier(filler)), IntNum(66)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(code)), IntNum(89)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int_else, opcode, noneval),false)),identifier(filler)), IntNum(51966)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(code)), IntNum(73)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int_else, opcode, intval),false)),identifier(value)), IntNum(7)) } diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs index 88854a504..196bb668e 100644 --- a/spec/rust/tests/test_switch_manual_int_size_else.rs +++ b/spec/rust/tests/test_switch_manual_int_size_else.rs @@ -1,22 +1,23 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::switch_manual_int_size_else::SwitchManualIntSizeElse; +use kaitai_test::switch_manual_int_size_else::*; use std::fs; #[test] fn test_switch_manual_int_size_else() { let data = fs::read("../../src/switch_tlv.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = SwitchManualIntSizeElse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.chunks.len(), 4); - // assert_eq!(r.chunks[0].code, 17); - // assert_eq!(r.chunks[0].body.title, "Stuff"); - // assert_eq!(r.chunks[0].body.author, "Me"); - // assert_eq!(r.chunks[1].code, 34); - // assert_eq!(r.chunks[1].body.entries, ["AAAA", "BBBB", "CCCC"]); - // assert_eq!(r.chunks[2].code, 51); - // assert_eq!(r.chunks[2].body.rest, vec!([0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80])); - // assert_eq!(r.chunks[3].code, 255); - // assert_eq!(r.chunks[3].body.rest, vec!([])); + let mut r = SwitchManualIntSizeElse::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),identifier(size)), IntNum(4)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(0)),identifier(code)), IntNum(17)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(0)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int_size_else, chunk, chunk_meta),false)),identifier(title)), Str(Stuff)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(0)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int_size_else, chunk, chunk_meta),false)),identifier(author)), Str(Me)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(1)),identifier(code)), IntNum(34)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(1)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int_size_else, chunk, chunk_dir),false)),identifier(entries)), List(ArrayBuffer(Str(AAAA), Str(BBBB), Str(CCCC)))) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(2)),identifier(code)), IntNum(51)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(2)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int_size_else, chunk, dummy),false)),identifier(rest)), List(ArrayBuffer(IntNum(16), IntNum(32), IntNum(48), IntNum(64), IntNum(80), IntNum(96), IntNum(112), IntNum(128)))) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(3)),identifier(code)), IntNum(255)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(chunks)),IntNum(3)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_int_size_else, chunk, dummy),false)),identifier(rest)), CastToType(List(List()),typeId(false,ArrayBuffer(bytes),false))) } diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs index 24f7d9571..d5a0cc152 100644 --- a/spec/rust/tests/test_switch_manual_str.rs +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -1,21 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::switch_manual_str::SwitchManualStr; +use kaitai_test::switch_manual_str::*; use std::fs; #[test] fn test_switch_manual_str() { let data = fs::read("../../src/switch_opcodes.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = SwitchManualStr::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.opcodes.len(), 4); - // assert_eq!(r.opcodes[0].code, "S"); - // assert_eq!(r.opcodes[0].body.value, "foobar"); - // assert_eq!(r.opcodes[1].code, "I"); - // assert_eq!(r.opcodes[1].body.value, 66); - // assert_eq!(r.opcodes[2].code, "I"); - // assert_eq!(r.opcodes[2].body.value, 55); - // assert_eq!(r.opcodes[3].code, "S"); - // assert_eq!(r.opcodes[3].body.value, ""); + let mut r = SwitchManualStr::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),identifier(size)), IntNum(4)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(code)), Str(S)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_str, opcode, strval),false)),identifier(value)), Str(foobar)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(code)), Str(I)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_str, opcode, intval),false)),identifier(value)), IntNum(66)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(code)), Str(I)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_str, opcode, intval),false)),identifier(value)), IntNum(55)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(code)), Str(S)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_str, opcode, strval),false)),identifier(value)), Str()) } diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs index 23ee34449..9a6736b4c 100644 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -1,21 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::switch_manual_str_else::SwitchManualStrElse; +use kaitai_test::switch_manual_str_else::*; use std::fs; #[test] fn test_switch_manual_str_else() { let data = fs::read("../../src/switch_opcodes2.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = SwitchManualStrElse::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.opcodes.len(), 4); - // assert_eq!(r.opcodes[0].code, "S"); - // assert_eq!(r.opcodes[0].body.value, "foo"); - // assert_eq!(r.opcodes[1].code, "X"); - // assert_eq!(r.opcodes[1].body.filler, 66); - // assert_eq!(r.opcodes[2].code, "Y"); - // assert_eq!(r.opcodes[2].body.filler, 51966); - // assert_eq!(r.opcodes[3].code, "I"); - // assert_eq!(r.opcodes[3].body.value, 7); + let mut r = SwitchManualStrElse::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),identifier(size)), IntNum(4)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(code)), Str(S)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(0)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_str_else, opcode, strval),false)),identifier(value)), Str(foo)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(code)), Str(X)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(1)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_str_else, opcode, noneval),false)),identifier(filler)), IntNum(66)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(code)), Str(Y)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(2)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_str_else, opcode, noneval),false)),identifier(filler)), IntNum(51966)) + // assert_eq!(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(code)), Str(I)) + // assert_eq!(Attribute(CastToType(Attribute(Subscript(Attribute(Name(identifier(q1w2e3)),identifier(opcodes)),IntNum(3)),identifier(body)),typeId(false,ArrayBuffer(switch_manual_str_else, opcode, intval),false)),identifier(value)), IntNum(7)) } diff --git a/spec/rust/tests/test_term_bytes.rs b/spec/rust/tests/test_term_bytes.rs index 558788d06..618707264 100644 --- a/spec/rust/tests/test_term_bytes.rs +++ b/spec/rust/tests/test_term_bytes.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::term_bytes::TermBytes; +use kaitai_test::term_bytes::*; use std::fs; #[test] fn test_term_bytes() { let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = TermBytes::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.s1, vec!([0x66, 0x6f, 0x6f])); - // assert_eq!(r.s2, vec!([0x62, 0x61, 0x72])); - // assert_eq!(r.s3, vec!([0x7c, 0x62, 0x61, 0x7a, 0x40])); + let mut r = TermBytes::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.s1, &[0x66, 0x6f, 0x6f]); + assert_eq!(r.s2, &[0x62, 0x61, 0x72]); + assert_eq!(r.s3, &[0x7c, 0x62, 0x61, 0x7a, 0x40]); } diff --git a/spec/rust/tests/test_term_strz.rs b/spec/rust/tests/test_term_strz.rs index 0fbe3f7a5..d4a0894cd 100644 --- a/spec/rust/tests/test_term_strz.rs +++ b/spec/rust/tests/test_term_strz.rs @@ -1,15 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::term_strz::TermStrz; +use kaitai_test::term_strz::*; use std::fs; #[test] fn test_term_strz() { let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = TermStrz::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.s1, "foo"); - // assert_eq!(r.s2, "bar"); - // assert_eq!(r.s3, "|baz@"); + let mut r = TermStrz::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.s1, "foo"); + assert_eq!(r.s2, "bar"); + assert_eq!(r.s3, "|baz@"); } diff --git a/spec/rust/tests/test_ts_packet_header.rs b/spec/rust/tests/test_ts_packet_header.rs index a1f474f84..2f739289e 100644 --- a/spec/rust/tests/test_ts_packet_header.rs +++ b/spec/rust/tests/test_ts_packet_header.rs @@ -1,19 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::ts_packet_header::TsPacketHeader; +use kaitai_test::ts_packet_header::*; use std::fs; #[test] fn test_ts_packet_header() { let data = fs::read("../../src/ts_packet.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = TsPacketHeader::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.sync_byte, 71); - // assert_eq!(r.transport_error_indicator, false); - // assert_eq!(r.payload_unit_start_indicator, false); - // assert_eq!(r.transport_priority, true); - // assert_eq!(r.pid, 33); - // assert_eq!(r.transport_scrambling_control, 0); - // assert_eq!(r.adaptation_field_control, adaptation_field_control_enum::PAYLOAD_ONLY); + let mut r = TsPacketHeader::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.sync_byte, 71); + assert_eq!(r.transport_error_indicator, false); + assert_eq!(r.payload_unit_start_indicator, false); + assert_eq!(r.transport_priority, true); + assert_eq!(r.pid, 33); + assert_eq!(r.transport_scrambling_control, 0); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(adaptation_field_control)), EnumByLabel(identifier(adaptation_field_control_enum),identifier(payload_only),typeId(false,ArrayBuffer(ts_packet_header),false))) } diff --git a/spec/rust/tests/test_type_int_unary_op.rs b/spec/rust/tests/test_type_int_unary_op.rs index 71900f1ad..1fc5c8c27 100644 --- a/spec/rust/tests/test_type_int_unary_op.rs +++ b/spec/rust/tests/test_type_int_unary_op.rs @@ -1,16 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::type_int_unary_op::TypeIntUnaryOp; +use kaitai_test::type_int_unary_op::*; use std::fs; #[test] fn test_type_int_unary_op() { let data = fs::read("../../src/fixed_struct.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = TypeIntUnaryOp::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.value_s2, 16720); - // assert_eq!(r.value_s8, 4706543082108963651); - // assert_eq!(r.unary_s2, -16720); - // assert_eq!(r.unary_s8, -4706543082108963651); + let mut r = TypeIntUnaryOp::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.value_s2, 16720); + assert_eq!(r.value_s8, 4706543082108963651); + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(unary_s2)), UnaryOp(Minus,IntNum(16720))) + // assert_eq!(Attribute(Name(identifier(q1w2e3)),identifier(unary_s8)), UnaryOp(Minus,IntNum(4706543082108963651))) } diff --git a/spec/rust/tests/test_type_ternary.rs b/spec/rust/tests/test_type_ternary.rs index 1d099db5e..fd2146ee2 100644 --- a/spec/rust/tests/test_type_ternary.rs +++ b/spec/rust/tests/test_type_ternary.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::type_ternary::TypeTernary; +use kaitai_test::type_ternary::*; use std::fs; #[test] fn test_type_ternary() { let data = fs::read("../../src/term_strz.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = TypeTernary::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.dif.value, 101); + let mut r = TypeTernary::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(dif)),identifier(value)), IntNum(101)) } diff --git a/spec/rust/tests/test_user_type.rs b/spec/rust/tests/test_user_type.rs index 37d5e13f0..f3fa809f5 100644 --- a/spec/rust/tests/test_user_type.rs +++ b/spec/rust/tests/test_user_type.rs @@ -1,14 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::user_type::UserType; +use kaitai_test::user_type::*; use std::fs; #[test] fn test_user_type() { let data = fs::read("../../src/repeat_until_s4.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = UserType::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.one.width, 66); - // assert_eq!(r.one.height, 4919); + let mut r = UserType::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one)),identifier(width)), IntNum(66)) + // assert_eq!(Attribute(Attribute(Name(identifier(q1w2e3)),identifier(one)),identifier(height)), IntNum(4919)) } diff --git a/spec/rust/tests/test_zlib_with_header_78.rs b/spec/rust/tests/test_zlib_with_header_78.rs index c46f32d3d..7484b3fbc 100644 --- a/spec/rust/tests/test_zlib_with_header_78.rs +++ b/spec/rust/tests/test_zlib_with_header_78.rs @@ -1,13 +1,14 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! use kaitai::{BytesReader, KStruct, KStructUnit}; -use kaitai_test::zlib_with_header_78::ZlibWithHeader78; +use kaitai_test::zlib_with_header_78::*; use std::fs; #[test] fn test_zlib_with_header_78() { let data = fs::read("../../src/zlib_with_header_78.bin").expect("Unable to read data."); let reader = BytesReader::new(&data[..]); - let r = ZlibWithHeader78::default().read(&reader, None, KStructUnit::parent_stack()).unwrap(); - // assert_eq!(r.data, vec!([0x61, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72])); + let mut r = ZlibWithHeader78::default(); + r.read(&reader, None, KStructUnit::parent_stack()).expect("Unable to parse data."); + assert_eq!(r.data, &[0x61, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72]); } diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 537ede41c..f22241f26 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -2,10 +2,13 @@ package io.kaitai.struct.testtranslator.specgenerators import _root_.io.kaitai.struct.testtranslator.{Main, TestAssert, TestSpec} import io.kaitai.struct.datatype.DataType +import io.kaitai.struct.datatype.DataType.{EnumType, SwitchType} import io.kaitai.struct.exprlang.Ast -import io.kaitai.struct.{ClassTypeProvider, RuntimeConfig} +import io.kaitai.struct.exprlang.Ast.expr.{Attribute, CastToType, Subscript} +import io.kaitai.struct.format.NamedIdentifier import io.kaitai.struct.languages.RustCompiler import io.kaitai.struct.translators.RustTranslator +import io.kaitai.struct.{ClassTypeProvider, RuntimeConfig} class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(spec) { @@ -16,7 +19,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) override def header(): Unit = { out.puts("use kaitai::{BytesReader, KStruct, KStructUnit};") - out.puts(s"use kaitai_test::${spec.id}::$className;") + out.puts(s"use kaitai_test::${spec.id}::*;") out.puts(s"use std::fs;") out.puts @@ -24,9 +27,14 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) out.puts(s"fn test_${spec.id}() {") out.inc - out.puts("let data = fs::read(\"../../src/" + spec.data + "\").expect(\"Unable to read data.\");") - out.puts(s"let reader = BytesReader::new(&data[..]);") - out.puts(s"let r = $className::default().read(&reader, None, KStructUnit::parent_stack()).unwrap();") + out.puts( + "let data = fs::read(\"../../src/" + spec.data + "\").expect(\"Unable to read data.\");" + ) + out.puts("let reader = BytesReader::new(&data[..]);") + out.puts(s"let mut r = $className::default();") + out.puts( + "r.read(&reader, None, KStructUnit::parent_stack()).expect(\"Unable to parse data.\");" + ) } override def footer(): Unit = { @@ -35,13 +43,9 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) } override def nullAssert(actual: Ast.expr): Unit = { - val actStr = translateAct(actual) - out.puts(s"// nullAsset($actStr);") + out.puts(s"// nullAsset(${translateActual(actual)});") } - def translateAct(x: Ast.expr): String = - translator.translate(x).replace("self." + Main.INIT_OBJ_NAME, "r") - override def trueArrayAssert(check: TestAssert, elType: DataType, elts: Seq[Ast.expr]): Unit = { @@ -49,12 +53,80 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) } override def simpleAssert(check: TestAssert): Unit = { - val actStr = translateAct(check.actual) - val expStr = translator.translate(check.expected) - out.puts(s"// assert_eq!($actStr, $expStr);") + + // TODO: Fix attribute chaining + check.actual match { + case attribute: Attribute if attribute.value.isInstanceOf[Attribute] => + out.puts(s"// assert_eq!(${check.actual}, ${check.expected})") + return + case attribute: Attribute if attribute.value.isInstanceOf[Subscript] => + out.puts(s"// assert_eq!(${check.actual}, ${check.expected})") + return + case attribute: Attribute if attribute.value.isInstanceOf[CastToType] => + out.puts(s"// assert_eq!(${check.actual}, ${check.expected})") + return + case _ => () + } + + // TODO: Fix instance unwrapping + val attrName = check.actual.asInstanceOf[Attribute].attr + val classSpec = provider.resolveClassSpec(provider.nowClass, spec.id) + if (classSpec.instances.exists(i => i._1.name == attrName.name)) { + out.puts(s"// assert_eq!(${check.actual}, ${check.expected})") + return + } + + // Normally you'd want to look up types through `translator.detectType`, + // but that doesn't properly handle things like SwitchType + // TODO: Fix enum equality checks + val attrType = classSpec.seq.find(a => a.id == NamedIdentifier(attrName.name)) + attrType match { + case Some(a) if a.dataType.isInstanceOf[EnumType] || a.dataType.isInstanceOf[SwitchType] => + out.puts(s"// assert_eq!(${check.actual}, ${check.expected})") + return + case _ => () + } + + out.puts(s"assert_eq!(${translateActual(check.actual)}, ${translator.translate(check.expected)});") } + def translateActual(actual: Ast.expr): String = + // Because we will try to look up attributes as if they're on `Main.INIT_OBJ_NAME`, + // trim that out of the lookup path + translator.translate(actual).replace("self." + Main.INIT_OBJ_NAME, "r") + override def indentStr: String = " " override def results: String = "// " + AUTOGEN_COMMENT + "\n\n" + out.result + + def actualIsOptional(x: Ast.expr): Boolean = { + // TODO: Need a much more robust way to check for `Option<>` types + val attrName = x match { + case a: Attribute => a.attr + case _ => return false + } + + // If it's an instance, it's guaranteed to be optional + if (provider + .resolveClassSpec(provider.nowClass, spec.id) + .instances + .keys + .exists(p => p.name == attrName.name)) + return true + + // Look up the type from the struct definition; `detectType` doesn't + // properly handle `SwitchType` for example + val seqType = provider + .resolveClassSpec(provider.nowClass, spec.id) + .seq + .filter(a => a.id == NamedIdentifier(attrName.name)) + .head + + seqType.dataType match { + case _: EnumType | _: SwitchType => return true + case _ => () + } + + false + } } From 8bd24f3e68905620d76ffeb83cbb1c7de3691261 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Wed, 22 May 2019 15:29:25 -0400 Subject: [PATCH 6/6] Fix starting `cargo junit` in the wrong directory --- ci-rust | 1 + 1 file changed, 1 insertion(+) diff --git a/ci-rust b/ci-rust index a7bda0545..9541e8fbc 100755 --- a/ci-rust +++ b/ci-rust @@ -12,4 +12,5 @@ for rs in $(ls "$FORMATS_COMPILED_DIR/rust/"); do echo "pub mod $mod_name;" >> "spec/rust/src/lib.rs" done +cd "spec/rust" cargo junit --name "../../$TEST_OUT_DIR/rust/results.xml"