diff --git a/.gitignore b/.gitignore
index 87289b07f..3ef97d4b3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,5 +12,12 @@ __pycache__/
_*
spec/nim/bin
-# Rust compiled code, cargo and rls data
+# Rust
+
+## Cargo lockfile and build cache
+spec/rust/Cargo.lock
spec/rust/target/
+
+## Files auto-generated by builder/rust_builder.rb
+spec/rust/tests/spec.rs
+spec/rust/src/formats.rs
diff --git a/aggregate/convert_to_json b/aggregate/convert_to_json
index 111639a12..e5f4baaad 100755
--- a/aggregate/convert_to_json
+++ b/aggregate/convert_to_json
@@ -95,13 +95,19 @@ when 'java'
),
infile
)
+when 'rust'
+ add_kst_adoption(
+ reports_to_h(
+ JUnitXMLParser.new("#{infile}/report.xml"),
+ BuildFailedParser.new("#{infile}/build_failed_tests.txt")
+ ),
+ infile
+ )
when 'lua', 'nim'
add_kst_adoption(
reports_to_h(JUnitXMLParser.new("#{infile}/report.xml")),
infile
)
-when 'rust'
- reports_to_h(JUnitXMLParser.new(infile))
when 'go', 'perl', 'python', 'construct', 'julia'
add_kst_adoption(
reports_to_h(JUnitXMLParser.new("#{infile}/report.xml")),
diff --git a/aggregate/junit_xml_parser.rb b/aggregate/junit_xml_parser.rb
index b52c6f7f7..8549357e5 100644
--- a/aggregate/junit_xml_parser.rb
+++ b/aggregate/junit_xml_parser.rb
@@ -33,6 +33,9 @@ def each_test
elsif name =~ /^t(?!est)(.*?)$/
# Nim output
name = underscore_to_ucamelcase($1)
+ elsif name =~ /^test_.*::test_(.*?)$/
+ # Rust output
+ name = underscore_to_ucamelcase($1)
elsif tc.attribute('classname') and tc.attribute('classname').value =~ /^\/(.*?) test$/
# Julia output
name = $1
diff --git a/builder/cpp_builder.rb b/builder/cpp_builder.rb
index 9096dcfb3..bce9e3014 100644
--- a/builder/cpp_builder.rb
+++ b/builder/cpp_builder.rb
@@ -85,7 +85,7 @@ def create_project(mand_files, disp_files)
(mand_files + disp_files).each { |l| f.puts(l) }
f.puts(")")
}
- @disposable_cmake
+ [@disposable_cmake]
end
def build_project(log_file)
diff --git a/builder/csharp_builder.rb b/builder/csharp_builder.rb
index 2ffc5c093..7c3423368 100644
--- a/builder/csharp_builder.rb
+++ b/builder/csharp_builder.rb
@@ -82,7 +82,7 @@ def create_project(mand_files, disp_files)
files_xml = (mand_files + disp_files).map { |x| " " }.join("\n")
project = tmpl.gsub(/%%%FILES%%%/, files_xml)
File.write(@project_file, project)
- @project_file
+ [@project_file]
end
def build_project(log_file)
diff --git a/builder/java_builder.rb b/builder/java_builder.rb
index 237555432..67ac4b790 100644
--- a/builder/java_builder.rb
+++ b/builder/java_builder.rb
@@ -40,7 +40,7 @@ def create_project(mand_files, disp_files)
File.open(@project_file, 'w') { |f|
(mand_files + disp_files).each { |l| f.puts "\"#{l}\"" }
}
- @project_file
+ [@project_file]
end
def build_project(log_file)
diff --git a/builder/partial_builder.rb b/builder/partial_builder.rb
index 6626da384..e3c8273d2 100644
--- a/builder/partial_builder.rb
+++ b/builder/partial_builder.rb
@@ -33,8 +33,8 @@ def command_line(arg)
l1 = list_mandatory_files
l2 = list_disposable_files
log "creating project with #{(l1 + l2).size} files"
- fn = create_project(l1, l2)
- log "project file created: #{fn.inspect}"
+ fns = create_project(l1, l2)
+ log "project files created: #{fns.inspect}"
elsif arg == ['--once']
@max_attempts = 1
exit run
@@ -78,8 +78,8 @@ def partial_build
attempt_str = @max_attempts ? "#{attempt}/#{@max_attempts}" : attempt
log "creating project with #{disp_files.size}/#{orig_size} files"
- fn = create_project(mand_files, disp_files)
- log "project file created: #{fn.inspect}"
+ fns = create_project(mand_files, disp_files)
+ log "project files created: #{fns.inspect}"
build_log = "#{@test_out_dir}/build-#{attempt}.log"
log "build attempt #{attempt_str} (log: #{build_log})"
@@ -215,7 +215,9 @@ def list_disposable_files
# Creates a project file, given a list of disposable and mandatory
# files to include in it.
- # @return [String] project file name created
+ # @param mand_files [Enumerable] collection of mandatory files
+ # @param disp_files [Enumerable] collection of disposable files
+ # @return [Array] project file names created
def create_project(mand_files, disp_files)
raise NotImplementedError
end
diff --git a/builder/rust_builder.rb b/builder/rust_builder.rb
new file mode 100644
index 000000000..39fd3c7c1
--- /dev/null
+++ b/builder/rust_builder.rb
@@ -0,0 +1,226 @@
+require 'fileutils'
+require 'set'
+require 'json'
+
+require_relative 'partial_builder'
+require_relative 'shellconfig'
+
+class RustBuilder < PartialBuilder
+ def initialize
+ super
+
+ base_spec_dir = 'spec/rust'
+ @base_spec_dir = File.absolute_path(base_spec_dir)
+
+ @spec_dir = File.join(@base_spec_dir, 'tests')
+ @formats_dir = File.join(@base_spec_dir, 'src/formats')
+ @spec_list_file = File.join(@base_spec_dir, 'tests/spec.rs')
+ @formats_list_file = File.join(@base_spec_dir, 'src/formats.rs')
+
+ test_out_dir = File.join(@config['TEST_OUT_DIR'], 'rust')
+ @test_out_dir = File.absolute_path(test_out_dir)
+ end
+
+ def list_mandatory_files
+ []
+ end
+
+ def list_disposable_files
+ spec_basenames = Dir.glob('test_*.rs', base: @spec_dir)
+ format_basenames = Dir.glob('*.rs', base: @formats_dir)
+
+ spec_basenames.map { |fn| File.join(@spec_dir, fn) } +
+ format_basenames.map { |fn| File.join(@formats_dir, fn) }
+ end
+
+ def create_project(mand_files, disp_files)
+ grouped_files = mand_files.chain(disp_files).group_by { |fn| file_to_kind(fn) }
+ if grouped_files.key?(nil)
+ raise "unexpected files that are neither ':spec' or ':format': #{grouped_files[nil].inspect}"
+ end
+
+ File.open(@spec_list_file, 'w') { |f|
+ f.puts '#![allow(unused_variables)]'
+ f.puts '#![allow(unused_assignments)]'
+ grouped_files[:spec].each { |fn| f.puts "pub mod #{File.basename(fn, '.rs')};" }
+ }
+ File.open(@formats_list_file, 'w') { |f|
+ f.puts '#![allow(unused_parens)]'
+ f.puts '#![allow(dead_code)]'
+ grouped_files[:format].each { |fn| f.puts "pub mod #{File.basename(fn, '.rs')};" }
+ }
+ [@spec_list_file, @formats_list_file]
+ end
+
+ def build_project(log_file)
+ Dir.chdir(@base_spec_dir) do
+ # We don't use `cargo check` here (which would seem like a more logical
+ # choice) because unfortunately it doesn't report all build errors, see
+ # https://doc.rust-lang.org/cargo/commands/cargo-check.html#description:
+ #
+ # > Some diagnostics and errors are only emitted during code generation,
+ # > so they inherently won't be reported with `cargo check`.
+ cli = %w[cargo test --no-run --test spec --message-format json]
+ run_cargo_build({}, cli, log_file).exitstatus
+ end
+ end
+
+ def parse_failed_build(log_file)
+ list = []
+
+ File.open(log_file, 'r') { |f|
+ f.each_line { |line|
+ line.chomp!
+ # See https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages
+ cargo_msg = JSON.parse(line)
+
+ # See https://doc.rust-lang.org/cargo/reference/external-tools.html#build-finished:
+ # > The "build-finished" message is emitted at the end of the build.
+ #
+ # > This message can be helpful for tools to know when to stop reading JSON messages.
+ break if cargo_msg['reason'] == 'build-finished'
+
+ next unless cargo_msg['reason'] == 'compiler-message'
+
+ # See https://doc.rust-lang.org/rustc/json.html
+ rustc_msg = cargo_msg['message']
+ next unless rustc_msg['$message_type'] == 'diagnostic'
+ next unless rustc_msg['level'] == 'error'
+
+ files =
+ select_rustc_msg_culprit_spans(rustc_msg['spans'])
+ .map { |span| File.absolute_path(span['file_name'], @base_spec_dir) }
+
+ list.concat(files)
+ }
+ }
+
+ list
+ end
+
+ def file_to_test(path)
+ kind = file_to_kind(path)
+ basename = File.basename(path, '.rs')
+ test_name = kind == :spec ? basename.delete_prefix('test_') : basename
+ [kind, underscore_to_ucamelcase(test_name)]
+ end
+
+ def run_tests
+ Dir.chdir(@base_spec_dir) do
+ cli = %w[cargo nextest run --test spec]
+ out_log = File.join(@test_out_dir, 'test_run.stdout')
+ run_and_tee({}, cli, out_log)
+
+ # See spec/rust/.config/nextest.toml
+ src_path = File.join(@base_spec_dir, 'target/nextest/default/junit.xml')
+ dest_path = File.join(@test_out_dir, 'report.xml')
+ FileUtils.copy_file(src_path, dest_path)
+ true
+ end
+ end
+
+ private
+
+ def select_rustc_msg_culprit_spans(spans)
+ primary_spans =
+ spans
+ .select { |span| span['is_primary'] }
+ .map do |span|
+ span = span['expansion']['span'] until span['expansion'].nil?
+ span
+ end
+ primary_spans.uniq { |span| span['file_name'] }
+ end
+
+ def file_to_kind(path)
+ if path_directly_in_dir?(path, @spec_dir)
+ :spec
+ elsif path_directly_in_dir?(path, @formats_dir)
+ :format
+ end
+ end
+
+ def run_cargo_build(environment, cmd, stdout_file)
+ log "running command: #{cmd.inspect}, log: #{stdout_file.inspect}"
+ process_status = nil
+ FileUtils.mkdir_p(File.dirname(stdout_file))
+ File.open(stdout_file, 'w') { |f|
+ Open3.popen3(environment, *cmd) { |_stdin, stdout, _stderr, wait_thread|
+ while (line = stdout.gets)
+ line.chomp!
+ line_summary = summarize_cargo_json_line(line)
+ puts line_summary unless line_summary.nil?
+ f.puts line
+ end
+ process_status = wait_thread.value
+ }
+ }
+ log "process_status: #{process_status.inspect}"
+ process_status
+ end
+
+ def summarize_cargo_json_line(line)
+ begin
+ # See https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages
+ cargo_msg = JSON.parse(line)
+ rescue JSON::ParserError => e
+ warn e.full_message
+ return line
+ end
+ reason = cargo_msg['reason']
+
+ case reason
+ when 'compiler-message'
+ # See https://doc.rust-lang.org/rustc/json.html
+ rustc_msg = cargo_msg['message']
+
+ if rustc_msg['$message_type'] == 'diagnostic'
+ files =
+ select_rustc_msg_culprit_spans(rustc_msg['spans'])
+ .map { |span| "#{span['file_name']}:#{span['line_start']}:#{span['column_start']}" }
+ code_appendix = rustc_msg['code'].nil? ? '' : "[#{rustc_msg['code']['code']}]"
+ files_prefix =
+ if files.empty?
+ ''
+ else
+ "#{files.join(', ')}: "
+ end
+ "#{files_prefix}#{rustc_msg['level']}#{code_appendix}: #{rustc_msg['message']}"
+ else
+ line
+ end
+ when 'compiler-artifact', 'build-script-executed'
+ # "[#{reason}] #{cargo_msg['package_id']}"
+ nil
+ when 'build-finished'
+ "[#{reason}] success: #{cargo_msg['success']}"
+ else
+ line
+ end
+ end
+
+ # Returns +true+ if +path+ is directly contained in the +dir_abs_path+ directory, and
+ # +false+ otherwise.
+ #
+ # The +dir_abs_path+ argument is expected to be normalized as if returned by
+ # the +File.absolute_path+ method, i.e. directory parts in path separated only
+ # by +File::SEPARATOR+ (forward slash +/+ on all platforms) and never
+ # +File::ALT_SEPARATOR+ (backslash +\+ on Windows), multiple consecutive
+ # slashes collapsed into one, no useless dots (+./+ or +../+ parts), no
+ # trailing slash, etc.
+ # @param path [String] relative (to the current directory) or absolute path
+ # @param dir_abs_path [String] normalized absolute path of the directory
+ def path_directly_in_dir?(path, dir_abs_path)
+ abs_path = File.absolute_path(path)
+ dir_abs_path += File::SEPARATOR
+ return false unless abs_path.start_with?(dir_abs_path)
+
+ path_rel_to_dir = abs_path.delete_prefix(dir_abs_path)
+ path_basename = File.basename(abs_path)
+ path_rel_to_dir == path_basename
+ end
+
+ def underscore_to_ucamelcase(s)
+ s.split(/_/).map { |x| x.capitalize }.join
+ end
+end
diff --git a/builder/spec/rust/.gitignore b/builder/spec/rust/.gitignore
new file mode 100644
index 000000000..e4b9ffa4b
--- /dev/null
+++ b/builder/spec/rust/.gitignore
@@ -0,0 +1,3 @@
+## Cargo lockfile and build cache
+*/spec/rust/Cargo.lock
+*/spec/rust/target/
diff --git a/builder/spec/rust/macro_expansion/config b/builder/spec/rust/macro_expansion/config
new file mode 100644
index 000000000..ddf89ece9
--- /dev/null
+++ b/builder/spec/rust/macro_expansion/config
@@ -0,0 +1 @@
+TEST_OUT_DIR=test_out
diff --git a/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml b/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml
new file mode 100644
index 000000000..e81cde3f0
--- /dev/null
+++ b/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "rust"
+edition = "2018"
+autotests = false
+
+[dependencies]
+
+[[test]]
+name = "spec"
diff --git a/builder/spec/rust/macro_expansion/spec/rust/src/formats.rs b/builder/spec/rust/macro_expansion/spec/rust/src/formats.rs
new file mode 100644
index 000000000..ddbd86e1d
--- /dev/null
+++ b/builder/spec/rust/macro_expansion/spec/rust/src/formats.rs
@@ -0,0 +1,3 @@
+#![allow(unused_parens)]
+#![allow(dead_code)]
+pub mod empty;
diff --git a/builder/spec/rust/macro_expansion/spec/rust/src/formats/empty.rs b/builder/spec/rust/macro_expansion/spec/rust/src/formats/empty.rs
new file mode 100644
index 000000000..e69de29bb
diff --git a/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs b/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs
new file mode 100644
index 000000000..87a6eeeec
--- /dev/null
+++ b/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs
@@ -0,0 +1,2 @@
+#[macro_export]
+macro_rules! our_assert_eq_wrapper { ($l:expr, $r:expr) => { assert_eq!($l, $r) } }
diff --git a/builder/spec/rust/macro_expansion/spec/rust/src/lib.rs b/builder/spec/rust/macro_expansion/spec/rust/src/lib.rs
new file mode 100644
index 000000000..a3e9c547e
--- /dev/null
+++ b/builder/spec/rust/macro_expansion/spec/rust/src/lib.rs
@@ -0,0 +1,2 @@
+pub mod formats;
+mod helpers;
diff --git a/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs b/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs
new file mode 100644
index 000000000..d2338d315
--- /dev/null
+++ b/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs
@@ -0,0 +1 @@
+pub mod test_nested;
diff --git a/builder/spec/rust/macro_expansion/spec/rust/tests/test_nested.rs b/builder/spec/rust/macro_expansion/spec/rust/tests/test_nested.rs
new file mode 100644
index 000000000..4d9dc7021
--- /dev/null
+++ b/builder/spec/rust/macro_expansion/spec/rust/tests/test_nested.rs
@@ -0,0 +1,8 @@
+use rust::our_assert_eq_wrapper;
+
+#[test]
+fn test_nested() {
+ // NOTE: This line intentionally triggers a "can't compare `{integer}` with `{float}`"
+ // error to check if RustBuilder recovers from it.
+ our_assert_eq_wrapper!(4, 2.5);
+}
diff --git a/builder/spec/rust/macro_expansion/test_out/rust/build-1.log b/builder/spec/rust/macro_expansion/test_out/rust/build-1.log
new file mode 100644
index 000000000..1d89fdd62
--- /dev/null
+++ b/builder/spec/rust/macro_expansion/test_out/rust/build-1.log
@@ -0,0 +1,7 @@
+{"reason":"compiler-artifact","package_id":"path+file:///mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust#0.0.0","manifest_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml","target":{"kind":["lib"],"crate_types":["lib"],"name":"rust","src_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/src/lib.rs","edition":"2018","doc":true,"doctest":true,"test":true},"profile":{"opt_level":"0","debuginfo":2,"debug_assertions":true,"overflow_checks":true,"test":false},"features":[],"filenames":["/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/target/debug/deps/librust-5cc6c6ffe0c910dd.rmeta"],"executable":null,"fresh":false}
+{"reason":"compiler-message","package_id":"path+file:///mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust#0.0.0","manifest_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml","target":{"kind":["test"],"crate_types":["bin"],"name":"spec","src_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs","edition":"2018","doc":false,"doctest":false,"test":true},"message":{"rendered":"error[E0277]: can't compare `{integer}` with `{float}`\n --> tests/test_nested.rs:7:5\n |\n7 | our_assert_eq_wrapper!(4, 2.5);\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `{integer} == {float}`\n |\n = help: the trait `PartialEq<{float}>` is not implemented for `{integer}`\n = help: the following other types implement trait `PartialEq`:\n isize\n i8\n i16\n i32\n i64\n i128\n usize\n u8\n and 6 others\n = note: this error originates in the macro `assert_eq` which comes from the expansion of the macro `our_assert_eq_wrapper` (in Nightly builds, run with -Z macro-backtrace for more info)\n\n","$message_type":"diagnostic","children":[{"children":[],"code":null,"level":"help","message":"the trait `PartialEq<{float}>` is not implemented for `{integer}`","rendered":null,"spans":[]},{"children":[],"code":null,"level":"help","message":"the following other types implement trait `PartialEq`:\n isize\n i8\n i16\n i32\n i64\n i128\n usize\n u8\nand 6 others","rendered":null,"spans":[]}],"code":{"code":"E0277","explanation":"You tried to use a type which doesn't implement some trait in a place which\nexpected that trait.\n\nErroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func(foo: T) {\n foo.bar();\n}\n\nfn main() {\n // we now call the method with the i32 type, which doesn't implement\n // the Foo trait\n some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n fn bar(&self);\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n fn bar(&self) {}\n}\n\nfn some_func(foo: T) {\n foo.bar(); // we can now use this method since i32 implements the\n // Foo trait\n}\n\nfn main() {\n some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func(foo: T) {\n println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n // implemented for the type `T`\n}\n\nfn main() {\n // We now call the method with the i32 type,\n // which *does* implement the Debug trait.\n some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function. Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function. It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func(foo: T) {\n println!(\"{:?}\", foo);\n}\n\nfn main() {\n // Calling the method is still fine, as i32 implements Debug.\n some_func(5i32);\n\n // This would fail to compile now:\n // struct WithoutDebug;\n // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","message":"can't compare `{integer}` with `{float}`","spans":[{"byte_end":1242,"byte_start":1240,"column_end":34,"column_start":32,"expansion":{"def_site_span":{"byte_end":1092,"byte_start":1070,"column_end":23,"column_start":1,"expansion":null,"file_name":"/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/macros/mod.rs","is_primary":false,"label":null,"line_end":36,"line_start":36,"suggested_replacement":null,"suggestion_applicability":null,"text":[]},"macro_decl_name":"assert_eq!","span":{"byte_end":95,"byte_start":77,"column_end":80,"column_start":62,"expansion":{"def_site_span":{"byte_end":50,"byte_start":16,"column_end":35,"column_start":1,"expansion":null,"file_name":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs","is_primary":false,"label":null,"line_end":2,"line_start":2,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":35,"highlight_start":1,"text":"macro_rules! our_assert_eq_wrapper { ($l:expr, $r:expr) => { assert_eq!($l, $r) } }"}]},"macro_decl_name":"our_assert_eq_wrapper!","span":{"byte_end":243,"byte_start":213,"column_end":35,"column_start":5,"expansion":null,"file_name":"tests/test_nested.rs","is_primary":false,"label":null,"line_end":7,"line_start":7,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":35,"highlight_start":5,"text":" our_assert_eq_wrapper!(4, 2.5);"}]}},"file_name":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs","is_primary":false,"label":null,"line_end":2,"line_start":2,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":80,"highlight_start":62,"text":"macro_rules! our_assert_eq_wrapper { ($l:expr, $r:expr) => { assert_eq!($l, $r) } }"}]}},"file_name":"/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/macros/mod.rs","is_primary":true,"label":"no implementation for `{integer} == {float}`","line_end":40,"line_start":40,"suggested_replacement":null,"suggestion_applicability":null,"text":[]}]}}
+{"reason":"compiler-message","package_id":"path+file:///mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust#0.0.0","manifest_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml","target":{"kind":["test"],"crate_types":["bin"],"name":"spec","src_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs","edition":"2018","doc":false,"doctest":false,"test":true},"message":{"rendered":"error[E0308]: mismatched types\n --> tests/test_nested.rs:7:5\n |\n7 | our_assert_eq_wrapper!(4, 2.5);\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected integer, found floating-point number\n |\n = note: this error originates in the macro `assert_eq` which comes from the expansion of the macro `our_assert_eq_wrapper` (in Nightly builds, run with -Z macro-backtrace for more info)\n\n","$message_type":"diagnostic","children":[],"code":{"code":"E0308","explanation":"Expected type did not match the received type.\n\nErroneous code examples:\n\n```compile_fail,E0308\nfn plus_one(x: i32) -> i32 {\n x + 1\n}\n\nplus_one(\"Not a number\");\n// ^^^^^^^^^^^^^^ expected `i32`, found `&str`\n\nif \"Not a bool\" {\n// ^^^^^^^^^^^^ expected `bool`, found `&str`\n}\n\nlet x: f32 = \"Not a float\";\n// --- ^^^^^^^^^^^^^ expected `f32`, found `&str`\n// |\n// expected due to this\n```\n\nThis error occurs when an expression was used in a place where the compiler\nexpected an expression of a different type. It can occur in several cases, the\nmost common being when calling a function and passing an argument which has a\ndifferent type than the matching type in the function declaration.\n"},"level":"error","message":"mismatched types","spans":[{"byte_end":1253,"byte_start":1243,"column_end":45,"column_start":35,"expansion":{"def_site_span":{"byte_end":1092,"byte_start":1070,"column_end":23,"column_start":1,"expansion":null,"file_name":"/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/macros/mod.rs","is_primary":false,"label":null,"line_end":36,"line_start":36,"suggested_replacement":null,"suggestion_applicability":null,"text":[]},"macro_decl_name":"assert_eq!","span":{"byte_end":95,"byte_start":77,"column_end":80,"column_start":62,"expansion":{"def_site_span":{"byte_end":50,"byte_start":16,"column_end":35,"column_start":1,"expansion":null,"file_name":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs","is_primary":false,"label":null,"line_end":2,"line_start":2,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":35,"highlight_start":1,"text":"macro_rules! our_assert_eq_wrapper { ($l:expr, $r:expr) => { assert_eq!($l, $r) } }"}]},"macro_decl_name":"our_assert_eq_wrapper!","span":{"byte_end":243,"byte_start":213,"column_end":35,"column_start":5,"expansion":null,"file_name":"tests/test_nested.rs","is_primary":false,"label":null,"line_end":7,"line_start":7,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":35,"highlight_start":5,"text":" our_assert_eq_wrapper!(4, 2.5);"}]}},"file_name":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs","is_primary":false,"label":null,"line_end":2,"line_start":2,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":80,"highlight_start":62,"text":"macro_rules! our_assert_eq_wrapper { ($l:expr, $r:expr) => { assert_eq!($l, $r) } }"}]}},"file_name":"/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/macros/mod.rs","is_primary":true,"label":"expected integer, found floating-point number","line_end":40,"line_start":40,"suggested_replacement":null,"suggestion_applicability":null,"text":[]}]}}
+{"reason":"compiler-message","package_id":"path+file:///mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust#0.0.0","manifest_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml","target":{"kind":["test"],"crate_types":["bin"],"name":"spec","src_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs","edition":"2018","doc":false,"doctest":false,"test":true},"message":{"rendered":"error: aborting due to 2 previous errors\n\n","$message_type":"diagnostic","children":[],"code":null,"level":"error","message":"aborting due to 2 previous errors","spans":[]}}
+{"reason":"compiler-message","package_id":"path+file:///mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust#0.0.0","manifest_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml","target":{"kind":["test"],"crate_types":["bin"],"name":"spec","src_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs","edition":"2018","doc":false,"doctest":false,"test":true},"message":{"rendered":"Some errors have detailed explanations: E0277, E0308.\n","$message_type":"diagnostic","children":[],"code":null,"level":"failure-note","message":"Some errors have detailed explanations: E0277, E0308.","spans":[]}}
+{"reason":"compiler-message","package_id":"path+file:///mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust#0.0.0","manifest_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml","target":{"kind":["test"],"crate_types":["bin"],"name":"spec","src_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs","edition":"2018","doc":false,"doctest":false,"test":true},"message":{"rendered":"For more information about an error, try `rustc --explain E0277`.\n","$message_type":"diagnostic","children":[],"code":null,"level":"failure-note","message":"For more information about an error, try `rustc --explain E0277`.","spans":[]}}
+{"reason":"build-finished","success":false}
diff --git a/builder/spec/rust/rust_builder_spec.rb b/builder/spec/rust/rust_builder_spec.rb
new file mode 100644
index 000000000..8cdd90c9b
--- /dev/null
+++ b/builder/spec/rust/rust_builder_spec.rb
@@ -0,0 +1,77 @@
+require_relative '../../rust_builder'
+
+# From https://stackoverflow.com/a/64278755
+RSpec.configure do |rspec|
+ rspec.expect_with :rspec do |c|
+ c.max_formatted_output_length = nil
+ end
+end
+
+RSpec.describe RustBuilder do
+ before :context do
+ @spec_dir = File.dirname(__FILE__)
+ end
+
+ # This case tests that RustBuilder can correctly identify the bad test file if
+ # it triggers a compile error via macro expansion. For example, the use of
+ # `assert_eq!` with incompatible types in a test spec will be expanded to a
+ # `==` operation in the `library/core/src/macros/mod.rs` file, which `rustc`
+ # will report as the primary error location in the JSON output of the build.
+ # However, we want the file name of the test spec that called the `assert_eq!`
+ # macro so we can exclude it from future builds. Therefore, RustBuilder must
+ # descend deeper into the JSON to get the location of the outermost macro
+ # invocation, which should be in the offending test spec.
+ #
+ # To demonstrate the recursive nature of the problem,
+ # `spec/rust/tests/test_nested.rs` doesn't use `assert_eq!` directly but via
+ # another `our_assert_eq_wrapper!` macro (this is obviously contrived, but we
+ # can't rule out that such scenario could happen in practice, so RustBuilder
+ # should support it). This means that we apply the descend step
+ # `span["expansion"]["span"]` twice to get the test spec name, since the JSON
+ # output looks like this (simplified):
+ #
+ # ```json
+ # "message": {
+ # "$message_type": "diagnostic",
+ # "level": "error",
+ # "message": "can't compare `{integer}` with `{float}`",
+ # "spans": [
+ # {
+ # "expansion": {
+ # "macro_decl_name": "assert_eq!",
+ # "span": {
+ # "expansion": {
+ # "macro_decl_name": "our_assert_eq_wrapper!",
+ # "span": {
+ # "expansion": null,
+ # "file_name": "tests/test_nested.rs",
+ # "is_primary": false
+ # }
+ # },
+ # "file_name": "/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs",
+ # "is_primary": false
+ # }
+ # },
+ # "file_name": "/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/macros/mod.rs",
+ # "is_primary": true
+ # }
+ # ]
+ # }
+ # ```
+ context 'macro_expansion' do
+ before :context do
+ Dir.chdir("#{@spec_dir}/macro_expansion")
+ @builder = RustBuilder.new
+ end
+
+ describe '#parse_failed_build' do
+ it 'parses failed build information' do
+ test_nested_path = File.absolute_path('spec/rust/tests/test_nested.rs')
+ expect(@builder.parse_failed_build('test_out/rust/build-1.log')).to eq [
+ test_nested_path,
+ test_nested_path,
+ ]
+ end
+ end
+ end
+end
diff --git a/ci-rust b/ci-rust
index 6afe5c4e7..262708b4a 100755
--- a/ci-rust
+++ b/ci-rust
@@ -2,11 +2,16 @@
. ./config
-mkdir -p "$TEST_OUT_DIR/rust"
-
-cd spec/rust
-mkdir src
-touch src/lib.rs
-cargo build
-cargo test-junit \
- --name "../../$TEST_OUT_DIR/rust/results.xml"
+if [ -f /download/runtime/Cargo.lock ]; then
+ # We're in the Docker container, let's copy the lockfile recording the
+ # prefetched dependencies into the runtime library dir
+ ( cd -- "$RUST_RUNTIME_DIR" && cp -v -t . /download/runtime/Cargo.lock )
+ # Tell Cargo to work in `--offline` mode (see
+ # https://doc.rust-lang.org/cargo/reference/config.html#netoffline)
+ export CARGO_NET_OFFLINE=true
+fi
+
+./run-rust
+
+./kst-adoption-report rust
+aggregate/convert_to_json rust "$TEST_OUT_DIR/rust" "$TEST_OUT_DIR/rust/ci.json"
diff --git a/config b/config
index 43a876185..b90081728 100644
--- a/config
+++ b/config
@@ -16,5 +16,6 @@ PERL_RUNTIME_DIR=../runtime/perl/lib
PHP_RUNTIME_DIR=../runtime/php
PYTHON_RUNTIME_DIR=../runtime/python
RUBY_RUNTIME_DIR=../runtime/ruby/lib
+RUST_RUNTIME_DIR=../runtime/rust
TEST_OUT_DIR=test_out
diff --git a/kst-adoption-report b/kst-adoption-report
index 952a44f09..958dd5738 100755
--- a/kst-adoption-report
+++ b/kst-adoption-report
@@ -34,6 +34,8 @@ def glob_spec_files(lang)
Dir.glob('spec/construct/**/test_*.py')
when 'ruby'
Dir.glob('spec/ruby/**/*_spec.rb')
+ when 'rust'
+ Dir.glob('spec/rust/tests/test_*.rs')
when 'julia'
Dir.glob('spec/julia/test_*.jl')
else
@@ -76,6 +78,9 @@ def spec_file_to_test_name(lang, fn)
when 'ruby'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^(.*?)_spec\.rb$/
underscore_to_ucamelcase($1)
+ when 'rust'
+ raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^test_(.*?)\.rs$/
+ underscore_to_ucamelcase($1)
when 'julia'
raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^test_(.*?)\.jl$/
underscore_to_ucamelcase($1)
diff --git a/run-rust b/run-rust
new file mode 100755
index 000000000..5189618ad
--- /dev/null
+++ b/run-rust
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+
+require_relative 'builder/rust_builder'
+RustBuilder.new.command_line(ARGV)
diff --git a/spec/rust/.config/nextest.toml b/spec/rust/.config/nextest.toml
new file mode 100644
index 000000000..2e631401c
--- /dev/null
+++ b/spec/rust/.config/nextest.toml
@@ -0,0 +1,11 @@
+# See https://nexte.st/book/configuration#profiles
+[profile.default]
+# Print stdout and stderr of failed tests only at the end of the run.
+failure-output = "final"
+# Do not cancel the test run on the first failure.
+fail-fast = false
+
+# See https://nexte.st/book/junit
+[profile.default.junit]
+# a JUnit report will be written out to spec/rust/target/nextest/default/junit.xml
+path = "junit.xml"
diff --git a/spec/rust/Cargo.lock b/spec/rust/Cargo.lock
deleted file mode 100644
index 31bdaab29..000000000
--- a/spec/rust/Cargo.lock
+++ /dev/null
@@ -1,121 +0,0 @@
-[[package]]
-name = "byteorder"
-version = "0.5.3"
-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"
-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)",
-]
-
-[[package]]
-name = "rust"
-version = "0.1.0"
-dependencies = [
- "kaitai_struct 0.2.0 (git+https://github.com/CWood1/kaitai_struct_rust_runtime)",
-]
-
-[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"
diff --git a/spec/rust/Cargo.toml b/spec/rust/Cargo.toml
index e79b56875..a33527d9c 100644
--- a/spec/rust/Cargo.toml
+++ b/spec/rust/Cargo.toml
@@ -1,8 +1,12 @@
[package]
name = "rust"
version = "0.1.0"
-authors = ["Connor Wood "]
-build = "build.rs"
+authors = ["Aon"]
+edition = "2018"
+autotests = false
[dependencies]
-kaitai_struct = { git = "https://github.com/CWood1/kaitai_struct_rust_runtime" }
+kaitai = { path = "../../../runtime/rust" }
+
+[[test]]
+name = "spec"
diff --git a/spec/rust/build.rs b/spec/rust/build.rs
deleted file mode 100644
index d629f0b37..000000000
--- a/spec/rust/build.rs
+++ /dev/null
@@ -1,52 +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"))?;
-
- write!(librs, "extern crate kaitai_struct;")?;
-
- 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/src/custom_fx.rs b/spec/rust/src/custom_fx.rs
new file mode 100644
index 000000000..b3bfe6d6a
--- /dev/null
+++ b/spec/rust/src/custom_fx.rs
@@ -0,0 +1,24 @@
+extern crate kaitai;
+
+#[allow(non_snake_case)]
+
+pub mod Nested {
+ pub mod Deeply {
+ pub struct CustomFx {}
+
+ impl CustomFx {
+ pub fn new(_p_key: u8) -> Self {
+ Self {}
+ }
+ }
+
+ impl kaitai::CustomDecoder for CustomFx {
+ fn decode(&self, bytes: &[u8]) -> Result, String> {
+ let mut res = bytes.to_vec();
+ res.insert(0, '_' as u8);
+ res.push('_' as u8);
+ Ok(res)
+ }
+ }
+ }
+}
diff --git a/spec/rust/src/custom_fx_no_args.rs b/spec/rust/src/custom_fx_no_args.rs
new file mode 100644
index 000000000..25fa080b7
--- /dev/null
+++ b/spec/rust/src/custom_fx_no_args.rs
@@ -0,0 +1,20 @@
+extern crate kaitai;
+use kaitai::CustomDecoder;
+
+pub struct CustomFxNoArgs {
+}
+
+impl CustomFxNoArgs {
+ pub fn new() -> Self {
+ Self {}
+ }
+}
+
+impl CustomDecoder for CustomFxNoArgs {
+ fn decode(&self, bytes: &[u8]) -> Result, String> {
+ let mut res = bytes.to_vec();
+ res.insert(0, '_' as u8);
+ res.push('_' as u8);
+ Ok(res)
+ }
+}
diff --git a/spec/rust/src/formats b/spec/rust/src/formats
new file mode 120000
index 000000000..22b964e74
--- /dev/null
+++ b/spec/rust/src/formats
@@ -0,0 +1 @@
+../../../compiled/rust
\ No newline at end of file
diff --git a/spec/rust/src/lib.rs b/spec/rust/src/lib.rs
new file mode 100644
index 000000000..825626cd9
--- /dev/null
+++ b/spec/rust/src/lib.rs
@@ -0,0 +1,5 @@
+pub mod formats;
+
+pub mod my_custom_fx;
+pub mod custom_fx;
+pub mod custom_fx_no_args;
diff --git a/spec/rust/src/my_custom_fx.rs b/spec/rust/src/my_custom_fx.rs
new file mode 100644
index 000000000..0b88c7ddf
--- /dev/null
+++ b/spec/rust/src/my_custom_fx.rs
@@ -0,0 +1,28 @@
+extern crate kaitai;
+use kaitai::CustomDecoder;
+
+pub struct MyCustomFx {
+ key: i32,
+}
+
+impl MyCustomFx {
+ pub fn new(p_key: u8, p_flag: bool, _p_some_bytes: &[u8]) -> Self {
+ if p_flag {
+ Self { key: p_key as i32 }
+ } else {
+ Self {
+ key: -(p_key as i32),
+ }
+ }
+ }
+}
+
+impl CustomDecoder for MyCustomFx {
+ fn decode(&self, bytes: &[u8]) -> Result, String> {
+ let mut res = bytes.to_vec();
+ for i in res.iter_mut() {
+ *i = (*i as i32 + self.key) as u8;
+ }
+ Ok(res)
+ }
+}
diff --git a/spec/rust/test_bits_shift_by_b32_le.rs b/spec/rust/test_bits_shift_by_b32_le.rs
deleted file mode 100644
index 79c69a18f..000000000
--- a/spec/rust/test_bits_shift_by_b32_le.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::BitsShiftByB32Le;
-
-#[test]
-fn test_bits_shift_by_b32_le() {
- if let Ok(r) = BitsShiftByB32Le::from_file("src/bits_shift_by_b32_le.bin") {
-
- assert_eq!(r.a, 4294967295);
- assert_eq!(r.b, 0);
- }
-}
diff --git a/spec/rust/test_bits_shift_by_b64_le.rs b/spec/rust/test_bits_shift_by_b64_le.rs
deleted file mode 100644
index 20a51ab94..000000000
--- a/spec/rust/test_bits_shift_by_b64_le.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::BitsShiftByB64Le;
-
-#[test]
-fn test_bits_shift_by_b64_le() {
- if let Ok(r) = BitsShiftByB64Le::from_file("src/bits_shift_by_b64_le.bin") {
-
- assert_eq!(r.a, 18446744073709551615);
- assert_eq!(r.b, 0);
- }
-}
diff --git a/spec/rust/test_bits_signed_res_b32_be.rs b/spec/rust/test_bits_signed_res_b32_be.rs
deleted file mode 100644
index 4efcec4c6..000000000
--- a/spec/rust/test_bits_signed_res_b32_be.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::BitsSignedResB32Be;
-
-#[test]
-fn test_bits_signed_res_b32_be() {
- if let Ok(r) = BitsSignedResB32Be::from_file("src/bits_shift_by_b32_le.bin") {
-
- assert_eq!(r.a, 4294967295);
- }
-}
diff --git a/spec/rust/test_bits_signed_res_b32_le.rs b/spec/rust/test_bits_signed_res_b32_le.rs
deleted file mode 100644
index 08f93abbc..000000000
--- a/spec/rust/test_bits_signed_res_b32_le.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::BitsSignedResB32Le;
-
-#[test]
-fn test_bits_signed_res_b32_le() {
- if let Ok(r) = BitsSignedResB32Le::from_file("src/bits_shift_by_b32_le.bin") {
-
- assert_eq!(r.a, 4294967295);
- }
-}
diff --git a/spec/rust/test_bits_signed_shift_b32_le.rs b/spec/rust/test_bits_signed_shift_b32_le.rs
deleted file mode 100644
index b57988f9f..000000000
--- a/spec/rust/test_bits_signed_shift_b32_le.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::BitsSignedShiftB32Le;
-
-#[test]
-fn test_bits_signed_shift_b32_le() {
- if let Ok(r) = BitsSignedShiftB32Le::from_file("src/bits_signed_shift_b32_le.bin") {
-
- assert_eq!(r.a, 0);
- assert_eq!(r.b, 255);
- }
-}
diff --git a/spec/rust/test_bits_signed_shift_b64_le.rs b/spec/rust/test_bits_signed_shift_b64_le.rs
deleted file mode 100644
index 196b6d995..000000000
--- a/spec/rust/test_bits_signed_shift_b64_le.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::BitsSignedShiftB64Le;
-
-#[test]
-fn test_bits_signed_shift_b64_le() {
- if let Ok(r) = BitsSignedShiftB64Le::from_file("src/bits_signed_shift_b64_le.bin") {
-
- assert_eq!(r.a, 0);
- assert_eq!(r.b, 255);
- }
-}
diff --git a/spec/rust/test_bits_unaligned_b32_be.rs b/spec/rust/test_bits_unaligned_b32_be.rs
deleted file mode 100644
index 8b79d1fc7..000000000
--- a/spec/rust/test_bits_unaligned_b32_be.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::BitsUnalignedB32Be;
-
-#[test]
-fn test_bits_unaligned_b32_be() {
- if let Ok(r) = BitsUnalignedB32Be::from_file("src/process_xor_4.bin") {
-
- assert_eq!(r.a, true);
- assert_eq!(r.b, 3648472617);
- assert_eq!(r.c, 10);
- }
-}
diff --git a/spec/rust/test_bits_unaligned_b32_le.rs b/spec/rust/test_bits_unaligned_b32_le.rs
deleted file mode 100644
index f10b8fea3..000000000
--- a/spec/rust/test_bits_unaligned_b32_le.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::BitsUnalignedB32Le;
-
-#[test]
-fn test_bits_unaligned_b32_le() {
- if let Ok(r) = BitsUnalignedB32Le::from_file("src/process_xor_4.bin") {
-
- assert_eq!(r.a, false);
- assert_eq!(r.b, 173137398);
- assert_eq!(r.c, 69);
- }
-}
diff --git a/spec/rust/test_bits_unaligned_b64_be.rs b/spec/rust/test_bits_unaligned_b64_be.rs
deleted file mode 100644
index f363228f6..000000000
--- a/spec/rust/test_bits_unaligned_b64_be.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::BitsUnalignedB64Be;
-
-#[test]
-fn test_bits_unaligned_b64_be() {
- if let Ok(r) = BitsUnalignedB64Be::from_file("src/process_xor_4.bin") {
-
- assert_eq!(r.a, true);
- assert_eq!(r.b, 15670070570729969769);
- assert_eq!(r.c, 14);
- }
-}
diff --git a/spec/rust/test_bits_unaligned_b64_le.rs b/spec/rust/test_bits_unaligned_b64_le.rs
deleted file mode 100644
index 01e65d299..000000000
--- a/spec/rust/test_bits_unaligned_b64_le.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::BitsUnalignedB64Le;
-
-#[test]
-fn test_bits_unaligned_b64_le() {
- if let Ok(r) = BitsUnalignedB64Le::from_file("src/process_xor_4.bin") {
-
- assert_eq!(r.a, false);
- assert_eq!(r.b, 1902324737369038326);
- assert_eq!(r.c, 71);
- }
-}
diff --git a/spec/rust/test_combine_bool.rs b/spec/rust/test_combine_bool.rs
deleted file mode 100644
index 6028ecc4a..000000000
--- a/spec/rust/test_combine_bool.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::CombineBool;
-
-#[test]
-fn test_combine_bool() {
- if let Ok(r) = CombineBool::from_file("src/enum_negative.bin") {
-
- assert_eq!(r.bool_bit, true);
- assert_eq!(r.bool_calc_bit, false);
- }
-}
diff --git a/spec/rust/test_combine_bytes.rs b/spec/rust/test_combine_bytes.rs
deleted file mode 100644
index 3478e95d8..000000000
--- a/spec/rust/test_combine_bytes.rs
+++ /dev/null
@@ -1,24 +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::CombineBytes;
-
-#[test]
-fn test_combine_bytes() {
- if let Ok(r) = CombineBytes::from_file("src/term_strz.bin") {
-
- assert_eq!(r.bytes_term, vec!([0x66, 0x6f, 0x6f]));
- assert_eq!(r.bytes_limit, vec!([0x62, 0x61, 0x72, 0x7c]));
- assert_eq!(r.bytes_eos, vec!([0x62, 0x61, 0x7a, 0x40]));
- assert_eq!(r.bytes_calc, vec!([0x52, 0x6e, 0x44]));
- assert_eq!(r.term_or_limit, vec!([0x66, 0x6f, 0x6f]));
- assert_eq!(r.term_or_eos, vec!([0x62, 0x61, 0x7a, 0x40]));
- assert_eq!(r.term_or_calc, vec!([0x66, 0x6f, 0x6f]));
- assert_eq!(r.limit_or_eos, vec!([0x62, 0x61, 0x72, 0x7c]));
- assert_eq!(r.limit_or_calc, vec!([0x52, 0x6e, 0x44]));
- assert_eq!(r.eos_or_calc, vec!([0x62, 0x61, 0x7a, 0x40]));
- }
-}
diff --git a/spec/rust/test_combine_enum.rs b/spec/rust/test_combine_enum.rs
deleted file mode 100644
index c8a1da4b6..000000000
--- a/spec/rust/test_combine_enum.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::CombineEnum;
-
-#[test]
-fn test_combine_enum() {
- if let Ok(r) = CombineEnum::from_file("src/enum_0.bin") {
-
- assert_eq!(r.enum_u4, CombineEnum__Animal::PIG);
- assert_eq!(r.enum_u2, CombineEnum__Animal::HORSE);
- assert_eq!(r.enum_u4_u2, CombineEnum__Animal::HORSE);
- }
-}
diff --git a/spec/rust/test_combine_str.rs b/spec/rust/test_combine_str.rs
deleted file mode 100644
index 19bbd71d6..000000000
--- a/spec/rust/test_combine_str.rs
+++ /dev/null
@@ -1,29 +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::CombineStr;
-
-#[test]
-fn test_combine_str() {
- if let Ok(r) = CombineStr::from_file("src/term_strz.bin") {
-
- assert_eq!(r.str_term, "foo");
- assert_eq!(r.str_limit, "bar|");
- assert_eq!(r.str_eos, "baz@");
- assert_eq!(r.str_calc, "bar");
- assert_eq!(r.str_calc_bytes, "baz");
- assert_eq!(r.term_or_limit, "foo");
- assert_eq!(r.term_or_eos, "baz@");
- assert_eq!(r.term_or_calc, "foo");
- assert_eq!(r.term_or_calc_bytes, "baz");
- assert_eq!(r.limit_or_eos, "bar|");
- assert_eq!(r.limit_or_calc, "bar");
- assert_eq!(r.limit_or_calc_bytes, "bar|");
- assert_eq!(r.eos_or_calc, "bar");
- assert_eq!(r.eos_or_calc_bytes, "baz@");
- assert_eq!(r.calc_or_calc_bytes, "baz");
- }
-}
diff --git a/spec/rust/test_debug_switch_user.rs b/spec/rust/test_debug_switch_user.rs
deleted file mode 100644
index a708987d3..000000000
--- a/spec/rust/test_debug_switch_user.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::DebugSwitchUser;
-
-#[test]
-fn test_debug_switch_user() {
- if let Ok(r) = DebugSwitchUser::from_file("src/nav_parent_switch.bin") {
-
- assert_eq!(r.code, 1);
- assert_eq!(r.data.val, -190);
- }
-}
diff --git a/spec/rust/test_enum_import_literals.rs b/spec/rust/test_enum_import_literals.rs
deleted file mode 100644
index 000c6dcf4..000000000
--- a/spec/rust/test_enum_import_literals.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::EnumImportLiterals;
-
-#[test]
-fn test_enum_import_literals() {
- if let Ok(r) = EnumImportLiterals::from_file("src/enum_0.bin") {
-
- assert_eq!(r.pet_1_to_i, 7);
- assert_eq!(r.pet_1_eq, true);
- assert_eq!(r.pet_2, EnumDeep__Container1__Container2__Animal::HARE);
- }
-}
diff --git a/spec/rust/test_enum_import_seq.rs b/spec/rust/test_enum_import_seq.rs
deleted file mode 100644
index 49d182ae1..000000000
--- a/spec/rust/test_enum_import_seq.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::EnumImportSeq;
-
-#[test]
-fn test_enum_import_seq() {
- if let Ok(r) = EnumImportSeq::from_file("src/enum_0.bin") {
-
- assert_eq!(r.pet_1, Enum0__Animal::CAT);
- assert_eq!(r.pet_2, EnumDeep__Container1__Container2__Animal::HARE);
- }
-}
diff --git a/spec/rust/test_enum_int_range_s.rs b/spec/rust/test_enum_int_range_s.rs
deleted file mode 100644
index c696c12ad..000000000
--- a/spec/rust/test_enum_int_range_s.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::EnumIntRangeS;
-
-#[test]
-fn test_enum_int_range_s() {
- if let Ok(r) = EnumIntRangeS::from_file("src/enum_int_range_s.bin") {
-
- assert_eq!(r.f1, EnumIntRangeS__Constants::INT_MIN);
- assert_eq!(r.f2, EnumIntRangeS__Constants::ZERO);
- assert_eq!(r.f3, EnumIntRangeS__Constants::INT_MAX);
- }
-}
diff --git a/spec/rust/test_enum_int_range_u.rs b/spec/rust/test_enum_int_range_u.rs
deleted file mode 100644
index fcb7d722c..000000000
--- a/spec/rust/test_enum_int_range_u.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::EnumIntRangeU;
-
-#[test]
-fn test_enum_int_range_u() {
- if let Ok(r) = EnumIntRangeU::from_file("src/enum_int_range_u.bin") {
-
- assert_eq!(r.f1, EnumIntRangeU__Constants::ZERO);
- assert_eq!(r.f2, EnumIntRangeU__Constants::INT_MAX);
- }
-}
diff --git a/spec/rust/test_enum_invalid.rs b/spec/rust/test_enum_invalid.rs
deleted file mode 100644
index de93ff0d7..000000000
--- a/spec/rust/test_enum_invalid.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::EnumInvalid;
-
-#[test]
-fn test_enum_invalid() {
- if let Ok(r) = EnumInvalid::from_file("src/term_strz.bin") {
-
- assert_eq!(r.pet_1, EnumInvalid__Animal::DOG);
- assert_eq!(r.pet_2, 111);
- }
-}
diff --git a/spec/rust/test_enum_long_range_s.rs b/spec/rust/test_enum_long_range_s.rs
deleted file mode 100644
index 4d6b324b0..000000000
--- a/spec/rust/test_enum_long_range_s.rs
+++ /dev/null
@@ -1,21 +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::EnumLongRangeS;
-
-#[test]
-fn test_enum_long_range_s() {
- if let Ok(r) = EnumLongRangeS::from_file("src/enum_long_range_s.bin") {
-
- assert_eq!(r.f1, EnumLongRangeS__Constants::LONG_MIN);
- assert_eq!(r.f2, EnumLongRangeS__Constants::INT_BELOW_MIN);
- assert_eq!(r.f3, EnumLongRangeS__Constants::INT_MIN);
- assert_eq!(r.f4, EnumLongRangeS__Constants::ZERO);
- assert_eq!(r.f5, EnumLongRangeS__Constants::INT_MAX);
- assert_eq!(r.f6, EnumLongRangeS__Constants::INT_OVER_MAX);
- assert_eq!(r.f7, EnumLongRangeS__Constants::LONG_MAX);
- }
-}
diff --git a/spec/rust/test_enum_long_range_u.rs b/spec/rust/test_enum_long_range_u.rs
deleted file mode 100644
index 9ebf317d4..000000000
--- a/spec/rust/test_enum_long_range_u.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::EnumLongRangeU;
-
-#[test]
-fn test_enum_long_range_u() {
- if let Ok(r) = EnumLongRangeU::from_file("src/enum_long_range_u.bin") {
-
- assert_eq!(r.f1, EnumLongRangeU__Constants::ZERO);
- assert_eq!(r.f2, EnumLongRangeU__Constants::INT_MAX);
- assert_eq!(r.f3, EnumLongRangeU__Constants::INT_OVER_MAX);
- assert_eq!(r.f4, EnumLongRangeU__Constants::LONG_MAX);
- }
-}
diff --git a/spec/rust/test_enum_to_i.rs b/spec/rust/test_enum_to_i.rs
deleted file mode 100644
index 6ed2bb37e..000000000
--- a/spec/rust/test_enum_to_i.rs
+++ /dev/null
@@ -1,22 +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::EnumToI;
-
-#[test]
-fn test_enum_to_i() {
- if let Ok(r) = EnumToI::from_file("src/enum_0.bin") {
-
- assert_eq!(r.pet_1, EnumToI__Animal::CAT);
- assert_eq!(r.pet_2, EnumToI__Animal::CHICKEN);
- assert_eq!(r.pet_1_i, 7);
- assert_eq!(r.pet_1_i_to_s, "7");
- assert_eq!(r.pet_1_mod, 32775);
- assert_eq!(r.one_lt_two, true);
- assert_eq!(r.pet_1_eq_int, true);
- assert_eq!(r.pet_2_eq_int, false);
- }
-}
diff --git a/spec/rust/test_enum_to_i_class_border_1.rs b/spec/rust/test_enum_to_i_class_border_1.rs
deleted file mode 100644
index 175c56a8c..000000000
--- a/spec/rust/test_enum_to_i_class_border_1.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::EnumToIClassBorder1;
-
-#[test]
-fn test_enum_to_i_class_border_1() {
- if let Ok(r) = EnumToIClassBorder1::from_file("src/enum_0.bin") {
-
- assert_eq!(r.pet_1, EnumToIClassBorder1__Animal::CAT);
- assert_eq!(r.pet_2, EnumToIClassBorder1__Animal::CHICKEN);
- assert_eq!(r.checker.is_dog, true);
- }
-}
diff --git a/spec/rust/test_expr_bits.rs b/spec/rust/test_expr_bits.rs
deleted file mode 100644
index 316b4a9b6..000000000
--- a/spec/rust/test_expr_bits.rs
+++ /dev/null
@@ -1,24 +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::ExprBits;
-
-#[test]
-fn test_expr_bits() {
- if let Ok(r) = ExprBits::from_file("src/switch_opcodes.bin") {
-
- assert_eq!(r.a, 2);
- assert_eq!(r.enum_seq, ExprBits__Items::FOO);
- assert_eq!(r.byte_size, vec!([0x66, 0x6f]));
- assert_eq!(r.repeat_expr.len(), 2);
- assert_eq!(r.repeat_expr[0], 111);
- assert_eq!(r.repeat_expr[1], 98);
- assert_eq!(r.switch_on_type, 97);
- assert_eq!(r.switch_on_endian.foo, 29184);
- assert_eq!(r.enum_inst, ExprBits__Items::BAR);
- assert_eq!(r.inst_pos, 111);
- }
-}
diff --git a/spec/rust/test_expr_bytes_non_literal.rs b/spec/rust/test_expr_bytes_non_literal.rs
deleted file mode 100644
index d61cc5872..000000000
--- a/spec/rust/test_expr_bytes_non_literal.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::ExprBytesNonLiteral;
-
-#[test]
-fn test_expr_bytes_non_literal() {
- if let Ok(r) = ExprBytesNonLiteral::from_file("src/enum_negative.bin") {
-
- assert_eq!(r.calc_bytes.len(), 2);
- assert_eq!(r.calc_bytes[0], 255);
- assert_eq!(r.calc_bytes[1], 1);
- }
-}
diff --git a/spec/rust/test_expr_bytes_ops.rs b/spec/rust/test_expr_bytes_ops.rs
deleted file mode 100644
index 093d4a182..000000000
--- a/spec/rust/test_expr_bytes_ops.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::ExprBytesOps;
-
-#[test]
-fn test_expr_bytes_ops() {
- if let Ok(r) = ExprBytesOps::from_file("src/nav_parent_switch.bin") {
-
- assert_eq!(r.one_size, 3);
- assert_eq!(r.one_first, 1);
- assert_eq!(r.one_mid, 66);
- assert_eq!(r.one_last, 255);
- assert_eq!(r.one_last.to_string(), "255");
- assert_eq!(r.one_min, 1);
- assert_eq!(r.one_max, 255);
- assert_eq!(r.one_max.to_string(), "255");
- assert_eq!(r.two_size, 3);
- assert_eq!(r.two_first, 65);
- assert_eq!(r.two_mid, 255);
- assert_eq!(r.two_mid.to_string(), "255");
- assert_eq!(r.two_last, 75);
- assert_eq!(r.two_min, 65);
- assert_eq!(r.two_max, 255);
- assert_eq!(r.two_max.to_string(), "255");
- }
-}
diff --git a/spec/rust/test_expr_calc_array_ops.rs b/spec/rust/test_expr_calc_array_ops.rs
deleted file mode 100644
index 6ce63be43..000000000
--- a/spec/rust/test_expr_calc_array_ops.rs
+++ /dev/null
@@ -1,32 +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::ExprCalcArrayOps;
-
-#[test]
-fn test_expr_calc_array_ops() {
- if let Ok(r) = ExprCalcArrayOps::from_file("src/fixed_struct.bin") {
-
- assert_eq!(r.int_array_size, 7);
- assert_eq!(r.int_array_first, 10);
- assert_eq!(r.int_array_mid, 25);
- assert_eq!(r.int_array_last, 1000);
- assert_eq!(r.int_array_min, 10);
- assert_eq!(r.int_array_max, 1000);
- assert_eq!(r.double_array_size, 5);
- assert_eq!(r.double_array_first, 10.0);
- assert_eq!(r.double_array_mid, 25.0);
- assert_eq!(r.double_array_last, 3.14159);
- assert_eq!(r.double_array_min, 3.14159);
- assert_eq!(r.double_array_max, 100.0);
- assert_eq!(r.str_array_size, 4);
- assert_eq!(r.str_array_first, "un");
- assert_eq!(r.str_array_mid, "deux");
- assert_eq!(r.str_array_last, "quatre");
- assert_eq!(r.str_array_min, "deux");
- assert_eq!(r.str_array_max, "un");
- }
-}
diff --git a/spec/rust/test_expr_fstring_0.rs b/spec/rust/test_expr_fstring_0.rs
deleted file mode 100644
index 7552f02d4..000000000
--- a/spec/rust/test_expr_fstring_0.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::ExprFstring0;
-
-#[test]
-fn test_expr_fstring_0() {
- if let Ok(r) = ExprFstring0::from_file("src/term_strz.bin") {
-
- assert_eq!(r.seq_str, "foo|b");
- assert_eq!(r.seq_int, 97);
- assert_eq!(r.empty, "");
- assert_eq!(r.literal, "abc");
- assert_eq!(r.literal_with_escapes, "abc\n\tt");
- assert_eq!(r.head_and_int_literal, "abc=123");
- assert_eq!(r.head_and_str_literal, "abc=foo");
- assert_eq!(r.head_and_int, "abc=97");
- assert_eq!(r.head_and_str, "abc=foo|b");
- }
-}
diff --git a/spec/rust/test_expr_if_int_ops.rs b/spec/rust/test_expr_if_int_ops.rs
deleted file mode 100644
index 5fcc93aa9..000000000
--- a/spec/rust/test_expr_if_int_ops.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::ExprIfIntOps;
-
-#[test]
-fn test_expr_if_int_ops() {
- if let Ok(r) = ExprIfIntOps::from_file("src/process_coerce_switch.bin") {
-
- assert_eq!(r.is_eq_prim, true);
- assert_eq!(r.is_eq_boxed, true);
- }
-}
diff --git a/spec/rust/test_expr_int_div.rs b/spec/rust/test_expr_int_div.rs
deleted file mode 100644
index 7ecb682ff..000000000
--- a/spec/rust/test_expr_int_div.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::ExprIntDiv;
-
-#[test]
-fn test_expr_int_div() {
- if let Ok(r) = ExprIntDiv::from_file("src/fixed_struct.bin") {
-
- assert_eq!(r.int_u, 1262698832);
- assert_eq!(r.int_s, -52947);
- assert_eq!(r.div_pos_const, 756);
- assert_eq!(r.div_neg_const, -757);
- assert_eq!(r.div_pos_seq, 97130679);
- assert_eq!(r.div_neg_seq, -4073);
- }
-}
diff --git a/spec/rust/test_expr_io_eof.rs b/spec/rust/test_expr_io_eof.rs
deleted file mode 100644
index cbf9b0606..000000000
--- a/spec/rust/test_expr_io_eof.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::ExprIoEof;
-
-#[test]
-fn test_expr_io_eof() {
- if let Ok(r) = ExprIoEof::from_file("src/fixed_struct.bin") {
-
- assert_eq!(r.substream1.one, 1262698832);
- assertNull(r.substream1.two);
- assert_eq!(r.substream2.one, 4294914349);
- assert_eq!(r.substream2.two, 1262698832);
- }
-}
diff --git a/spec/rust/test_expr_io_ternary.rs b/spec/rust/test_expr_io_ternary.rs
deleted file mode 100644
index 5fc6c9715..000000000
--- a/spec/rust/test_expr_io_ternary.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::ExprIoTernary;
-
-#[test]
-fn test_expr_io_ternary() {
- if let Ok(r) = ExprIoTernary::from_file("src/if_struct.bin") {
-
- assert_eq!(r.one_or_two_io_size1, 8);
- assert_eq!(r.one_or_two_io_size2, 8);
- assert_eq!(r.one_or_two_io_size_add_3, 11);
- }
-}
diff --git a/spec/rust/test_expr_ops_parens.rs b/spec/rust/test_expr_ops_parens.rs
deleted file mode 100644
index 7cfd742ca..000000000
--- a/spec/rust/test_expr_ops_parens.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::ExprOpsParens;
-
-#[test]
-fn test_expr_ops_parens() {
- if let Ok(r) = ExprOpsParens::from_file("src/enum_negative.bin") {
-
- assert_eq!(r.i_sum_to_str, "29");
- assert_eq!(r.f_sum_to_int, 9);
- assert_eq!(r.str_concat_len, 10);
- assert_eq!(r.str_concat_rev, "9876543210");
- assert_eq!(r.str_concat_substr_2_to_7, "23456");
- assert_eq!(r.str_concat_to_i, 123456789);
- assert_eq!(r.bool_eq, 0);
- assert_eq!(r.bool_and, 0);
- assert_eq!(r.bool_or, 1);
- }
-}
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_expr_str_encodings.rs b/spec/rust/test_expr_str_encodings.rs
deleted file mode 100644
index c4f9b64b4..000000000
--- a/spec/rust/test_expr_str_encodings.rs
+++ /dev/null
@@ -1,21 +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::ExprStrEncodings;
-
-#[test]
-fn test_expr_str_encodings() {
- if let Ok(r) = ExprStrEncodings::from_file("src/str_encodings.bin") {
-
- assert_eq!(r.str1_eq, true);
- assert_eq!(r.str2_eq, true);
- assert_eq!(r.str3_eq, true);
- assert_eq!(r.str3_eq_str2, true);
- assert_eq!(r.str4_eq, true);
- assert_eq!(r.str4_gt_str_calc, true);
- assert_eq!(r.str4_gt_str_from_bytes, true);
- }
-}
diff --git a/spec/rust/test_expr_str_ops.rs b/spec/rust/test_expr_str_ops.rs
deleted file mode 100644
index bba9cda5b..000000000
--- a/spec/rust/test_expr_str_ops.rs
+++ /dev/null
@@ -1,32 +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::ExprStrOps;
-
-#[test]
-fn test_expr_str_ops() {
- if let Ok(r) = ExprStrOps::from_file("src/term_strz.bin") {
-
- assert_eq!(r.one, "foo|b");
- assert_eq!(r.one_len, 5);
- assert_eq!(r.one_rev, "b|oof");
- assert_eq!(r.one_substr_0_to_3, "foo");
- assert_eq!(r.one_substr_2_to_5, "o|b");
- assert_eq!(r.one_substr_3_to_3, "");
- assert_eq!(r.one_substr_0_to_0, "");
- assert_eq!(r.two, "0123456789");
- assert_eq!(r.two_len, 10);
- assert_eq!(r.two_rev, "9876543210");
- assert_eq!(r.two_substr_0_to_7, "0123456");
- assert_eq!(r.two_substr_4_to_10, "456789");
- assert_eq!(r.two_substr_0_to_10, "0123456789");
- assert_eq!(r.to_i_attr, 9173);
- assert_eq!(r.to_i_r10, -72);
- assert_eq!(r.to_i_r2, 86);
- assert_eq!(r.to_i_r8, 465);
- assert_eq!(r.to_i_r16, 18383);
- }
-}
diff --git a/spec/rust/test_imports_abs_abs.rs b/spec/rust/test_imports_abs_abs.rs
deleted file mode 100644
index 386641991..000000000
--- a/spec/rust/test_imports_abs_abs.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-extern crate kaitai_struct;
-extern crate rust;
-
-use kaitai_struct::KaitaiStruct;
-use rust::ImportsAbsAbs;
-
-#[test]
-fn test_imports_abs_abs() {
- if let Ok(r) = ImportsAbsAbs::from_file("src/fixed_struct.bin") {
-
- assert_eq!(r.one, 80);
- assert_eq!(r.two.one, 65);
- assert_eq!(r.two.two.one, 67);
- }
-}
diff --git a/spec/rust/test_imports_abs_rel.rs b/spec/rust/test_imports_abs_rel.rs
deleted file mode 100644
index d6394effd..000000000
--- a/spec/rust/test_imports_abs_rel.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-extern crate kaitai_struct;
-extern crate rust;
-
-use kaitai_struct::KaitaiStruct;
-use rust::ImportsAbsRel;
-
-#[test]
-fn test_imports_abs_rel() {
- if let Ok(r) = ImportsAbsRel::from_file("src/fixed_struct.bin") {
-
- assert_eq!(r.one, 80);
- assert_eq!(r.two.one, 65);
- assert_eq!(r.two.two.one, 67);
- }
-}
diff --git a/spec/rust/test_imports_circular_a.rs b/spec/rust/test_imports_circular_a.rs
deleted file mode 100644
index 5be49aa2c..000000000
--- a/spec/rust/test_imports_circular_a.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::ImportsCircularA;
-
-#[test]
-fn test_imports_circular_a() {
- if let Ok(r) = ImportsCircularA::from_file("src/fixed_struct.bin") {
-
- assert_eq!(r.code, 80);
- assert_eq!(r.two.initial, 65);
- assert_eq!(r.two.back_ref.code, 67);
- assert_eq!(r.two.back_ref.two.initial, 75);
- assertNull(r.two.back_ref.two.back_ref);
- }
-}
diff --git a/spec/rust/test_imports_params_def_enum_imported.rs b/spec/rust/test_imports_params_def_enum_imported.rs
deleted file mode 100644
index 9e22015b1..000000000
--- a/spec/rust/test_imports_params_def_enum_imported.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::ImportsParamsDefEnumImported;
-
-#[test]
-fn test_imports_params_def_enum_imported() {
- if let Ok(r) = ImportsParamsDefEnumImported::from_file("src/enum_0.bin") {
-
- assert_eq!(r.one.pet_1, Enum0__Animal::CAT);
- assert_eq!(r.one.pet_2, EnumDeep__Container1__Container2__Animal::HARE);
- assert_eq!(r.two.pet_1_param, Enum0__Animal::CAT);
- assert_eq!(r.two.pet_2_param, EnumDeep__Container1__Container2__Animal::HARE);
- }
-}
diff --git a/spec/rust/test_imports_rel_1.rs b/spec/rust/test_imports_rel_1.rs
deleted file mode 100644
index 767d1f753..000000000
--- a/spec/rust/test_imports_rel_1.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::ImportsRel1;
-
-#[test]
-fn test_imports_rel_1() {
- if let Ok(r) = ImportsRel1::from_file("src/fixed_struct.bin") {
-
- assert_eq!(r.one, 80);
- assert_eq!(r.two.one, 65);
- assert_eq!(r.two.two.one, 67);
- }
-}
diff --git a/spec/rust/test_integers_double_overflow.rs b/spec/rust/test_integers_double_overflow.rs
deleted file mode 100644
index 0d9a8f9f2..000000000
--- a/spec/rust/test_integers_double_overflow.rs
+++ /dev/null
@@ -1,22 +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::IntegersDoubleOverflow;
-
-#[test]
-fn test_integers_double_overflow() {
- if let Ok(r) = IntegersDoubleOverflow::from_file("src/integers_double_overflow.bin") {
-
- assert_eq!(r.signed_safe_min_be, -9007199254740991);
- assert_eq!(r.signed_safe_min_le, -9007199254740991);
- assert_eq!(r.signed_safe_max_be, 9007199254740991);
- assert_eq!(r.signed_safe_max_le, 9007199254740991);
- assert_eq!(r.signed_unsafe_neg_be.to_string(), "-9007199254740993");
- assert_eq!(r.signed_unsafe_neg_le.to_string(), "-9007199254740993");
- assert_eq!(r.signed_unsafe_pos_be.to_string(), "9007199254740993");
- assert_eq!(r.signed_unsafe_pos_be.to_string(), "9007199254740993");
- }
-}
diff --git a/spec/rust/test_integers_min_max.rs b/spec/rust/test_integers_min_max.rs
deleted file mode 100644
index 1740c0dfb..000000000
--- a/spec/rust/test_integers_min_max.rs
+++ /dev/null
@@ -1,42 +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::IntegersMinMax;
-
-#[test]
-fn test_integers_min_max() {
- if let Ok(r) = IntegersMinMax::from_file("src/integers_min_max.bin") {
-
- assert_eq!(r.unsigned_min.u1, 0);
- assert_eq!(r.unsigned_min.u2le, 0);
- assert_eq!(r.unsigned_min.u4le, 0);
- assert_eq!(r.unsigned_min.u8le, 0);
- assert_eq!(r.unsigned_min.u2be, 0);
- assert_eq!(r.unsigned_min.u4be, 0);
- assert_eq!(r.unsigned_min.u8be, 0);
- assert_eq!(r.unsigned_max.u1, 255);
- assert_eq!(r.unsigned_max.u2le, 65535);
- assert_eq!(r.unsigned_max.u4le, 4294967295);
- assert_eq!(r.unsigned_max.u8le, 18446744073709551615);
- assert_eq!(r.unsigned_max.u2be, 65535);
- assert_eq!(r.unsigned_max.u4be, 4294967295);
- assert_eq!(r.unsigned_max.u8be, 18446744073709551615);
- assert_eq!(r.signed_min.s1, -128);
- assert_eq!(r.signed_min.s2le, -32768);
- assert_eq!(r.signed_min.s4le, -2147483648);
- assert_eq!(r.signed_min.s8le, -9223372036854775808);
- assert_eq!(r.signed_min.s2be, -32768);
- assert_eq!(r.signed_min.s4be, -2147483648);
- assert_eq!(r.signed_min.s8be, -9223372036854775808);
- assert_eq!(r.signed_max.s1, 127);
- assert_eq!(r.signed_max.s2le, 32767);
- assert_eq!(r.signed_max.s4le, 2147483647);
- assert_eq!(r.signed_max.s8le, 9223372036854775807);
- assert_eq!(r.signed_max.s2be, 32767);
- assert_eq!(r.signed_max.s4be, 2147483647);
- assert_eq!(r.signed_max.s8be, 9223372036854775807);
- }
-}
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_nav_parent_switch_cast.rs b/spec/rust/test_nav_parent_switch_cast.rs
deleted file mode 100644
index 68f83a4a4..000000000
--- a/spec/rust/test_nav_parent_switch_cast.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::NavParentSwitchCast;
-
-#[test]
-fn test_nav_parent_switch_cast() {
- if let Ok(r) = NavParentSwitchCast::from_file("src/switch_integers.bin") {
-
- assert_eq!(r.main.buf_type, 1);
- assert_eq!(r.main.flag, 7);
- assert_eq!(r.main.buf.branch.flag, 7);
- }
-}
diff --git a/spec/rust/test_nested_type_param.rs b/spec/rust/test_nested_type_param.rs
deleted file mode 100644
index a0734e442..000000000
--- a/spec/rust/test_nested_type_param.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::NestedTypeParam;
-
-#[test]
-fn test_nested_type_param() {
- if let Ok(r) = NestedTypeParam::from_file("src/term_strz.bin") {
-
- assert_eq!(r.main_seq.my_len, 5);
- assert_eq!(r.main_seq.body, "foo|b");
- }
-}
diff --git a/spec/rust/test_nested_types_import.rs b/spec/rust/test_nested_types_import.rs
deleted file mode 100644
index e37060a8d..000000000
--- a/spec/rust/test_nested_types_import.rs
+++ /dev/null
@@ -1,17 +0,0 @@
-extern crate kaitai_struct;
-extern crate rust;
-
-use kaitai_struct::KaitaiStruct;
-use rust::NestedTypesImport;
-
-#[test]
-fn test_nested_types_import() {
- if let Ok(r) = NestedTypesImport::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);
- }
-}
diff --git a/spec/rust/test_opaque_external_type_02_parent.rs b/spec/rust/test_opaque_external_type_02_parent.rs
deleted file mode 100644
index 776be1f18..000000000
--- a/spec/rust/test_opaque_external_type_02_parent.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-extern crate kaitai_struct;
-extern crate rust;
-
-use kaitai_struct::KaitaiStruct;
-use rust::OpaqueExternalType02Parent;
-
-#[test]
-fn test_opaque_external_type_02_parent() {
- if let Ok(r) = OpaqueExternalType02Parent::from_file("src/term_strz.bin") {
-
- assert_eq!(r.parent.child.s1, "foo");
- assert_eq!(r.parent.child.s2, "bar");
- assert_eq!(r.parent.child.s3.s3, "|baz@");
- }
-}
diff --git a/spec/rust/test_optional_id.rs b/spec/rust/test_optional_id.rs
deleted file mode 100644
index aa4df6d26..000000000
--- a/spec/rust/test_optional_id.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-extern crate kaitai_struct;
-extern crate rust;
-
-use kaitai_struct::KaitaiStruct;
-use rust::OptionalId;
-
-#[test]
-fn test_optional_id() {
- if let Ok(r) = OptionalId::from_file("src/fixed_struct.bin") {
-
- assert_eq!(r._unnamed0, 80);
- assert_eq!(r._unnamed1, 65);
- assert_eq!(r._unnamed2, vec!([0x43, 0x4b, 0x2d, 0x31, 0xff]));
- }
-}
diff --git a/spec/rust/test_params_call.rs b/spec/rust/test_params_call.rs
deleted file mode 100644
index 16a05638d..000000000
--- a/spec/rust/test_params_call.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::ParamsCall;
-
-#[test]
-fn test_params_call() {
- if let Ok(r) = ParamsCall::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);
- }
-}
diff --git a/spec/rust/test_params_call_extra_parens.rs b/spec/rust/test_params_call_extra_parens.rs
deleted file mode 100644
index 31bc621b7..000000000
--- a/spec/rust/test_params_call_extra_parens.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::ParamsCallExtraParens;
-
-#[test]
-fn test_params_call_extra_parens() {
- if let Ok(r) = ParamsCallExtraParens::from_file("src/term_strz.bin") {
-
- assert_eq!(r.buf1.body, "foo|b");
- }
-}
diff --git a/spec/rust/test_params_pass_array_int.rs b/spec/rust/test_params_pass_array_int.rs
deleted file mode 100644
index 68c3450e8..000000000
--- a/spec/rust/test_params_pass_array_int.rs
+++ /dev/null
@@ -1,21 +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::ParamsPassArrayInt;
-
-#[test]
-fn test_params_pass_array_int() {
- if let Ok(r) = ParamsPassArrayInt::from_file("src/position_to_end.bin") {
-
- assert_eq!(r.pass_ints.nums.len(), 3);
- assert_eq!(r.pass_ints.nums[0], 513);
- assert_eq!(r.pass_ints.nums[1], 1027);
- assert_eq!(r.pass_ints.nums[2], 1541);
- assert_eq!(r.pass_ints_calc.nums.len(), 2);
- assert_eq!(r.pass_ints_calc.nums[0], 27643);
- assert_eq!(r.pass_ints_calc.nums[1], 7);
- }
-}
diff --git a/spec/rust/test_params_pass_array_str.rs b/spec/rust/test_params_pass_array_str.rs
deleted file mode 100644
index 2890396db..000000000
--- a/spec/rust/test_params_pass_array_str.rs
+++ /dev/null
@@ -1,21 +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::ParamsPassArrayStr;
-
-#[test]
-fn test_params_pass_array_str() {
- if let Ok(r) = ParamsPassArrayStr::from_file("src/term_strz.bin") {
-
- assert_eq!(r.pass_str_array.strs.len(), 3);
- assert_eq!(r.pass_str_array.strs[0], "fo");
- assert_eq!(r.pass_str_array.strs[1], "o|");
- assert_eq!(r.pass_str_array.strs[2], "ba");
- assert_eq!(r.pass_str_array_calc.strs.len(), 2);
- assert_eq!(r.pass_str_array_calc.strs[0], "aB");
- assert_eq!(r.pass_str_array_calc.strs[1], "Cd");
- }
-}
diff --git a/spec/rust/test_params_pass_array_struct.rs b/spec/rust/test_params_pass_array_struct.rs
deleted file mode 100644
index 9ccada67d..000000000
--- a/spec/rust/test_params_pass_array_struct.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::ParamsPassArrayStruct;
-
-#[test]
-fn test_params_pass_array_struct() {
- if let Ok(r) = ParamsPassArrayStruct::from_file("src/position_to_end.bin") {
-
- assert_eq!(r.pass_structs.structs.len(), 2);
- assert_eq!(r.pass_structs.structs[0].f, 1);
- assert_eq!(r.pass_structs.structs[1].b, 2);
- }
-}
diff --git a/spec/rust/test_params_pass_array_usertype.rs b/spec/rust/test_params_pass_array_usertype.rs
deleted file mode 100644
index 089c58c63..000000000
--- a/spec/rust/test_params_pass_array_usertype.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::ParamsPassArrayUsertype;
-
-#[test]
-fn test_params_pass_array_usertype() {
- if let Ok(r) = ParamsPassArrayUsertype::from_file("src/position_to_end.bin") {
-
- assert_eq!(r.pass_blocks.bar.len(), 2);
- assert_eq!(r.pass_blocks.bar[0].foo, 1);
- assert_eq!(r.pass_blocks.bar[1].foo, 2);
- assert_eq!(r.pass_blocks.one, vec!([0x3]));
- assert_eq!(r.pass_blocks.two, vec!([0x4, 0x5]));
- }
-}
diff --git a/spec/rust/test_params_pass_bool.rs b/spec/rust/test_params_pass_bool.rs
deleted file mode 100644
index e33003d08..000000000
--- a/spec/rust/test_params_pass_bool.rs
+++ /dev/null
@@ -1,28 +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::ParamsPassBool;
-
-#[test]
-fn test_params_pass_bool() {
- if let Ok(r) = ParamsPassBool::from_file("src/term_strz.bin") {
-
- assert_eq!(r.s_false, false);
- assert_eq!(r.s_true, true);
- assert_eq!(r.seq_b1.arg, true);
- assert_eq!(r.seq_b1.foo.len(), 1);
- assert_eq!(r.seq_bool.arg, false);
- assert_eq!(r.seq_bool.foo.len(), 2);
- assert_eq!(r.literal_b1.arg, false);
- assert_eq!(r.literal_b1.foo.len(), 2);
- assert_eq!(r.literal_bool.arg, true);
- assert_eq!(r.literal_bool.foo.len(), 1);
- assert_eq!(r.inst_b1.arg, true);
- assert_eq!(r.inst_b1.foo.len(), 1);
- assert_eq!(r.inst_bool.arg, false);
- assert_eq!(r.inst_bool.foo.len(), 2);
- }
-}
diff --git a/spec/rust/test_params_pass_struct.rs b/spec/rust/test_params_pass_struct.rs
deleted file mode 100644
index de5b00b67..000000000
--- a/spec/rust/test_params_pass_struct.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::ParamsPassStruct;
-
-#[test]
-fn test_params_pass_struct() {
- if let Ok(r) = ParamsPassStruct::from_file("src/enum_negative.bin") {
-
- assert_eq!(r.first.foo, 255);
- assert_eq!(r.one.bar.qux, 1);
- assert_eq!(r.one.foo.foo, 255);
- assert_eq!(r.one.bar.foo.foo, 255);
- }
-}
diff --git a/spec/rust/test_process_custom_no_args.rs b/spec/rust/test_process_custom_no_args.rs
deleted file mode 100644
index 5de1d925e..000000000
--- a/spec/rust/test_process_custom_no_args.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::ProcessCustomNoArgs;
-
-#[test]
-fn test_process_custom_no_args() {
- if let Ok(r) = ProcessCustomNoArgs::from_file("src/process_rotate.bin") {
-
- assert_eq!(r.buf, vec!([0x5f, 0x9, 0xac, 0x8d, 0x8d, 0xed, 0x5f]));
- }
-}
diff --git a/spec/rust/test_process_repeat_bytes.rs b/spec/rust/test_process_repeat_bytes.rs
deleted file mode 100644
index 9be158d1f..000000000
--- a/spec/rust/test_process_repeat_bytes.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::ProcessRepeatBytes;
-
-#[test]
-fn test_process_repeat_bytes() {
- if let Ok(r) = ProcessRepeatBytes::from_file("src/process_xor_4.bin") {
-
- assert_eq!(r.bufs[0], vec!([0x72, 0x25, 0x3d, 0x8a, 0x14]));
- assert_eq!(r.bufs[1], vec!([0x4a, 0x52, 0xaa, 0x10, 0x44]));
- }
-}
diff --git a/spec/rust/test_process_repeat_usertype.rs b/spec/rust/test_process_repeat_usertype.rs
deleted file mode 100644
index 997487790..000000000
--- a/spec/rust/test_process_repeat_usertype.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::ProcessRepeatUsertype;
-
-#[test]
-fn test_process_repeat_usertype() {
- if let Ok(r) = ProcessRepeatUsertype::from_file("src/process_xor_4.bin") {
-
- assert_eq!(r.blocks[0].a, -1975704206);
- assert_eq!(r.blocks[0].b, 20);
- assert_eq!(r.blocks[1].a, 279597642);
- assert_eq!(r.blocks[1].b, 68);
- }
-}
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);
- }
-}
diff --git a/spec/rust/test_repeat_until_calc_array_type.rs b/spec/rust/test_repeat_until_calc_array_type.rs
deleted file mode 100644
index ad35a2b62..000000000
--- a/spec/rust/test_repeat_until_calc_array_type.rs
+++ /dev/null
@@ -1,21 +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::RepeatUntilCalcArrayType;
-
-#[test]
-fn test_repeat_until_calc_array_type() {
- if let Ok(r) = RepeatUntilCalcArrayType::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/test_str_encodings_utf16.rs b/spec/rust/test_str_encodings_utf16.rs
deleted file mode 100644
index 7c7e79e07..000000000
--- a/spec/rust/test_str_encodings_utf16.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::StrEncodingsUtf16;
-
-#[test]
-fn test_str_encodings_utf16() {
- if let Ok(r) = StrEncodingsUtf16::from_file("src/str_encodings_utf16.bin") {
-
- assert_eq!(r.len_be, 12);
- assert_eq!(r.be_bom_removed.bom, 65279);
- assert_eq!(r.be_bom_removed.str, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}");
- assert_eq!(r.len_le, 12);
- assert_eq!(r.le_bom_removed.bom, 65279);
- assert_eq!(r.le_bom_removed.str, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}");
- }
-}
diff --git a/spec/rust/test_switch_else_only.rs b/spec/rust/test_switch_else_only.rs
deleted file mode 100644
index be7d21115..000000000
--- a/spec/rust/test_switch_else_only.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::SwitchElseOnly;
-
-#[test]
-fn test_switch_else_only() {
- if let Ok(r) = SwitchElseOnly::from_file("src/switch_opcodes.bin") {
-
- assert_eq!(r.opcode, 83);
- assert_eq!(r.prim_byte, 102);
- assert_eq!(r.ut.value, vec!([0x72, 0x0, 0x49, 0x42]));
- }
-}
diff --git a/spec/rust/test_switch_manual_enum_invalid.rs b/spec/rust/test_switch_manual_enum_invalid.rs
deleted file mode 100644
index ea7bc0a8e..000000000
--- a/spec/rust/test_switch_manual_enum_invalid.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::SwitchManualEnumInvalid;
-
-#[test]
-fn test_switch_manual_enum_invalid() {
- if let Ok(r) = SwitchManualEnumInvalid::from_file("src/enum_negative.bin") {
-
- assert_eq!(r.opcodes.len(), 2);
- assert_eq!(r.opcodes[0].code, 255);
- assertNull(r.opcodes[0].body);
- assert_eq!(r.opcodes[1].code, 1);
- assertNull(r.opcodes[1].body);
- }
-}
diff --git a/spec/rust/test_switch_manual_enum_invalid_else.rs b/spec/rust/test_switch_manual_enum_invalid_else.rs
deleted file mode 100644
index e11c5ea0d..000000000
--- a/spec/rust/test_switch_manual_enum_invalid_else.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::SwitchManualEnumInvalidElse;
-
-#[test]
-fn test_switch_manual_enum_invalid_else() {
- if let Ok(r) = SwitchManualEnumInvalidElse::from_file("src/enum_negative.bin") {
-
- assert_eq!(r.opcodes.len(), 2);
- assert_eq!(r.opcodes[0].code, 255);
- assert_eq!(r.opcodes[0].body.value, 123);
- assert_eq!(r.opcodes[1].code, 1);
- assert_eq!(r.opcodes[1].body.value, 123);
- }
-}
diff --git a/spec/rust/test_switch_manual_int_size.rs b/spec/rust/test_switch_manual_int_size.rs
deleted file mode 100644
index 9dcfbe71a..000000000
--- a/spec/rust/test_switch_manual_int_size.rs
+++ /dev/null
@@ -1,24 +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::SwitchManualIntSize;
-
-#[test]
-fn test_switch_manual_int_size() {
- if let Ok(r) = SwitchManualIntSize::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, vec!([0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]));
- assert_eq!(r.chunks[3].code, 255);
- assert_eq!(r.chunks[3].body, vec!([]));
- }
-}
diff --git a/spec/rust/test_switch_manual_int_size_eos.rs b/spec/rust/test_switch_manual_int_size_eos.rs
deleted file mode 100644
index 734dde0c3..000000000
--- a/spec/rust/test_switch_manual_int_size_eos.rs
+++ /dev/null
@@ -1,24 +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::SwitchManualIntSizeEos;
-
-#[test]
-fn test_switch_manual_int_size_eos() {
- if let Ok(r) = SwitchManualIntSizeEos::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.body.title, "Stuff");
- assert_eq!(r.chunks[0].body.body.author, "Me");
- assert_eq!(r.chunks[1].code, 34);
- assert_eq!(r.chunks[1].body.body.entries, ["AAAA", "BBBB", "CCCC"]);
- assert_eq!(r.chunks[2].code, 51);
- assert_eq!(r.chunks[2].body.body, vec!([0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]));
- assert_eq!(r.chunks[3].code, 255);
- assert_eq!(r.chunks[3].body.body, vec!([]));
- }
-}
diff --git a/spec/rust/test_switch_multi_bool_ops.rs b/spec/rust/test_switch_multi_bool_ops.rs
deleted file mode 100644
index 044aac09a..000000000
--- a/spec/rust/test_switch_multi_bool_ops.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::SwitchMultiBoolOps;
-
-#[test]
-fn test_switch_multi_bool_ops() {
- if let Ok(r) = SwitchMultiBoolOps::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);
- }
-}
diff --git a/spec/rust/test_switch_repeat_expr.rs b/spec/rust/test_switch_repeat_expr.rs
deleted file mode 100644
index 7fbb69a2e..000000000
--- a/spec/rust/test_switch_repeat_expr.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::SwitchRepeatExpr;
-
-#[test]
-fn test_switch_repeat_expr() {
- if let Ok(r) = SwitchRepeatExpr::from_file("src/switch_tlv.bin") {
-
- assert_eq!(r.code, 17);
- assert_eq!(r.size, 9);
- assert_eq!(r.body[0].first, vec!([0x53, 0x74, 0x75, 0x66, 0x66, 0x0, 0x4d, 0x65, 0x0]));
- }
-}
diff --git a/spec/rust/test_switch_repeat_expr_invalid.rs b/spec/rust/test_switch_repeat_expr_invalid.rs
deleted file mode 100644
index 6249eb70f..000000000
--- a/spec/rust/test_switch_repeat_expr_invalid.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::SwitchRepeatExprInvalid;
-
-#[test]
-fn test_switch_repeat_expr_invalid() {
- if let Ok(r) = SwitchRepeatExprInvalid::from_file("src/switch_tlv.bin") {
-
- assert_eq!(r.code, 17);
- assert_eq!(r.size, 9);
- assert_eq!(r.body[0], vec!([0x53, 0x74, 0x75, 0x66, 0x66, 0x0, 0x4d, 0x65, 0x0]));
- }
-}
diff --git a/spec/rust/test_term_u1_val.rs b/spec/rust/test_term_u1_val.rs
deleted file mode 100644
index bff937bcf..000000000
--- a/spec/rust/test_term_u1_val.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::TermU1Val;
-
-#[test]
-fn test_term_u1_val() {
- if let Ok(r) = TermU1Val::from_file("src/str_encodings.bin") {
-
- assert_eq!(r.foo, vec!([0xa, 0x0, 0x53, 0x6f, 0x6d, 0x65, 0x20, 0x41, 0x53, 0x43, 0x49, 0x49, 0xf, 0x0]));
- assert_eq!(r.bar, "\u{3053}\u{3093}\u{306b}");
- }
-}
diff --git a/spec/rust/test_type_ternary_2nd_falsy.rs b/spec/rust/test_type_ternary_2nd_falsy.rs
deleted file mode 100644
index db684c869..000000000
--- a/spec/rust/test_type_ternary_2nd_falsy.rs
+++ /dev/null
@@ -1,27 +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::TypeTernary2ndFalsy;
-
-#[test]
-fn test_type_ternary_2nd_falsy() {
- if let Ok(r) = TypeTernary2ndFalsy::from_file("src/switch_integers.bin") {
-
- assert_eq!(r.v_false, false);
- assert_eq!(r.v_int_zero, 0);
- assert_eq!(r.v_int_neg_zero, -0);
- assert_eq!(r.v_float_zero, 0.0);
- assert_eq!(r.v_float_neg_zero, -0.0);
- assert_eq!(r.v_str_w_zero, "0");
- assert_eq!(r.v_str_w_zero.len(), 1);
- assert_eq!(r.ut.m, 7);
- assertNull(r.v_null_ut);
- assert_eq!(r.v_str_empty, "");
- assert_eq!(r.v_str_empty.len(), 0);
- assert_eq!(r.int_array.len(), 2);
- assert_eq!(r.v_int_array_empty.len(), 0);
- }
-}
diff --git a/spec/rust/test_valid_eq_str_encodings.rs b/spec/rust/test_valid_eq_str_encodings.rs
deleted file mode 100644
index 543823869..000000000
--- a/spec/rust/test_valid_eq_str_encodings.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::ValidEqStrEncodings;
-
-#[test]
-fn test_valid_eq_str_encodings() {
- if let Ok(r) = ValidEqStrEncodings::from_file("src/str_encodings.bin") {
-
- }
-}
diff --git a/spec/rust/test_valid_long.rs b/spec/rust/test_valid_long.rs
deleted file mode 100644
index bd8b3ec66..000000000
--- a/spec/rust/test_valid_long.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::ValidLong;
-
-#[test]
-fn test_valid_long() {
- if let Ok(r) = ValidLong::from_file("src/fixed_struct.bin") {
-
- }
-}
diff --git a/spec/rust/test_valid_not_parsed_if.rs b/spec/rust/test_valid_not_parsed_if.rs
deleted file mode 100644
index 400418205..000000000
--- a/spec/rust/test_valid_not_parsed_if.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::ValidNotParsedIf;
-
-#[test]
-fn test_valid_not_parsed_if() {
- if let Ok(r) = ValidNotParsedIf::from_file("src/fixed_struct.bin") {
-
- }
-}
diff --git a/spec/rust/test_valid_short.rs b/spec/rust/test_valid_short.rs
deleted file mode 100644
index f857b0d14..000000000
--- a/spec/rust/test_valid_short.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::ValidShort;
-
-#[test]
-fn test_valid_short() {
- if let Ok(r) = ValidShort::from_file("src/fixed_struct.bin") {
-
- }
-}
diff --git a/spec/rust/test_valid_switch.rs b/spec/rust/test_valid_switch.rs
deleted file mode 100644
index 33111ad07..000000000
--- a/spec/rust/test_valid_switch.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::ValidSwitch;
-
-#[test]
-fn test_valid_switch() {
- if let Ok(r) = ValidSwitch::from_file("src/fixed_struct.bin") {
-
- }
-}
diff --git a/spec/rust/test_yaml_ints.rs b/spec/rust/test_yaml_ints.rs
deleted file mode 100644
index 4723d3dae..000000000
--- a/spec/rust/test_yaml_ints.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::YamlInts;
-
-#[test]
-fn test_yaml_ints() {
- if let Ok(r) = YamlInts::from_file("src/fixed_struct.bin") {
-
- assert_eq!(r.test_u4_dec, 4294967295);
- assert_eq!(r.test_u4_hex, 4294967295);
- assert_eq!(r.test_u8_dec, 18446744073709551615);
- assert_eq!(r.test_u8_hex, 18446744073709551615);
- }
-}
diff --git a/spec/rust/test_zlib_surrounded.rs b/spec/rust/test_zlib_surrounded.rs
deleted file mode 100644
index d10797e26..000000000
--- a/spec/rust/test_zlib_surrounded.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::ZlibSurrounded;
-
-#[test]
-fn test_zlib_surrounded() {
- if let Ok(r) = ZlibSurrounded::from_file("src/zlib_surrounded.bin") {
-
- assert_eq!(r.zlib.num, -1);
- }
-}
diff --git a/spec/rust/tests/test_bcd_user_type_be.rs b/spec/rust/tests/test_bcd_user_type_be.rs
index 640195c8b..56580f5d6 100644
--- a/spec/rust/tests/test_bcd_user_type_be.rs
+++ b/spec/rust/tests/test_bcd_user_type_be.rs
@@ -1,19 +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::BcdUserTypeBe;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bcd_user_type_be::*;
#[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");
- }
+fn test_bcd_user_type_be() -> KResult<()> {
+ let bytes = fs::read("../../src/bcd_user_type_be.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BcdUserTypeBe::read_into(&_io, None, None)?;
+
+ 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");
+ Ok(())
}
diff --git a/spec/rust/tests/test_bcd_user_type_le.rs b/spec/rust/tests/test_bcd_user_type_le.rs
index 9769abc1a..e368eb7ea 100644
--- a/spec/rust/tests/test_bcd_user_type_le.rs
+++ b/spec/rust/tests/test_bcd_user_type_le.rs
@@ -1,19 +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::BcdUserTypeLe;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bcd_user_type_le::*;
#[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");
- }
+fn test_bcd_user_type_le() -> KResult<()> {
+ let bytes = fs::read("../../src/bcd_user_type_le.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BcdUserTypeLe::read_into(&_io, None, None)?;
+
+ 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");
+ Ok(())
}
diff --git a/spec/rust/tests/test_bits_byte_aligned.rs b/spec/rust/tests/test_bits_byte_aligned.rs
index 128edb632..b2d0fa08a 100644
--- a/spec/rust/tests/test_bits_byte_aligned.rs
+++ b/spec/rust/tests/test_bits_byte_aligned.rs
@@ -1,22 +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::BitsByteAligned;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_byte_aligned::*;
#[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);
- }
+fn test_bits_byte_aligned() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsByteAligned::read_into(&_io, None, None)?;
+
+ 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![0xffu8]);
+ assert_eq!(*r.full_byte(), 255);
+ assert_eq!(*r.byte_4(), 80);
+ Ok(())
}
diff --git a/spec/rust/tests/test_bits_enum.rs b/spec/rust/tests/test_bits_enum.rs
new file mode 100644
index 000000000..5e0980071
--- /dev/null
+++ b/spec/rust/tests/test_bits_enum.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_enum::*;
+
+#[test]
+fn test_bits_enum() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsEnum::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one(), BitsEnum_Animal::Platypus);
+ assert_eq!(*r.two(), BitsEnum_Animal::Horse);
+ assert_eq!(*r.three(), BitsEnum_Animal::Cat);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_bits_seq_endian_combo.rs b/spec/rust/tests/test_bits_seq_endian_combo.rs
new file mode 100644
index 000000000..85c0aa469
--- /dev/null
+++ b/spec/rust/tests/test_bits_seq_endian_combo.rs
@@ -0,0 +1,23 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_seq_endian_combo::*;
+
+#[test]
+fn test_bits_seq_endian_combo() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsSeqEndianCombo::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.be1(), 59);
+ assert_eq!(*r.be2(), 187);
+ assert_eq!(*r.le3(), 163);
+ assert_eq!(*r.be4(), 20);
+ assert_eq!(*r.le5(), 10);
+ assert_eq!(*r.le6(), 36);
+ assert_eq!(*r.le7(), 26);
+ assert_eq!(*r.be8(), true);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_bits_shift_by_b32_le.rs b/spec/rust/tests/test_bits_shift_by_b32_le.rs
new file mode 100644
index 000000000..6fe70947d
--- /dev/null
+++ b/spec/rust/tests/test_bits_shift_by_b32_le.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_shift_by_b32_le::*;
+
+#[test]
+fn test_bits_shift_by_b32_le() -> KResult<()> {
+ let bytes = fs::read("../../src/bits_shift_by_b32_le.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsShiftByB32Le::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.a(), 4294967295);
+ assert_eq!(*r.b(), 0);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_bits_shift_by_b64_le.rs b/spec/rust/tests/test_bits_shift_by_b64_le.rs
new file mode 100644
index 000000000..3349e8b8e
--- /dev/null
+++ b/spec/rust/tests/test_bits_shift_by_b64_le.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_shift_by_b64_le::*;
+
+#[test]
+fn test_bits_shift_by_b64_le() -> KResult<()> {
+ let bytes = fs::read("../../src/bits_shift_by_b64_le.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsShiftByB64Le::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.a(), 18446744073709551615);
+ assert_eq!(*r.b(), 0);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_bits_signed_res_b32_be.rs b/spec/rust/tests/test_bits_signed_res_b32_be.rs
new file mode 100644
index 000000000..6d9416cce
--- /dev/null
+++ b/spec/rust/tests/test_bits_signed_res_b32_be.rs
@@ -0,0 +1,16 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_signed_res_b32_be::*;
+
+#[test]
+fn test_bits_signed_res_b32_be() -> KResult<()> {
+ let bytes = fs::read("../../src/bits_shift_by_b32_le.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsSignedResB32Be::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.a(), 4294967295);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_bits_signed_res_b32_le.rs b/spec/rust/tests/test_bits_signed_res_b32_le.rs
new file mode 100644
index 000000000..1d277e33b
--- /dev/null
+++ b/spec/rust/tests/test_bits_signed_res_b32_le.rs
@@ -0,0 +1,16 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_signed_res_b32_le::*;
+
+#[test]
+fn test_bits_signed_res_b32_le() -> KResult<()> {
+ let bytes = fs::read("../../src/bits_shift_by_b32_le.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsSignedResB32Le::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.a(), 4294967295);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_bits_signed_shift_b32_le.rs b/spec/rust/tests/test_bits_signed_shift_b32_le.rs
new file mode 100644
index 000000000..e925c956d
--- /dev/null
+++ b/spec/rust/tests/test_bits_signed_shift_b32_le.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_signed_shift_b32_le::*;
+
+#[test]
+fn test_bits_signed_shift_b32_le() -> KResult<()> {
+ let bytes = fs::read("../../src/bits_signed_shift_b32_le.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsSignedShiftB32Le::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.a(), 0);
+ assert_eq!(*r.b(), 255);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_bits_signed_shift_b64_le.rs b/spec/rust/tests/test_bits_signed_shift_b64_le.rs
new file mode 100644
index 000000000..ef3999e13
--- /dev/null
+++ b/spec/rust/tests/test_bits_signed_shift_b64_le.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_signed_shift_b64_le::*;
+
+#[test]
+fn test_bits_signed_shift_b64_le() -> KResult<()> {
+ let bytes = fs::read("../../src/bits_signed_shift_b64_le.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsSignedShiftB64Le::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.a(), 0);
+ assert_eq!(*r.b(), 255);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_bits_simple.rs b/spec/rust/tests/test_bits_simple.rs
index c3eb6a06c..6f529bfae 100644
--- a/spec/rust/tests/test_bits_simple.rs
+++ b/spec/rust/tests/test_bits_simple.rs
@@ -1,27 +1,29 @@
// 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 std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_simple::*;
#[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);
- }
+fn test_bits_simple() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsSimple::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_bits_simple_le.rs b/spec/rust/tests/test_bits_simple_le.rs
new file mode 100644
index 000000000..424c46aba
--- /dev/null
+++ b/spec/rust/tests/test_bits_simple_le.rs
@@ -0,0 +1,29 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_simple_le::*;
+
+#[test]
+fn test_bits_simple_le() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsSimpleLe::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.byte_1(), 80);
+ assert_eq!(*r.byte_2(), 65);
+ assert_eq!(*r.bits_a(), true);
+ assert_eq!(*r.bits_b(), 1);
+ assert_eq!(*r.bits_c(), 4);
+ assert_eq!(*r.large_bits_1(), 331);
+ assert_eq!(*r.spacer(), 3);
+ assert_eq!(*r.large_bits_2(), 393);
+ assert_eq!(*r.normal_s2(), -1);
+ assert_eq!(*r.byte_8_9_10(), 4407632);
+ assert_eq!(*r.byte_11_to_14(), 760556875);
+ assert_eq!(*r.byte_15_to_19(), 1099499455812);
+ assert_eq!(*r.byte_20_to_27(), 18446744073709551615);
+ assert_eq!(*r.test_if_b1()?, 123);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_bits_unaligned_b32_be.rs b/spec/rust/tests/test_bits_unaligned_b32_be.rs
new file mode 100644
index 000000000..761e27ec5
--- /dev/null
+++ b/spec/rust/tests/test_bits_unaligned_b32_be.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_unaligned_b32_be::*;
+
+#[test]
+fn test_bits_unaligned_b32_be() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsUnalignedB32Be::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.a(), true);
+ assert_eq!(*r.b(), 3648472617);
+ assert_eq!(*r.c(), 10);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_bits_unaligned_b32_le.rs b/spec/rust/tests/test_bits_unaligned_b32_le.rs
new file mode 100644
index 000000000..8e57c1cae
--- /dev/null
+++ b/spec/rust/tests/test_bits_unaligned_b32_le.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_unaligned_b32_le::*;
+
+#[test]
+fn test_bits_unaligned_b32_le() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsUnalignedB32Le::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.a(), false);
+ assert_eq!(*r.b(), 173137398);
+ assert_eq!(*r.c(), 69);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_bits_unaligned_b64_be.rs b/spec/rust/tests/test_bits_unaligned_b64_be.rs
new file mode 100644
index 000000000..3e1f97844
--- /dev/null
+++ b/spec/rust/tests/test_bits_unaligned_b64_be.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_unaligned_b64_be::*;
+
+#[test]
+fn test_bits_unaligned_b64_be() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsUnalignedB64Be::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.a(), true);
+ assert_eq!(*r.b(), 15670070570729969769);
+ assert_eq!(*r.c(), 14);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_bits_unaligned_b64_le.rs b/spec/rust/tests/test_bits_unaligned_b64_le.rs
new file mode 100644
index 000000000..2dac88bce
--- /dev/null
+++ b/spec/rust/tests/test_bits_unaligned_b64_le.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bits_unaligned_b64_le::*;
+
+#[test]
+fn test_bits_unaligned_b64_le() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BitsUnalignedB64Le::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.a(), false);
+ assert_eq!(*r.b(), 1902324737369038326);
+ assert_eq!(*r.c(), 71);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_buffered_struct.rs b/spec/rust/tests/test_buffered_struct.rs
index 2b4a8d82e..e298de3fc 100644
--- a/spec/rust/tests/test_buffered_struct.rs
+++ b/spec/rust/tests/test_buffered_struct.rs
@@ -1,20 +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::BufferedStruct;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::buffered_struct::*;
#[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);
- }
+fn test_buffered_struct() -> KResult<()> {
+ let bytes = fs::read("../../src/buffered_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BufferedStruct::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_bytes_pad_term.rs b/spec/rust/tests/test_bytes_pad_term.rs
index 87ac91cd8..c05f43821 100644
--- a/spec/rust/tests/test_bytes_pad_term.rs
+++ b/spec/rust/tests/test_bytes_pad_term.rs
@@ -1,17 +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::BytesPadTerm;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::bytes_pad_term::*;
#[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]));
- }
+fn test_bytes_pad_term() -> KResult<()> {
+ let bytes = fs::read("../../src/str_pad_term.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = BytesPadTerm::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.str_pad(), vec![0x73u8, 0x74u8, 0x72u8, 0x31u8]);
+ assert_eq!(*r.str_term(), vec![0x73u8, 0x74u8, 0x72u8, 0x32u8, 0x66u8, 0x6fu8, 0x6fu8]);
+ assert_eq!(*r.str_term_and_pad(), vec![0x73u8, 0x74u8, 0x72u8, 0x2bu8, 0x2bu8, 0x2bu8, 0x33u8, 0x62u8, 0x61u8, 0x72u8, 0x2bu8, 0x2bu8, 0x2bu8]);
+ assert_eq!(*r.str_term_include(), vec![0x73u8, 0x74u8, 0x72u8, 0x34u8, 0x62u8, 0x61u8, 0x7au8, 0x40u8]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_cast_nested.rs b/spec/rust/tests/test_cast_nested.rs
index 80a1d7566..6bcd94a62 100644
--- a/spec/rust/tests/test_cast_nested.rs
+++ b/spec/rust/tests/test_cast_nested.rs
@@ -1,17 +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::CastNested;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::cast_nested::*;
#[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);
- }
+fn test_cast_nested() -> KResult<()> {
+ let bytes = fs::read("../../src/switch_opcodes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = CastNested::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_cast_to_top.rs b/spec/rust/tests/test_cast_to_top.rs
index 8c248dc84..bee130a0d 100644
--- a/spec/rust/tests/test_cast_to_top.rs
+++ b/spec/rust/tests/test_cast_to_top.rs
@@ -1,16 +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::CastToTop;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::cast_to_top::*;
#[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);
- }
+fn test_cast_to_top() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = CastToTop::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.code(), 80);
+ assert_eq!(*r.header()?.code(), 65);
+ assert_eq!(*r.header_casted()?.code(), 65);
+ Ok(())
}
diff --git a/spec/rust/tests/test_combine_bool.rs b/spec/rust/tests/test_combine_bool.rs
new file mode 100644
index 000000000..8aed9f1f0
--- /dev/null
+++ b/spec/rust/tests/test_combine_bool.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::combine_bool::*;
+
+#[test]
+fn test_combine_bool() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_negative.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = CombineBool::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.bool_bit(), true);
+ assert_eq!(*r.bool_calc_bit()?, false);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_combine_bytes.rs b/spec/rust/tests/test_combine_bytes.rs
new file mode 100644
index 000000000..9d4dad51b
--- /dev/null
+++ b/spec/rust/tests/test_combine_bytes.rs
@@ -0,0 +1,25 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::combine_bytes::*;
+
+#[test]
+fn test_combine_bytes() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = CombineBytes::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.bytes_term(), vec![0x66u8, 0x6fu8, 0x6fu8]);
+ assert_eq!(*r.bytes_limit(), vec![0x62u8, 0x61u8, 0x72u8, 0x7cu8]);
+ assert_eq!(*r.bytes_eos(), vec![0x62u8, 0x61u8, 0x7au8, 0x40u8]);
+ assert_eq!(*r.bytes_calc()?, vec![0x52u8, 0x6eu8, 0x44u8]);
+ assert_eq!(*r.term_or_limit()?, vec![0x66u8, 0x6fu8, 0x6fu8]);
+ assert_eq!(*r.term_or_eos()?, vec![0x62u8, 0x61u8, 0x7au8, 0x40u8]);
+ assert_eq!(*r.term_or_calc()?, vec![0x66u8, 0x6fu8, 0x6fu8]);
+ assert_eq!(*r.limit_or_eos()?, vec![0x62u8, 0x61u8, 0x72u8, 0x7cu8]);
+ assert_eq!(*r.limit_or_calc()?, vec![0x52u8, 0x6eu8, 0x44u8]);
+ assert_eq!(*r.eos_or_calc()?, vec![0x62u8, 0x61u8, 0x7au8, 0x40u8]);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_combine_enum.rs b/spec/rust/tests/test_combine_enum.rs
new file mode 100644
index 000000000..ec19095ef
--- /dev/null
+++ b/spec/rust/tests/test_combine_enum.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::combine_enum::*;
+
+#[test]
+fn test_combine_enum() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = CombineEnum::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.enum_u4(), CombineEnum_Animal::Pig);
+ assert_eq!(*r.enum_u2(), CombineEnum_Animal::Horse);
+ assert_eq!(*r.enum_u4_u2()?, CombineEnum_Animal::Horse);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_combine_str.rs b/spec/rust/tests/test_combine_str.rs
new file mode 100644
index 000000000..0fc1a1a90
--- /dev/null
+++ b/spec/rust/tests/test_combine_str.rs
@@ -0,0 +1,30 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::combine_str::*;
+
+#[test]
+fn test_combine_str() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = CombineStr::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.str_term(), "foo");
+ assert_eq!(*r.str_limit(), "bar|");
+ assert_eq!(*r.str_eos(), "baz@");
+ assert_eq!(*r.str_calc()?, "bar");
+ assert_eq!(*r.str_calc_bytes()?, "baz");
+ assert_eq!(*r.term_or_limit()?, "foo");
+ assert_eq!(*r.term_or_eos()?, "baz@");
+ assert_eq!(*r.term_or_calc()?, "foo");
+ assert_eq!(*r.term_or_calc_bytes()?, "baz");
+ assert_eq!(*r.limit_or_eos()?, "bar|");
+ assert_eq!(*r.limit_or_calc()?, "bar");
+ assert_eq!(*r.limit_or_calc_bytes()?, "bar|");
+ assert_eq!(*r.eos_or_calc()?, "bar");
+ assert_eq!(*r.eos_or_calc_bytes()?, "baz@");
+ assert_eq!(*r.calc_or_calc_bytes()?, "baz");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_debug_array_user.rs b/spec/rust/tests/test_debug_array_user.rs
new file mode 100644
index 000000000..239f258cf
--- /dev/null
+++ b/spec/rust/tests/test_debug_array_user.rs
@@ -0,0 +1,17 @@
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::debug_array_user::*;
+
+#[test]
+fn test_debug_array_user() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = DebugArrayUser::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one_cat().meow(), 0x50);
+ assert_eq!(*r.array_of_cats()[0].meow(), 0x41);
+ assert_eq!(*r.array_of_cats()[1].meow(), 0x43);
+ assert_eq!(*r.array_of_cats()[2].meow(), 0x4b);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_debug_switch_user.rs b/spec/rust/tests/test_debug_switch_user.rs
new file mode 100644
index 000000000..9332bec41
--- /dev/null
+++ b/spec/rust/tests/test_debug_switch_user.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::debug_switch_user::*;
+
+#[test]
+fn test_debug_switch_user() -> KResult<()> {
+ let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = DebugSwitchUser::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.code(), 1);
+ assert_eq!(*Into::>::into(&*r.data().as_ref().unwrap()).val(), -190);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_default_big_endian.rs b/spec/rust/tests/test_default_big_endian.rs
index f5fc0ee75..9caf51944 100644
--- a/spec/rust/tests/test_default_big_endian.rs
+++ b/spec/rust/tests/test_default_big_endian.rs
@@ -1,14 +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::DefaultBigEndian;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::default_big_endian::*;
#[test]
-fn test_default_big_endian() {
- if let Ok(r) = DefaultBigEndian::from_file("src/enum_0.bin") {
- assert_eq!(r.one, 117440512);
- }
+fn test_default_big_endian() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = DefaultBigEndian::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one(), 117440512);
+ Ok(())
}
diff --git a/spec/rust/tests/test_default_bit_endian_mod.rs b/spec/rust/tests/test_default_bit_endian_mod.rs
new file mode 100644
index 000000000..55aa156ff
--- /dev/null
+++ b/spec/rust/tests/test_default_bit_endian_mod.rs
@@ -0,0 +1,19 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::default_bit_endian_mod::*;
+
+#[test]
+fn test_default_bit_endian_mod() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = DefaultBitEndianMod::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.main().one(), 336);
+ assert_eq!(*r.main().two(), 8608);
+ assert_eq!(*r.main().nest().two(), 11595);
+ assert_eq!(*r.main().nest_be().two(), 12799);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_default_endian_expr_exception.rs b/spec/rust/tests/test_default_endian_expr_exception.rs
new file mode 100644
index 000000000..002c9a229
--- /dev/null
+++ b/spec/rust/tests/test_default_endian_expr_exception.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::default_endian_expr_exception::*;
+
+#[test]
+fn test_default_endian_expr_exception() -> KResult<()> {
+ let bytes = fs::read("../../src/endian_expr.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let res: KResult> = DefaultEndianExprException::read_into(&_io, None, None);
+ let err = res.expect_err("expected Err representing UndecidedEndiannessError, but got Ok");
+ assert!(
+ matches!(err, KError::UndecidedEndianness { .. }),
+ "expected: {}\n but got: {:?}",
+ "KError::UndecidedEndianness { .. }", err
+ );
+ Ok(())
+}
diff --git a/spec/rust/tests/test_default_endian_expr_inherited.rs b/spec/rust/tests/test_default_endian_expr_inherited.rs
index f48bf523f..a6959e186 100644
--- a/spec/rust/tests/test_default_endian_expr_inherited.rs
+++ b/spec/rust/tests/test_default_endian_expr_inherited.rs
@@ -1,28 +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::DefaultEndianExprInherited;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::default_endian_expr_inherited::*;
#[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);
- }
+fn test_default_endian_expr_inherited() -> KResult<()> {
+ let bytes = fs::read("../../src/endian_expr.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = DefaultEndianExprInherited::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.docs()[0 as usize].indicator(), vec![0x49u8, 0x49u8]);
+ assert_eq!(*r.docs()[0 as usize].main().insides().some_int(), 66);
+ assert_eq!(*r.docs()[0 as usize].main().insides().more().some_int1(), 16896);
+ assert_eq!(*r.docs()[0 as usize].main().insides().more().some_int2(), 66);
+ assert_eq!(*r.docs()[0 as usize].main().insides().more().some_inst()?, 66);
+ assert_eq!(*r.docs()[1 as usize].indicator(), vec![0x4du8, 0x4du8]);
+ assert_eq!(*r.docs()[1 as usize].main().insides().some_int(), 66);
+ assert_eq!(*r.docs()[1 as usize].main().insides().more().some_int1(), 66);
+ assert_eq!(*r.docs()[1 as usize].main().insides().more().some_int2(), 16896);
+ assert_eq!(*r.docs()[1 as usize].main().insides().more().some_inst()?, 1107296256);
+ assert_eq!(*r.docs()[2 as usize].indicator(), vec![0x58u8, 0x58u8]);
+ assert_eq!(*r.docs()[2 as usize].main().insides().some_int(), 66);
+ assert_eq!(*r.docs()[2 as usize].main().insides().more().some_int1(), 66);
+ assert_eq!(*r.docs()[2 as usize].main().insides().more().some_int2(), 16896);
+ assert_eq!(*r.docs()[2 as usize].main().insides().more().some_inst()?, 1107296256);
+ Ok(())
}
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..35be8e9fc 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,33 @@
// 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 std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::default_endian_expr_is_be::*;
#[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);
- }
+fn test_default_endian_expr_is_be() -> KResult<()> {
+ let bytes = fs::read("../../src/endian_expr.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = DefaultEndianExprIsBe::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.docs()[0 as usize].indicator(), vec![0x49u8, 0x49u8]);
+ assert_eq!(*r.docs()[0 as usize].main().some_int(), 66);
+ assert_eq!(*r.docs()[0 as usize].main().some_int_be(), 66);
+ assert_eq!(*r.docs()[0 as usize].main().some_int_le(), 66);
+ assert_eq!(*r.docs()[0 as usize].main().inst_int()?, 66);
+ assert_eq!(*r.docs()[0 as usize].main().inst_sub()?.foo(), 66);
+ assert_eq!(*r.docs()[1 as usize].indicator(), vec![0x4du8, 0x4du8]);
+ assert_eq!(*r.docs()[1 as usize].main().some_int(), 66);
+ assert_eq!(*r.docs()[1 as usize].main().some_int_be(), 66);
+ assert_eq!(*r.docs()[1 as usize].main().some_int_le(), 66);
+ assert_eq!(*r.docs()[1 as usize].main().inst_int()?, 1107296256);
+ assert_eq!(*r.docs()[1 as usize].main().inst_sub()?.foo(), 1107296256);
+ assert_eq!(*r.docs()[2 as usize].indicator(), vec![0x58u8, 0x58u8]);
+ assert_eq!(*r.docs()[2 as usize].main().some_int(), 1107296256);
+ assert_eq!(*r.docs()[2 as usize].main().some_int_be(), 66);
+ assert_eq!(*r.docs()[2 as usize].main().some_int_le(), 66);
+ assert_eq!(*r.docs()[2 as usize].main().inst_int()?, 66);
+ assert_eq!(*r.docs()[2 as usize].main().inst_sub()?.foo(), 66);
+ Ok(())
}
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..881a656cb 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,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::DefaultEndianExprIsLe;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::default_endian_expr_is_le::*;
#[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);
- }
+fn test_default_endian_expr_is_le() -> KResult<()> {
+ let bytes = fs::read("../../src/endian_expr.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = DefaultEndianExprIsLe::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.docs()[0 as usize].indicator(), vec![0x49u8, 0x49u8]);
+ assert_eq!(*r.docs()[0 as usize].main().some_int(), 66);
+ assert_eq!(*r.docs()[0 as usize].main().some_int_be(), 66);
+ assert_eq!(*r.docs()[0 as usize].main().some_int_le(), 66);
+ assert_eq!(*r.docs()[1 as usize].indicator(), vec![0x4du8, 0x4du8]);
+ assert_eq!(*r.docs()[1 as usize].main().some_int(), 66);
+ assert_eq!(*r.docs()[1 as usize].main().some_int_be(), 66);
+ assert_eq!(*r.docs()[1 as usize].main().some_int_le(), 66);
+ assert_eq!(*r.docs()[2 as usize].indicator(), vec![0x58u8, 0x58u8]);
+ assert_eq!(*r.docs()[2 as usize].main().some_int(), 66);
+ assert_eq!(*r.docs()[2 as usize].main().some_int_be(), 66);
+ assert_eq!(*r.docs()[2 as usize].main().some_int_le(), 66);
+ Ok(())
}
diff --git a/spec/rust/tests/test_default_endian_mod.rs b/spec/rust/tests/test_default_endian_mod.rs
index d8f21e85b..7361a6b06 100644
--- a/spec/rust/tests/test_default_endian_mod.rs
+++ b/spec/rust/tests/test_default_endian_mod.rs
@@ -1,16 +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::DefaultEndianMod;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::default_endian_mod::*;
#[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);
- }
+fn test_default_endian_mod() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = DefaultEndianMod::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.main().one(), 1262698832);
+ assert_eq!(*r.main().nest().two(), -52947);
+ assert_eq!(*r.main().nest_be().two(), 1346454347);
+ Ok(())
}
diff --git a/spec/rust/tests/test_docstrings.rs b/spec/rust/tests/test_docstrings.rs
index c71d39911..18f5d48e0 100644
--- a/spec/rust/tests/test_docstrings.rs
+++ b/spec/rust/tests/test_docstrings.rs
@@ -1,13 +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::Docstrings;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::docstrings::*;
#[test]
-fn test_docstrings() {
- if let Ok(r) = Docstrings::from_file("src/fixed_struct.bin") {
- }
+fn test_docstrings() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = Docstrings::read_into(&_io, None, None)?;
+
+ Ok(())
}
diff --git a/spec/rust/tests/test_docstrings_docref.rs b/spec/rust/tests/test_docstrings_docref.rs
index 6a0603587..06b5817e0 100644
--- a/spec/rust/tests/test_docstrings_docref.rs
+++ b/spec/rust/tests/test_docstrings_docref.rs
@@ -1,13 +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::DocstringsDocref;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::docstrings_docref::*;
#[test]
-fn test_docstrings_docref() {
- if let Ok(r) = DocstringsDocref::from_file("src/fixed_struct.bin") {
- }
+fn test_docstrings_docref() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = DocstringsDocref::read_into(&_io, None, None)?;
+
+ Ok(())
}
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..5e32f8f71
--- /dev/null
+++ b/spec/rust/tests/test_docstrings_docref_multi.rs
@@ -0,0 +1,15 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::docstrings_docref_multi::*;
+
+#[test]
+fn test_docstrings_docref_multi() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = DocstringsDocrefMulti::read_into(&_io, None, None)?;
+
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_0.rs b/spec/rust/tests/test_enum_0.rs
new file mode 100644
index 000000000..93ab85e68
--- /dev/null
+++ b/spec/rust/tests/test_enum_0.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_0::*;
+
+#[test]
+fn test_enum_0() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = Enum0::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.pet_1(), Enum0_Animal::Cat);
+ assert_eq!(*r.pet_2(), Enum0_Animal::Chicken);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_1.rs b/spec/rust/tests/test_enum_1.rs
new file mode 100644
index 000000000..9f0681564
--- /dev/null
+++ b/spec/rust/tests/test_enum_1.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_1::*;
+
+#[test]
+fn test_enum_1() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = Enum1::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.main().submain().pet_1(), Enum1_MainObj_Animal::Cat);
+ assert_eq!(*r.main().submain().pet_2(), Enum1_MainObj_Animal::Chicken);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_deep.rs b/spec/rust/tests/test_enum_deep.rs
new file mode 100644
index 000000000..ac0d15274
--- /dev/null
+++ b/spec/rust/tests/test_enum_deep.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_deep::*;
+
+#[test]
+fn test_enum_deep() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumDeep::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.pet_1(), EnumDeep_Container1_Animal::Cat);
+ assert_eq!(*r.pet_2(), EnumDeep_Container1_Container2_Animal::Hare);
+ Ok(())
+}
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..b407c716d
--- /dev/null
+++ b/spec/rust/tests/test_enum_deep_literals.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_deep_literals::*;
+
+#[test]
+fn test_enum_deep_literals() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumDeepLiterals::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.is_pet_1_ok()?, true);
+ assert_eq!(*r.is_pet_2_ok()?, true);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_fancy.rs b/spec/rust/tests/test_enum_fancy.rs
new file mode 100644
index 000000000..abf186cee
--- /dev/null
+++ b/spec/rust/tests/test_enum_fancy.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_fancy::*;
+
+#[test]
+fn test_enum_fancy() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumFancy::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.pet_1(), EnumFancy_Animal::Cat);
+ assert_eq!(*r.pet_2(), EnumFancy_Animal::Chicken);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_if.rs b/spec/rust/tests/test_enum_if.rs
new file mode 100644
index 000000000..e94b7957a
--- /dev/null
+++ b/spec/rust/tests/test_enum_if.rs
@@ -0,0 +1,22 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_if::*;
+
+#[test]
+fn test_enum_if() -> KResult<()> {
+ let bytes = fs::read("../../src/if_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumIf::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.op1().opcode(), EnumIf_Opcodes::AString);
+ assert_eq!(*r.op1().arg_str().str(), "foo");
+ assert_eq!(*r.op2().opcode(), EnumIf_Opcodes::ATuple);
+ assert_eq!(*r.op2().arg_tuple().num1(), 66);
+ assert_eq!(*r.op2().arg_tuple().num2(), 67);
+ assert_eq!(*r.op3().opcode(), EnumIf_Opcodes::AString);
+ assert_eq!(*r.op3().arg_str().str(), "bar");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_import_literals.rs b/spec/rust/tests/test_enum_import_literals.rs
new file mode 100644
index 000000000..61f8a6686
--- /dev/null
+++ b/spec/rust/tests/test_enum_import_literals.rs
@@ -0,0 +1,19 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_import_literals::*;
+use rust::formats::enum_deep::*;
+
+#[test]
+fn test_enum_import_literals() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumImportLiterals::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.pet_1_to_i()?, 7);
+ assert_eq!(*r.pet_1_eq()?, true);
+ assert_eq!(*r.pet_2()?, EnumDeep_Container1_Container2_Animal::Hare);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_import_seq.rs b/spec/rust/tests/test_enum_import_seq.rs
new file mode 100644
index 000000000..92e4fbf34
--- /dev/null
+++ b/spec/rust/tests/test_enum_import_seq.rs
@@ -0,0 +1,19 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_import_seq::*;
+use rust::formats::enum_0::*;
+use rust::formats::enum_deep::*;
+
+#[test]
+fn test_enum_import_seq() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumImportSeq::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.pet_1(), Enum0_Animal::Cat);
+ assert_eq!(*r.pet_2(), EnumDeep_Container1_Container2_Animal::Hare);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_int_range_s.rs b/spec/rust/tests/test_enum_int_range_s.rs
new file mode 100644
index 000000000..3f4dc8276
--- /dev/null
+++ b/spec/rust/tests/test_enum_int_range_s.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_int_range_s::*;
+
+#[test]
+fn test_enum_int_range_s() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_int_range_s.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumIntRangeS::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.f1(), EnumIntRangeS_Constants::IntMin);
+ assert_eq!(*r.f2(), EnumIntRangeS_Constants::Zero);
+ assert_eq!(*r.f3(), EnumIntRangeS_Constants::IntMax);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_int_range_u.rs b/spec/rust/tests/test_enum_int_range_u.rs
new file mode 100644
index 000000000..1559ce9f1
--- /dev/null
+++ b/spec/rust/tests/test_enum_int_range_u.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_int_range_u::*;
+
+#[test]
+fn test_enum_int_range_u() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_int_range_u.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumIntRangeU::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.f1(), EnumIntRangeU_Constants::Zero);
+ assert_eq!(*r.f2(), EnumIntRangeU_Constants::IntMax);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_invalid.rs b/spec/rust/tests/test_enum_invalid.rs
new file mode 100644
index 000000000..30a63169b
--- /dev/null
+++ b/spec/rust/tests/test_enum_invalid.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_invalid::*;
+
+#[test]
+fn test_enum_invalid() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumInvalid::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.pet_1(), EnumInvalid_Animal::Dog);
+ let n: i64 = (&*r.pet_2()).into();
+ assert_eq!(n, 111);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_long_range_s.rs b/spec/rust/tests/test_enum_long_range_s.rs
new file mode 100644
index 000000000..a91369b4e
--- /dev/null
+++ b/spec/rust/tests/test_enum_long_range_s.rs
@@ -0,0 +1,22 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_long_range_s::*;
+
+#[test]
+fn test_enum_long_range_s() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_long_range_s.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumLongRangeS::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.f1(), EnumLongRangeS_Constants::LongMin);
+ assert_eq!(*r.f2(), EnumLongRangeS_Constants::IntBelowMin);
+ assert_eq!(*r.f3(), EnumLongRangeS_Constants::IntMin);
+ assert_eq!(*r.f4(), EnumLongRangeS_Constants::Zero);
+ assert_eq!(*r.f5(), EnumLongRangeS_Constants::IntMax);
+ assert_eq!(*r.f6(), EnumLongRangeS_Constants::IntOverMax);
+ assert_eq!(*r.f7(), EnumLongRangeS_Constants::LongMax);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_long_range_u.rs b/spec/rust/tests/test_enum_long_range_u.rs
new file mode 100644
index 000000000..f5e40d48a
--- /dev/null
+++ b/spec/rust/tests/test_enum_long_range_u.rs
@@ -0,0 +1,19 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_long_range_u::*;
+
+#[test]
+fn test_enum_long_range_u() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_long_range_u.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumLongRangeU::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.f1(), EnumLongRangeU_Constants::Zero);
+ assert_eq!(*r.f2(), EnumLongRangeU_Constants::IntMax);
+ assert_eq!(*r.f3(), EnumLongRangeU_Constants::IntOverMax);
+ assert_eq!(*r.f4(), EnumLongRangeU_Constants::LongMax);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_negative.rs b/spec/rust/tests/test_enum_negative.rs
new file mode 100644
index 000000000..58cd60012
--- /dev/null
+++ b/spec/rust/tests/test_enum_negative.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_negative::*;
+
+#[test]
+fn test_enum_negative() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_negative.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumNegative::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.f1(), EnumNegative_Constants::NegativeOne);
+ assert_eq!(*r.f2(), EnumNegative_Constants::PositiveOne);
+ Ok(())
+}
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..568d021e6
--- /dev/null
+++ b/spec/rust/tests/test_enum_of_value_inst.rs
@@ -0,0 +1,19 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_of_value_inst::*;
+
+#[test]
+fn test_enum_of_value_inst() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumOfValueInst::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.pet_1(), EnumOfValueInst_Animal::Cat);
+ assert_eq!(*r.pet_2(), EnumOfValueInst_Animal::Chicken);
+ assert_eq!(*r.pet_3()?, EnumOfValueInst_Animal::Dog);
+ assert_eq!(*r.pet_4()?, EnumOfValueInst_Animal::Dog);
+ Ok(())
+}
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..a477f8a48
--- /dev/null
+++ b/spec/rust/tests/test_enum_to_i.rs
@@ -0,0 +1,23 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_to_i::*;
+
+#[test]
+fn test_enum_to_i() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumToI::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.pet_1(), EnumToI_Animal::Cat);
+ assert_eq!(*r.pet_2(), EnumToI_Animal::Chicken);
+ assert_eq!(*r.pet_1_i()?, 7);
+ assert_eq!(*r.pet_1_i_to_s()?, "7");
+ assert_eq!(*r.pet_1_mod()?, 32775);
+ assert_eq!(*r.one_lt_two()?, true);
+ assert_eq!(*r.pet_1_eq_int()?, true);
+ assert_eq!(*r.pet_2_eq_int()?, false);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_to_i_class_border_1.rs b/spec/rust/tests/test_enum_to_i_class_border_1.rs
new file mode 100644
index 000000000..f67646a02
--- /dev/null
+++ b/spec/rust/tests/test_enum_to_i_class_border_1.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_to_i_class_border_1::*;
+
+#[test]
+fn test_enum_to_i_class_border_1() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumToIClassBorder1::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.pet_1(), EnumToIClassBorder1_Animal::Cat);
+ assert_eq!(*r.pet_2(), EnumToIClassBorder1_Animal::Chicken);
+ assert_eq!(*r.checker()?.is_dog()?, true);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_enum_to_i_invalid.rs b/spec/rust/tests/test_enum_to_i_invalid.rs
new file mode 100644
index 000000000..3a1054dd5
--- /dev/null
+++ b/spec/rust/tests/test_enum_to_i_invalid.rs
@@ -0,0 +1,24 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::enum_to_i_invalid::*;
+
+#[test]
+fn test_enum_to_i_invalid() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = EnumToIInvalid::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.pet_1(), EnumToIInvalid_Animal::Dog);
+ let n: i64 = (&*r.pet_2()).into();
+ assert_eq!(n, 111);
+ assert_eq!(*r.pet_2_i()?, 111);
+ assert_eq!(*r.pet_2_i_to_s()?, "111");
+ assert_eq!(*r.pet_2_mod()?, 32879);
+ assert_eq!(*r.one_lt_two()?, true);
+ assert_eq!(*r.pet_2_eq_int_t()?, true);
+ assert_eq!(*r.pet_2_eq_int_f()?, false);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_eof_exception_bytes.rs b/spec/rust/tests/test_eof_exception_bytes.rs
new file mode 100644
index 000000000..ecbfca685
--- /dev/null
+++ b/spec/rust/tests/test_eof_exception_bytes.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::eof_exception_bytes::*;
+
+#[test]
+fn test_eof_exception_bytes() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let res: KResult> = EofExceptionBytes::read_into(&_io, None, None);
+ let err = res.expect_err("expected Err representing EndOfStreamError, but got Ok");
+ assert!(
+ matches!(err, KError::Eof { .. }),
+ "expected: {}\n but got: {:?}",
+ "KError::Eof { .. }", err
+ );
+ Ok(())
+}
diff --git a/spec/rust/tests/test_eof_exception_sized.rs b/spec/rust/tests/test_eof_exception_sized.rs
new file mode 100644
index 000000000..09a318501
--- /dev/null
+++ b/spec/rust/tests/test_eof_exception_sized.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::eof_exception_sized::*;
+
+#[test]
+fn test_eof_exception_sized() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let res: KResult> = EofExceptionSized::read_into(&_io, None, None);
+ let err = res.expect_err("expected Err representing EndOfStreamError, but got Ok");
+ assert!(
+ matches!(err, KError::Eof { .. }),
+ "expected: {}\n but got: {:?}",
+ "KError::Eof { .. }", err
+ );
+ Ok(())
+}
diff --git a/spec/rust/tests/test_eof_exception_u4.rs b/spec/rust/tests/test_eof_exception_u4.rs
new file mode 100644
index 000000000..128d85792
--- /dev/null
+++ b/spec/rust/tests/test_eof_exception_u4.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::eof_exception_u4::*;
+
+#[test]
+fn test_eof_exception_u4() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let res: KResult> = EofExceptionU4::read_into(&_io, None, None);
+ let err = res.expect_err("expected Err representing EndOfStreamError, but got Ok");
+ assert!(
+ matches!(err, KError::Eof { .. }),
+ "expected: {}\n but got: {:?}",
+ "KError::Eof { .. }", err
+ );
+ Ok(())
+}
diff --git a/spec/rust/tests/test_eos_exception_bytes.rs b/spec/rust/tests/test_eos_exception_bytes.rs
new file mode 100644
index 000000000..317991d41
--- /dev/null
+++ b/spec/rust/tests/test_eos_exception_bytes.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::eos_exception_bytes::*;
+
+#[test]
+fn test_eos_exception_bytes() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let res: KResult> = EosExceptionBytes::read_into(&_io, None, None);
+ let err = res.expect_err("expected Err representing EndOfStreamError, but got Ok");
+ assert!(
+ matches!(err, KError::Eof { .. }),
+ "expected: {}\n but got: {:?}",
+ "KError::Eof { .. }", err
+ );
+ Ok(())
+}
diff --git a/spec/rust/tests/test_eos_exception_sized.rs b/spec/rust/tests/test_eos_exception_sized.rs
new file mode 100644
index 000000000..ba580389c
--- /dev/null
+++ b/spec/rust/tests/test_eos_exception_sized.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::eos_exception_sized::*;
+
+#[test]
+fn test_eos_exception_sized() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let res: KResult> = EosExceptionSized::read_into(&_io, None, None);
+ let err = res.expect_err("expected Err representing EndOfStreamError, but got Ok");
+ assert!(
+ matches!(err, KError::Eof { .. }),
+ "expected: {}\n but got: {:?}",
+ "KError::Eof { .. }", err
+ );
+ Ok(())
+}
diff --git a/spec/rust/tests/test_eos_exception_u4.rs b/spec/rust/tests/test_eos_exception_u4.rs
new file mode 100644
index 000000000..7a1cfd7f1
--- /dev/null
+++ b/spec/rust/tests/test_eos_exception_u4.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::eos_exception_u4::*;
+
+#[test]
+fn test_eos_exception_u4() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let res: KResult> = EosExceptionU4::read_into(&_io, None, None);
+ let err = res.expect_err("expected Err representing EndOfStreamError, but got Ok");
+ assert!(
+ matches!(err, KError::Eof { .. }),
+ "expected: {}\n but got: {:?}",
+ "KError::Eof { .. }", err
+ );
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_0.rs b/spec/rust/tests/test_expr_0.rs
index 686cfdd53..8aabe6a58 100644
--- a/spec/rust/tests/test_expr_0.rs
+++ b/spec/rust/tests/test_expr_0.rs
@@ -1,15 +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::Expr0;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_0::*;
#[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");
- }
+fn test_expr_0() -> KResult<()> {
+ let bytes = fs::read("../../src/str_encodings.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = Expr0::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.must_be_f7()?, 247);
+ assert_eq!(*r.must_be_abc123()?, "abc123");
+ Ok(())
}
diff --git a/spec/rust/tests/test_expr_1.rs b/spec/rust/tests/test_expr_1.rs
index 7b1377902..25119966c 100644
--- a/spec/rust/tests/test_expr_1.rs
+++ b/spec/rust/tests/test_expr_1.rs
@@ -1,17 +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::Expr1;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_1::*;
#[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);
- }
+fn test_expr_1() -> KResult<()> {
+ let bytes = fs::read("../../src/str_encodings.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = Expr1::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_expr_2.rs b/spec/rust/tests/test_expr_2.rs
index eb7a2cb6a..e028d9e50 100644
--- a/spec/rust/tests/test_expr_2.rs
+++ b/spec/rust/tests/test_expr_2.rs
@@ -1,30 +1,32 @@
// 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;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_2::*;
#[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);
- }
+fn test_expr_2() -> KResult<()> {
+ let bytes = fs::read("../../src/str_encodings.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = Expr2::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_expr_3.rs b/spec/rust/tests/test_expr_3.rs
index 9998e367a..2e82e518b 100644
--- a/spec/rust/tests/test_expr_3.rs
+++ b/spec/rust/tests/test_expr_3.rs
@@ -1,25 +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::Expr3;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_3::*;
#[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);
- }
+fn test_expr_3() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = Expr3::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_expr_array.rs b/spec/rust/tests/test_expr_array.rs
index 21504b7d4..6b89c2ffb 100644
--- a/spec/rust/tests/test_expr_array.rs
+++ b/spec/rust/tests/test_expr_array.rs
@@ -1,28 +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::ExprArray;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_array::*;
#[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");
- }
+fn test_expr_array() -> KResult<()> {
+ let bytes = fs::read("../../src/expr_array.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprArray::read_into(&_io, None, None)?;
+
+ 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");
+ Ok(())
}
diff --git a/spec/rust/tests/test_expr_bits.rs b/spec/rust/tests/test_expr_bits.rs
new file mode 100644
index 000000000..8ff2d7e30
--- /dev/null
+++ b/spec/rust/tests/test_expr_bits.rs
@@ -0,0 +1,25 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_bits::*;
+
+#[test]
+fn test_expr_bits() -> KResult<()> {
+ let bytes = fs::read("../../src/switch_opcodes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprBits::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.a(), 2);
+ assert_eq!(*r.enum_seq(), ExprBits_Items::Foo);
+ assert_eq!(*r.byte_size(), vec![0x66u8, 0x6fu8]);
+ assert_eq!(r.repeat_expr().len(), 2);
+ assert_eq!(r.repeat_expr()[0 as usize], 111);
+ assert_eq!(r.repeat_expr()[1 as usize], 98);
+ assert_eq!(r.switch_on_type(), 97);
+ assert_eq!(*r.switch_on_endian().foo(), 29184);
+ assert_eq!(*r.enum_inst()?, ExprBits_Items::Bar);
+ assert_eq!(*r.inst_pos()?, 111);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_bytes_cmp.rs b/spec/rust/tests/test_expr_bytes_cmp.rs
index 58656b11c..75144846c 100644
--- a/spec/rust/tests/test_expr_bytes_cmp.rs
+++ b/spec/rust/tests/test_expr_bytes_cmp.rs
@@ -1,23 +1,25 @@
// 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 std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_bytes_cmp::*;
#[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);
- }
+fn test_expr_bytes_cmp() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprBytesCmp::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one(), vec![0x50u8]);
+ assert_eq!(*r.two(), vec![0x41u8, 0x43u8, 0x4bu8]);
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_expr_bytes_non_literal.rs b/spec/rust/tests/test_expr_bytes_non_literal.rs
new file mode 100644
index 000000000..4ea35de9a
--- /dev/null
+++ b/spec/rust/tests/test_expr_bytes_non_literal.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_bytes_non_literal::*;
+
+#[test]
+fn test_expr_bytes_non_literal() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_negative.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprBytesNonLiteral::read_into(&_io, None, None)?;
+
+ assert_eq!(r.calc_bytes()?.len(), 2);
+ assert_eq!(r.calc_bytes()?[0 as usize], 255);
+ assert_eq!(r.calc_bytes()?[1 as usize], 1);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_bytes_ops.rs b/spec/rust/tests/test_expr_bytes_ops.rs
new file mode 100644
index 000000000..251ddafee
--- /dev/null
+++ b/spec/rust/tests/test_expr_bytes_ops.rs
@@ -0,0 +1,31 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_bytes_ops::*;
+
+#[test]
+fn test_expr_bytes_ops() -> KResult<()> {
+ let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprBytesOps::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one_size()?, 3);
+ assert_eq!(*r.one_first()?, 1);
+ assert_eq!(*r.one_mid()?, 66);
+ assert_eq!(*r.one_last()?, 255);
+ assert_eq!(r.one_last()?.to_string(), "255");
+ assert_eq!(*r.one_min()?, 1);
+ assert_eq!(*r.one_max()?, 255);
+ assert_eq!(r.one_max()?.to_string(), "255");
+ assert_eq!(*r.two_size()?, 3);
+ assert_eq!(*r.two_first()?, 65);
+ assert_eq!(*r.two_mid()?, 255);
+ assert_eq!(r.two_mid()?.to_string(), "255");
+ assert_eq!(*r.two_last()?, 75);
+ assert_eq!(*r.two_min()?, 65);
+ assert_eq!(*r.two_max()?, 255);
+ assert_eq!(r.two_max()?.to_string(), "255");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_calc_array_ops.rs b/spec/rust/tests/test_expr_calc_array_ops.rs
new file mode 100644
index 000000000..a48014489
--- /dev/null
+++ b/spec/rust/tests/test_expr_calc_array_ops.rs
@@ -0,0 +1,33 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_calc_array_ops::*;
+
+#[test]
+fn test_expr_calc_array_ops() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprCalcArrayOps::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.int_array_size()?, 7);
+ assert_eq!(*r.int_array_first()?, 10);
+ assert_eq!(*r.int_array_mid()?, 25);
+ assert_eq!(*r.int_array_last()?, 1000);
+ assert_eq!(*r.int_array_min()?, 10);
+ assert_eq!(*r.int_array_max()?, 1000);
+ assert_eq!(*r.double_array_size()?, 5);
+ assert_eq!(*r.double_array_first()?, 10.0);
+ assert_eq!(*r.double_array_mid()?, 25.0);
+ assert_eq!(*r.double_array_last()?, 3.14159);
+ assert_eq!(*r.double_array_min()?, 3.14159);
+ assert_eq!(*r.double_array_max()?, 100.0);
+ assert_eq!(*r.str_array_size()?, 4);
+ assert_eq!(*r.str_array_first()?, "un");
+ assert_eq!(*r.str_array_mid()?, "deux");
+ assert_eq!(*r.str_array_last()?, "quatre");
+ assert_eq!(*r.str_array_min()?, "deux");
+ assert_eq!(*r.str_array_max()?, "un");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_enum.rs b/spec/rust/tests/test_expr_enum.rs
new file mode 100644
index 000000000..50a7cc7c5
--- /dev/null
+++ b/spec/rust/tests/test_expr_enum.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_enum::*;
+
+#[test]
+fn test_expr_enum() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprEnum::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.const_dog()?, ExprEnum_Animal::Dog);
+ assert_eq!(*r.derived_boom()?, ExprEnum_Animal::Boom);
+ assert_eq!(*r.derived_dog()?, ExprEnum_Animal::Dog);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_fstring_0.rs b/spec/rust/tests/test_expr_fstring_0.rs
new file mode 100644
index 000000000..3dcccd777
--- /dev/null
+++ b/spec/rust/tests/test_expr_fstring_0.rs
@@ -0,0 +1,24 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_fstring_0::*;
+
+#[test]
+fn test_expr_fstring_0() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprFstring0::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.seq_str(), "foo|b");
+ assert_eq!(*r.seq_int(), 97);
+ assert_eq!(*r.empty()?, "");
+ assert_eq!(*r.literal()?, "abc");
+ assert_eq!(*r.literal_with_escapes()?, "abc\n\tt");
+ assert_eq!(*r.head_and_int_literal()?, "abc=123");
+ assert_eq!(*r.head_and_str_literal()?, "abc=foo");
+ assert_eq!(*r.head_and_int()?, "abc=97");
+ assert_eq!(*r.head_and_str()?, "abc=foo|b");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_if_int_ops.rs b/spec/rust/tests/test_expr_if_int_ops.rs
new file mode 100644
index 000000000..d30eb9b63
--- /dev/null
+++ b/spec/rust/tests/test_expr_if_int_ops.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_if_int_ops::*;
+
+#[test]
+fn test_expr_if_int_ops() -> KResult<()> {
+ let bytes = fs::read("../../src/process_coerce_switch.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprIfIntOps::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.is_eq_prim()?, true);
+ assert_eq!(*r.is_eq_boxed()?, true);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_int_div.rs b/spec/rust/tests/test_expr_int_div.rs
new file mode 100644
index 000000000..0ebe54e6e
--- /dev/null
+++ b/spec/rust/tests/test_expr_int_div.rs
@@ -0,0 +1,21 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_int_div::*;
+
+#[test]
+fn test_expr_int_div() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprIntDiv::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.int_u(), 1262698832);
+ assert_eq!(*r.int_s(), -52947);
+ assert_eq!(*r.div_pos_const()?, 756);
+ assert_eq!(*r.div_neg_const()?, -757);
+ assert_eq!(*r.div_pos_seq()?, 97130679);
+ assert_eq!(*r.div_neg_seq()?, -4073);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_io_eof.rs b/spec/rust/tests/test_expr_io_eof.rs
new file mode 100644
index 000000000..07b1798f0
--- /dev/null
+++ b/spec/rust/tests/test_expr_io_eof.rs
@@ -0,0 +1,19 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_io_eof::*;
+
+#[test]
+fn test_expr_io_eof() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprIoEof::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.substream1().one(), 1262698832);
+ assert!(r.substream1().two().is_none());
+ assert_eq!(*r.substream2().one(), 4294914349);
+ assert_eq!(*r.substream2().two(), 1262698832);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_io_pos.rs b/spec/rust/tests/test_expr_io_pos.rs
index f2410bae0..c02dc685c 100644
--- a/spec/rust/tests/test_expr_io_pos.rs
+++ b/spec/rust/tests/test_expr_io_pos.rs
@@ -1,19 +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::ExprIoPos;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_io_pos::*;
#[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);
- }
+fn test_expr_io_pos() -> KResult<()> {
+ let bytes = fs::read("../../src/expr_io_pos.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprIoPos::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.substream1().my_str(), "CURIOSITY");
+ assert_eq!(*r.substream1().body(), vec![0x11u8, 0x22u8, 0x33u8, 0x44u8]);
+ assert_eq!(*r.substream1().number(), 66);
+ assert_eq!(*r.substream2().my_str(), "KILLED");
+ assert_eq!(*r.substream2().body(), vec![0x61u8, 0x20u8, 0x63u8, 0x61u8, 0x74u8]);
+ assert_eq!(*r.substream2().number(), 103);
+ Ok(())
}
diff --git a/spec/rust/tests/test_expr_io_ternary.rs b/spec/rust/tests/test_expr_io_ternary.rs
new file mode 100644
index 000000000..5dc3fbcca
--- /dev/null
+++ b/spec/rust/tests/test_expr_io_ternary.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_io_ternary::*;
+
+#[test]
+fn test_expr_io_ternary() -> KResult<()> {
+ let bytes = fs::read("../../src/if_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprIoTernary::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one_or_two_io_size1()?, 8);
+ assert_eq!(*r.one_or_two_io_size2()?, 8);
+ assert_eq!(*r.one_or_two_io_size_add_3()?, 11);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_mod.rs b/spec/rust/tests/test_expr_mod.rs
index 14001402e..88dffcc3e 100644
--- a/spec/rust/tests/test_expr_mod.rs
+++ b/spec/rust/tests/test_expr_mod.rs
@@ -1,19 +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::ExprMod;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_mod::*;
#[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);
- }
+fn test_expr_mod() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprMod::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_expr_ops_parens.rs b/spec/rust/tests/test_expr_ops_parens.rs
new file mode 100644
index 000000000..f670acae5
--- /dev/null
+++ b/spec/rust/tests/test_expr_ops_parens.rs
@@ -0,0 +1,24 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_ops_parens::*;
+
+#[test]
+fn test_expr_ops_parens() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_negative.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprOpsParens::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.i_sum_to_str()?, "29");
+ assert_eq!(*r.f_sum_to_int()?, 9);
+ assert_eq!(*r.str_concat_len()?, 10);
+ assert_eq!(*r.str_concat_rev()?, "9876543210");
+ assert_eq!(*r.str_concat_substr_2_to_7()?, "23456");
+ assert_eq!(*r.str_concat_to_i()?, 123456789);
+ assert_eq!(*r.bool_eq()?, 0);
+ assert_eq!(*r.bool_and()?, 0);
+ assert_eq!(*r.bool_or()?, 1);
+ Ok(())
+}
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..783b85160
--- /dev/null
+++ b/spec/rust/tests/test_expr_sizeof_type_0.rs
@@ -0,0 +1,16 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_sizeof_type_0::*;
+
+#[test]
+fn test_expr_sizeof_type_0() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprSizeofType0::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.sizeof_block()?, (((1 + 4) as i32) + (2 as i32)));
+ Ok(())
+}
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..6d5cd4c3b
--- /dev/null
+++ b/spec/rust/tests/test_expr_sizeof_type_1.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_sizeof_type_1::*;
+
+#[test]
+fn test_expr_sizeof_type_1() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprSizeofType1::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.sizeof_block()?, (((((1 + 4) as i32) + (2 as i32)) as i32) + (4 as i32)));
+ assert_eq!(*r.sizeof_subblock()?, 4);
+ Ok(())
+}
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..14f7472e1
--- /dev/null
+++ b/spec/rust/tests/test_expr_sizeof_value_0.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_sizeof_value_0::*;
+
+#[test]
+fn test_expr_sizeof_value_0() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprSizeofValue0::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.self_sizeof()?, (((((1 + 4) as i32) + (2 as i32)) as i32) + (2 as i32)));
+ assert_eq!(*r.sizeof_block()?, (((1 + 4) as i32) + (2 as i32)));
+ assert_eq!(*r.sizeof_block_a()?, 1);
+ assert_eq!(*r.sizeof_block_b()?, 4);
+ assert_eq!(*r.sizeof_block_c()?, 2);
+ Ok(())
+}
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..4ce4dae42
--- /dev/null
+++ b/spec/rust/tests/test_expr_sizeof_value_sized.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_sizeof_value_sized::*;
+
+#[test]
+fn test_expr_sizeof_value_sized() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprSizeofValueSized::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_str_encodings.rs b/spec/rust/tests/test_expr_str_encodings.rs
new file mode 100644
index 000000000..904418076
--- /dev/null
+++ b/spec/rust/tests/test_expr_str_encodings.rs
@@ -0,0 +1,22 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_str_encodings::*;
+
+#[test]
+fn test_expr_str_encodings() -> KResult<()> {
+ let bytes = fs::read("../../src/str_encodings.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprStrEncodings::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.str1_eq()?, true);
+ assert_eq!(*r.str2_eq()?, true);
+ assert_eq!(*r.str3_eq()?, true);
+ assert_eq!(*r.str3_eq_str2()?, true);
+ assert_eq!(*r.str4_eq()?, true);
+ assert_eq!(*r.str4_gt_str_calc()?, true);
+ assert_eq!(*r.str4_gt_str_from_bytes()?, true);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_str_ops.rs b/spec/rust/tests/test_expr_str_ops.rs
new file mode 100644
index 000000000..e03b70e20
--- /dev/null
+++ b/spec/rust/tests/test_expr_str_ops.rs
@@ -0,0 +1,33 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_str_ops::*;
+
+#[test]
+fn test_expr_str_ops() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprStrOps::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one(), "foo|b");
+ assert_eq!(*r.one_len()?, 5);
+ assert_eq!(*r.one_rev()?, "b|oof");
+ assert_eq!(*r.one_substr_0_to_3()?, "foo");
+ assert_eq!(*r.one_substr_2_to_5()?, "o|b");
+ assert_eq!(*r.one_substr_3_to_3()?, "");
+ assert_eq!(*r.one_substr_0_to_0()?, "");
+ assert_eq!(*r.two()?, "0123456789");
+ assert_eq!(*r.two_len()?, 10);
+ assert_eq!(*r.two_rev()?, "9876543210");
+ assert_eq!(*r.two_substr_0_to_7()?, "0123456");
+ assert_eq!(*r.two_substr_4_to_10()?, "456789");
+ assert_eq!(*r.two_substr_0_to_10()?, "0123456789");
+ assert_eq!(*r.to_i_attr()?, 9173);
+ assert_eq!(*r.to_i_r10()?, -72);
+ assert_eq!(*r.to_i_r2()?, 86);
+ assert_eq!(*r.to_i_r8()?, 465);
+ assert_eq!(*r.to_i_r16()?, 18383);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_expr_to_i_trailing.rs b/spec/rust/tests/test_expr_to_i_trailing.rs
new file mode 100644
index 000000000..cd31f1b02
--- /dev/null
+++ b/spec/rust/tests/test_expr_to_i_trailing.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::expr_to_i_trailing::*;
+
+#[test]
+fn test_expr_to_i_trailing() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ExprToITrailing::read_into(&_io, None, None)?;
+
+ let err = r.to_i_r10().expect_err("expected Err representing ConversionError, but got Ok");
+ assert_eq!(err, KError::CastError);
+ assert_eq!(*r.to_i_r16()?, 152517308);
+ let err = r.to_i_garbage().expect_err("expected Err representing ConversionError, but got Ok");
+ assert_eq!(err, KError::CastError);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_fixed_contents.rs b/spec/rust/tests/test_fixed_contents.rs
index fb0a425c0..d22e41ded 100644
--- a/spec/rust/tests/test_fixed_contents.rs
+++ b/spec/rust/tests/test_fixed_contents.rs
@@ -1,13 +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::FixedContents;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::fixed_contents::*;
#[test]
-fn test_fixed_contents() {
- if let Ok(r) = FixedContents::from_file("src/fixed_struct.bin") {
- }
+fn test_fixed_contents() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = FixedContents::read_into(&_io, None, None)?;
+
+ Ok(())
}
diff --git a/spec/rust/tests/test_fixed_struct.rs b/spec/rust/tests/test_fixed_struct.rs
index a47a7e8d5..05b306caa 100644
--- a/spec/rust/tests/test_fixed_struct.rs
+++ b/spec/rust/tests/test_fixed_struct.rs
@@ -1,33 +1,35 @@
// 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;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::fixed_struct::*;
#[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);
- }
+fn test_fixed_struct() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = FixedStruct::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_float_to_i.rs b/spec/rust/tests/test_float_to_i.rs
index 661d31f48..6ef3d0c58 100644
--- a/spec/rust/tests/test_float_to_i.rs
+++ b/spec/rust/tests/test_float_to_i.rs
@@ -1,21 +1,23 @@
// 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 std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::float_to_i::*;
#[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);
- }
+fn test_float_to_i() -> KResult<()> {
+ let bytes = fs::read("../../src/floating_points.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = FloatToI::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_floating_points.rs b/spec/rust/tests/test_floating_points.rs
new file mode 100644
index 000000000..08ccb82f8
--- /dev/null
+++ b/spec/rust/tests/test_floating_points.rs
@@ -0,0 +1,23 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::floating_points::*;
+
+#[test]
+fn test_floating_points() -> KResult<()> {
+ let bytes = fs::read("../../src/floating_points.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = FloatingPoints::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.single_value(), (0.5 as f32));
+ assert_eq!(*r.single_value_be(), (0.5 as f32));
+ 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);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_hello_world.rs b/spec/rust/tests/test_hello_world.rs
index 6397cfb2a..ec15fad1a 100644
--- a/spec/rust/tests/test_hello_world.rs
+++ b/spec/rust/tests/test_hello_world.rs
@@ -1,14 +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::HelloWorld;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::hello_world::*;
#[test]
-fn test_hello_world() {
- if let Ok(r) = HelloWorld::from_file("src/fixed_struct.bin") {
- assert_eq!(r.one, 80);
- }
+fn test_hello_world() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = HelloWorld::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one(), 80);
+ Ok(())
}
diff --git a/spec/rust/tests/test_if_instances.rs b/spec/rust/tests/test_if_instances.rs
new file mode 100644
index 000000000..8ae2ef7c0
--- /dev/null
+++ b/spec/rust/tests/test_if_instances.rs
@@ -0,0 +1,16 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::if_instances::*;
+
+#[test]
+fn test_if_instances() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = IfInstances::read_into(&_io, None, None)?;
+
+ assert!(r.never_happens()?.is_none());
+ Ok(())
+}
diff --git a/spec/rust/tests/test_if_struct.rs b/spec/rust/tests/test_if_struct.rs
index 475ef1e50..70ee30a44 100644
--- a/spec/rust/tests/test_if_struct.rs
+++ b/spec/rust/tests/test_if_struct.rs
@@ -1,20 +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::IfStruct;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::if_struct::*;
#[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");
- }
+fn test_if_struct() -> KResult<()> {
+ let bytes = fs::read("../../src/if_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = IfStruct::read_into(&_io, None, None)?;
+
+ 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");
+ Ok(())
}
diff --git a/spec/rust/tests/test_if_values.rs b/spec/rust/tests/test_if_values.rs
index a0ce3dab8..3699e8766 100644
--- a/spec/rust/tests/test_if_values.rs
+++ b/spec/rust/tests/test_if_values.rs
@@ -1,19 +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::IfValues;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::if_values::*;
#[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);
- }
+fn test_if_values() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = IfValues::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.codes()[0 as usize].opcode(), 80);
+ assert_eq!(*r.codes()[0 as usize].half_opcode()?, 40);
+ assert_eq!(*r.codes()[1 as usize].opcode(), 65);
+ assert!(r.codes()[1 as usize].half_opcode()?.is_none());
+ assert_eq!(*r.codes()[2 as usize].opcode(), 67);
+ assert!(r.codes()[2 as usize].half_opcode()?.is_none());
+ Ok(())
}
diff --git a/spec/rust/tests/test_imports0.rs b/spec/rust/tests/test_imports0.rs
new file mode 100644
index 000000000..10d92c7b2
--- /dev/null
+++ b/spec/rust/tests/test_imports0.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::imports0::*;
+
+#[test]
+fn test_imports0() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = Imports0::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.two(), 80);
+ assert_eq!(*r.hw().one(), 65);
+ assert_eq!(*r.hw_one()?, 65);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_imports_abs.rs b/spec/rust/tests/test_imports_abs.rs
new file mode 100644
index 000000000..e12130fe2
--- /dev/null
+++ b/spec/rust/tests/test_imports_abs.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::imports_abs::*;
+
+#[test]
+fn test_imports_abs() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ImportsAbs::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.len().value()?, 80);
+ assert_eq!(r.body().len(), 80);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_imports_abs_abs.rs b/spec/rust/tests/test_imports_abs_abs.rs
new file mode 100644
index 000000000..55edac7d7
--- /dev/null
+++ b/spec/rust/tests/test_imports_abs_abs.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::imports_abs_abs::*;
+
+#[test]
+fn test_imports_abs_abs() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ImportsAbsAbs::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one(), 80);
+ assert_eq!(*r.two().one(), 65);
+ assert_eq!(*r.two().two().one(), 67);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_imports_abs_rel.rs b/spec/rust/tests/test_imports_abs_rel.rs
new file mode 100644
index 000000000..629f9b6e1
--- /dev/null
+++ b/spec/rust/tests/test_imports_abs_rel.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::imports_abs_rel::*;
+
+#[test]
+fn test_imports_abs_rel() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ImportsAbsRel::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one(), 80);
+ assert_eq!(*r.two().one(), 65);
+ assert_eq!(*r.two().two().one(), 67);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_imports_cast_to_imported.rs b/spec/rust/tests/test_imports_cast_to_imported.rs
new file mode 100644
index 000000000..4309da29a
--- /dev/null
+++ b/spec/rust/tests/test_imports_cast_to_imported.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::imports_cast_to_imported::*;
+
+#[test]
+fn test_imports_cast_to_imported() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ImportsCastToImported::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.hw().one(), 236);
+ assert_eq!(*r.two().hw_one()?, 236);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_imports_cast_to_imported2.rs b/spec/rust/tests/test_imports_cast_to_imported2.rs
new file mode 100644
index 000000000..44fe73fc2
--- /dev/null
+++ b/spec/rust/tests/test_imports_cast_to_imported2.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::imports_cast_to_imported2::*;
+
+#[test]
+fn test_imports_cast_to_imported2() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ImportsCastToImported2::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.hw().one(), 236);
+ assert_eq!(*r.two().hw()?.one(), 236);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_imports_circular_a.rs b/spec/rust/tests/test_imports_circular_a.rs
new file mode 100644
index 000000000..35cb096fd
--- /dev/null
+++ b/spec/rust/tests/test_imports_circular_a.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::imports_circular_a::*;
+
+#[test]
+fn test_imports_circular_a() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ImportsCircularA::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.code(), 80);
+ assert_eq!(*r.two().initial(), 65);
+ assert_eq!(*r.two().back_ref().code(), 67);
+ assert_eq!(*r.two().back_ref().two().initial(), 75);
+ assert!(r.two().back_ref().two().back_ref().is_none());
+ Ok(())
+}
diff --git a/spec/rust/tests/test_imports_params_def_array_usertype_imported.rs b/spec/rust/tests/test_imports_params_def_array_usertype_imported.rs
new file mode 100644
index 000000000..da3eedfde
--- /dev/null
+++ b/spec/rust/tests/test_imports_params_def_array_usertype_imported.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::imports_params_def_array_usertype_imported::*;
+
+#[test]
+fn test_imports_params_def_array_usertype_imported() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ImportsParamsDefArrayUsertypeImported::read_into(&_io, None, None)?;
+
+ assert_eq!(r.hws().len(), 2);
+ assert_eq!(*r.hws()[0 as usize].one(), 236);
+ assert_eq!(*r.hws()[1 as usize].one(), 187);
+ assert_eq!(*r.two().hw0_one()?, 236);
+ assert_eq!(*r.two().hw1_one()?, 187);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_imports_params_def_enum_imported.rs b/spec/rust/tests/test_imports_params_def_enum_imported.rs
new file mode 100644
index 000000000..eeb4cc911
--- /dev/null
+++ b/spec/rust/tests/test_imports_params_def_enum_imported.rs
@@ -0,0 +1,21 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::imports_params_def_enum_imported::*;
+use rust::formats::enum_0::*;
+use rust::formats::enum_deep::*;
+
+#[test]
+fn test_imports_params_def_enum_imported() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ImportsParamsDefEnumImported::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one().pet_1(), Enum0_Animal::Cat);
+ assert_eq!(*r.one().pet_2(), EnumDeep_Container1_Container2_Animal::Hare);
+ assert_eq!(*r.two().pet_1_param(), Enum0_Animal::Cat);
+ assert_eq!(*r.two().pet_2_param(), EnumDeep_Container1_Container2_Animal::Hare);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_imports_params_def_usertype_imported.rs b/spec/rust/tests/test_imports_params_def_usertype_imported.rs
new file mode 100644
index 000000000..46faf20ad
--- /dev/null
+++ b/spec/rust/tests/test_imports_params_def_usertype_imported.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::imports_params_def_usertype_imported::*;
+
+#[test]
+fn test_imports_params_def_usertype_imported() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ImportsParamsDefUsertypeImported::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.hw().one(), 236);
+ assert_eq!(*r.two().hw_one()?, 236);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_imports_rel_1.rs b/spec/rust/tests/test_imports_rel_1.rs
new file mode 100644
index 000000000..0f9cea606
--- /dev/null
+++ b/spec/rust/tests/test_imports_rel_1.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::imports_rel_1::*;
+
+#[test]
+fn test_imports_rel_1() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ImportsRel1::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one(), 80);
+ assert_eq!(*r.two().one(), 65);
+ assert_eq!(*r.two().two().one(), 67);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_index_sizes.rs b/spec/rust/tests/test_index_sizes.rs
index 8d9e033d3..e73f6b981 100644
--- a/spec/rust/tests/test_index_sizes.rs
+++ b/spec/rust/tests/test_index_sizes.rs
@@ -1,20 +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::IndexSizes;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::index_sizes::*;
#[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");
- }
+fn test_index_sizes() -> KResult<()> {
+ let bytes = fs::read("../../src/index_sizes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = IndexSizes::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.qty(), 3);
+ assert_eq!(r.sizes()[0 as usize], 1);
+ assert_eq!(r.sizes()[1 as usize], 8);
+ assert_eq!(r.sizes()[2 as usize], 4);
+ assert_eq!(r.bufs()[0 as usize], "A");
+ assert_eq!(r.bufs()[1 as usize], "BBBBBBBB");
+ assert_eq!(r.bufs()[2 as usize], "CCCC");
+ Ok(())
}
diff --git a/spec/rust/tests/test_index_to_param_eos.rs b/spec/rust/tests/test_index_to_param_eos.rs
index f727d6f72..bc1a2c978 100644
--- a/spec/rust/tests/test_index_to_param_eos.rs
+++ b/spec/rust/tests/test_index_to_param_eos.rs
@@ -1,20 +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::IndexToParamEos;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::index_to_param_eos::*;
#[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");
- }
+fn test_index_to_param_eos() -> KResult<()> {
+ let bytes = fs::read("../../src/index_sizes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = IndexToParamEos::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.qty(), 3);
+ assert_eq!(r.sizes()[0 as usize], 1);
+ assert_eq!(r.sizes()[1 as usize], 8);
+ assert_eq!(r.sizes()[2 as usize], 4);
+ assert_eq!(*r.blocks()[0 as usize].buf(), "A");
+ assert_eq!(*r.blocks()[1 as usize].buf(), "BBBBBBBB");
+ assert_eq!(*r.blocks()[2 as usize].buf(), "CCCC");
+ Ok(())
}
diff --git a/spec/rust/tests/test_index_to_param_expr.rs b/spec/rust/tests/test_index_to_param_expr.rs
index 321f27012..f39add36d 100644
--- a/spec/rust/tests/test_index_to_param_expr.rs
+++ b/spec/rust/tests/test_index_to_param_expr.rs
@@ -1,20 +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::IndexToParamExpr;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::index_to_param_expr::*;
#[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");
- }
+fn test_index_to_param_expr() -> KResult<()> {
+ let bytes = fs::read("../../src/index_sizes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = IndexToParamExpr::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.qty(), 3);
+ assert_eq!(r.sizes()[0 as usize], 1);
+ assert_eq!(r.sizes()[1 as usize], 8);
+ assert_eq!(r.sizes()[2 as usize], 4);
+ assert_eq!(*r.blocks()[0 as usize].buf(), "A");
+ assert_eq!(*r.blocks()[1 as usize].buf(), "BBBBBBBB");
+ assert_eq!(*r.blocks()[2 as usize].buf(), "CCCC");
+ Ok(())
}
diff --git a/spec/rust/tests/test_index_to_param_until.rs b/spec/rust/tests/test_index_to_param_until.rs
index 71d09ffbe..9378ab36a 100644
--- a/spec/rust/tests/test_index_to_param_until.rs
+++ b/spec/rust/tests/test_index_to_param_until.rs
@@ -1,20 +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::IndexToParamUntil;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::index_to_param_until::*;
#[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");
- }
+fn test_index_to_param_until() -> KResult<()> {
+ let bytes = fs::read("../../src/index_sizes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = IndexToParamUntil::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.qty(), 3);
+ assert_eq!(r.sizes()[0 as usize], 1);
+ assert_eq!(r.sizes()[1 as usize], 8);
+ assert_eq!(r.sizes()[2 as usize], 4);
+ assert_eq!(*r.blocks()[0 as usize].buf(), "A");
+ assert_eq!(*r.blocks()[1 as usize].buf(), "BBBBBBBB");
+ assert_eq!(*r.blocks()[2 as usize].buf(), "CCCC");
+ Ok(())
}
diff --git a/spec/rust/tests/test_instance_io_user.rs b/spec/rust/tests/test_instance_io_user.rs
index c389a5d3b..05c8e0b06 100644
--- a/spec/rust/tests/test_instance_io_user.rs
+++ b/spec/rust/tests/test_instance_io_user.rs
@@ -1,17 +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::InstanceIoUser;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::instance_io_user::*;
#[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");
- }
+fn test_instance_io_user() -> KResult<()> {
+ let bytes = fs::read("../../src/instance_io.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = InstanceIoUser::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.qty_entries(), 3);
+ assert_eq!(*r.entries()[0 as usize].name()?, "the");
+ assert_eq!(*r.entries()[1 as usize].name()?, "rainy");
+ assert_eq!(*r.entries()[2 as usize].name()?, "day it is");
+ Ok(())
}
diff --git a/spec/rust/tests/test_instance_std.rs b/spec/rust/tests/test_instance_std.rs
index 0a798b75c..a67938100 100644
--- a/spec/rust/tests/test_instance_std.rs
+++ b/spec/rust/tests/test_instance_std.rs
@@ -1,14 +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::InstanceStd;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::instance_std::*;
#[test]
-fn test_instance_std() {
- if let Ok(r) = InstanceStd::from_file("src/str_encodings.bin") {
- assert_eq!(r.header, "Some ");
- }
+fn test_instance_std() -> KResult<()> {
+ let bytes = fs::read("../../src/str_encodings.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = InstanceStd::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.header()?, "Some ");
+ Ok(())
}
diff --git a/spec/rust/tests/test_instance_std_array.rs b/spec/rust/tests/test_instance_std_array.rs
index 07df25cd1..257564064 100644
--- a/spec/rust/tests/test_instance_std_array.rs
+++ b/spec/rust/tests/test_instance_std_array.rs
@@ -1,20 +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::InstanceStdArray;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::instance_std_array::*;
#[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]));
- }
+fn test_instance_std_array() -> KResult<()> {
+ let bytes = fs::read("../../src/instance_std_array.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = InstanceStdArray::read_into(&_io, None, None)?;
+
+ 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 as usize], vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]);
+ assert_eq!(r.entries()?[1 as usize], vec![0x22u8, 0x22u8, 0x22u8, 0x22u8]);
+ assert_eq!(r.entries()?[2 as usize], vec![0x33u8, 0x33u8, 0x33u8, 0x33u8]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_instance_user_array.rs b/spec/rust/tests/test_instance_user_array.rs
index 3cbf3c76d..473e86eb8 100644
--- a/spec/rust/tests/test_instance_user_array.rs
+++ b/spec/rust/tests/test_instance_user_array.rs
@@ -1,23 +1,25 @@
// 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;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::instance_user_array::*;
#[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);
- }
+fn test_instance_user_array() -> KResult<()> {
+ let bytes = fs::read("../../src/instance_std_array.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = InstanceUserArray::read_into(&_io, None, None)?;
+
+ 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 as usize].word1(), 4369);
+ assert_eq!(*r.user_entries()?[0 as usize].word2(), 4369);
+ assert_eq!(*r.user_entries()?[1 as usize].word1(), 8738);
+ assert_eq!(*r.user_entries()?[1 as usize].word2(), 8738);
+ assert_eq!(*r.user_entries()?[2 as usize].word1(), 13107);
+ assert_eq!(*r.user_entries()?[2 as usize].word2(), 13107);
+ Ok(())
}
diff --git a/spec/rust/tests/test_integers.rs b/spec/rust/tests/test_integers.rs
new file mode 100644
index 000000000..f69bd3511
--- /dev/null
+++ b/spec/rust/tests/test_integers.rs
@@ -0,0 +1,35 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::integers::*;
+
+#[test]
+fn test_integers() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = Integers::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_integers_double_overflow.rs b/spec/rust/tests/test_integers_double_overflow.rs
new file mode 100644
index 000000000..d5b002df1
--- /dev/null
+++ b/spec/rust/tests/test_integers_double_overflow.rs
@@ -0,0 +1,23 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::integers_double_overflow::*;
+
+#[test]
+fn test_integers_double_overflow() -> KResult<()> {
+ let bytes = fs::read("../../src/integers_double_overflow.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = IntegersDoubleOverflow::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.signed_safe_min_be(), -9007199254740991);
+ assert_eq!(*r.signed_safe_min_le(), -9007199254740991);
+ assert_eq!(*r.signed_safe_max_be(), 9007199254740991);
+ assert_eq!(*r.signed_safe_max_le(), 9007199254740991);
+ assert_eq!(r.signed_unsafe_neg_be().to_string(), "-9007199254740993");
+ assert_eq!(r.signed_unsafe_neg_le().to_string(), "-9007199254740993");
+ assert_eq!(r.signed_unsafe_pos_be().to_string(), "9007199254740993");
+ assert_eq!(r.signed_unsafe_pos_be().to_string(), "9007199254740993");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_integers_min_max.rs b/spec/rust/tests/test_integers_min_max.rs
new file mode 100644
index 000000000..cf82dca25
--- /dev/null
+++ b/spec/rust/tests/test_integers_min_max.rs
@@ -0,0 +1,43 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::integers_min_max::*;
+
+#[test]
+fn test_integers_min_max() -> KResult<()> {
+ let bytes = fs::read("../../src/integers_min_max.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = IntegersMinMax::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.unsigned_min().u1(), 0);
+ assert_eq!(*r.unsigned_min().u2le(), 0);
+ assert_eq!(*r.unsigned_min().u4le(), 0);
+ assert_eq!(*r.unsigned_min().u8le(), 0);
+ assert_eq!(*r.unsigned_min().u2be(), 0);
+ assert_eq!(*r.unsigned_min().u4be(), 0);
+ assert_eq!(*r.unsigned_min().u8be(), 0);
+ assert_eq!(*r.unsigned_max().u1(), 255);
+ assert_eq!(*r.unsigned_max().u2le(), 65535);
+ assert_eq!(*r.unsigned_max().u4le(), 4294967295);
+ assert_eq!(*r.unsigned_max().u8le(), 18446744073709551615);
+ assert_eq!(*r.unsigned_max().u2be(), 65535);
+ assert_eq!(*r.unsigned_max().u4be(), 4294967295);
+ assert_eq!(*r.unsigned_max().u8be(), 18446744073709551615);
+ assert_eq!(*r.signed_min().s1(), -128);
+ assert_eq!(*r.signed_min().s2le(), -32768);
+ assert_eq!(*r.signed_min().s4le(), -2147483648);
+ assert_eq!(*r.signed_min().s8le(), -9223372036854775808);
+ assert_eq!(*r.signed_min().s2be(), -32768);
+ assert_eq!(*r.signed_min().s4be(), -2147483648);
+ assert_eq!(*r.signed_min().s8be(), -9223372036854775808);
+ assert_eq!(*r.signed_max().s1(), 127);
+ assert_eq!(*r.signed_max().s2le(), 32767);
+ assert_eq!(*r.signed_max().s4le(), 2147483647);
+ assert_eq!(*r.signed_max().s8le(), 9223372036854775807);
+ assert_eq!(*r.signed_max().s2be(), 32767);
+ assert_eq!(*r.signed_max().s4be(), 2147483647);
+ assert_eq!(*r.signed_max().s8be(), 9223372036854775807);
+ Ok(())
+}
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..ec7d3bda9
--- /dev/null
+++ b/spec/rust/tests/test_io_local_var.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::io_local_var::*;
+
+#[test]
+fn test_io_local_var() -> KResult<()> {
+ let bytes = fs::read("../../src/full256.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = IoLocalVar::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.skip(), vec![0x0u8, 0x1u8, 0x2u8, 0x3u8, 0x4u8, 0x5u8, 0x6u8, 0x7u8, 0x8u8, 0x9u8, 0xau8, 0xbu8, 0xcu8, 0xdu8, 0xeu8, 0xfu8, 0x10u8, 0x11u8, 0x12u8, 0x13u8]);
+ assert_eq!(*r.followup(), 20);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_js_signed_right_shift.rs b/spec/rust/tests/test_js_signed_right_shift.rs
index 305913aa5..6afb2fac5 100644
--- a/spec/rust/tests/test_js_signed_right_shift.rs
+++ b/spec/rust/tests/test_js_signed_right_shift.rs
@@ -1,15 +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::JsSignedRightShift;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::js_signed_right_shift::*;
#[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);
- }
+fn test_js_signed_right_shift() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = JsSignedRightShift::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.should_be_40000000()?, 1073741824);
+ assert_eq!(*r.should_be_a00000()?, 10485760);
+ Ok(())
}
diff --git a/spec/rust/tests/test_meta_tags.rs b/spec/rust/tests/test_meta_tags.rs
new file mode 100644
index 000000000..f54ebf3a0
--- /dev/null
+++ b/spec/rust/tests/test_meta_tags.rs
@@ -0,0 +1,15 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::meta_tags::*;
+
+#[test]
+fn test_meta_tags() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = MetaTags::read_into(&_io, None, None)?;
+
+ Ok(())
+}
diff --git a/spec/rust/tests/test_meta_xref.rs b/spec/rust/tests/test_meta_xref.rs
index 9f068b47a..d5db58492 100644
--- a/spec/rust/tests/test_meta_xref.rs
+++ b/spec/rust/tests/test_meta_xref.rs
@@ -1,13 +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::MetaXref;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::meta_xref::*;
#[test]
-fn test_meta_xref() {
- if let Ok(r) = MetaXref::from_file("src/fixed_struct.bin") {
- }
+fn test_meta_xref() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = MetaXref::read_into(&_io, None, None)?;
+
+ Ok(())
}
diff --git a/spec/rust/tests/test_multiple_use.rs b/spec/rust/tests/test_multiple_use.rs
index c66faece9..59749afe0 100644
--- a/spec/rust/tests/test_multiple_use.rs
+++ b/spec/rust/tests/test_multiple_use.rs
@@ -1,15 +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::MultipleUse;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::multiple_use::*;
#[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);
- }
+fn test_multiple_use() -> KResult<()> {
+ let bytes = fs::read("../../src/position_abs.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = MultipleUse::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.t1().first_use().value(), 32);
+ assert_eq!(*r.t2().second_use()?.value(), 32);
+ Ok(())
}
diff --git a/spec/rust/tests/test_nav_parent.rs b/spec/rust/tests/test_nav_parent.rs
index c43fbd303..be20edd72 100644
--- a/spec/rust/tests/test_nav_parent.rs
+++ b/spec/rust/tests/test_nav_parent.rs
@@ -1,18 +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::NavParent;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nav_parent::*;
#[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__");
- }
+fn test_nav_parent() -> KResult<()> {
+ let bytes = fs::read("../../src/nav.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NavParent::read_into(&_io, None, None)?;
+
+ 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 as usize].filename(), "FIRST___");
+ assert_eq!(*r.index().entries()[1 as usize].filename(), "SECOND__");
+ Ok(())
}
diff --git a/spec/rust/tests/test_nav_parent2.rs b/spec/rust/tests/test_nav_parent2.rs
index c2f6d256f..777048c05 100644
--- a/spec/rust/tests/test_nav_parent2.rs
+++ b/spec/rust/tests/test_nav_parent2.rs
@@ -1,23 +1,25 @@
// 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 std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nav_parent2::*;
#[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");
- }
+fn test_nav_parent2() -> KResult<()> {
+ let bytes = fs::read("../../src/nav_parent2.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NavParent2::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.ofs_tags(), 8);
+ assert_eq!(*r.num_tags(), 2);
+ assert_eq!(*r.tags()[0 as usize].name(), "RAHC");
+ assert_eq!(*r.tags()[0 as usize].ofs(), 32);
+ assert_eq!(*r.tags()[0 as usize].num_items(), 3);
+ assert_eq!(*r.tags()[0 as usize].tag_content()?.as_ref().unwrap().content(), "foo");
+ assert_eq!(*r.tags()[1 as usize].name(), "RAHC");
+ assert_eq!(*r.tags()[1 as usize].ofs(), 35);
+ assert_eq!(*r.tags()[1 as usize].num_items(), 6);
+ assert_eq!(*r.tags()[1 as usize].tag_content()?.as_ref().unwrap().content(), "barbaz");
+ Ok(())
}
diff --git a/spec/rust/tests/test_nav_parent3.rs b/spec/rust/tests/test_nav_parent3.rs
index cc5abd5b2..c36906289 100644
--- a/spec/rust/tests/test_nav_parent3.rs
+++ b/spec/rust/tests/test_nav_parent3.rs
@@ -1,23 +1,25 @@
// 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 std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nav_parent3::*;
#[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");
- }
+fn test_nav_parent3() -> KResult<()> {
+ let bytes = fs::read("../../src/nav_parent2.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NavParent3::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.ofs_tags(), 8);
+ assert_eq!(*r.num_tags(), 2);
+ assert_eq!(*r.tags()?[0 as usize].name(), "RAHC");
+ assert_eq!(*r.tags()?[0 as usize].ofs(), 32);
+ assert_eq!(*r.tags()?[0 as usize].num_items(), 3);
+ assert_eq!(*r.tags()?[0 as usize].tag_content()?.as_ref().unwrap().content(), "foo");
+ assert_eq!(*r.tags()?[1 as usize].name(), "RAHC");
+ assert_eq!(*r.tags()?[1 as usize].ofs(), 35);
+ assert_eq!(*r.tags()?[1 as usize].num_items(), 6);
+ assert_eq!(*r.tags()?[1 as usize].tag_content()?.as_ref().unwrap().content(), "barbaz");
+ Ok(())
}
diff --git a/spec/rust/tests/test_nav_parent_false.rs b/spec/rust/tests/test_nav_parent_false.rs
index f8e935120..c0b2add72 100644
--- a/spec/rust/tests/test_nav_parent_false.rs
+++ b/spec/rust/tests/test_nav_parent_false.rs
@@ -1,18 +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::NavParentFalse;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nav_parent_false::*;
#[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);
- }
+fn test_nav_parent_false() -> KResult<()> {
+ let bytes = fs::read("../../src/nav_parent_codes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NavParentFalse::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.child_size(), 3);
+ assert_eq!(*r.element_a().foo().code(), 73);
+ assert_eq!(*r.element_a().foo().more(), vec![0x31u8, 0x32u8, 0x33u8]);
+ assert_eq!(*r.element_a().bar().foo().code(), 66);
+ assert_eq!(*r.element_b().foo().code(), 98);
+ Ok(())
}
diff --git a/spec/rust/tests/test_nav_parent_false2.rs b/spec/rust/tests/test_nav_parent_false2.rs
index 868d60f24..fd0ea572e 100644
--- a/spec/rust/tests/test_nav_parent_false2.rs
+++ b/spec/rust/tests/test_nav_parent_false2.rs
@@ -1,14 +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::NavParentFalse2;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nav_parent_false2::*;
#[test]
-fn test_nav_parent_false2() {
- if let Ok(r) = NavParentFalse2::from_file("src/fixed_struct.bin") {
- assert_eq!(r.parentless.foo, 80);
- }
+fn test_nav_parent_false2() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NavParentFalse2::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.parentless().foo(), 80);
+ Ok(())
}
diff --git a/spec/rust/tests/test_nav_parent_override.rs b/spec/rust/tests/test_nav_parent_override.rs
index 2ebc78835..d1fb3f40e 100644
--- a/spec/rust/tests/test_nav_parent_override.rs
+++ b/spec/rust/tests/test_nav_parent_override.rs
@@ -1,16 +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::NavParentOverride;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nav_parent_override::*;
#[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]));
- }
+fn test_nav_parent_override() -> KResult<()> {
+ let bytes = fs::read("../../src/nav_parent_codes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NavParentOverride::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.child_size(), 3);
+ assert_eq!(*r.child_1().data(), vec![0x49u8, 0x31u8, 0x32u8]);
+ assert_eq!(*r.mediator_2().child_2().data(), vec![0x33u8, 0x42u8, 0x62u8]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_nav_parent_recursive.rs b/spec/rust/tests/test_nav_parent_recursive.rs
new file mode 100644
index 000000000..aa24f9886
--- /dev/null
+++ b/spec/rust/tests/test_nav_parent_recursive.rs
@@ -0,0 +1,19 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nav_parent_recursive::*;
+
+#[test]
+fn test_nav_parent_recursive() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_negative.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NavParentRecursive::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.value(), 255);
+ assert_eq!(*r.next().value(), 1);
+ assert_eq!(*r.next().parent_value()?, 255);
+ assert!(r.next().next().is_none());
+ Ok(())
+}
diff --git a/spec/rust/tests/test_nav_parent_switch.rs b/spec/rust/tests/test_nav_parent_switch.rs
index b2373ef91..c57225c12 100644
--- a/spec/rust/tests/test_nav_parent_switch.rs
+++ b/spec/rust/tests/test_nav_parent_switch.rs
@@ -1,16 +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::NavParentSwitch;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nav_parent_switch::*;
#[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);
- }
+fn test_nav_parent_switch() -> KResult<()> {
+ let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NavParentSwitch::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.category(), 1);
+ assert_eq!(*Into::>::into(&*r.content().as_ref().unwrap()).foo(), 66);
+ assert_eq!(*Into::>::into(&*r.content().as_ref().unwrap()).subelement().bar(), 255);
+ Ok(())
}
diff --git a/spec/rust/tests/test_nav_parent_switch_cast.rs b/spec/rust/tests/test_nav_parent_switch_cast.rs
new file mode 100644
index 000000000..f81c930f4
--- /dev/null
+++ b/spec/rust/tests/test_nav_parent_switch_cast.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nav_parent_switch_cast::*;
+
+#[test]
+fn test_nav_parent_switch_cast() -> KResult<()> {
+ let bytes = fs::read("../../src/switch_integers.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NavParentSwitchCast::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.main().buf_type(), 1);
+ assert_eq!(*r.main().flag(), 7);
+ assert_eq!(*Into::>::into(&*r.main().buf().as_ref().unwrap()).branch().flag()?, 7);
+ Ok(())
+}
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..7c91d176b 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,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::NavParentVsValueInst;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nav_parent_vs_value_inst::*;
#[test]
-fn test_nav_parent_vs_value_inst() {
- if let Ok(r) = NavParentVsValueInst::from_file("src/term_strz.bin") {
- assert_eq!(r.s1, "foo");
- }
+fn test_nav_parent_vs_value_inst() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NavParentVsValueInst::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.s1(), "foo");
+ Ok(())
}
diff --git a/spec/rust/tests/test_nav_root.rs b/spec/rust/tests/test_nav_root.rs
index 1bf59f436..8f91dfea4 100644
--- a/spec/rust/tests/test_nav_root.rs
+++ b/spec/rust/tests/test_nav_root.rs
@@ -1,18 +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::NavRoot;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nav_root::*;
#[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__");
- }
+fn test_nav_root() -> KResult<()> {
+ let bytes = fs::read("../../src/nav.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NavRoot::read_into(&_io, None, None)?;
+
+ 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 as usize].filename(), "FIRST___");
+ assert_eq!(*r.index().entries()[1 as usize].filename(), "SECOND__");
+ Ok(())
}
diff --git a/spec/rust/tests/test_nav_root_recursive.rs b/spec/rust/tests/test_nav_root_recursive.rs
new file mode 100644
index 000000000..42f08335f
--- /dev/null
+++ b/spec/rust/tests/test_nav_root_recursive.rs
@@ -0,0 +1,19 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nav_root_recursive::*;
+
+#[test]
+fn test_nav_root_recursive() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_negative.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NavRootRecursive::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.value(), 255);
+ assert_eq!(*r.next().value(), 1);
+ assert_eq!(*r.next().root_value()?, 255);
+ assert!(r.next().next().is_none());
+ Ok(())
+}
diff --git a/spec/rust/tests/test_nested_same_name.rs b/spec/rust/tests/test_nested_same_name.rs
index ca73804cf..41b48f77d 100644
--- a/spec/rust/tests/test_nested_same_name.rs
+++ b/spec/rust/tests/test_nested_same_name.rs
@@ -1,15 +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::NestedSameName;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nested_same_name::*;
#[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]));
- }
+fn test_nested_same_name() -> KResult<()> {
+ let bytes = fs::read("../../src/repeat_n_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NestedSameName::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.main_data().main_size(), 2);
+ assert_eq!(*r.main_data().foo().data(), vec![0x10u8, 0x0u8, 0x0u8, 0x0u8]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_nested_same_name2.rs b/spec/rust/tests/test_nested_same_name2.rs
index 1087cb851..28138b012 100644
--- a/spec/rust/tests/test_nested_same_name2.rs
+++ b/spec/rust/tests/test_nested_same_name2.rs
@@ -1,18 +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::NestedSameName2;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nested_same_name2::*;
#[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]));
- }
+fn test_nested_same_name2() -> KResult<()> {
+ let bytes = fs::read("../../src/nested_same_name2.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NestedSameName2::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.version(), 66);
+ assert_eq!(*r.main_data().main_size(), 2);
+ assert_eq!(*r.main_data().foo().data1(), vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]);
+ assert_eq!(*r.dummy().dummy_size(), 3);
+ assert_eq!(*r.dummy().foo().data2(), vec![0x22u8, 0x22u8, 0x22u8, 0x22u8, 0x22u8, 0x22u8]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_nested_type_param.rs b/spec/rust/tests/test_nested_type_param.rs
new file mode 100644
index 000000000..46bea7a44
--- /dev/null
+++ b/spec/rust/tests/test_nested_type_param.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nested_type_param::*;
+
+#[test]
+fn test_nested_type_param() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NestedTypeParam::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.main_seq().my_len(), 5);
+ assert_eq!(*r.main_seq().body(), "foo|b");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_nested_types.rs b/spec/rust/tests/test_nested_types.rs
index 796b4dda8..f86801e7f 100644
--- a/spec/rust/tests/test_nested_types.rs
+++ b/spec/rust/tests/test_nested_types.rs
@@ -1,16 +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::NestedTypes;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nested_types::*;
#[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);
- }
+fn test_nested_types() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NestedTypes::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_nested_types2.rs b/spec/rust/tests/test_nested_types2.rs
index ed295df76..a0040cc84 100644
--- a/spec/rust/tests/test_nested_types2.rs
+++ b/spec/rust/tests/test_nested_types2.rs
@@ -1,20 +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::NestedTypes2;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nested_types2::*;
#[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);
- }
+fn test_nested_types2() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NestedTypes2::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_nested_types3.rs b/spec/rust/tests/test_nested_types3.rs
index ee2fd8f97..3748a20f6 100644
--- a/spec/rust/tests/test_nested_types3.rs
+++ b/spec/rust/tests/test_nested_types3.rs
@@ -1,18 +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::NestedTypes3;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nested_types3::*;
#[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);
- }
+fn test_nested_types3() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NestedTypes3::read_into(&_io, None, None)?;
+
+ 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);
+ Ok(())
}
diff --git a/spec/rust/tests/test_nested_types_import.rs b/spec/rust/tests/test_nested_types_import.rs
new file mode 100644
index 000000000..41edef086
--- /dev/null
+++ b/spec/rust/tests/test_nested_types_import.rs
@@ -0,0 +1,24 @@
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::nested_types_import::*;
+
+#[test]
+fn test_nested_types_import() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NestedTypesImport::read_into(&_io, None, None)?;
+
+ 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);
+ assert!(r.a_cc()._parent.get_value().borrow().upgrade().is_none());
+ assert!(r.a_cc()._root.get_value().borrow().upgrade().is_none());
+ assert!(r.a_c_d()._parent.get_value().borrow().upgrade().is_none());
+ assert!(r.a_c_d()._root.get_value().borrow().upgrade().is_none());
+ assert!(r.b()._parent.get_value().borrow().upgrade().is_none());
+ assert!(r.b()._root.get_value().borrow().upgrade().is_none());
+ Ok(())
+}
diff --git a/spec/rust/tests/test_non_standard.rs b/spec/rust/tests/test_non_standard.rs
index c649b8283..d12978c07 100644
--- a/spec/rust/tests/test_non_standard.rs
+++ b/spec/rust/tests/test_non_standard.rs
@@ -1,14 +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::NonStandard;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::non_standard::*;
#[test]
-fn test_non_standard() {
- if let Ok(r) = NonStandard::from_file("src/fixed_struct.bin") {
- assert_eq!(r.foo, 80);
- }
+fn test_non_standard() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = NonStandard::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.foo(), 80);
+ Ok(())
}
diff --git a/spec/rust/tests/test_opaque_external_type.rs b/spec/rust/tests/test_opaque_external_type.rs
new file mode 100644
index 000000000..20bf3f557
--- /dev/null
+++ b/spec/rust/tests/test_opaque_external_type.rs
@@ -0,0 +1,16 @@
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::opaque_external_type::*;
+
+#[test]
+fn test_opaque_external_type() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = OpaqueExternalType::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one().s1(), "foo");
+ assert_eq!(*r.one().s2(), "bar");
+ assert_eq!(*r.one().s3(), "|baz@");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_opaque_external_type_02_parent.rs b/spec/rust/tests/test_opaque_external_type_02_parent.rs
new file mode 100644
index 000000000..84a397039
--- /dev/null
+++ b/spec/rust/tests/test_opaque_external_type_02_parent.rs
@@ -0,0 +1,16 @@
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::opaque_external_type_02_parent::*;
+
+#[test]
+fn test_opaque_external_type_02_parent() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = OpaqueExternalType02Parent::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.parent().child().s1(), "foo");
+ assert_eq!(*r.parent().child().s2(), "bar");
+ assert_eq!(*r.parent().child().s3().s3(), "|baz@");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_opaque_with_param.rs b/spec/rust/tests/test_opaque_with_param.rs
new file mode 100644
index 000000000..b8b1befbc
--- /dev/null
+++ b/spec/rust/tests/test_opaque_with_param.rs
@@ -0,0 +1,15 @@
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::opaque_with_param::*;
+
+#[test]
+fn test_opaque_with_param() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = OpaqueWithParam::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one().buf(), "foo|b");
+ assert_eq!(*r.one().trailer(), 0x61);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_optional_id.rs b/spec/rust/tests/test_optional_id.rs
new file mode 100644
index 000000000..8abc492a0
--- /dev/null
+++ b/spec/rust/tests/test_optional_id.rs
@@ -0,0 +1,16 @@
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::optional_id::*;
+
+#[test]
+fn test_optional_id() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = OptionalId::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.unnamed0(), 80);
+ assert_eq!(*r.unnamed1(), 65);
+ assert_eq!(*r.unnamed2(), vec![0x43, 0x4B, 0x2D, 0x31, 0xFF]);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_params_call.rs b/spec/rust/tests/test_params_call.rs
new file mode 100644
index 000000000..16170785b
--- /dev/null
+++ b/spec/rust/tests/test_params_call.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::params_call::*;
+
+#[test]
+fn test_params_call() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ParamsCall::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.buf1().body(), "foo|b");
+ assert_eq!(*r.buf2().body(), "ar|ba");
+ assert_eq!(*r.buf2().trailer(), 122);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_params_call_extra_parens.rs b/spec/rust/tests/test_params_call_extra_parens.rs
new file mode 100644
index 000000000..1d3da910e
--- /dev/null
+++ b/spec/rust/tests/test_params_call_extra_parens.rs
@@ -0,0 +1,16 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::params_call_extra_parens::*;
+
+#[test]
+fn test_params_call_extra_parens() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ParamsCallExtraParens::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.buf1().body(), "foo|b");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_params_def.rs b/spec/rust/tests/test_params_def.rs
new file mode 100644
index 000000000..a366ef4d5
--- /dev/null
+++ b/spec/rust/tests/test_params_def.rs
@@ -0,0 +1,16 @@
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::params_def::*;
+
+#[test]
+fn test_params_def() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let f = |t: &mut ParamsDef| Ok(t.set_params(5, true));
+ let r: OptRc = ParamsDef::read_into_with_init(&_io, None, None, &f)?;
+
+ assert_eq!(*r.buf(), "foo|b");
+ assert_eq!(*r.trailer(), 0x61);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_params_enum.rs b/spec/rust/tests/test_params_enum.rs
new file mode 100644
index 000000000..b5a0ff4f8
--- /dev/null
+++ b/spec/rust/tests/test_params_enum.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::params_enum::*;
+
+#[test]
+fn test_params_enum() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ParamsEnum::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one(), ParamsEnum_Animal::Cat);
+ assert_eq!(*r.invoke_with_param().is_cat()?, true);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_params_pass_array_int.rs b/spec/rust/tests/test_params_pass_array_int.rs
new file mode 100644
index 000000000..235d20d26
--- /dev/null
+++ b/spec/rust/tests/test_params_pass_array_int.rs
@@ -0,0 +1,22 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::params_pass_array_int::*;
+
+#[test]
+fn test_params_pass_array_int() -> KResult<()> {
+ let bytes = fs::read("../../src/position_to_end.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ParamsPassArrayInt::read_into(&_io, None, None)?;
+
+ assert_eq!(r.pass_ints().nums().len(), 3);
+ assert_eq!(r.pass_ints().nums()[0 as usize], 513);
+ assert_eq!(r.pass_ints().nums()[1 as usize], 1027);
+ assert_eq!(r.pass_ints().nums()[2 as usize], 1541);
+ assert_eq!(r.pass_ints_calc().nums().len(), 2);
+ assert_eq!(r.pass_ints_calc().nums()[0 as usize], 27643);
+ assert_eq!(r.pass_ints_calc().nums()[1 as usize], 7);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_params_pass_array_str.rs b/spec/rust/tests/test_params_pass_array_str.rs
new file mode 100644
index 000000000..fbd85cfe1
--- /dev/null
+++ b/spec/rust/tests/test_params_pass_array_str.rs
@@ -0,0 +1,22 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::params_pass_array_str::*;
+
+#[test]
+fn test_params_pass_array_str() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ParamsPassArrayStr::read_into(&_io, None, None)?;
+
+ assert_eq!(r.pass_str_array().strs().len(), 3);
+ assert_eq!(r.pass_str_array().strs()[0 as usize], "fo");
+ assert_eq!(r.pass_str_array().strs()[1 as usize], "o|");
+ assert_eq!(r.pass_str_array().strs()[2 as usize], "ba");
+ assert_eq!(r.pass_str_array_calc().strs().len(), 2);
+ assert_eq!(r.pass_str_array_calc().strs()[0 as usize], "aB");
+ assert_eq!(r.pass_str_array_calc().strs()[1 as usize], "Cd");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_params_pass_array_struct.rs b/spec/rust/tests/test_params_pass_array_struct.rs
new file mode 100644
index 000000000..c452043f7
--- /dev/null
+++ b/spec/rust/tests/test_params_pass_array_struct.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::params_pass_array_struct::*;
+
+#[test]
+fn test_params_pass_array_struct() -> KResult<()> {
+ let bytes = fs::read("../../src/position_to_end.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ParamsPassArrayStruct::read_into(&_io, None, None)?;
+
+ assert_eq!(r.pass_structs().structs().len(), 2);
+ assert_eq!(*Into::>::into(&r.pass_structs().structs()[0 as usize]).f(), 1);
+ assert_eq!(*Into::>::into(&r.pass_structs().structs()[1 as usize]).b(), 2);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_params_pass_array_usertype.rs b/spec/rust/tests/test_params_pass_array_usertype.rs
new file mode 100644
index 000000000..414678896
--- /dev/null
+++ b/spec/rust/tests/test_params_pass_array_usertype.rs
@@ -0,0 +1,20 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::params_pass_array_usertype::*;
+
+#[test]
+fn test_params_pass_array_usertype() -> KResult<()> {
+ let bytes = fs::read("../../src/position_to_end.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ParamsPassArrayUsertype::read_into(&_io, None, None)?;
+
+ assert_eq!(r.pass_blocks().bar().len(), 2);
+ assert_eq!(*r.pass_blocks().bar()[0 as usize].foo(), 1);
+ assert_eq!(*r.pass_blocks().bar()[1 as usize].foo(), 2);
+ assert_eq!(*r.pass_blocks().one(), vec![0x3u8]);
+ assert_eq!(*r.pass_blocks().two(), vec![0x4u8, 0x5u8]);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_params_pass_bool.rs b/spec/rust/tests/test_params_pass_bool.rs
new file mode 100644
index 000000000..1169b496f
--- /dev/null
+++ b/spec/rust/tests/test_params_pass_bool.rs
@@ -0,0 +1,29 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::params_pass_bool::*;
+
+#[test]
+fn test_params_pass_bool() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ParamsPassBool::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.s_false(), false);
+ assert_eq!(*r.s_true(), true);
+ assert_eq!(*r.seq_b1().arg(), true);
+ assert_eq!(r.seq_b1().foo().len(), 1);
+ assert_eq!(*r.seq_bool().arg(), false);
+ assert_eq!(r.seq_bool().foo().len(), 2);
+ assert_eq!(*r.literal_b1().arg(), false);
+ assert_eq!(r.literal_b1().foo().len(), 2);
+ assert_eq!(*r.literal_bool().arg(), true);
+ assert_eq!(r.literal_bool().foo().len(), 1);
+ assert_eq!(*r.inst_b1().arg(), true);
+ assert_eq!(r.inst_b1().foo().len(), 1);
+ assert_eq!(*r.inst_bool().arg(), false);
+ assert_eq!(r.inst_bool().foo().len(), 2);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_params_pass_struct.rs b/spec/rust/tests/test_params_pass_struct.rs
new file mode 100644
index 000000000..c2c10a13b
--- /dev/null
+++ b/spec/rust/tests/test_params_pass_struct.rs
@@ -0,0 +1,19 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::params_pass_struct::*;
+
+#[test]
+fn test_params_pass_struct() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_negative.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ParamsPassStruct::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.first().foo(), 255);
+ assert_eq!(*r.one().bar().qux(), 1);
+ assert_eq!(*Into::>::into(&*r.one().foo()).foo(), 255);
+ assert_eq!(*Into::>::into(&*r.one().bar().foo()).foo(), 255);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_params_pass_usertype.rs b/spec/rust/tests/test_params_pass_usertype.rs
index 619950a9f..e2952dee4 100644
--- a/spec/rust/tests/test_params_pass_usertype.rs
+++ b/spec/rust/tests/test_params_pass_usertype.rs
@@ -1,15 +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::ParamsPassUsertype;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::params_pass_usertype::*;
#[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]));
- }
+fn test_params_pass_usertype() -> KResult<()> {
+ let bytes = fs::read("../../src/position_in_seq.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ParamsPassUsertype::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.first().foo(), 1);
+ assert_eq!(*r.one().buf(), vec![0x2u8]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_position_abs.rs b/spec/rust/tests/test_position_abs.rs
index 27c477617..79fddf658 100644
--- a/spec/rust/tests/test_position_abs.rs
+++ b/spec/rust/tests/test_position_abs.rs
@@ -1,15 +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::PositionAbs;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::position_abs::*;
#[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");
- }
+fn test_position_abs() -> KResult<()> {
+ let bytes = fs::read("../../src/position_abs.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = PositionAbs::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.index_offset(), 32);
+ assert_eq!(*r.index()?.entry(), "foo");
+ Ok(())
}
diff --git a/spec/rust/tests/test_position_in_seq.rs b/spec/rust/tests/test_position_in_seq.rs
index 31a69b08e..1d6559197 100644
--- a/spec/rust/tests/test_position_in_seq.rs
+++ b/spec/rust/tests/test_position_in_seq.rs
@@ -1,14 +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::PositionInSeq;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::position_in_seq::*;
#[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]);
- }
+fn test_position_in_seq() -> KResult<()> {
+ let bytes = fs::read("../../src/position_in_seq.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = PositionInSeq::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.numbers(), vec![(0 + 1), 2, 3]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_position_to_end.rs b/spec/rust/tests/test_position_to_end.rs
index 97f5ddd06..0f74aab5e 100644
--- a/spec/rust/tests/test_position_to_end.rs
+++ b/spec/rust/tests/test_position_to_end.rs
@@ -1,15 +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::PositionToEnd;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::position_to_end::*;
#[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);
- }
+fn test_position_to_end() -> KResult<()> {
+ let bytes = fs::read("../../src/position_to_end.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = PositionToEnd::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.index()?.foo(), 66);
+ assert_eq!(*r.index()?.bar(), 4660);
+ Ok(())
}
diff --git a/spec/rust/tests/test_process_coerce_bytes.rs b/spec/rust/tests/test_process_coerce_bytes.rs
index 3cc865f9f..27fe0f0f1 100644
--- a/spec/rust/tests/test_process_coerce_bytes.rs
+++ b/spec/rust/tests/test_process_coerce_bytes.rs
@@ -1,17 +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::ProcessCoerceBytes;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_coerce_bytes::*;
#[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]));
- }
+fn test_process_coerce_bytes() -> KResult<()> {
+ let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessCoerceBytes::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.records()[0 as usize].flag(), 0);
+ assert_eq!(*r.records()[0 as usize].buf()?, vec![0x41u8, 0x41u8, 0x41u8, 0x41u8]);
+ assert_eq!(*r.records()[1 as usize].flag(), 1);
+ assert_eq!(*r.records()[1 as usize].buf()?, vec![0x42u8, 0x42u8, 0x42u8, 0x42u8]);
+ Ok(())
}
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
index e5b91114d..bb5d0b057 100644
--- a/spec/rust/tests/test_process_coerce_usertype1.rs
+++ b/spec/rust/tests/test_process_coerce_usertype1.rs
@@ -1,17 +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::ProcessCoerceUsertype1;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_coerce_usertype1::*;
#[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);
- }
+fn test_process_coerce_usertype1() -> KResult<()> {
+ let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessCoerceUsertype1::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.records()[0 as usize].flag(), 0);
+ assert_eq!(*r.records()[0 as usize].buf()?.value(), 1094795585);
+ assert_eq!(*r.records()[1 as usize].flag(), 1);
+ assert_eq!(*r.records()[1 as usize].buf()?.value(), 1111638594);
+ Ok(())
}
diff --git a/spec/rust/tests/test_process_coerce_usertype2.rs b/spec/rust/tests/test_process_coerce_usertype2.rs
index b0ecbd8cf..e4472c066 100644
--- a/spec/rust/tests/test_process_coerce_usertype2.rs
+++ b/spec/rust/tests/test_process_coerce_usertype2.rs
@@ -1,17 +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::ProcessCoerceUsertype2;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_coerce_usertype2::*;
#[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);
- }
+fn test_process_coerce_usertype2() -> KResult<()> {
+ let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessCoerceUsertype2::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.records()[0 as usize].flag(), 0);
+ assert_eq!(*r.records()[0 as usize].buf()?.value(), 1094795585);
+ assert_eq!(*r.records()[1 as usize].flag(), 1);
+ assert_eq!(*r.records()[1 as usize].buf()?.value(), 1111638594);
+ Ok(())
}
diff --git a/spec/rust/tests/test_process_custom.rs b/spec/rust/tests/test_process_custom.rs
index d07d106b2..c8779af13 100644
--- a/spec/rust/tests/test_process_custom.rs
+++ b/spec/rust/tests/test_process_custom.rs
@@ -1,16 +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::ProcessCustom;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_custom::*;
#[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]));
- }
+fn test_process_custom() -> KResult<()> {
+ let bytes = fs::read("../../src/process_rotate.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessCustom::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.buf1(), vec![0x10u8, 0xb3u8, 0x94u8, 0x94u8, 0xf4u8]);
+ assert_eq!(*r.buf2(), vec![0x5fu8, 0xbau8, 0x7bu8, 0x93u8, 0x63u8, 0x23u8, 0x5fu8]);
+ assert_eq!(*r.buf3(), vec![0x29u8, 0x33u8, 0xb1u8, 0x38u8, 0xb1u8]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_process_custom_no_args.rs b/spec/rust/tests/test_process_custom_no_args.rs
new file mode 100644
index 000000000..1a07ec3c1
--- /dev/null
+++ b/spec/rust/tests/test_process_custom_no_args.rs
@@ -0,0 +1,16 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_custom_no_args::*;
+
+#[test]
+fn test_process_custom_no_args() -> KResult<()> {
+ let bytes = fs::read("../../src/process_rotate.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessCustomNoArgs::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.buf(), vec![0x5fu8, 0x9u8, 0xacu8, 0x8du8, 0x8du8, 0xedu8, 0x5fu8]);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_process_repeat_bytes.rs b/spec/rust/tests/test_process_repeat_bytes.rs
new file mode 100644
index 000000000..1d5e90777
--- /dev/null
+++ b/spec/rust/tests/test_process_repeat_bytes.rs
@@ -0,0 +1,17 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_repeat_bytes::*;
+
+#[test]
+fn test_process_repeat_bytes() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessRepeatBytes::read_into(&_io, None, None)?;
+
+ assert_eq!(r.bufs()[0 as usize], vec![0x72u8, 0x25u8, 0x3du8, 0x8au8, 0x14u8]);
+ assert_eq!(r.bufs()[1 as usize], vec![0x4au8, 0x52u8, 0xaau8, 0x10u8, 0x44u8]);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_process_repeat_usertype.rs b/spec/rust/tests/test_process_repeat_usertype.rs
new file mode 100644
index 000000000..1f560d2f1
--- /dev/null
+++ b/spec/rust/tests/test_process_repeat_usertype.rs
@@ -0,0 +1,19 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_repeat_usertype::*;
+
+#[test]
+fn test_process_repeat_usertype() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessRepeatUsertype::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.blocks()[0 as usize].a(), -1975704206);
+ assert_eq!(*r.blocks()[0 as usize].b(), 20);
+ assert_eq!(*r.blocks()[1 as usize].a(), 279597642);
+ assert_eq!(*r.blocks()[1 as usize].b(), 68);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_process_rotate.rs b/spec/rust/tests/test_process_rotate.rs
index 1ab694a8f..56a85b19c 100644
--- a/spec/rust/tests/test_process_rotate.rs
+++ b/spec/rust/tests/test_process_rotate.rs
@@ -1,16 +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::ProcessRotate;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_rotate::*;
#[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]));
- }
+fn test_process_rotate() -> KResult<()> {
+ let bytes = fs::read("../../src/process_rotate.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessRotate::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.buf1(), vec![0x48u8, 0x65u8, 0x6cu8, 0x6cu8, 0x6fu8]);
+ assert_eq!(*r.buf2(), vec![0x57u8, 0x6fu8, 0x72u8, 0x6cu8, 0x64u8]);
+ assert_eq!(*r.buf3(), vec![0x54u8, 0x68u8, 0x65u8, 0x72u8, 0x65u8]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_process_to_user.rs b/spec/rust/tests/test_process_to_user.rs
index 35fe9f85c..ade867ee8 100644
--- a/spec/rust/tests/test_process_to_user.rs
+++ b/spec/rust/tests/test_process_to_user.rs
@@ -1,14 +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::ProcessToUser;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_to_user::*;
#[test]
-fn test_process_to_user() {
- if let Ok(r) = ProcessToUser::from_file("src/process_rotate.bin") {
- assert_eq!(r.buf1.str, "Hello");
- }
+fn test_process_to_user() -> KResult<()> {
+ let bytes = fs::read("../../src/process_rotate.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessToUser::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.buf1().str(), "Hello");
+ Ok(())
}
diff --git a/spec/rust/tests/test_process_xor4_const.rs b/spec/rust/tests/test_process_xor4_const.rs
index cb41dcc7f..a9e7e9231 100644
--- a/spec/rust/tests/test_process_xor4_const.rs
+++ b/spec/rust/tests/test_process_xor4_const.rs
@@ -1,15 +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::ProcessXor4Const;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_xor4_const::*;
#[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]));
- }
+fn test_process_xor4_const() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessXor4Const::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.key(), vec![0xecu8, 0xbbu8, 0xa3u8, 0x14u8]);
+ assert_eq!(*r.buf(), vec![0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_process_xor4_value.rs b/spec/rust/tests/test_process_xor4_value.rs
index deff2c110..70dc81077 100644
--- a/spec/rust/tests/test_process_xor4_value.rs
+++ b/spec/rust/tests/test_process_xor4_value.rs
@@ -1,15 +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::ProcessXor4Value;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_xor4_value::*;
#[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]));
- }
+fn test_process_xor4_value() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessXor4Value::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.key(), vec![0xecu8, 0xbbu8, 0xa3u8, 0x14u8]);
+ assert_eq!(*r.buf(), vec![0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_process_xor_const.rs b/spec/rust/tests/test_process_xor_const.rs
index 268c1e802..707743b8e 100644
--- a/spec/rust/tests/test_process_xor_const.rs
+++ b/spec/rust/tests/test_process_xor_const.rs
@@ -1,15 +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::ProcessXorConst;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_xor_const::*;
#[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]));
- }
+fn test_process_xor_const() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_1.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessXorConst::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.key(), 255);
+ assert_eq!(*r.buf(), vec![0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_process_xor_value.rs b/spec/rust/tests/test_process_xor_value.rs
index e0a266145..98e0226f8 100644
--- a/spec/rust/tests/test_process_xor_value.rs
+++ b/spec/rust/tests/test_process_xor_value.rs
@@ -1,15 +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::ProcessXorValue;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::process_xor_value::*;
#[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]));
- }
+fn test_process_xor_value() -> KResult<()> {
+ let bytes = fs::read("../../src/process_xor_1.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = ProcessXorValue::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.key(), 255);
+ assert_eq!(*r.buf(), vec![0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_recursive_one.rs b/spec/rust/tests/test_recursive_one.rs
new file mode 100644
index 000000000..04119611a
--- /dev/null
+++ b/spec/rust/tests/test_recursive_one.rs
@@ -0,0 +1,19 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::recursive_one::*;
+
+#[test]
+fn test_recursive_one() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = RecursiveOne::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.one(), 80);
+ assert_eq!(*Into::>::into(&*r.next().as_ref().unwrap()).one(), 65);
+ assert_eq!(*Into::>::into(&*Into::>::into(&*r.next().as_ref().unwrap()).next().as_ref().unwrap()).one(), 67);
+ assert_eq!(*Into::>::into(&*Into::>::into(&*Into::>::into(&*r.next().as_ref().unwrap()).next().as_ref().unwrap()).next().as_ref().unwrap()).finisher(), 11595);
+ Ok(())
+}
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..0d8524b5a
--- /dev/null
+++ b/spec/rust/tests/test_repeat_eos_bit.rs
@@ -0,0 +1,16 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::repeat_eos_bit::*;
+
+#[test]
+fn test_repeat_eos_bit() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_0.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = RepeatEosBit::read_into(&_io, None, None)?;
+
+ assert_eq!(r.nibbles().len(), 16);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs
index 2eca3a73c..acef8f0f8 100644
--- a/spec/rust/tests/test_repeat_eos_struct.rs
+++ b/spec/rust/tests/test_repeat_eos_struct.rs
@@ -1,18 +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::RepeatEosStruct;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::repeat_eos_struct::*;
#[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);
- }
+fn test_repeat_eos_struct() -> KResult<()> {
+ let bytes = fs::read("../../src/repeat_eos_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = RepeatEosStruct::read_into(&_io, None, None)?;
+
+ assert_eq!(r.chunks().len(), 2);
+ assert_eq!(*r.chunks()[0 as usize].offset(), 0);
+ assert_eq!(*r.chunks()[0 as usize].len(), 66);
+ assert_eq!(*r.chunks()[1 as usize].offset(), 66);
+ assert_eq!(*r.chunks()[1 as usize].len(), 2069);
+ Ok(())
}
diff --git a/spec/rust/tests/test_repeat_eos_u4.rs b/spec/rust/tests/test_repeat_eos_u4.rs
index 74f5d24cf..e8852549e 100644
--- a/spec/rust/tests/test_repeat_eos_u4.rs
+++ b/spec/rust/tests/test_repeat_eos_u4.rs
@@ -1,14 +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::RepeatEosU4;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::repeat_eos_u4::*;
#[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]);
- }
+fn test_repeat_eos_u4() -> KResult<()> {
+ let bytes = fs::read("../../src/repeat_eos_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = RepeatEosU4::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.numbers(), vec![0, 66, 66, 2069]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs
index 802fb7497..6b625365c 100644
--- a/spec/rust/tests/test_repeat_n_struct.rs
+++ b/spec/rust/tests/test_repeat_n_struct.rs
@@ -1,18 +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::RepeatNStruct;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::repeat_n_struct::*;
#[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);
- }
+fn test_repeat_n_struct() -> KResult<()> {
+ let bytes = fs::read("../../src/repeat_n_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = RepeatNStruct::read_into(&_io, None, None)?;
+
+ assert_eq!(r.chunks().len(), 2);
+ assert_eq!(*r.chunks()[0 as usize].offset(), 16);
+ assert_eq!(*r.chunks()[0 as usize].len(), 8312);
+ assert_eq!(*r.chunks()[1 as usize].offset(), 8328);
+ assert_eq!(*r.chunks()[1 as usize].len(), 15);
+ Ok(())
}
diff --git a/spec/rust/tests/test_repeat_n_strz.rs b/spec/rust/tests/test_repeat_n_strz.rs
index 87c87b8d4..a614b1958 100644
--- a/spec/rust/tests/test_repeat_n_strz.rs
+++ b/spec/rust/tests/test_repeat_n_strz.rs
@@ -1,15 +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::RepeatNStrz;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::repeat_n_strz::*;
#[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"]);
- }
+fn test_repeat_n_strz() -> KResult<()> {
+ let bytes = fs::read("../../src/repeat_n_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = RepeatNStrz::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.qty(), 2);
+ assert_eq!(*r.lines(), vec!["foo".to_string(), "bar".to_string()]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_repeat_n_strz_double.rs b/spec/rust/tests/test_repeat_n_strz_double.rs
index 0286318ab..05fc9fc66 100644
--- a/spec/rust/tests/test_repeat_n_strz_double.rs
+++ b/spec/rust/tests/test_repeat_n_strz_double.rs
@@ -1,16 +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::RepeatNStrzDouble;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::repeat_n_strz_double::*;
#[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"]);
- }
+fn test_repeat_n_strz_double() -> KResult<()> {
+ let bytes = fs::read("../../src/repeat_n_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = RepeatNStrzDouble::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.qty(), 2);
+ assert_eq!(*r.lines1(), vec!["foo".to_string()]);
+ assert_eq!(*r.lines2(), vec!["bar".to_string()]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_repeat_until_calc_array_type.rs b/spec/rust/tests/test_repeat_until_calc_array_type.rs
new file mode 100644
index 000000000..1490384c9
--- /dev/null
+++ b/spec/rust/tests/test_repeat_until_calc_array_type.rs
@@ -0,0 +1,22 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::repeat_until_calc_array_type::*;
+
+#[test]
+fn test_repeat_until_calc_array_type() -> KResult<()> {
+ let bytes = fs::read("../../src/repeat_until_process.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = RepeatUntilCalcArrayType::read_into(&_io, None, None)?;
+
+ assert_eq!(r.records().len(), 3);
+ assert_eq!(*r.records()[0 as usize].marker(), 232);
+ assert_eq!(*r.records()[0 as usize].body(), 2863311546);
+ assert_eq!(*r.records()[1 as usize].marker(), 250);
+ assert_eq!(*r.records()[1 as usize].body(), 2863315102);
+ assert_eq!(*r.records()[2 as usize].marker(), 170);
+ assert_eq!(*r.records()[2 as usize].body(), 1431655765);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_repeat_until_complex.rs b/spec/rust/tests/test_repeat_until_complex.rs
index 158fc16b9..9ad7b0cfa 100644
--- a/spec/rust/tests/test_repeat_until_complex.rs
+++ b/spec/rust/tests/test_repeat_until_complex.rs
@@ -1,28 +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::RepeatUntilComplex;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::repeat_until_complex::*;
#[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]);
- }
+fn test_repeat_until_complex() -> KResult<()> {
+ let bytes = fs::read("../../src/repeat_until_complex.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = RepeatUntilComplex::read_into(&_io, None, None)?;
+
+ assert_eq!(r.first().len(), 3);
+ assert_eq!(*r.first()[0 as usize].count(), 4);
+ assert_eq!(*r.first()[0 as usize].values(), vec![(0 + 1), 2, 3, 4]);
+ assert_eq!(*r.first()[1 as usize].count(), 2);
+ assert_eq!(*r.first()[1 as usize].values(), vec![(0 + 1), 2]);
+ assert_eq!(*r.first()[2 as usize].count(), 0);
+ assert_eq!(r.second().len(), 4);
+ assert_eq!(*r.second()[0 as usize].count(), 6);
+ assert_eq!(*r.second()[0 as usize].values(), vec![(0 + 1), 2, 3, 4, 5, 6]);
+ assert_eq!(*r.second()[1 as usize].count(), 3);
+ assert_eq!(*r.second()[1 as usize].values(), vec![(0 + 1), 2, 3]);
+ assert_eq!(*r.second()[2 as usize].count(), 4);
+ assert_eq!(*r.second()[2 as usize].values(), vec![(0 + 1), 2, 3, 4]);
+ assert_eq!(*r.second()[3 as usize].count(), 0);
+ assert_eq!(*r.third(), vec![(0 + 102), 111, 111, 98, 97, 114, 0]);
+ Ok(())
}
diff --git a/spec/rust/tests/test_repeat_until_s4.rs b/spec/rust/tests/test_repeat_until_s4.rs
index 2fe282b51..b0f5b4ff1 100644
--- a/spec/rust/tests/test_repeat_until_s4.rs
+++ b/spec/rust/tests/test_repeat_until_s4.rs
@@ -1,15 +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::RepeatUntilS4;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::repeat_until_s4::*;
#[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");
- }
+fn test_repeat_until_s4() -> KResult<()> {
+ let bytes = fs::read("../../src/repeat_until_s4.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = RepeatUntilS4::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.entries(), vec![66, 4919, -251658241, -1]);
+ assert_eq!(*r.afterall(), "foobar");
+ Ok(())
}
diff --git a/spec/rust/tests/test_repeat_until_sized.rs b/spec/rust/tests/test_repeat_until_sized.rs
index 3d23c1efc..4e5abe69f 100644
--- a/spec/rust/tests/test_repeat_until_sized.rs
+++ b/spec/rust/tests/test_repeat_until_sized.rs
@@ -1,20 +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::RepeatUntilSized;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::repeat_until_sized::*;
#[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);
- }
+fn test_repeat_until_sized() -> KResult<()> {
+ let bytes = fs::read("../../src/repeat_until_process.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = RepeatUntilSized::read_into(&_io, None, None)?;
+
+ assert_eq!(r.records().len(), 3);
+ assert_eq!(*r.records()[0 as usize].marker(), 232);
+ assert_eq!(*r.records()[0 as usize].body(), 2863311546);
+ assert_eq!(*r.records()[1 as usize].marker(), 250);
+ assert_eq!(*r.records()[1 as usize].body(), 2863315102);
+ assert_eq!(*r.records()[2 as usize].marker(), 170);
+ assert_eq!(*r.records()[2 as usize].body(), 1431655765);
+ Ok(())
}
diff --git a/spec/rust/tests/test_str_encodings.rs b/spec/rust/tests/test_str_encodings.rs
index 7759fd83f..ce1687cc6 100644
--- a/spec/rust/tests/test_str_encodings.rs
+++ b/spec/rust/tests/test_str_encodings.rs
@@ -1,17 +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::StrEncodings;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::str_encodings::*;
#[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}");
- }
+fn test_str_encodings() -> KResult<()> {
+ let bytes = fs::read("../../src/str_encodings.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = StrEncodings::read_into(&_io, None, None)?;
+
+ 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}");
+ Ok(())
}
diff --git a/spec/rust/tests/test_str_encodings_default.rs b/spec/rust/tests/test_str_encodings_default.rs
index e2cdd782a..6fb85ea1b 100644
--- a/spec/rust/tests/test_str_encodings_default.rs
+++ b/spec/rust/tests/test_str_encodings_default.rs
@@ -1,17 +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::StrEncodingsDefault;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::str_encodings_default::*;
#[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}");
- }
+fn test_str_encodings_default() -> KResult<()> {
+ let bytes = fs::read("../../src/str_encodings.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = StrEncodingsDefault::read_into(&_io, None, None)?;
+
+ 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}");
+ Ok(())
}
diff --git a/spec/rust/tests/test_str_encodings_escaping_enc.rs b/spec/rust/tests/test_str_encodings_escaping_enc.rs
new file mode 100644
index 000000000..c76102339
--- /dev/null
+++ b/spec/rust/tests/test_str_encodings_escaping_enc.rs
@@ -0,0 +1,21 @@
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::str_encodings_escaping_enc::*;
+
+#[test]
+fn test_str_encodings_escaping_enc() -> KResult<()> {
+ let bytes = fs::read("../../src/str_encodings.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = StrEncodingsEscapingEnc::read_into(&_io, None, None)?;
+
+ let err = r.str1().v().expect_err(r#"expected Err representing UnknownEncodingError('ASCII\\x'), but got Ok"#);
+ assert_eq!(err, KError::UnknownEncoding { name: "ASCII\\\\x".to_string() });
+ let err = r.str2().v().expect_err(r#"expected Err representing UnknownEncodingError("UTF-8\\'x"), but got Ok"#);
+ assert_eq!(err, KError::UnknownEncoding { name: "UTF-8\\'x".to_string() });
+ let err = r.str3().v().expect_err(r#"expected Err representing UnknownEncodingError('SJIS\"x'), but got Ok"#);
+ assert_eq!(err, KError::UnknownEncoding { name: "SJIS\\\"x".to_string() });
+ let err = r.str4().v().expect_err(r#"expected Err representing UnknownEncodingError('IBM437\nx'), but got Ok"#);
+ assert_eq!(err, KError::UnknownEncoding { name: "IBM437\\nx".to_string() });
+ Ok(())
+}
diff --git a/spec/rust/tests/test_str_encodings_escaping_to_s.rs b/spec/rust/tests/test_str_encodings_escaping_to_s.rs
new file mode 100644
index 000000000..c1cfed60c
--- /dev/null
+++ b/spec/rust/tests/test_str_encodings_escaping_to_s.rs
@@ -0,0 +1,21 @@
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::str_encodings_escaping_to_s::*;
+
+#[test]
+fn test_str_encodings_escaping_to_s() -> KResult<()> {
+ let bytes = fs::read("../../src/str_encodings.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = StrEncodingsEscapingToS::read_into(&_io, None, None)?;
+
+ let err = r.str1().expect_err(r#"expected Err representing UnknownEncodingError('ASCII\\x'), but got Ok"#);
+ assert_eq!(err, KError::UnknownEncoding { name: "ASCII\\\\x".to_string() });
+ let err = r.str2().expect_err(r#"expected Err representing UnknownEncodingError("UTF-8\\'x"), but got Ok"#);
+ assert_eq!(err, KError::UnknownEncoding { name: "UTF-8\\'x".to_string() });
+ let err = r.str3().expect_err(r#"expected Err representing UnknownEncodingError('SJIS\"x'), but got Ok"#);
+ assert_eq!(err, KError::UnknownEncoding { name: "SJIS\\\"x".to_string() });
+ let err = r.str4().expect_err(r#"expected Err representing UnknownEncodingError('IBM437\nx'), but got Ok"#);
+ assert_eq!(err, KError::UnknownEncoding { name: "IBM437\\nx".to_string() });
+ Ok(())
+}
diff --git a/spec/rust/tests/test_str_encodings_utf16.rs b/spec/rust/tests/test_str_encodings_utf16.rs
new file mode 100644
index 000000000..431577988
--- /dev/null
+++ b/spec/rust/tests/test_str_encodings_utf16.rs
@@ -0,0 +1,21 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::str_encodings_utf16::*;
+
+#[test]
+fn test_str_encodings_utf16() -> KResult<()> {
+ let bytes = fs::read("../../src/str_encodings_utf16.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = StrEncodingsUtf16::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.len_be(), 12);
+ assert_eq!(*r.be_bom_removed().bom(), 65279);
+ assert_eq!(*r.be_bom_removed().str(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}");
+ assert_eq!(*r.len_le(), 12);
+ assert_eq!(*r.le_bom_removed().bom(), 65279);
+ assert_eq!(*r.le_bom_removed().str(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_str_eos.rs b/spec/rust/tests/test_str_eos.rs
index dda25ba85..b7f83d320 100644
--- a/spec/rust/tests/test_str_eos.rs
+++ b/spec/rust/tests/test_str_eos.rs
@@ -1,14 +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::StrEos;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::str_eos::*;
#[test]
-fn test_str_eos() {
- if let Ok(r) = StrEos::from_file("src/term_strz.bin") {
- assert_eq!(r.str, "foo|bar|baz@");
- }
+fn test_str_eos() -> KResult<()> {
+ let bytes = fs::read("../../src/term_strz.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = StrEos::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.str(), "foo|bar|baz@");
+ Ok(())
}
diff --git a/spec/rust/tests/test_str_literals.rs b/spec/rust/tests/test_str_literals.rs
new file mode 100644
index 000000000..48e9efeef
--- /dev/null
+++ b/spec/rust/tests/test_str_literals.rs
@@ -0,0 +1,18 @@
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::str_literals::*;
+
+#[test]
+fn test_str_literals() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = StrLiterals::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.complex_str()?, "\u{0}\u{1}\u{2}\u{7}\u{8}\u{a}\u{d}\u{9}\u{b}\u{c}\u{1b}\u{3d}\u{7}\u{a}\u{24}\u{263b}");
+ assert_eq!(*r.double_quotes()?, "\u{22}\u{22}\u{22}");
+ assert_eq!(*r.backslashes()?, "\u{5c}\u{5c}\u{5c}");
+ assert_eq!(*r.octal_eatup()?, "\u{0}\u{32}\u{32}");
+ assert_eq!(*r.octal_eatup2()?, "\u{2}\u{32}");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_str_literals2.rs b/spec/rust/tests/test_str_literals2.rs
index 95c5148a8..d039f917c 100644
--- a/spec/rust/tests/test_str_literals2.rs
+++ b/spec/rust/tests/test_str_literals2.rs
@@ -1,17 +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::StrLiterals2;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::str_literals2::*;
#[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");
- }
+fn test_str_literals2() -> KResult<()> {
+ let bytes = fs::read("../../src/fixed_struct.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = StrLiterals2::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.dollar1()?, "$foo");
+ assert_eq!(*r.dollar2()?, "${foo}");
+ assert_eq!(*r.hash()?, "#{foo}");
+ assert_eq!(*r.at_sign()?, "@foo");
+ Ok(())
}
diff --git a/spec/rust/tests/test_str_pad_term.rs b/spec/rust/tests/test_str_pad_term.rs
index 8b953fd98..0d1411890 100644
--- a/spec/rust/tests/test_str_pad_term.rs
+++ b/spec/rust/tests/test_str_pad_term.rs
@@ -1,17 +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::StrPadTerm;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::str_pad_term::*;
#[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@");
- }
+fn test_str_pad_term() -> KResult<()> {
+ let bytes = fs::read("../../src/str_pad_term.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = StrPadTerm::read_into(&_io, None, None)?;
+
+ 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@");
+ Ok(())
}
diff --git a/spec/rust/tests/test_str_pad_term_empty.rs b/spec/rust/tests/test_str_pad_term_empty.rs
index 72ef1bd5c..ca78aba31 100644
--- a/spec/rust/tests/test_str_pad_term_empty.rs
+++ b/spec/rust/tests/test_str_pad_term_empty.rs
@@ -1,17 +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::StrPadTermEmpty;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::str_pad_term_empty::*;
#[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, "@");
- }
+fn test_str_pad_term_empty() -> KResult<()> {
+ let bytes = fs::read("../../src/str_pad_term_empty.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = StrPadTermEmpty::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.str_pad(), "");
+ assert_eq!(*r.str_term(), "");
+ assert_eq!(*r.str_term_and_pad(), "");
+ assert_eq!(*r.str_term_include(), "@");
+ Ok(())
}
diff --git a/spec/rust/tests/test_str_pad_term_utf16.rs b/spec/rust/tests/test_str_pad_term_utf16.rs
new file mode 100644
index 000000000..50993aae0
--- /dev/null
+++ b/spec/rust/tests/test_str_pad_term_utf16.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::str_pad_term_utf16::*;
+
+#[test]
+fn test_str_pad_term_utf16() -> KResult<()> {
+ let bytes = fs::read("../../src/str_pad_term_utf16.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = StrPadTermUtf16::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.str_term(), "a\u{200}b");
+ assert_eq!(*r.str_term_include(), "c\u{200}d\u{0}");
+ assert_eq!(*r.str_term_and_pad(), "e\u{200}f");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs
index 427692a69..2c6aae985 100644
--- a/spec/rust/tests/test_switch_bytearray.rs
+++ b/spec/rust/tests/test_switch_bytearray.rs
@@ -1,22 +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::SwitchBytearray;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::switch_bytearray::*;
#[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, "");
- }
+fn test_switch_bytearray() -> KResult<()> {
+ let bytes = fs::read("../../src/switch_opcodes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = SwitchBytearray::read_into(&_io, None, None)?;
+
+ assert_eq!(r.opcodes().len(), 4);
+ assert_eq!(*r.opcodes()[0 as usize].code(), vec![0x53u8]);
+ assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value(), "foobar");
+ assert_eq!(*r.opcodes()[1 as usize].code(), vec![0x49u8]);
+ assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value(), 66);
+ assert_eq!(*r.opcodes()[2 as usize].code(), vec![0x49u8]);
+ assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).value(), 55);
+ assert_eq!(*r.opcodes()[3 as usize].code(), vec![0x53u8]);
+ assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), "");
+ Ok(())
}
diff --git a/spec/rust/tests/test_switch_cast.rs b/spec/rust/tests/test_switch_cast.rs
new file mode 100644
index 000000000..ad1637dfa
--- /dev/null
+++ b/spec/rust/tests/test_switch_cast.rs
@@ -0,0 +1,16 @@
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::switch_cast::*;
+
+#[test]
+#[should_panic(expected = "expected SwitchCast_Opcode_Body::SwitchCast_Strval, got SwitchCast_Intval(")]
+fn test_switch_cast() {
+ let bytes = fs::read("../../src/switch_opcodes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = SwitchCast::read_into(&_io, None, None).unwrap();
+
+ assert_eq!("foobar", *r.first_obj().unwrap().value());
+ assert_eq!(0x42, *r.second_val().unwrap());
+ let _ = r.err_cast();
+}
diff --git a/spec/rust/tests/test_switch_else_only.rs b/spec/rust/tests/test_switch_else_only.rs
new file mode 100644
index 000000000..fe19c2631
--- /dev/null
+++ b/spec/rust/tests/test_switch_else_only.rs
@@ -0,0 +1,18 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::switch_else_only::*;
+
+#[test]
+fn test_switch_else_only() -> KResult<()> {
+ let bytes = fs::read("../../src/switch_opcodes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = SwitchElseOnly::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.opcode(), 83);
+ assert_eq!(r.prim_byte(), 102);
+ assert_eq!(*r.ut().as_ref().unwrap().value(), vec![0x72u8, 0x0u8, 0x49u8, 0x42u8]);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_switch_integers.rs b/spec/rust/tests/test_switch_integers.rs
index f873b3bda..889c1a3da 100644
--- a/spec/rust/tests/test_switch_integers.rs
+++ b/spec/rust/tests/test_switch_integers.rs
@@ -1,22 +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::SwitchIntegers;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::switch_integers::*;
#[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);
- }
+fn test_switch_integers() -> KResult<()> {
+ let bytes = fs::read("../../src/switch_integers.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = SwitchIntegers::read_into(&_io, None, None)?;
+
+ assert_eq!(r.opcodes().len(), 4);
+ assert_eq!(*r.opcodes()[0 as usize].code(), 1);
+ assert_eq!(r.opcodes()[0 as usize].body(), 7);
+ assert_eq!(*r.opcodes()[1 as usize].code(), 2);
+ assert_eq!(r.opcodes()[1 as usize].body(), 16448);
+ assert_eq!(*r.opcodes()[2 as usize].code(), 4);
+ assert_eq!(r.opcodes()[2 as usize].body(), 4919);
+ assert_eq!(*r.opcodes()[3 as usize].code(), 8);
+ assert_eq!(r.opcodes()[3 as usize].body(), 4919);
+ Ok(())
}
diff --git a/spec/rust/tests/test_switch_integers2.rs b/spec/rust/tests/test_switch_integers2.rs
index 6e7872a2f..8ba2b286f 100644
--- a/spec/rust/tests/test_switch_integers2.rs
+++ b/spec/rust/tests/test_switch_integers2.rs
@@ -1,18 +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::SwitchIntegers2;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::switch_integers2::*;
#[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");
- }
+fn test_switch_integers2() -> KResult<()> {
+ let bytes = fs::read("../../src/switch_integers.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = SwitchIntegers2::read_into(&_io, None, None)?;
+
+ assert_eq!(*r.code(), 1);
+ assert_eq!(r.len(), 7);
+ assert_eq!(*r.ham(), vec![0x2u8, 0x40u8, 0x40u8, 0x4u8, 0x37u8, 0x13u8, 0x0u8]);
+ assert_eq!(*r.padding(), 0);
+ assert_eq!(*r.len_mod_str()?, "13");
+ Ok(())
}
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..1d2aa8f9d
--- /dev/null
+++ b/spec/rust/tests/test_switch_manual_enum.rs
@@ -0,0 +1,24 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::switch_manual_enum::*;
+
+#[test]
+fn test_switch_manual_enum() -> KResult<()> {
+ let bytes = fs::read("../../src/switch_opcodes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = SwitchManualEnum::read_into(&_io, None, None)?;
+
+ assert_eq!(r.opcodes().len(), 4);
+ assert_eq!(*r.opcodes()[0 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Strval);
+ assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value(), "foobar");
+ assert_eq!(*r.opcodes()[1 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Intval);
+ assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value(), 66);
+ assert_eq!(*r.opcodes()[2 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Intval);
+ assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).value(), 55);
+ assert_eq!(*r.opcodes()[3 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Strval);
+ assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), "");
+ Ok(())
+}
diff --git a/spec/rust/tests/test_switch_manual_enum_invalid.rs b/spec/rust/tests/test_switch_manual_enum_invalid.rs
new file mode 100644
index 000000000..e2e40e22c
--- /dev/null
+++ b/spec/rust/tests/test_switch_manual_enum_invalid.rs
@@ -0,0 +1,20 @@
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::switch_manual_enum_invalid::*;
+
+#[test]
+fn test_switch_manual_enum_invalid() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_negative.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = SwitchManualEnumInvalid::read_into(&_io, None, None)?;
+
+ assert_eq!(r.opcodes().len(), 2);
+ let n: i64 = (&*r.opcodes()[0 as usize].code()).into();
+ assert_eq!(n, 255);
+ assert!(r.opcodes()[0 as usize].body().is_none());
+ let n: i64 = (&*r.opcodes()[1 as usize].code()).into();
+ assert_eq!(n, 1);
+ assert!(r.opcodes()[1 as usize].body().is_none());
+ Ok(())
+}
diff --git a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs
new file mode 100644
index 000000000..2f4f08f71
--- /dev/null
+++ b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs
@@ -0,0 +1,22 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::switch_manual_enum_invalid_else::*;
+
+#[test]
+fn test_switch_manual_enum_invalid_else() -> KResult<()> {
+ let bytes = fs::read("../../src/enum_negative.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = SwitchManualEnumInvalidElse::read_into(&_io, None, None)?;
+
+ assert_eq!(r.opcodes().len(), 2);
+ let n: i64 = (&*r.opcodes()[0 as usize].code()).into();
+ assert_eq!(n, 255);
+ assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value()?, 123);
+ let n: i64 = (&*r.opcodes()[1 as usize].code()).into();
+ assert_eq!(n, 1);
+ assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value()?, 123);
+ Ok(())
+}
diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs
index 776a6b1b2..42bd4e748 100644
--- a/spec/rust/tests/test_switch_manual_int.rs
+++ b/spec/rust/tests/test_switch_manual_int.rs
@@ -1,22 +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::SwitchManualInt;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::switch_manual_int::*;
#[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, "");
- }
+fn test_switch_manual_int() -> KResult<()> {
+ let bytes = fs::read("../../src/switch_opcodes.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = SwitchManualInt::read_into(&_io, None, None)?;
+
+ assert_eq!(r.opcodes().len(), 4);
+ assert_eq!(*r.opcodes()[0 as usize].code(), 83);
+ assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value(), "foobar");
+ assert_eq!(*r.opcodes()[1 as usize].code(), 73);
+ assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value(), 66);
+ assert_eq!(*r.opcodes()[2 as usize].code(), 73);
+ assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).value(), 55);
+ assert_eq!(*r.opcodes()[3 as usize].code(), 83);
+ assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), "");
+ Ok(())
}
diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs
index cae8cfba0..3a8b8aa81 100644
--- a/spec/rust/tests/test_switch_manual_int_else.rs
+++ b/spec/rust/tests/test_switch_manual_int_else.rs
@@ -1,22 +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::SwitchManualIntElse;
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::switch_manual_int_else::*;
#[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);
- }
+fn test_switch_manual_int_else() -> KResult<()> {
+ let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = SwitchManualIntElse::read_into(&_io, None, None)?;
+
+ assert_eq!(r.opcodes().len(), 4);
+ assert_eq!(*r.opcodes()[0 as usize].code(), 83);
+ assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value(), "foo");
+ assert_eq!(*r.opcodes()[1 as usize].code(), 88);
+ assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).filler(), 66);
+ assert_eq!(*r.opcodes()[2 as usize].code(), 89);
+ assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).filler(), 51966);
+ assert_eq!(*r.opcodes()[3 as usize].code(), 73);
+ assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), 7);
+ Ok(())
}
diff --git a/spec/rust/tests/test_switch_manual_int_size.rs b/spec/rust/tests/test_switch_manual_int_size.rs
new file mode 100644
index 000000000..0a3644d2f
--- /dev/null
+++ b/spec/rust/tests/test_switch_manual_int_size.rs
@@ -0,0 +1,25 @@
+// Autogenerated from KST: please remove this line if doing any edits by hand!
+
+use std::fs;
+extern crate kaitai;
+use self::kaitai::*;
+use rust::formats::switch_manual_int_size::*;
+
+#[test]
+fn test_switch_manual_int_size() -> KResult<()> {
+ let bytes = fs::read("../../src/switch_tlv.bin").unwrap();
+ let _io = BytesReader::from(bytes);
+ let r: OptRc = SwitchManualIntSize::read_into(&_io, None, None)?;
+
+ assert_eq!(r.chunks().len(), 4);
+ assert_eq!(*r.chunks()[0 as usize].code(), 17);
+ assert_eq!(*Into::>::into(&*r.chunks()[0 as usize].body().as_ref().unwrap()).title(), "Stuff");
+ assert_eq!(*Into::>::into(&*r.chunks()[0 as usize].body().as_ref().unwrap()).author(), "Me");
+ assert_eq!(*r.chunks()[1 as usize].code(), 34);
+ assert_eq!(*Into::