From a93318a413351ca1de1aefab3b1cf5c99df1e3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Sch=C3=B6ning?= <6223655+ams-tschoening@users.noreply.github.com> Date: Mon, 8 Mar 2021 16:50:21 +0100 Subject: [PATCH 1/2] Test to distinguish equality validation of bytes vs. strings. This makes sure that a textual error message is thrown instead of HEX-bytes. https://github.com/kaitai-io/kaitai_struct_ruby_runtime/pull/7 --- formats/valid_fail_eq_str.ksy | 8 ++++++++ spec/ks/valid_fail_eq_str.kst | 3 +++ spec/ruby/valid_fail_eq_str_spec.rb | 13 +++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 formats/valid_fail_eq_str.ksy create mode 100644 spec/ks/valid_fail_eq_str.kst create mode 100644 spec/ruby/valid_fail_eq_str_spec.rb diff --git a/formats/valid_fail_eq_str.ksy b/formats/valid_fail_eq_str.ksy new file mode 100644 index 000000000..50a72e9cc --- /dev/null +++ b/formats/valid_fail_eq_str.ksy @@ -0,0 +1,8 @@ +meta: + id: valid_fail_eq_str + encoding: ASCII +seq: + - id: foo + size: 4 + type: str + valid: '"BACK"' # there is actually "PACK" in the file diff --git a/spec/ks/valid_fail_eq_str.kst b/spec/ks/valid_fail_eq_str.kst new file mode 100644 index 000000000..b23877605 --- /dev/null +++ b/spec/ks/valid_fail_eq_str.kst @@ -0,0 +1,3 @@ +id: valid_fail_eq_str +data: fixed_struct.bin +exception: ValidationNotEqualError diff --git a/spec/ruby/valid_fail_eq_str_spec.rb b/spec/ruby/valid_fail_eq_str_spec.rb new file mode 100644 index 000000000..49f315c94 --- /dev/null +++ b/spec/ruby/valid_fail_eq_str_spec.rb @@ -0,0 +1,13 @@ +require 'valid_fail_eq_str' + +RSpec.describe ValidFailEqStr do + it 'parses test properly' do + expect { + r = ValidFailEqStr.from_file('src/fixed_struct.bin') + }.to raise_error( + # Make extra sure that handling of "byte[]" is not used by looking at the message. + Kaitai::Struct::ValidationNotEqualError, + a_string_including('"BACK"', '"PACK"') + ) + end +end From 706316fb159783ea3c599458d986eb9fc549b634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20Sch=C3=B6ning?= <6223655+ams-tschoening@users.noreply.github.com> Date: Wed, 10 Mar 2021 16:29:29 +0100 Subject: [PATCH 2/2] Make sure that HEX is used for bytes. --- spec/ruby/valid_fail_eq_bytes_spec.rb | 8 +++++--- spec/ruby/valid_fail_eq_str_spec.rb | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/ruby/valid_fail_eq_bytes_spec.rb b/spec/ruby/valid_fail_eq_bytes_spec.rb index 8bc4f0917..404956165 100644 --- a/spec/ruby/valid_fail_eq_bytes_spec.rb +++ b/spec/ruby/valid_fail_eq_bytes_spec.rb @@ -1,11 +1,13 @@ -# Autogenerated from KST: please remove this line if doing any edits by hand! - require 'valid_fail_eq_bytes' RSpec.describe ValidFailEqBytes do it 'parses test properly' do expect { r = ValidFailEqBytes.from_file('src/fixed_struct.bin') - }.to raise_error(Kaitai::Struct::ValidationNotEqualError) + }.to raise_error( + # Make extra sure that handling of "byte[]" is used by looking at the message. + Kaitai::Struct::ValidationNotEqualError, + a_string_including('[51 41]', '[50 41]') + ) end end diff --git a/spec/ruby/valid_fail_eq_str_spec.rb b/spec/ruby/valid_fail_eq_str_spec.rb index 49f315c94..9c48b5615 100644 --- a/spec/ruby/valid_fail_eq_str_spec.rb +++ b/spec/ruby/valid_fail_eq_str_spec.rb @@ -5,7 +5,7 @@ expect { r = ValidFailEqStr.from_file('src/fixed_struct.bin') }.to raise_error( - # Make extra sure that handling of "byte[]" is not used by looking at the message. + # Make extra sure that handling of "byte[]" is NOT used by looking at the message. Kaitai::Struct::ValidationNotEqualError, a_string_including('"BACK"', '"PACK"') )