├── testing ├── subjects │ ├── enum_0.bin │ ├── if_struct.bin │ ├── term_strz.bin │ ├── nav_parent_codes.bin │ ├── process_coerce_switch.bin │ ├── repeat_n_strz.bin │ ├── bcd_user_type_be.bin │ ├── bcd_user_type_le.bin │ ├── switch_opcodes.bin │ ├── repeat_eos_struct.bin │ ├── switch_integers.bin │ ├── endian_expr.bin │ ├── expr_io_pos.bin │ ├── index_sizes.bin │ ├── nested_same_name2.bin │ ├── position_to_end.bin │ ├── nav_parent2.bin │ ├── repeat_until_complex.bin │ ├── nav.bin │ ├── full256.bin │ ├── str_pad_term.bin │ ├── ts_packet.bin │ ├── expr_array.bin │ ├── fixed_struct.bin │ ├── instance_io.bin │ ├── position_abs.bin │ ├── switch_tlv.bin │ ├── enum_negative.bin │ ├── process_rotate.bin │ ├── process_xor_1.bin │ ├── process_xor_4.bin │ ├── str_encodings.bin │ ├── str_pad_term_empty.bin │ ├── buffered_struct.bin │ ├── enum_int_range_s.bin │ ├── enum_int_range_u.bin │ ├── enum_long_range_s.bin │ ├── enum_long_range_u.bin │ ├── floating_points.bin │ ├── integers_min_max.bin │ ├── nav_parent_switch.bin │ ├── position_in_seq.bin │ ├── repeat_n_struct.bin │ ├── repeat_until_s4.bin │ ├── switch_opcodes2.bin │ ├── zlib_surrounded.bin │ ├── instance_std_array.bin │ ├── zlib_with_header_78.bin │ ├── process_coerce_bytes.bin │ └── repeat_until_process.bin ├── tests │ ├── meta_tags.kst │ ├── meta_xref.kst │ ├── docstrings.kst │ ├── valid_long.kst │ ├── valid_short.kst │ ├── valid_switch.kst │ ├── fixed_contents.kst │ ├── docstrings_docref.kst │ ├── valid_not_parsed_if.kst │ ├── docstrings_docref_multi.kst │ ├── eof_exception_u4.kst │ ├── eos_exception_u4.kst │ ├── eof_exception_bytes.kst │ ├── eos_exception_bytes.kst │ ├── valid_fail_eq_int.kst │ ├── valid_fail_expr.kst │ ├── valid_fail_inst.kst │ ├── valid_fail_max_int.kst │ ├── valid_fail_min_int.kst │ ├── valid_fail_anyof_int.kst │ ├── valid_fail_contents.kst │ ├── valid_fail_eq_bytes.kst │ ├── valid_fail_range_int.kst │ ├── valid_fail_range_str.kst │ ├── default_endian_expr_exception.kst │ ├── valid_fail_range_bytes.kst │ ├── valid_fail_range_float.kst │ ├── hello_world.kst │ ├── non_standard.kst │ ├── str_eos.kst │ ├── repeat_eos_bit.kst │ ├── type_ternary.kst │ ├── default_big_endian.kst │ ├── if_instances.kst │ ├── instance_std.kst │ ├── zlib_surrounded.kst │ ├── nav_parent_false2.kst │ ├── process_to_user.kst │ ├── expr_sizeof_type_0.kst │ ├── nav_parent_vs_value_inst.kst │ ├── position_in_seq.kst │ ├── repeat_eos_u4.kst │ ├── params_call_extra_parens.kst │ ├── process_custom_no_args.kst │ ├── combine_bool.kst │ ├── expr_0.kst │ ├── repeat_n_strz.kst │ ├── user_type.kst │ ├── enum_0.kst │ ├── enum_deep_literals.kst │ ├── position_abs.kst │ ├── debug_switch_user.kst │ ├── enum_invalid.kst │ ├── params_pass_usertype.kst │ ├── position_to_end.kst │ ├── expr_if_int_ops.kst │ ├── nested_type_param.kst │ ├── multiple_use.kst │ ├── params_enum.kst │ ├── enum_fancy.kst │ ├── expr_sizeof_type_1.kst │ ├── imports_abs.kst │ ├── process_xor_const.kst │ ├── process_xor_value.kst │ ├── repeat_until_s4.kst │ ├── cast_to_imported.kst │ ├── js_signed_right_shift.kst │ ├── nested_same_name.kst │ ├── enum_deep.kst │ ├── io_local_var.kst │ ├── enum_1.kst │ ├── enum_negative.kst │ ├── enum_int_range_u.kst │ ├── process_xor4_const.kst │ ├── process_xor4_value.kst │ ├── process_repeat_bytes.kst │ ├── term_strz.kst │ ├── cast_to_top.kst │ ├── expr_bytes_literal.kst │ ├── repeat_n_strz_double.kst │ ├── imports0.kst │ ├── zlib_with_header_78.kst │ ├── nested_types.kst │ ├── params_call_short.kst │ ├── enum_import.kst │ ├── term_bytes.kst │ ├── switch_else_only.kst │ ├── default_endian_mod.kst │ ├── nav_parent_switch.kst │ ├── nav_parent_switch_cast.kst │ ├── bits_enum.kst │ ├── process_coerce_switch.kst │ ├── expr_enum.kst │ ├── combine_enum.kst │ ├── nav_parent_override.kst │ ├── expr_1.kst │ ├── imports_rel_1.kst │ ├── process_rotate.kst │ ├── process_custom.kst │ ├── enum_int_range_s.kst │ ├── str_encodings.kst │ ├── str_literals2.kst │ ├── expr_io_eof.kst │ ├── str_pad_term_empty.kst │ ├── instance_io_user.kst │ ├── str_encodings_default.kst │ ├── enum_to_i_class_border_1.kst │ ├── params_pass_array_struct.kst │ ├── process_repeat_usertype.kst │ ├── str_pad_term.kst │ ├── type_int_unary_op.kst │ ├── yaml_ints.kst │ ├── cast_nested.kst │ ├── default_bit_endian_mod.kst │ ├── params_pass_struct.kst │ ├── process_coerce_usertype1.kst │ ├── process_coerce_usertype2.kst │ ├── process_coerce_bytes.kst │ ├── nested_types3.kst │ ├── enum_of_value_inst.kst │ ├── enum_to_i.kst │ ├── expr_sizeof_value_sized.kst │ ├── repeat_eos_struct.kst │ ├── repeat_n_struct.kst │ ├── switch_integers2.kst │ ├── enum_long_range_u.kst │ ├── expr_sizeof_value_0.kst │ ├── recursive_one.kst │ ├── nav_root.kst │ ├── switch_manual_enum_invalid.kst │ ├── nav_parent.kst │ ├── nav_parent_false.kst │ ├── expr_mod.kst │ ├── params_pass_array_usertype.kst │ ├── expr_int_div.kst │ ├── nested_same_name2.kst │ ├── bytes_pad_term.kst │ ├── imports_circular_a.kst │ ├── if_values.kst │ ├── index_sizes.kst │ ├── bcd_user_type_be.kst │ ├── bcd_user_type_le.kst │ ├── switch_manual_enum_invalid_else.kst │ ├── index_to_param_eos.kst │ ├── index_to_param_expr.kst │ ├── index_to_param_until.kst │ ├── buffered_struct.kst │ ├── expr_io_pos.kst │ ├── if_struct.kst │ ├── float_to_i.kst │ ├── instance_std_array.kst │ ├── params_pass_array_int.kst │ ├── repeat_until_sized.kst │ ├── bits_seq_endian_combo.kst │ ├── repeat_until_calc_array_type.kst │ ├── enum_if.kst │ ├── nested_types2.kst │ ├── ts_packet_header.kst │ ├── expr_ops_parens.kst │ ├── params_pass_array_str.kst │ ├── floating_points.kst │ ├── bits_byte_aligned.kst │ ├── enum_long_range_s.kst │ ├── switch_integers.kst │ ├── expr_bytes_cmp.kst │ ├── switch_manual_int.kst │ ├── switch_manual_int_else.kst │ ├── switch_bytearray.kst │ ├── switch_manual_str.kst │ ├── switch_manual_str_else.kst │ ├── expr_bits.kst │ ├── nav_parent2.kst │ └── nav_parent3.kst ├── specs │ ├── meta_tags.ksj │ ├── meta_xref.ksj │ ├── hello_world.ksj │ ├── eof_exception_bytes.ksj │ ├── default_big_endian.ksj │ ├── repeat_eos_bit.ksj │ ├── valid_fail_eq_int.ksj │ ├── valid_fail_eq_bytes.ksj │ ├── if_instances.ksj │ ├── str_eos.ksj │ ├── zlib_with_header_78.ksj │ ├── opaque_external_type.ksj │ ├── opaque_with_param.ksj │ ├── process_custom_no_args.ksj │ ├── repeat_eos_u4.ksj │ ├── optional_id.ksj │ ├── valid_fail_contents.ksj │ ├── valid_fail_max_int.ksj │ ├── valid_fail_min_int.ksj │ ├── eof_exception_u4.ksj │ ├── instance_std.ksj │ ├── valid_fail_range_int.ksj │ ├── process_repeat_bytes.ksj │ ├── valid_fail_range_float.ksj │ ├── js_signed_right_shift.ksj │ ├── valid_fail_range_bytes.ksj │ ├── process_xor4_value.ksj │ ├── process_xor4_const.ksj │ ├── process_xor_const.ksj │ ├── process_xor_value.ksj │ ├── imports_rel_1.ksj │ ├── fixed_contents.ksj │ ├── imports_abs.ksj │ ├── imports_circular_a.ksj │ ├── valid_fail_range_str.ksj │ ├── imports_abs_abs.ksj │ ├── imports_abs_rel.ksj │ ├── valid_fail_inst.ksj │ ├── docstrings_docref_multi.ksj │ ├── enum_for_unknown_id.ksj │ ├── expr_bytes_literal.ksj │ ├── cast_to_imported.ksj │ ├── combine_bool.ksj │ ├── repeat_n_strz.ksj │ ├── valid_not_parsed_if.ksj │ ├── cast_to_top.ksj │ ├── expr_0.ksj │ ├── str_literals2.ksj │ ├── debug_0.ksj │ ├── imports_circular_b.ksj │ ├── eos_exception_bytes.ksj │ ├── repeat_until_s4.ksj │ ├── term_bytes.ksj │ ├── imports0.ksj │ ├── nav_parent_false2.ksj │ ├── valid_fail_expr.ksj │ ├── valid_long.ksj │ ├── yaml_ints.ksj │ ├── valid_short.ksj │ ├── to_string_custom.ksj │ ├── valid_fail_anyof_int.ksj │ ├── enum_invalid.ksj │ ├── enum_negative.ksj │ ├── enum_to_i_class_border_2.ksj │ ├── valid_switch.ksj │ ├── enum_import.ksj │ ├── enum_0.ksj │ ├── type_int_unary_op.ksj │ ├── enum_int_range_u.ksj │ ├── opaque_external_type_02_parent.ksj │ ├── user_type.ksj │ ├── eos_exception_u4.ksj │ ├── process_to_user.ksj │ ├── expr_1.ksj │ ├── position_to_end.ksj │ ├── process_rotate.ksj │ ├── repeat_eos_struct.ksj │ ├── debug_array_user.ksj │ ├── index_sizes.ksj │ ├── params_def.ksj │ ├── str_literals.ksj │ ├── bits_enum.ksj │ ├── combine_enum.ksj │ ├── instance_std_array.ksj │ ├── position_abs.ksj │ ├── zlib_surrounded.ksj │ ├── expr_sizeof_type_0.ksj │ ├── process_custom.ksj │ ├── repeat_n_strz_double.ksj │ ├── expr_if_int_ops.ksj │ ├── nav_parent_vs_value_inst.ksj │ ├── params_call_extra_parens.ksj │ ├── expr_mod.ksj │ ├── repeat_until_sized.ksj │ ├── term_strz.ksj │ ├── expr_int_div.ksj │ ├── enum_int_range_s.ksj │ ├── if_values.ksj │ ├── position_in_seq.ksj │ ├── process_repeat_usertype.ksj │ ├── bytes_pad_term.ksj │ ├── repeat_n_struct.ksj │ ├── expr_enum.ksj │ ├── recursive_one.ksj │ ├── type_ternary_opaque.ksj │ ├── bits_seq_endian_combo.ksj │ ├── nested_type_param.ksj │ ├── enum_fancy.ksj │ ├── enum_to_i.ksj │ ├── io_local_var.ksj │ ├── enum_of_value_inst.ksj │ ├── switch_integers.ksj │ ├── str_pad_term.ksj │ ├── params_pass_usertype.ksj │ ├── nav_parent_override.ksj │ ├── str_pad_term_empty.ksj │ ├── switch_integers2.ksj │ ├── enum_long_range_u.ksj │ ├── params_pass_array_int.ksj │ ├── bits_byte_aligned.ksj │ ├── debug_switch_user.ksj │ ├── expr_io_eof.ksj │ ├── expr_io_pos.ksj │ ├── enum_to_i_class_border_1.ksj │ ├── multiple_use.ksj │ ├── repeat_until_calc_array_type.ksj │ ├── params_enum.ksj │ ├── switch_else_only.ksj │ ├── switch_multi_bool_ops.ksj │ ├── type_ternary.ksj │ ├── params_pass_array_str.ksj │ ├── buffered_struct.ksj │ ├── floating_points.ksj │ ├── enum_deep.ksj │ ├── process_coerce_bytes.ksj │ ├── index_to_param_eos.ksj │ ├── nav_parent_switch.ksj │ ├── instance_user_array.ksj │ ├── index_to_param_expr.ksj │ ├── nested_same_name.ksj │ ├── index_to_param_until.ksj │ ├── switch_repeat_expr.ksj │ ├── params_pass_array_usertype.ksj │ ├── nested_types.ksj │ ├── non_standard.ksj │ ├── enum_1.ksj │ ├── expr_sizeof_type_1.ksj │ ├── params_pass_array_struct.ksj │ ├── str_encodings.ksj │ ├── expr_bytes_cmp.ksj │ ├── combine_bytes.ksj │ ├── float_to_i.ksj │ ├── docstrings_docref.ksj │ ├── opaque_external_type_02_child.ksj │ ├── expr_3.ksj │ ├── expr_sizeof_value_0.ksj │ ├── expr_bytes_ops.ksj │ ├── expr_sizeof_value_sized.ksj │ ├── process_coerce_switch.ksj │ └── process_coerce_usertype2.ksj ├── testutils.nim └── README.md ├── .gitattributes ├── nimitai.nimble ├── src └── nimitai │ └── identutils.nim └── flow.dot /testing/subjects/enum_0.bin: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /testing/subjects/if_struct.bin: -------------------------------------------------------------------------------- 1 | SfooTBCSbar -------------------------------------------------------------------------------- /testing/subjects/term_strz.bin: -------------------------------------------------------------------------------- 1 | foo|bar|baz@ -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.ucl linguist-language=yaml 2 | -------------------------------------------------------------------------------- /testing/subjects/nav_parent_codes.bin: -------------------------------------------------------------------------------- 1 | I123Bb -------------------------------------------------------------------------------- /testing/subjects/process_coerce_switch.bin: -------------------------------------------------------------------------------- 1 | AAAA -------------------------------------------------------------------------------- /testing/subjects/repeat_n_strz.bin: -------------------------------------------------------------------------------- 1 | foobar -------------------------------------------------------------------------------- /testing/subjects/bcd_user_type_be.bin: -------------------------------------------------------------------------------- 1 | 4Vx4Vx4V -------------------------------------------------------------------------------- /testing/subjects/bcd_user_type_le.bin: -------------------------------------------------------------------------------- 1 | xV4xV4V4 -------------------------------------------------------------------------------- /testing/subjects/switch_opcodes.bin: -------------------------------------------------------------------------------- 1 | SfoobarIBI7S -------------------------------------------------------------------------------- /testing/subjects/repeat_eos_struct.bin: -------------------------------------------------------------------------------- 1 | BB -------------------------------------------------------------------------------- /testing/subjects/switch_integers.bin: -------------------------------------------------------------------------------- 1 | @@77 -------------------------------------------------------------------------------- /testing/subjects/endian_expr.bin: -------------------------------------------------------------------------------- 1 | IIBBBMMBBBXXBBB -------------------------------------------------------------------------------- /testing/subjects/expr_io_pos.bin: -------------------------------------------------------------------------------- 1 | CURIOSITY"3DBKILLEDa catg -------------------------------------------------------------------------------- /testing/subjects/index_sizes.bin: -------------------------------------------------------------------------------- 1 | ABBBBBBBBCCCC -------------------------------------------------------------------------------- /testing/subjects/nested_same_name2.bin: -------------------------------------------------------------------------------- 1 | B"""""" -------------------------------------------------------------------------------- /testing/subjects/position_to_end.bin: -------------------------------------------------------------------------------- 1 |  2 | B4 -------------------------------------------------------------------------------- /testing/subjects/nav_parent2.bin: -------------------------------------------------------------------------------- 1 | RAHC RAHC#foobarbaz -------------------------------------------------------------------------------- /testing/subjects/repeat_until_complex.bin: -------------------------------------------------------------------------------- 1 | foobar -------------------------------------------------------------------------------- /testing/tests/meta_tags.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "meta_tags", 3 | "data": "fixed_struct.bin" 4 | } -------------------------------------------------------------------------------- /testing/tests/meta_xref.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "meta_xref", 3 | "data": "fixed_struct.bin" 4 | } -------------------------------------------------------------------------------- /testing/tests/docstrings.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "docstrings", 3 | "data": "fixed_struct.bin" 4 | } -------------------------------------------------------------------------------- /testing/tests/valid_long.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_long", 3 | "data": "fixed_struct.bin" 4 | } -------------------------------------------------------------------------------- /testing/tests/valid_short.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_short", 3 | "data": "fixed_struct.bin" 4 | } -------------------------------------------------------------------------------- /testing/tests/valid_switch.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_switch", 3 | "data": "fixed_struct.bin" 4 | } -------------------------------------------------------------------------------- /testing/subjects/nav.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/nav.bin -------------------------------------------------------------------------------- /testing/tests/fixed_contents.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "fixed_contents", 3 | "data": "fixed_struct.bin" 4 | } -------------------------------------------------------------------------------- /testing/subjects/full256.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/full256.bin -------------------------------------------------------------------------------- /testing/tests/docstrings_docref.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "docstrings_docref", 3 | "data": "fixed_struct.bin" 4 | } -------------------------------------------------------------------------------- /testing/subjects/str_pad_term.bin: -------------------------------------------------------------------------------- 1 | str1@@@@@@@@@@@@@@@@str2foo@++++++++++++str+++3bar+++@++++++str4baz@............ -------------------------------------------------------------------------------- /testing/subjects/ts_packet.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/ts_packet.bin -------------------------------------------------------------------------------- /testing/tests/valid_not_parsed_if.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_not_parsed_if", 3 | "data": "fixed_struct.bin" 4 | } -------------------------------------------------------------------------------- /testing/subjects/expr_array.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/expr_array.bin -------------------------------------------------------------------------------- /testing/subjects/fixed_struct.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/fixed_struct.bin -------------------------------------------------------------------------------- /testing/subjects/instance_io.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/instance_io.bin -------------------------------------------------------------------------------- /testing/subjects/position_abs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/position_abs.bin -------------------------------------------------------------------------------- /testing/subjects/switch_tlv.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/switch_tlv.bin -------------------------------------------------------------------------------- /testing/subjects/enum_negative.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/enum_negative.bin -------------------------------------------------------------------------------- /testing/subjects/process_rotate.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/process_rotate.bin -------------------------------------------------------------------------------- /testing/subjects/process_xor_1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/process_xor_1.bin -------------------------------------------------------------------------------- /testing/subjects/process_xor_4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/process_xor_4.bin -------------------------------------------------------------------------------- /testing/subjects/str_encodings.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/str_encodings.bin -------------------------------------------------------------------------------- /testing/subjects/str_pad_term_empty.bin: -------------------------------------------------------------------------------- 1 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@++++++++++++@tr+++3bar+++@++++++@@@@@@@@............ -------------------------------------------------------------------------------- /testing/tests/docstrings_docref_multi.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "docstrings_docref_multi", 3 | "data": "fixed_struct.bin" 4 | } -------------------------------------------------------------------------------- /testing/subjects/buffered_struct.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/buffered_struct.bin -------------------------------------------------------------------------------- /testing/subjects/enum_int_range_s.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/enum_int_range_s.bin -------------------------------------------------------------------------------- /testing/subjects/enum_int_range_u.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/enum_int_range_u.bin -------------------------------------------------------------------------------- /testing/subjects/enum_long_range_s.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/enum_long_range_s.bin -------------------------------------------------------------------------------- /testing/subjects/enum_long_range_u.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/enum_long_range_u.bin -------------------------------------------------------------------------------- /testing/subjects/floating_points.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/floating_points.bin -------------------------------------------------------------------------------- /testing/subjects/integers_min_max.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/integers_min_max.bin -------------------------------------------------------------------------------- /testing/subjects/nav_parent_switch.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/nav_parent_switch.bin -------------------------------------------------------------------------------- /testing/subjects/position_in_seq.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/position_in_seq.bin -------------------------------------------------------------------------------- /testing/subjects/repeat_n_struct.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/repeat_n_struct.bin -------------------------------------------------------------------------------- /testing/subjects/repeat_until_s4.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/repeat_until_s4.bin -------------------------------------------------------------------------------- /testing/subjects/switch_opcodes2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/switch_opcodes2.bin -------------------------------------------------------------------------------- /testing/subjects/zlib_surrounded.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/zlib_surrounded.bin -------------------------------------------------------------------------------- /testing/subjects/instance_std_array.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/instance_std_array.bin -------------------------------------------------------------------------------- /testing/subjects/zlib_with_header_78.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/zlib_with_header_78.bin -------------------------------------------------------------------------------- /testing/subjects/process_coerce_bytes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/process_coerce_bytes.bin -------------------------------------------------------------------------------- /testing/subjects/repeat_until_process.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sealmove/nimitai/HEAD/testing/subjects/repeat_until_process.bin -------------------------------------------------------------------------------- /testing/tests/eof_exception_u4.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "eof_exception_u4", 3 | "data": "term_strz.bin", 4 | "exception": "EndOfStreamError" 5 | } -------------------------------------------------------------------------------- /testing/tests/eos_exception_u4.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "eos_exception_u4", 3 | "data": "term_strz.bin", 4 | "exception": "EndOfStreamError" 5 | } -------------------------------------------------------------------------------- /testing/tests/eof_exception_bytes.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "eof_exception_bytes", 3 | "data": "term_strz.bin", 4 | "exception": "EndOfStreamError" 5 | } -------------------------------------------------------------------------------- /testing/tests/eos_exception_bytes.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "eos_exception_bytes", 3 | "data": "term_strz.bin", 4 | "exception": "EndOfStreamError" 5 | } -------------------------------------------------------------------------------- /testing/tests/valid_fail_eq_int.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_fail_eq_int", 3 | "data": "fixed_struct.bin", 4 | "exception": "ValidationNotEqualError" 5 | } -------------------------------------------------------------------------------- /testing/tests/valid_fail_expr.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_fail_expr", 3 | "data": "nav_parent_switch.bin", 4 | "exception": "ValidationExprError" 5 | } -------------------------------------------------------------------------------- /testing/tests/valid_fail_inst.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_fail_inst", 3 | "data": "fixed_struct.bin", 4 | "exception": "ValidationNotEqualError" 5 | } -------------------------------------------------------------------------------- /testing/tests/valid_fail_max_int.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_fail_max_int", 3 | "data": "fixed_struct.bin", 4 | "exception": "ValidationGreaterThanError" 5 | } -------------------------------------------------------------------------------- /testing/tests/valid_fail_min_int.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_fail_min_int", 3 | "data": "fixed_struct.bin", 4 | "exception": "ValidationLessThanError" 5 | } -------------------------------------------------------------------------------- /testing/tests/valid_fail_anyof_int.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_fail_anyof_int", 3 | "data": "fixed_struct.bin", 4 | "exception": "ValidationNotAnyOfError" 5 | } -------------------------------------------------------------------------------- /testing/tests/valid_fail_contents.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_fail_contents", 3 | "data": "fixed_struct.bin", 4 | "exception": "ValidationNotEqualError" 5 | } -------------------------------------------------------------------------------- /testing/tests/valid_fail_eq_bytes.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_fail_eq_bytes", 3 | "data": "fixed_struct.bin", 4 | "exception": "ValidationNotEqualError" 5 | } -------------------------------------------------------------------------------- /testing/tests/valid_fail_range_int.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_fail_range_int", 3 | "data": "fixed_struct.bin", 4 | "exception": "ValidationGreaterThanError" 5 | } -------------------------------------------------------------------------------- /testing/tests/valid_fail_range_str.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_fail_range_str", 3 | "data": "fixed_struct.bin", 4 | "exception": "ValidationGreaterThanError" 5 | } -------------------------------------------------------------------------------- /testing/specs/meta_tags.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "meta_tags", 4 | "tags": [ 5 | "foo", 6 | "bar", 7 | "baz" 8 | ] 9 | } 10 | } -------------------------------------------------------------------------------- /testing/tests/default_endian_expr_exception.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "default_endian_expr_exception", 3 | "data": "endian_expr.bin", 4 | "exception": "UndecidedEndiannessError" 5 | } -------------------------------------------------------------------------------- /testing/tests/valid_fail_range_bytes.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_fail_range_bytes", 3 | "data": "fixed_struct.bin", 4 | "exception": "ValidationGreaterThanError" 5 | } -------------------------------------------------------------------------------- /testing/tests/valid_fail_range_float.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "valid_fail_range_float", 3 | "data": "floating_points.bin", 4 | "exception": "ValidationGreaterThanError" 5 | } -------------------------------------------------------------------------------- /testing/specs/meta_xref.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "meta_xref", 4 | "xref": { 5 | "wikidata": "foo", 6 | "repo": "https://example.com/" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /testing/specs/hello_world.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "hello_world" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "one", 8 | "type": "u1" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /testing/specs/eof_exception_bytes.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "eof_exception_bytes" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "buf", 8 | "size": 13 9 | } 10 | ] 11 | } -------------------------------------------------------------------------------- /nimitai.nimble: -------------------------------------------------------------------------------- 1 | version = "0.1.0" 2 | author = "Stefanos Mandalas" 3 | description = "Parser generator for binary data" 4 | license = "MIT" 5 | 6 | requires "regex" 7 | requires "npeg" 8 | -------------------------------------------------------------------------------- /testing/tests/hello_world.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "hello_world", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "one", 7 | "expected": "0x50" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/tests/non_standard.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "non_standard", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "foo", 7 | "expected": "0x50" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/tests/str_eos.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "str_eos", 3 | "data": "term_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "str", 7 | "expected": "\"foo|bar|baz@\"" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/tests/repeat_eos_bit.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "repeat_eos_bit", 3 | "data": "enum_0.bin", 4 | "asserts": [ 5 | { 6 | "actual": "nibbles.size", 7 | "expected": 16 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/tests/type_ternary.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "type_ternary", 3 | "data": "term_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "dif.value", 7 | "expected": "0x65" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/tests/default_big_endian.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "default_big_endian", 3 | "data": "enum_0.bin", 4 | "asserts": [ 5 | { 6 | "actual": "one", 7 | "expected": "0x7000000" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/tests/if_instances.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "if_instances", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "never_happens", 7 | "expected": "null" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/tests/instance_std.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "instance_std", 3 | "data": "str_encodings.bin", 4 | "asserts": [ 5 | { 6 | "actual": "header", 7 | "expected": "\"Some \"" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/tests/zlib_surrounded.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "zlib_surrounded", 3 | "data": "zlib_surrounded.bin", 4 | "asserts": [ 5 | { 6 | "actual": "zlib.num", 7 | "expected": -1 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/specs/default_big_endian.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "default_big_endian", 4 | "endian": "be" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "one", 9 | "type": "u4" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /testing/specs/repeat_eos_bit.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "repeat_eos_bit" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "nibbles", 8 | "type": "b4", 9 | "repeat": "eos" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /testing/specs/valid_fail_eq_int.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_fail_eq_int" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "foo", 8 | "type": "u1", 9 | "valid": 123 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /testing/tests/nav_parent_false2.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nav_parent_false2", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "parentless.foo", 7 | "expected": 80 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/tests/process_to_user.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_to_user", 3 | "data": "process_rotate.bin", 4 | "asserts": [ 5 | { 6 | "actual": "buf1.str", 7 | "expected": "\"Hello\"" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/specs/valid_fail_eq_bytes.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_fail_eq_bytes" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "foo", 8 | "size": 2, 9 | "valid": "[0x51, 0x41]" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /testing/tests/expr_sizeof_type_0.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_sizeof_type_0", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "sizeof_block", 7 | "expected": "1 + 4 + 2" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/tests/nav_parent_vs_value_inst.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nav_parent_vs_value_inst", 3 | "data": "term_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "s1", 7 | "expected": "\"foo\"" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/tests/position_in_seq.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "position_in_seq", 3 | "data": "position_in_seq.bin", 4 | "asserts": [ 5 | { 6 | "actual": "numbers", 7 | "expected": "[0 + 1, 2, 3]" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/specs/if_instances.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "if_instances" 4 | }, 5 | "instances": { 6 | "never_happens": { 7 | "pos": 100500, 8 | "type": "u1", 9 | "if": "false" 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /testing/specs/str_eos.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "str_eos" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "str", 8 | "type": "str", 9 | "size-eos": true, 10 | "encoding": "UTF-8" 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /testing/specs/zlib_with_header_78.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "zlib_with_header_78" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "data", 8 | "size-eos": true, 9 | "process": "zlib" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /testing/tests/repeat_eos_u4.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "repeat_eos_u4", 3 | "data": "repeat_eos_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "numbers", 7 | "expected": "[0, 0x42, 0x42, 0x815]" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/specs/opaque_external_type.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "opaque_external_type", 4 | "ks-opaque-types": true 5 | }, 6 | "seq": [ 7 | { 8 | "id": "one", 9 | "type": "term_strz" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /testing/tests/params_call_extra_parens.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "params_call_extra_parens", 3 | "data": "term_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "buf1.body", 7 | "expected": "\"foo|b\"" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/specs/opaque_with_param.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "opaque_with_param", 4 | "ks-opaque-types": true 5 | }, 6 | "seq": [ 7 | { 8 | "id": "one", 9 | "type": "params_def(5, true)" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /testing/specs/process_custom_no_args.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_custom_no_args" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "buf", 8 | "size": 5, 9 | "process": "custom_fx_no_args" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /testing/specs/repeat_eos_u4.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "repeat_eos_u4", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "numbers", 9 | "type": "u4", 10 | "repeat": "eos" 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /testing/specs/optional_id.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "optional_id" 4 | }, 5 | "seq": [ 6 | { 7 | "type": "u1" 8 | }, 9 | { 10 | "type": "u1" 11 | }, 12 | { 13 | "size": 5 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /testing/specs/valid_fail_contents.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_fail_contents" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "foo", 8 | "contents": [ 9 | "0x51", 10 | "0x41" 11 | ] 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/specs/valid_fail_max_int.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_fail_max_int" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "foo", 8 | "type": "u1", 9 | "valid": { 10 | "max": 12 11 | } 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/specs/valid_fail_min_int.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_fail_min_int" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "foo", 8 | "type": "u1", 9 | "valid": { 10 | "min": 123 11 | } 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/process_custom_no_args.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_custom_no_args", 3 | "data": "process_rotate.bin", 4 | "asserts": [ 5 | { 6 | "actual": "buf", 7 | "expected": "[0x5f, 0x09, 0xac, 0x8d, 0x8d, 0xed, 0x5f]" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/specs/eof_exception_u4.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "eof_exception_u4" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "prebuf", 8 | "size": 9 9 | }, 10 | { 11 | "id": "fail_int", 12 | "type": "u4le" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /testing/specs/instance_std.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "instance_std", 4 | "endian": "le" 5 | }, 6 | "instances": { 7 | "header": { 8 | "pos": 2, 9 | "type": "str", 10 | "size": 5, 11 | "encoding": "ASCII" 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /testing/specs/valid_fail_range_int.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_fail_range_int" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "foo", 8 | "type": "u1", 9 | "valid": { 10 | "min": 5, 11 | "max": 10 12 | } 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /testing/specs/process_repeat_bytes.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_repeat_bytes" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "bufs", 8 | "size": 5, 9 | "repeat": "expr", 10 | "repeat-expr": 2, 11 | "process": "xor(0x9e)" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/specs/valid_fail_range_float.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_fail_range_float" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "foo", 8 | "type": "f4le", 9 | "valid": { 10 | "min": 0.2, 11 | "max": 0.4 12 | } 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /testing/specs/js_signed_right_shift.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "js_signed_right_shift" 4 | }, 5 | "instances": { 6 | "should_be_40000000": { 7 | "value": "0x80000000 >> 1" 8 | }, 9 | "should_be_a00000": { 10 | "value": "0xa0000000 >> 8" 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /testing/specs/valid_fail_range_bytes.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_fail_range_bytes" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "foo", 8 | "size": 2, 9 | "valid": { 10 | "min": "[72, 64]", 11 | "max": "[79, 126]" 12 | } 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /testing/tests/combine_bool.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "combine_bool", 3 | "data": "enum_negative.bin", 4 | "asserts": [ 5 | { 6 | "actual": "bool_bit", 7 | "expected": true 8 | }, 9 | { 10 | "actual": "bool_calc_bit", 11 | "expected": false 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/expr_0.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_0", 3 | "data": "str_encodings.bin", 4 | "asserts": [ 5 | { 6 | "actual": "must_be_f7", 7 | "expected": "0xf7" 8 | }, 9 | { 10 | "actual": "must_be_abc123", 11 | "expected": "\"abc123\"" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/repeat_n_strz.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "repeat_n_strz", 3 | "data": "repeat_n_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "qty", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "lines", 11 | "expected": "[\"foo\", \"bar\"]" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/user_type.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "user_type", 3 | "data": "repeat_until_s4.bin", 4 | "asserts": [ 5 | { 6 | "actual": "one.width", 7 | "expected": "0x42" 8 | }, 9 | { 10 | "actual": "one.height", 11 | "expected": "0x1337" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/specs/process_xor4_value.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_xor4_value" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "key", 8 | "size": 4 9 | }, 10 | { 11 | "id": "buf", 12 | "size-eos": true, 13 | "process": "xor(key)" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /testing/tests/enum_0.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_0", 3 | "data": "enum_0.bin", 4 | "asserts": [ 5 | { 6 | "actual": "pet_1", 7 | "expected": "enum_0::animal::cat" 8 | }, 9 | { 10 | "actual": "pet_2", 11 | "expected": "enum_0::animal::chicken" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/enum_deep_literals.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_deep_literals", 3 | "data": "enum_0.bin", 4 | "asserts": [ 5 | { 6 | "actual": "is_pet_1_ok", 7 | "expected": true 8 | }, 9 | { 10 | "actual": "is_pet_2_ok", 11 | "expected": true 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/position_abs.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "position_abs", 3 | "data": "position_abs.bin", 4 | "asserts": [ 5 | { 6 | "actual": "index_offset", 7 | "expected": "0x20" 8 | }, 9 | { 10 | "actual": "index.entry", 11 | "expected": "\"foo\"" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/debug_switch_user.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "debug_switch_user", 3 | "data": "nav_parent_switch.bin", 4 | "asserts": [ 5 | { 6 | "actual": "code", 7 | "expected": 1 8 | }, 9 | { 10 | "actual": "data.one.val", 11 | "expected": -190 12 | } 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /testing/tests/enum_invalid.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_invalid", 3 | "data": "term_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "pet_1", 7 | "expected": "enum_invalid::animal::dog" 8 | }, 9 | { 10 | "actual": "pet_2", 11 | "expected": "0x6f" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/params_pass_usertype.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "params_pass_usertype", 3 | "data": "position_in_seq.bin", 4 | "asserts": [ 5 | { 6 | "actual": "first.foo", 7 | "expected": 1 8 | }, 9 | { 10 | "actual": "one.buf", 11 | "expected": "[2]" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/position_to_end.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "position_to_end", 3 | "data": "position_to_end.bin", 4 | "asserts": [ 5 | { 6 | "actual": "index.foo", 7 | "expected": "0x42" 8 | }, 9 | { 10 | "actual": "index.bar", 11 | "expected": "0x1234" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/expr_if_int_ops.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_if_int_ops", 3 | "data": "process_coerce_switch.bin", 4 | "asserts": [ 5 | { 6 | "actual": "is_eq_prim", 7 | "expected": true 8 | }, 9 | { 10 | "actual": "is_eq_boxed", 11 | "expected": true 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/nested_type_param.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nested_type_param", 3 | "data": "term_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "main_seq.my_len", 7 | "expected": 5 8 | }, 9 | { 10 | "actual": "main_seq.body", 11 | "expected": "\"foo|b\"" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/multiple_use.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "multiple_use", 3 | "data": "position_abs.bin", 4 | "asserts": [ 5 | { 6 | "actual": "t1.first_use.value", 7 | "expected": "0x20" 8 | }, 9 | { 10 | "actual": "t2.second_use.value", 11 | "expected": "0x20" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/params_enum.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "params_enum", 3 | "data": "enum_0.bin", 4 | "asserts": [ 5 | { 6 | "actual": "one", 7 | "expected": "params_enum::animal::cat" 8 | }, 9 | { 10 | "actual": "invoke_with_param.is_cat", 11 | "expected": true 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/specs/process_xor4_const.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_xor4_const" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "key", 8 | "size": 4 9 | }, 10 | { 11 | "id": "buf", 12 | "size-eos": true, 13 | "process": "xor([0xec, 0xbb, 0xa3, 0x14])" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /testing/tests/enum_fancy.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_fancy", 3 | "data": "enum_0.bin", 4 | "asserts": [ 5 | { 6 | "actual": "pet_1", 7 | "expected": "enum_fancy::animal::cat" 8 | }, 9 | { 10 | "actual": "pet_2", 11 | "expected": "enum_fancy::animal::chicken" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/expr_sizeof_type_1.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_sizeof_type_1", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "sizeof_block", 7 | "expected": "1 + 4 + 2 + 4" 8 | }, 9 | { 10 | "actual": "sizeof_subblock", 11 | "expected": 4 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/imports_abs.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "imports_abs", 3 | "data": "fixed_struct.bin", 4 | "imports": "vlq_base128_le", 5 | "asserts": [ 6 | { 7 | "actual": "len.value", 8 | "expected": 80 9 | }, 10 | { 11 | "actual": "body.length", 12 | "expected": 80 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /testing/specs/process_xor_const.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_xor_const", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "key", 9 | "type": "u1" 10 | }, 11 | { 12 | "id": "buf", 13 | "size-eos": true, 14 | "process": "xor(0xff)" 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /testing/specs/process_xor_value.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_xor_value", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "key", 9 | "type": "u1" 10 | }, 11 | { 12 | "id": "buf", 13 | "size-eos": true, 14 | "process": "xor(key)" 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /testing/tests/process_xor_const.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_xor_const", 3 | "data": "process_xor_1.bin", 4 | "asserts": [ 5 | { 6 | "actual": "key", 7 | "expected": "0xff" 8 | }, 9 | { 10 | "actual": "buf", 11 | "expected": "[0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72]" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/process_xor_value.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_xor_value", 3 | "data": "process_xor_1.bin", 4 | "asserts": [ 5 | { 6 | "actual": "key", 7 | "expected": "0xff" 8 | }, 9 | { 10 | "actual": "buf", 11 | "expected": "[0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72]" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/repeat_until_s4.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "repeat_until_s4", 3 | "data": "repeat_until_s4.bin", 4 | "asserts": [ 5 | { 6 | "actual": "entries", 7 | "expected": "[0x42, 0x1337, -251658241, -1]" 8 | }, 9 | { 10 | "actual": "afterall", 11 | "expected": "\"foobar\"" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/specs/imports_rel_1.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "imports_rel_1", 4 | "imports": [ 5 | "for_rel_imports/imported_1" 6 | ] 7 | }, 8 | "seq": [ 9 | { 10 | "id": "one", 11 | "type": "u1" 12 | }, 13 | { 14 | "id": "two", 15 | "type": "imported_1" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/fixed_contents.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "fixed_contents" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "normal", 8 | "contents": "\"PACK-1\"" 9 | }, 10 | { 11 | "id": "high_bit_8", 12 | "contents": [ 13 | "0xff", 14 | "0xff" 15 | ] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /testing/specs/imports_abs.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "imports_abs", 4 | "imports": [ 5 | "/common/vlq_base128_le" 6 | ] 7 | }, 8 | "seq": [ 9 | { 10 | "id": "len", 11 | "type": "vlq_base128_le" 12 | }, 13 | { 14 | "id": "body", 15 | "size": "len.value" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/tests/cast_to_imported.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "cast_to_imported", 3 | "data": "fixed_struct.bin", 4 | "imports": "hello_world", 5 | "asserts": [ 6 | { 7 | "actual": "one.one", 8 | "expected": "0x50" 9 | }, 10 | { 11 | "actual": "one_casted.one", 12 | "expected": "0x50" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /testing/tests/js_signed_right_shift.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "js_signed_right_shift", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "should_be_40000000", 7 | "expected": "0x40000000" 8 | }, 9 | { 10 | "actual": "should_be_a00000", 11 | "expected": "0xa00000" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/nested_same_name.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nested_same_name", 3 | "data": "repeat_n_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "main_data.main_size", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "main_data.foo.data", 11 | "expected": "[0x10, 0x00, 0x00, 0x00]" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/specs/imports_circular_a.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "imports_circular_a", 4 | "imports": [ 5 | "imports_circular_b" 6 | ] 7 | }, 8 | "seq": [ 9 | { 10 | "id": "code", 11 | "type": "u1" 12 | }, 13 | { 14 | "id": "two", 15 | "type": "imports_circular_b" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/valid_fail_range_str.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_fail_range_str", 4 | "encoding": "ASCII" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "foo", 9 | "size": 2, 10 | "type": "str", 11 | "valid": { 12 | "min": "\"H@\"", 13 | "max": "\"O~\"" 14 | } 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /testing/tests/enum_deep.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_deep", 3 | "data": "enum_0.bin", 4 | "asserts": [ 5 | { 6 | "actual": "pet_1", 7 | "expected": "enum_deep::container1::animal::cat" 8 | }, 9 | { 10 | "actual": "pet_2", 11 | "expected": "enum_deep::container1::container2::animal::hare" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/io_local_var.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "io_local_var", 3 | "data": "full256.bin", 4 | "asserts": [ 5 | { 6 | "actual": "skip", 7 | "expected": "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]" 8 | }, 9 | { 10 | "actual": "followup", 11 | "expected": 20 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/specs/imports_abs_abs.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "imports_abs_abs", 4 | "imports": [ 5 | "/for_abs_imports/imported_and_abs" 6 | ] 7 | }, 8 | "seq": [ 9 | { 10 | "id": "one", 11 | "type": "u1" 12 | }, 13 | { 14 | "id": "two", 15 | "type": "imported_and_abs" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/imports_abs_rel.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "imports_abs_rel", 4 | "imports": [ 5 | "/for_abs_imports/imported_and_rel" 6 | ] 7 | }, 8 | "seq": [ 9 | { 10 | "id": "one", 11 | "type": "u1" 12 | }, 13 | { 14 | "id": "two", 15 | "type": "imported_and_rel" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/valid_fail_inst.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_fail_inst" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "a", 8 | "type": "u1", 9 | "if": "inst >= 0" 10 | } 11 | ], 12 | "instances": { 13 | "inst": { 14 | "pos": 5, 15 | "type": "u1", 16 | "valid": "0x50" 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /testing/tests/enum_1.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_1", 3 | "data": "enum_0.bin", 4 | "asserts": [ 5 | { 6 | "actual": "main.submain.pet_1", 7 | "expected": "enum_1::main_obj::animal::cat" 8 | }, 9 | { 10 | "actual": "main.submain.pet_2", 11 | "expected": "enum_1::main_obj::animal::chicken" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/enum_negative.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_negative", 3 | "data": "enum_negative.bin", 4 | "asserts": [ 5 | { 6 | "actual": "f1", 7 | "expected": "enum_negative::constants::negative_one" 8 | }, 9 | { 10 | "actual": "f2", 11 | "expected": "enum_negative::constants::positive_one" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/specs/docstrings_docref_multi.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "docstrings_docref_multi" 4 | }, 5 | "doc": "Sample docstring", 6 | "doc-ref": [ 7 | "Plain text description of doc ref, page 42", 8 | "http://www.example.com/some/path/?even_with=query&more=2", 9 | "http://www.example.com/three Documentation name" 10 | ] 11 | } -------------------------------------------------------------------------------- /testing/specs/enum_for_unknown_id.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_for_unknown_id" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "one", 8 | "type": "u1", 9 | "enum": "animal" 10 | } 11 | ], 12 | "enums": { 13 | "animal": { 14 | "4": "dog", 15 | "7": "cat", 16 | "12": "chicken" 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /testing/tests/enum_int_range_u.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_int_range_u", 3 | "data": "enum_int_range_u.bin", 4 | "asserts": [ 5 | { 6 | "actual": "f1", 7 | "expected": "enum_int_range_u::constants::zero" 8 | }, 9 | { 10 | "actual": "f2", 11 | "expected": "enum_int_range_u::constants::int_max" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/process_xor4_const.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_xor4_const", 3 | "data": "process_xor_4.bin", 4 | "asserts": [ 5 | { 6 | "actual": "key", 7 | "expected": "[0xec, 0xbb, 0xa3, 0x14]" 8 | }, 9 | { 10 | "actual": "buf", 11 | "expected": "[0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72]" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/process_xor4_value.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_xor4_value", 3 | "data": "process_xor_4.bin", 4 | "asserts": [ 5 | { 6 | "actual": "key", 7 | "expected": "[0xec, 0xbb, 0xa3, 0x14]" 8 | }, 9 | { 10 | "actual": "buf", 11 | "expected": "[0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72]" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/specs/expr_bytes_literal.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_bytes_literal" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "one", 8 | "type": "s1" 9 | }, 10 | { 11 | "id": "two", 12 | "type": "s1" 13 | } 14 | ], 15 | "instances": { 16 | "literal": { 17 | "value": "[one, two]" 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /testing/tests/process_repeat_bytes.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_repeat_bytes", 3 | "data": "process_xor_4.bin", 4 | "asserts": [ 5 | { 6 | "actual": "bufs[0]", 7 | "expected": "[0x72, 0x25, 0x3d, 0x8a, 0x14]" 8 | }, 9 | { 10 | "actual": "bufs[1]", 11 | "expected": "[0x4a, 0x52, 0xaa, 0x10, 0x44]" 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /testing/tests/term_strz.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "term_strz", 3 | "data": "term_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "s1", 7 | "expected": "\"foo\"" 8 | }, 9 | { 10 | "actual": "s2", 11 | "expected": "\"bar\"" 12 | }, 13 | { 14 | "actual": "s3", 15 | "expected": "\"|baz@\"" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/cast_to_imported.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "cast_to_imported", 4 | "imports": [ 5 | "hello_world" 6 | ] 7 | }, 8 | "seq": [ 9 | { 10 | "id": "one", 11 | "type": "hello_world" 12 | } 13 | ], 14 | "instances": { 15 | "one_casted": { 16 | "value": "one.as" 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /testing/specs/combine_bool.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "combine_bool" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "bool_bit", 8 | "type": "b1" 9 | } 10 | ], 11 | "instances": { 12 | "bool_calc": { 13 | "value": false 14 | }, 15 | "bool_calc_bit": { 16 | "value": "true ? bool_calc : bool_bit" 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /testing/specs/repeat_n_strz.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "repeat_n_strz", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "qty", 9 | "type": "u4" 10 | }, 11 | { 12 | "id": "lines", 13 | "type": "strz", 14 | "encoding": "UTF-8", 15 | "repeat": "expr", 16 | "repeat-expr": "qty" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /testing/specs/valid_not_parsed_if.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_not_parsed_if" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "not_parsed", 8 | "if": false, 9 | "type": "u1", 10 | "valid": 42 11 | }, 12 | { 13 | "id": "parsed", 14 | "if": true, 15 | "type": "u1", 16 | "valid": "0x50" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /testing/specs/cast_to_top.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "cast_to_top" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "code", 8 | "type": "u1" 9 | } 10 | ], 11 | "instances": { 12 | "header": { 13 | "pos": 1, 14 | "type": "cast_to_top" 15 | }, 16 | "header_casted": { 17 | "value": "header.as" 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /testing/specs/expr_0.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_0", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "len_of_1", 9 | "type": "u2" 10 | } 11 | ], 12 | "instances": { 13 | "must_be_f7": { 14 | "value": "7 + 0xf0" 15 | }, 16 | "must_be_abc123": { 17 | "value": "\"abc\" + \"123\"" 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /testing/specs/str_literals2.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "str_literals2" 4 | }, 5 | "instances": { 6 | "dollar1": { 7 | "value": "\"$foo\"" 8 | }, 9 | "dollar2": { 10 | "value": "\"${foo}\"" 11 | }, 12 | "hash": { 13 | "value": "\"#{foo}\"" 14 | }, 15 | "at_sign": { 16 | "value": "\"@foo\"" 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /testing/specs/debug_0.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "debug_0", 4 | "ks-debug": true 5 | }, 6 | "seq": [ 7 | { 8 | "id": "one", 9 | "type": "u1" 10 | }, 11 | { 12 | "id": "array_of_ints", 13 | "type": "u1", 14 | "repeat": "expr", 15 | "repeat-expr": 3 16 | }, 17 | { 18 | "type": "u1" 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /testing/tests/cast_to_top.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "cast_to_top", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "code", 7 | "expected": "0x50" 8 | }, 9 | { 10 | "actual": "header.code", 11 | "expected": "0x41" 12 | }, 13 | { 14 | "actual": "header_casted.code", 15 | "expected": "0x41" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/tests/expr_bytes_literal.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_bytes_literal", 3 | "data": "enum_negative.bin", 4 | "asserts": [ 5 | { 6 | "actual": "literal.size", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "literal[0]", 11 | "expected": -1 12 | }, 13 | { 14 | "actual": "literal[1]", 15 | "expected": 1 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/imports_circular_b.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "imports_circular_b", 4 | "imports": [ 5 | "imports_circular_a" 6 | ] 7 | }, 8 | "seq": [ 9 | { 10 | "id": "initial", 11 | "type": "u1" 12 | }, 13 | { 14 | "id": "back_ref", 15 | "type": "imports_circular_a", 16 | "if": "initial == 0x41" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /testing/tests/repeat_n_strz_double.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "repeat_n_strz_double", 3 | "data": "repeat_n_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "qty", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "lines1", 11 | "expected": "[\"foo\"]" 12 | }, 13 | { 14 | "actual": "lines2", 15 | "expected": "[\"bar\"]" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/eos_exception_bytes.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "eos_exception_bytes" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "envelope", 8 | "type": "data", 9 | "size": 6 10 | } 11 | ], 12 | "types": { 13 | "data": { 14 | "seq": [ 15 | { 16 | "id": "buf", 17 | "size": 7 18 | } 19 | ] 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /testing/specs/repeat_until_s4.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "repeat_until_s4", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "entries", 9 | "type": "s4", 10 | "repeat": "until", 11 | "repeat-until": "_ == -1" 12 | }, 13 | { 14 | "id": "afterall", 15 | "type": "strz", 16 | "encoding": "ASCII" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /testing/specs/term_bytes.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "term_bytes" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "s1", 8 | "terminator": "0x7c" 9 | }, 10 | { 11 | "id": "s2", 12 | "terminator": "0x7c", 13 | "consume": false 14 | }, 15 | { 16 | "id": "s3", 17 | "terminator": "0x40", 18 | "include": true 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /testing/tests/imports0.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "imports0", 3 | "data": "fixed_struct.bin", 4 | "imports": "hello_world", 5 | "asserts": [ 6 | { 7 | "actual": "two", 8 | "expected": "0x50" 9 | }, 10 | { 11 | "actual": "hw.one", 12 | "expected": "0x41" 13 | }, 14 | { 15 | "actual": "hw_one", 16 | "expected": "0x41" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /testing/tests/zlib_with_header_78.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "zlib_with_header_78", 3 | "data": "zlib_with_header_78.bin", 4 | "asserts": [ 5 | { 6 | "actual": "data", 7 | "expected": "[0x61, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x20,\n 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f,\n 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20,\n 0x6f, 0x76, 0x65, 0x72]" 8 | } 9 | ] 10 | } -------------------------------------------------------------------------------- /testing/tests/nested_types.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nested_types", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "one.typed_at_root.value_b", 7 | "expected": 80 8 | }, 9 | { 10 | "actual": "one.typed_here.value_c", 11 | "expected": 65 12 | }, 13 | { 14 | "actual": "two.value_b", 15 | "expected": 67 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/tests/params_call_short.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "params_call_short", 3 | "data": "term_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "buf1.body", 7 | "expected": "\"foo|b\"" 8 | }, 9 | { 10 | "actual": "buf2.body", 11 | "expected": "\"ar|ba\"" 12 | }, 13 | { 14 | "actual": "buf2.trailer", 15 | "expected": "0x7a" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/imports0.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "imports0", 4 | "imports": [ 5 | "hello_world" 6 | ] 7 | }, 8 | "seq": [ 9 | { 10 | "id": "two", 11 | "type": "u1" 12 | }, 13 | { 14 | "id": "hw", 15 | "type": "hello_world" 16 | } 17 | ], 18 | "instances": { 19 | "hw_one": { 20 | "value": "hw.one" 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /testing/specs/nav_parent_false2.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "nav_parent_false2" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "parentless", 8 | "type": "child", 9 | "parent": false 10 | } 11 | ], 12 | "types": { 13 | "child": { 14 | "seq": [ 15 | { 16 | "id": "foo", 17 | "type": "u1" 18 | } 19 | ] 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /testing/specs/valid_fail_expr.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_fail_expr" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "foo", 8 | "type": "u1", 9 | "valid": { 10 | "expr": "_ == 1" 11 | } 12 | }, 13 | { 14 | "id": "bar", 15 | "type": "s2le", 16 | "valid": { 17 | "expr": "_ < -190 or _ > -190" 18 | } 19 | } 20 | ] 21 | } -------------------------------------------------------------------------------- /testing/specs/valid_long.ksj: -------------------------------------------------------------------------------- 1 | /home/sealmove/Git/sealmove/nimyaml2json/nimyaml2json.nim(6) nimyaml2json 2 | /home/sealmove/.nimble/pkgs/yaml-0.14.0/yaml/tojson.nim(205) loadToJson 3 | /home/sealmove/.nimble/pkgs/yaml-0.14.0/yaml/tojson.nim(136) constructJson 4 | /home/sealmove/.nimble/pkgs/yaml-0.14.0/yaml/tojson.nim(73) jsonFromScalar 5 | Error: unhandled exception: Cannot parse numeric value [YamlConstructionError] -------------------------------------------------------------------------------- /testing/specs/yaml_ints.ksj: -------------------------------------------------------------------------------- 1 | /home/sealmove/Git/sealmove/nimyaml2json/nimyaml2json.nim(6) nimyaml2json 2 | /home/sealmove/.nimble/pkgs/yaml-0.14.0/yaml/tojson.nim(205) loadToJson 3 | /home/sealmove/.nimble/pkgs/yaml-0.14.0/yaml/tojson.nim(136) constructJson 4 | /home/sealmove/.nimble/pkgs/yaml-0.14.0/yaml/tojson.nim(73) jsonFromScalar 5 | Error: unhandled exception: Cannot parse numeric value [YamlConstructionError] -------------------------------------------------------------------------------- /testing/tests/enum_import.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_import", 3 | "data": "enum_0.bin", 4 | "imports": [ 5 | "enum_0", 6 | "enum_deep" 7 | ], 8 | "asserts": [ 9 | { 10 | "actual": "pet_1", 11 | "expected": "enum_0::animal::cat" 12 | }, 13 | { 14 | "actual": "pet_2", 15 | "expected": "enum_deep::container1::container2::animal::hare" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/tests/term_bytes.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "term_bytes", 3 | "data": "term_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "s1", 7 | "expected": "[0x66, 0x6f, 0x6f]" 8 | }, 9 | { 10 | "actual": "s2", 11 | "expected": "[0x62, 0x61, 0x72]" 12 | }, 13 | { 14 | "actual": "s3", 15 | "expected": "[0x7c, 0x62, 0x61, 0x7a, 0x40]" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/valid_short.ksj: -------------------------------------------------------------------------------- 1 | /home/sealmove/Git/sealmove/nimyaml2json/nimyaml2json.nim(6) nimyaml2json 2 | /home/sealmove/.nimble/pkgs/yaml-0.14.0/yaml/tojson.nim(205) loadToJson 3 | /home/sealmove/.nimble/pkgs/yaml-0.14.0/yaml/tojson.nim(136) constructJson 4 | /home/sealmove/.nimble/pkgs/yaml-0.14.0/yaml/tojson.nim(73) jsonFromScalar 5 | Error: unhandled exception: Cannot parse numeric value [YamlConstructionError] -------------------------------------------------------------------------------- /testing/tests/switch_else_only.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "switch_else_only", 3 | "data": "switch_opcodes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "opcode", 7 | "expected": "0x53" 8 | }, 9 | { 10 | "actual": "prim_byte", 11 | "expected": "0x66" 12 | }, 13 | { 14 | "actual": "ut.c0", 15 | "expected": "[0x72, 0x00, 0x49, 0x42]" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /testing/specs/to_string_custom.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "to_string_custom", 4 | "encoding": "UTF-8" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "s1", 9 | "type": "str", 10 | "terminator": "0x7c" 11 | }, 12 | { 13 | "id": "s2", 14 | "type": "strz", 15 | "terminator": "0x7c" 16 | } 17 | ], 18 | "to-string": "\"s1 = \" + s1 + \", s2 = \" + s2\n" 19 | } -------------------------------------------------------------------------------- /testing/tests/default_endian_mod.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "default_endian_mod", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "main.one", 7 | "expected": "0x4b434150" 8 | }, 9 | { 10 | "actual": "main.nest.two", 11 | "expected": -52947 12 | }, 13 | { 14 | "actual": "main.nest_be.two", 15 | "expected": "0x5041434b" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/tests/nav_parent_switch.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nav_parent_switch", 3 | "data": "nav_parent_switch.bin", 4 | "asserts": [ 5 | { 6 | "actual": "category", 7 | "expected": 1 8 | }, 9 | { 10 | "actual": "content.c0.foo", 11 | "expected": "0x42" 12 | }, 13 | { 14 | "actual": "content.c0.subelement.bar", 15 | "expected": "0xff" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /testing/tests/nav_parent_switch_cast.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nav_parent_switch_cast", 3 | "data": "switch_integers.bin", 4 | "asserts": [ 5 | { 6 | "actual": "main.buf_type", 7 | "expected": 1 8 | }, 9 | { 10 | "actual": "main.flag", 11 | "expected": 7 12 | }, 13 | { 14 | "actual": "main.buf.c1.branch.flag", 15 | "expected": 7 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /testing/specs/valid_fail_anyof_int.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_fail_anyof_int" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "foo", 8 | "type": "u1", 9 | "valid": { 10 | "any-of": [ 11 | 5, 12 | 6, 13 | 7, 14 | 8, 15 | 10, 16 | 11, 17 | 12, 18 | 47 19 | ] 20 | } 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /testing/tests/bits_enum.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "bits_enum", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "one", 7 | "expected": "bits_enum::animal::platypus" 8 | }, 9 | { 10 | "actual": "two", 11 | "expected": "bits_enum::animal::horse" 12 | }, 13 | { 14 | "actual": "three", 15 | "expected": "bits_enum::animal::cat" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/tests/process_coerce_switch.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_coerce_switch", 3 | "data": "process_coerce_switch.bin", 4 | "asserts": [ 5 | { 6 | "actual": "buf_type", 7 | "expected": 0 8 | }, 9 | { 10 | "actual": "flag", 11 | "expected": 0 12 | }, 13 | { 14 | "actual": "buf.c0.bar", 15 | "expected": "[0x41, 0x41, 0x41, 0x41]" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /testing/specs/enum_invalid.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_invalid" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "pet_1", 8 | "type": "u1", 9 | "enum": "animal" 10 | }, 11 | { 12 | "id": "pet_2", 13 | "type": "u1", 14 | "enum": "animal" 15 | } 16 | ], 17 | "enums": { 18 | "animal": { 19 | "0x66": "dog", 20 | "0x7c": "cat" 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /testing/tests/expr_enum.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_enum", 3 | "data": "term_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "const_dog", 7 | "expected": "expr_enum::animal::dog" 8 | }, 9 | { 10 | "actual": "derived_boom", 11 | "expected": "expr_enum::animal::boom" 12 | }, 13 | { 14 | "actual": "derived_dog", 15 | "expected": "expr_enum::animal::dog" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/enum_negative.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_negative" 4 | }, 5 | "enums": { 6 | "constants": { 7 | "-1": "negative_one", 8 | "1": "positive_one" 9 | } 10 | }, 11 | "seq": [ 12 | { 13 | "id": "f1", 14 | "type": "s1", 15 | "enum": "constants" 16 | }, 17 | { 18 | "id": "f2", 19 | "type": "s1", 20 | "enum": "constants" 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /testing/specs/enum_to_i_class_border_2.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_to_i_class_border_2", 4 | "endian": "le", 5 | "imports": [ 6 | "enum_to_i_class_border_1" 7 | ] 8 | }, 9 | "params": [ 10 | { 11 | "id": "parent", 12 | "type": "enum_to_i_class_border_1" 13 | } 14 | ], 15 | "instances": { 16 | "is_dog": { 17 | "value": "parent.some_dog.to_i == 4" 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /testing/tests/combine_enum.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "combine_enum", 3 | "data": "enum_0.bin", 4 | "asserts": [ 5 | { 6 | "actual": "enum_u4", 7 | "expected": "combine_enum::animal::pig" 8 | }, 9 | { 10 | "actual": "enum_u2", 11 | "expected": "combine_enum::animal::horse" 12 | }, 13 | { 14 | "actual": "enum_u4_u2", 15 | "expected": "combine_enum::animal::horse" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/tests/nav_parent_override.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nav_parent_override", 3 | "data": "nav_parent_codes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "child_size", 7 | "expected": 3 8 | }, 9 | { 10 | "actual": "child_1.data", 11 | "expected": "[0x49, 0x31, 0x32]" 12 | }, 13 | { 14 | "actual": "mediator_2.child_2.data", 15 | "expected": "[0x33, 0x42, 0x62]" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/valid_switch.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "valid_switch" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "a", 8 | "type": "u1", 9 | "valid": "0x50" 10 | }, 11 | { 12 | "id": "b", 13 | "type": { 14 | "switch-on": "a", 15 | "cases": { 16 | "0x50": "u2le", 17 | "_": "u2be" 18 | } 19 | }, 20 | "valid": "0x4341" 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /testing/tests/expr_1.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_1", 3 | "data": "str_encodings.bin", 4 | "asserts": [ 5 | { 6 | "actual": "len_of_1", 7 | "expected": 10 8 | }, 9 | { 10 | "actual": "len_of_1_mod", 11 | "expected": 8 12 | }, 13 | { 14 | "actual": "str1", 15 | "expected": "\"Some ASC\"" 16 | }, 17 | { 18 | "actual": "str1_len", 19 | "expected": 8 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/imports_rel_1.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "imports_rel_1", 3 | "data": "fixed_struct.bin", 4 | "imports": [ 5 | "imported_1", 6 | "imported_2" 7 | ], 8 | "asserts": [ 9 | { 10 | "actual": "one", 11 | "expected": "0x50" 12 | }, 13 | { 14 | "actual": "two.one", 15 | "expected": "0x41" 16 | }, 17 | { 18 | "actual": "two.two.one", 19 | "expected": "0x43" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/process_rotate.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_rotate", 3 | "data": "process_rotate.bin", 4 | "asserts": [ 5 | { 6 | "actual": "buf1", 7 | "expected": "[0x48, 0x65, 0x6c, 0x6c, 0x6f]" 8 | }, 9 | { 10 | "actual": "buf2", 11 | "expected": "[0x57, 0x6f, 0x72, 0x6c, 0x64]" 12 | }, 13 | { 14 | "actual": "buf3", 15 | "expected": "[0x54, 0x68, 0x65, 0x72, 0x65]" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/enum_import.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_import", 4 | "endian": "le", 5 | "imports": [ 6 | "enum_0", 7 | "enum_deep" 8 | ] 9 | }, 10 | "seq": [ 11 | { 12 | "id": "pet_1", 13 | "type": "u4", 14 | "enum": "enum_0::animal" 15 | }, 16 | { 17 | "id": "pet_2", 18 | "type": "u4", 19 | "enum": "enum_deep::container1::container2::animal" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/specs/enum_0.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_0", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "pet_1", 9 | "type": "u4", 10 | "enum": "animal" 11 | }, 12 | { 13 | "id": "pet_2", 14 | "type": "u4", 15 | "enum": "animal" 16 | } 17 | ], 18 | "enums": { 19 | "animal": { 20 | "4": "dog", 21 | "7": "cat", 22 | "12": "chicken" 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /testing/specs/type_int_unary_op.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "type_int_unary_op", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "value_s2", 9 | "type": "s2" 10 | }, 11 | { 12 | "id": "value_s8", 13 | "type": "s8" 14 | } 15 | ], 16 | "instances": { 17 | "unary_s2": { 18 | "value": "-value_s2" 19 | }, 20 | "unary_s8": { 21 | "value": "-value_s8" 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /testing/tests/process_custom.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_custom", 3 | "data": "process_rotate.bin", 4 | "asserts": [ 5 | { 6 | "actual": "buf1", 7 | "expected": "[0x10, 0xb3, 0x94, 0x94, 0xf4]" 8 | }, 9 | { 10 | "actual": "buf2", 11 | "expected": "[0x5f, 0xba, 0x7b, 0x93, 0x63, 0x23, 0x5f]" 12 | }, 13 | { 14 | "actual": "buf3", 15 | "expected": "[0x29, 0x33, 0xb1, 0x38, 0xb1]" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/tests/enum_int_range_s.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_int_range_s", 3 | "data": "enum_int_range_s.bin", 4 | "asserts": [ 5 | { 6 | "actual": "f1", 7 | "expected": "enum_int_range_s::constants::int_min" 8 | }, 9 | { 10 | "actual": "f2", 11 | "expected": "enum_int_range_s::constants::zero" 12 | }, 13 | { 14 | "actual": "f3", 15 | "expected": "enum_int_range_s::constants::int_max" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/specs/enum_int_range_u.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_int_range_u", 4 | "endian": "be" 5 | }, 6 | "enums": { 7 | "constants": { 8 | "0": "zero", 9 | "4294967295": "int_max" 10 | } 11 | }, 12 | "seq": [ 13 | { 14 | "id": "f1", 15 | "type": "u4", 16 | "enum": "constants" 17 | }, 18 | { 19 | "id": "f2", 20 | "type": "u4", 21 | "enum": "constants" 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /testing/specs/opaque_external_type_02_parent.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "opaque_external_type_02_parent", 4 | "ks-opaque-types": true 5 | }, 6 | "seq": [ 7 | { 8 | "id": "parent", 9 | "type": "parent_obj" 10 | } 11 | ], 12 | "types": { 13 | "parent_obj": { 14 | "seq": [ 15 | { 16 | "id": "child", 17 | "type": "opaque_external_type_02_child" 18 | } 19 | ] 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /testing/specs/user_type.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "user_type", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "one", 9 | "type": "header" 10 | } 11 | ], 12 | "types": { 13 | "header": { 14 | "seq": [ 15 | { 16 | "id": "width", 17 | "type": "u4" 18 | }, 19 | { 20 | "id": "height", 21 | "type": "u4" 22 | } 23 | ] 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /testing/tests/str_encodings.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "str_encodings", 3 | "data": "str_encodings.bin", 4 | "asserts": [ 5 | { 6 | "actual": "str1", 7 | "expected": "\"Some ASCII\"" 8 | }, 9 | { 10 | "actual": "str2", 11 | "expected": "\"こんにちは\"" 12 | }, 13 | { 14 | "actual": "str3", 15 | "expected": "\"こんにちは\"" 16 | }, 17 | { 18 | "actual": "str4", 19 | "expected": "\"░▒▓\"" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/str_literals2.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "str_literals2", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "dollar1", 7 | "expected": "\"$foo\"" 8 | }, 9 | { 10 | "actual": "dollar2", 11 | "expected": "\"${foo}\"" 12 | }, 13 | { 14 | "actual": "hash", 15 | "expected": "\"#{foo}\"" 16 | }, 17 | { 18 | "actual": "at_sign", 19 | "expected": "\"@foo\"" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/specs/eos_exception_u4.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "eos_exception_u4" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "envelope", 8 | "type": "data", 9 | "size": 6 10 | } 11 | ], 12 | "types": { 13 | "data": { 14 | "seq": [ 15 | { 16 | "id": "prebuf", 17 | "size": 3 18 | }, 19 | { 20 | "id": "fail_int", 21 | "type": "u4le" 22 | } 23 | ] 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /testing/testutils.nim: -------------------------------------------------------------------------------- 1 | import fenv, options 2 | 3 | proc `~=`*[T, U](a: T, b: U): bool = 4 | when T is U: 5 | when T is SomeFloat: 6 | return abs(a - b) <= epsilon(T) 7 | else: 8 | return a == b 9 | elif T is Option: 10 | return get(a) ~= b 11 | elif T is seq: 12 | if a.len != b.len: 13 | return false 14 | for i in 0 ..< a.len: 15 | if not a[i] ~= b[i]: 16 | return false 17 | return true 18 | else: 19 | return a ~= b.T 20 | -------------------------------------------------------------------------------- /testing/specs/process_to_user.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_to_user" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "buf1", 8 | "size": 5, 9 | "process": "rol(3)", 10 | "type": "just_str" 11 | } 12 | ], 13 | "types": { 14 | "just_str": { 15 | "seq": [ 16 | { 17 | "id": "str", 18 | "type": "str", 19 | "encoding": "UTF-8", 20 | "size-eos": true 21 | } 22 | ] 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /testing/tests/expr_io_eof.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_io_eof", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "substream1.one", 7 | "expected": 1262698832 8 | }, 9 | { 10 | "actual": "substream1.two", 11 | "expected": "null" 12 | }, 13 | { 14 | "actual": "substream2.one", 15 | "expected": 4294914349 16 | }, 17 | { 18 | "actual": "substream2.two", 19 | "expected": 1262698832 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/str_pad_term_empty.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "str_pad_term_empty", 3 | "data": "str_pad_term_empty.bin", 4 | "asserts": [ 5 | { 6 | "actual": "str_pad", 7 | "expected": "\"\"" 8 | }, 9 | { 10 | "actual": "str_term", 11 | "expected": "\"\"" 12 | }, 13 | { 14 | "actual": "str_term_and_pad", 15 | "expected": "\"\"" 16 | }, 17 | { 18 | "actual": "str_term_include", 19 | "expected": "\"@\"" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/instance_io_user.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "instance_io_user", 3 | "data": "instance_io.bin", 4 | "asserts": [ 5 | { 6 | "actual": "qty_entries", 7 | "expected": 3 8 | }, 9 | { 10 | "actual": "entries[0].name", 11 | "expected": "\"the\"" 12 | }, 13 | { 14 | "actual": "entries[1].name", 15 | "expected": "\"rainy\"" 16 | }, 17 | { 18 | "actual": "entries[2].name", 19 | "expected": "\"day it is\"" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/str_encodings_default.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "str_encodings_default", 3 | "data": "str_encodings.bin", 4 | "asserts": [ 5 | { 6 | "actual": "str1", 7 | "expected": "\"Some ASCII\"" 8 | }, 9 | { 10 | "actual": "rest.str2", 11 | "expected": "\"こんにちは\"" 12 | }, 13 | { 14 | "actual": "rest.str3", 15 | "expected": "\"こんにちは\"" 16 | }, 17 | { 18 | "actual": "rest.str4", 19 | "expected": "\"░▒▓\"" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/specs/expr_1.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_1", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "len_of_1", 9 | "type": "u2" 10 | }, 11 | { 12 | "id": "str1", 13 | "type": "str", 14 | "size": "len_of_1_mod", 15 | "encoding": "ASCII" 16 | } 17 | ], 18 | "instances": { 19 | "len_of_1_mod": { 20 | "value": "len_of_1 - 2" 21 | }, 22 | "str1_len": { 23 | "value": "str1.length" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /testing/specs/position_to_end.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "position_to_end", 4 | "endian": "le" 5 | }, 6 | "instances": { 7 | "index": { 8 | "pos": "_io.size - 8", 9 | "type": "index_obj" 10 | } 11 | }, 12 | "types": { 13 | "index_obj": { 14 | "seq": [ 15 | { 16 | "id": "foo", 17 | "type": "u4" 18 | }, 19 | { 20 | "id": "bar", 21 | "type": "u4" 22 | } 23 | ] 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /testing/tests/enum_to_i_class_border_1.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_to_i_class_border_1", 3 | "data": "enum_0.bin", 4 | "imports": "enum_to_i_class_border_2", 5 | "asserts": [ 6 | { 7 | "actual": "pet_1", 8 | "expected": "enum_to_i_class_border_1::animal::cat" 9 | }, 10 | { 11 | "actual": "pet_2", 12 | "expected": "enum_to_i_class_border_1::animal::chicken" 13 | }, 14 | { 15 | "actual": "checker.is_dog", 16 | "expected": true 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /testing/tests/params_pass_array_struct.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "params_pass_array_struct", 3 | "data": "position_to_end.bin", 4 | "asserts": [ 5 | { 6 | "actual": "pass_structs.structs.size", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "pass_structs.structs[0].as.f", 11 | "expected": 1 12 | }, 13 | { 14 | "actual": "pass_structs.structs[1].as.b", 15 | "expected": 2 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /testing/tests/process_repeat_usertype.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_repeat_usertype", 3 | "data": "process_xor_4.bin", 4 | "asserts": [ 5 | { 6 | "actual": "blocks[0].a", 7 | "expected": -1975704206 8 | }, 9 | { 10 | "actual": "blocks[0].b", 11 | "expected": "0x14" 12 | }, 13 | { 14 | "actual": "blocks[1].a", 15 | "expected": "0x10aa524a" 16 | }, 17 | { 18 | "actual": "blocks[1].b", 19 | "expected": "0x44" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/str_pad_term.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "str_pad_term", 3 | "data": "str_pad_term.bin", 4 | "asserts": [ 5 | { 6 | "actual": "str_pad", 7 | "expected": "\"str1\"" 8 | }, 9 | { 10 | "actual": "str_term", 11 | "expected": "\"str2foo\"" 12 | }, 13 | { 14 | "actual": "str_term_and_pad", 15 | "expected": "\"str+++3bar+++\"" 16 | }, 17 | { 18 | "actual": "str_term_include", 19 | "expected": "\"str4baz@\"" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/type_int_unary_op.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "type_int_unary_op", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "value_s2", 7 | "expected": "0x4150" 8 | }, 9 | { 10 | "actual": "value_s8", 11 | "expected": "0x4150ffff312d4b43" 12 | }, 13 | { 14 | "actual": "unary_s2", 15 | "expected": "-0x4150" 16 | }, 17 | { 18 | "actual": "unary_s8", 19 | "expected": "-0x4150ffff312d4b43" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/yaml_ints.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "yaml_ints", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "test_u4_dec", 7 | "expected": "0xffffffff" 8 | }, 9 | { 10 | "actual": "test_u4_hex", 11 | "expected": "0xffffffff" 12 | }, 13 | { 14 | "actual": "test_u8_dec", 15 | "expected": "0xffffffffffffffff" 16 | }, 17 | { 18 | "actual": "test_u8_hex", 19 | "expected": "0xffffffffffffffff" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/specs/process_rotate.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_rotate", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "buf1", 9 | "size": 5, 10 | "process": "rol(3)" 11 | }, 12 | { 13 | "id": "buf2", 14 | "size": 5, 15 | "process": "ror(3)" 16 | }, 17 | { 18 | "id": "key", 19 | "type": "u1" 20 | }, 21 | { 22 | "id": "buf3", 23 | "size": 5, 24 | "process": "rol(key)" 25 | } 26 | ] 27 | } -------------------------------------------------------------------------------- /testing/specs/repeat_eos_struct.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "repeat_eos_struct", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "chunks", 9 | "type": "chunk", 10 | "repeat": "eos" 11 | } 12 | ], 13 | "types": { 14 | "chunk": { 15 | "seq": [ 16 | { 17 | "id": "offset", 18 | "type": "u4" 19 | }, 20 | { 21 | "id": "len", 22 | "type": "u4" 23 | } 24 | ] 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /testing/tests/cast_nested.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "cast_nested", 3 | "data": "switch_opcodes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "opcodes_0_str.value", 7 | "expected": "\"foobar\"" 8 | }, 9 | { 10 | "actual": "opcodes_0_str_value", 11 | "expected": "\"foobar\"" 12 | }, 13 | { 14 | "actual": "opcodes_1_int.value", 15 | "expected": "0x42" 16 | }, 17 | { 18 | "actual": "opcodes_1_int_value", 19 | "expected": "0x42" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/default_bit_endian_mod.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "default_bit_endian_mod", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "main.one", 7 | "expected": "0b1_01010000" 8 | }, 9 | { 10 | "actual": "main.two", 11 | "expected": "0b01000011_0100000" 12 | }, 13 | { 14 | "actual": "main.nest.two", 15 | "expected": "0x2d_4b" 16 | }, 17 | { 18 | "actual": "main.nest_be.two", 19 | "expected": "0x31_ff" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/specs/debug_array_user.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "debug_array_user", 4 | "ks-debug": true 5 | }, 6 | "seq": [ 7 | { 8 | "id": "one_cat", 9 | "type": "cat" 10 | }, 11 | { 12 | "id": "array_of_cats", 13 | "type": "cat", 14 | "repeat": "expr", 15 | "repeat-expr": 3 16 | } 17 | ], 18 | "types": { 19 | "cat": { 20 | "seq": [ 21 | { 22 | "id": "meow", 23 | "type": "u1" 24 | } 25 | ] 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /testing/tests/params_pass_struct.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "params_pass_struct", 3 | "data": "enum_negative.bin", 4 | "asserts": [ 5 | { 6 | "actual": "first.foo", 7 | "expected": 255 8 | }, 9 | { 10 | "actual": "one.bar.qux", 11 | "expected": 1 12 | }, 13 | { 14 | "actual": "one.foo.as.foo", 15 | "expected": 255 16 | }, 17 | { 18 | "actual": "one.bar.foo.as.foo", 19 | "expected": 255 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/process_coerce_usertype1.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_coerce_usertype1", 3 | "data": "process_coerce_bytes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "records[0].flag", 7 | "expected": 0 8 | }, 9 | { 10 | "actual": "records[0].buf.value", 11 | "expected": "0x41414141" 12 | }, 13 | { 14 | "actual": "records[1].flag", 15 | "expected": 1 16 | }, 17 | { 18 | "actual": "records[1].buf.value", 19 | "expected": "0x42424242" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/process_coerce_usertype2.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_coerce_usertype2", 3 | "data": "process_coerce_bytes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "records[0].flag", 7 | "expected": 0 8 | }, 9 | { 10 | "actual": "records[0].buf.value", 11 | "expected": "0x41414141" 12 | }, 13 | { 14 | "actual": "records[1].flag", 15 | "expected": 1 16 | }, 17 | { 18 | "actual": "records[1].buf.value", 19 | "expected": "0x42424242" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/specs/index_sizes.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "index_sizes", 4 | "endian": "le", 5 | "encoding": "ASCII" 6 | }, 7 | "seq": [ 8 | { 9 | "id": "qty", 10 | "type": "u4" 11 | }, 12 | { 13 | "id": "sizes", 14 | "type": "u4", 15 | "repeat": "expr", 16 | "repeat-expr": "qty" 17 | }, 18 | { 19 | "id": "bufs", 20 | "type": "str", 21 | "size": "sizes[_index]", 22 | "repeat": "expr", 23 | "repeat-expr": "qty" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/specs/params_def.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "params_def", 4 | "endian": "le" 5 | }, 6 | "params": [ 7 | { 8 | "id": "len", 9 | "type": "u4" 10 | }, 11 | { 12 | "id": "has_trailer", 13 | "type": "bool" 14 | } 15 | ], 16 | "seq": [ 17 | { 18 | "id": "buf", 19 | "type": "str", 20 | "size": "len", 21 | "encoding": "UTF-8" 22 | }, 23 | { 24 | "id": "trailer", 25 | "type": "u1", 26 | "if": "has_trailer" 27 | } 28 | ] 29 | } -------------------------------------------------------------------------------- /testing/tests/process_coerce_bytes.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "process_coerce_bytes", 3 | "data": "process_coerce_bytes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "records[0].flag", 7 | "expected": 0 8 | }, 9 | { 10 | "actual": "records[0].buf", 11 | "expected": "[0x41, 0x41, 0x41, 0x41]" 12 | }, 13 | { 14 | "actual": "records[1].flag", 15 | "expected": 1 16 | }, 17 | { 18 | "actual": "records[1].buf", 19 | "expected": "[0x42, 0x42, 0x42, 0x42]" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/specs/str_literals.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "str_literals" 4 | }, 5 | "instances": { 6 | "complex_str": { 7 | "value": "\"\\0\\1\\2\\a\\b\\n\\r\\t\\v\\f\\e\\75\\7\\u000a\\u0024\\u263b\"" 8 | }, 9 | "double_quotes": { 10 | "value": "\"\\\"\\u0022\\42\"" 11 | }, 12 | "backslashes": { 13 | "value": "\"\\\\\\u005c\\134\"" 14 | }, 15 | "octal_eatup": { 16 | "value": "\"\\0\\62\\62\"" 17 | }, 18 | "octal_eatup2": { 19 | "value": "\"\\2\\62\"" 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /testing/tests/nested_types3.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nested_types3", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "a_cc.value_cc", 7 | "expected": 80 8 | }, 9 | { 10 | "actual": "a_c_d.value_d", 11 | "expected": 65 12 | }, 13 | { 14 | "actual": "b.value_b", 15 | "expected": 67 16 | }, 17 | { 18 | "actual": "b.a_cc.value_cc", 19 | "expected": 75 20 | }, 21 | { 22 | "actual": "b.a_c_d.value_d", 23 | "expected": 45 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/specs/bits_enum.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "bits_enum" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "one", 8 | "type": "b4", 9 | "enum": "animal" 10 | }, 11 | { 12 | "id": "two", 13 | "type": "b8", 14 | "enum": "animal" 15 | }, 16 | { 17 | "id": "three", 18 | "type": "b1", 19 | "enum": "animal" 20 | } 21 | ], 22 | "enums": { 23 | "animal": { 24 | "0": "cat", 25 | "1": "dog", 26 | "4": "horse", 27 | "5": "platypus" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /testing/specs/combine_enum.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "combine_enum", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "enum_u4", 9 | "type": "u4", 10 | "enum": "animal" 11 | }, 12 | { 13 | "id": "enum_u2", 14 | "type": "u2", 15 | "enum": "animal" 16 | } 17 | ], 18 | "enums": { 19 | "animal": { 20 | "7": "pig", 21 | "12": "horse" 22 | } 23 | }, 24 | "instances": { 25 | "enum_u4_u2": { 26 | "value": "false ? enum_u4 : enum_u2" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /testing/specs/instance_std_array.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "instance_std_array", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "ofs", 9 | "type": "u4" 10 | }, 11 | { 12 | "id": "entry_size", 13 | "type": "u4" 14 | }, 15 | { 16 | "id": "qty_entries", 17 | "type": "u4" 18 | } 19 | ], 20 | "instances": { 21 | "entries": { 22 | "pos": "ofs", 23 | "repeat": "expr", 24 | "repeat-expr": "qty_entries", 25 | "size": "entry_size" 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /testing/specs/position_abs.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "position_abs", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "index_offset", 9 | "type": "u4" 10 | } 11 | ], 12 | "types": { 13 | "index_obj": { 14 | "seq": [ 15 | { 16 | "id": "entry", 17 | "type": "strz", 18 | "encoding": "UTF-8" 19 | } 20 | ] 21 | } 22 | }, 23 | "instances": { 24 | "index": { 25 | "pos": "index_offset", 26 | "type": "index_obj" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /testing/specs/zlib_surrounded.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "zlib_surrounded" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "pre", 8 | "size": 4 9 | }, 10 | { 11 | "id": "zlib", 12 | "size": 12, 13 | "process": "zlib", 14 | "type": "inflated" 15 | }, 16 | { 17 | "id": "post", 18 | "size": 4 19 | } 20 | ], 21 | "types": { 22 | "inflated": { 23 | "seq": [ 24 | { 25 | "id": "num", 26 | "type": "s4le" 27 | } 28 | ] 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /testing/specs/expr_sizeof_type_0.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_sizeof_type_0", 4 | "endian": "le" 5 | }, 6 | "types": { 7 | "block": { 8 | "seq": [ 9 | { 10 | "id": "a", 11 | "type": "u1" 12 | }, 13 | { 14 | "id": "b", 15 | "type": "u4" 16 | }, 17 | { 18 | "id": "c", 19 | "size": 2 20 | } 21 | ] 22 | } 23 | }, 24 | "instances": { 25 | "sizeof_block": { 26 | "value": "sizeof" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /testing/specs/process_custom.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_custom" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "buf1", 8 | "size": 5, 9 | "process": "my_custom_fx(7, true, [0x20, 0x30, 0x40])" 10 | }, 11 | { 12 | "id": "buf2", 13 | "size": 5, 14 | "process": "nested.deeply.custom_fx(7)" 15 | }, 16 | { 17 | "id": "key", 18 | "type": "u1" 19 | }, 20 | { 21 | "id": "buf3", 22 | "size": 5, 23 | "process": "my_custom_fx(key, false, [0x00])" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/specs/repeat_n_strz_double.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "repeat_n_strz_double", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "qty", 9 | "type": "u4" 10 | }, 11 | { 12 | "id": "lines1", 13 | "type": "strz", 14 | "encoding": "UTF-8", 15 | "repeat": "expr", 16 | "repeat-expr": "qty / 2" 17 | }, 18 | { 19 | "id": "lines2", 20 | "type": "strz", 21 | "encoding": "UTF-8", 22 | "repeat": "expr", 23 | "repeat-expr": "qty / 2" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/tests/enum_of_value_inst.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_of_value_inst", 3 | "data": "enum_0.bin", 4 | "asserts": [ 5 | { 6 | "actual": "pet_1", 7 | "expected": "enum_of_value_inst::animal::cat" 8 | }, 9 | { 10 | "actual": "pet_2", 11 | "expected": "enum_of_value_inst::animal::chicken" 12 | }, 13 | { 14 | "actual": "pet_3", 15 | "expected": "enum_of_value_inst::animal::dog" 16 | }, 17 | { 18 | "actual": "pet_4", 19 | "expected": "enum_of_value_inst::animal::dog" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/enum_to_i.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_to_i", 3 | "data": "enum_0.bin", 4 | "asserts": [ 5 | { 6 | "actual": "pet_1", 7 | "expected": "enum_to_i::animal::cat" 8 | }, 9 | { 10 | "actual": "pet_2", 11 | "expected": "enum_to_i::animal::chicken" 12 | }, 13 | { 14 | "actual": "pet_1_i", 15 | "expected": 7 16 | }, 17 | { 18 | "actual": "pet_1_mod", 19 | "expected": "0x8007" 20 | }, 21 | { 22 | "actual": "one_lt_two", 23 | "expected": true 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/specs/expr_if_int_ops.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_if_int_ops", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "skip", 9 | "size": 2 10 | }, 11 | { 12 | "id": "it", 13 | "type": "s2", 14 | "if": true 15 | }, 16 | { 17 | "id": "boxed", 18 | "type": "s2", 19 | "if": true 20 | } 21 | ], 22 | "instances": { 23 | "is_eq_prim": { 24 | "value": "it == 0x4141" 25 | }, 26 | "is_eq_boxed": { 27 | "value": "it == boxed" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /testing/tests/expr_sizeof_value_sized.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_sizeof_value_sized", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "self_sizeof", 7 | "expected": "12 + 2" 8 | }, 9 | { 10 | "actual": "sizeof_block", 11 | "expected": 12 12 | }, 13 | { 14 | "actual": "sizeof_block_a", 15 | "expected": 1 16 | }, 17 | { 18 | "actual": "sizeof_block_b", 19 | "expected": 4 20 | }, 21 | { 22 | "actual": "sizeof_block_c", 23 | "expected": 2 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/specs/nav_parent_vs_value_inst.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "nav_parent_vs_value_inst", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "s1", 9 | "type": "strz", 10 | "encoding": "UTF-8", 11 | "terminator": "0x7C" 12 | }, 13 | { 14 | "id": "child", 15 | "type": "child_obj" 16 | } 17 | ], 18 | "types": { 19 | "child_obj": { 20 | "instances": { 21 | "do_something": { 22 | "value": "_parent.s1 == 'foo' ? true : false" 23 | } 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /testing/specs/params_call_extra_parens.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "params_call_extra_parens" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "buf1", 8 | "type": "my_str1((5))" 9 | } 10 | ], 11 | "types": { 12 | "my_str1": { 13 | "params": [ 14 | { 15 | "id": "len", 16 | "type": "u4" 17 | } 18 | ], 19 | "seq": [ 20 | { 21 | "id": "body", 22 | "type": "str", 23 | "size": "len", 24 | "encoding": "UTF-8" 25 | } 26 | ] 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /testing/tests/repeat_eos_struct.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "repeat_eos_struct", 3 | "data": "repeat_eos_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "chunks.size", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "chunks[0].offset", 11 | "expected": 0 12 | }, 13 | { 14 | "actual": "chunks[0].len", 15 | "expected": "0x42" 16 | }, 17 | { 18 | "actual": "chunks[1].offset", 19 | "expected": "0x42" 20 | }, 21 | { 22 | "actual": "chunks[1].len", 23 | "expected": "0x815" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/tests/repeat_n_struct.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "repeat_n_struct", 3 | "data": "repeat_n_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "chunks.size", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "chunks[0].offset", 11 | "expected": "0x10" 12 | }, 13 | { 14 | "actual": "chunks[0].len", 15 | "expected": "0x2078" 16 | }, 17 | { 18 | "actual": "chunks[1].offset", 19 | "expected": "0x2088" 20 | }, 21 | { 22 | "actual": "chunks[1].len", 23 | "expected": "0xf" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/tests/switch_integers2.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "switch_integers2", 3 | "data": "switch_integers.bin", 4 | "asserts": [ 5 | { 6 | "actual": "code", 7 | "expected": 1 8 | }, 9 | { 10 | "actual": "len.c0", 11 | "expected": 7 12 | }, 13 | { 14 | "actual": "ham", 15 | "expected": "[0x02, 0x40, 0x40, 0x04, 0x37, 0x13, 0x00]" 16 | }, 17 | { 18 | "actual": "padding", 19 | "expected": 0 20 | }, 21 | { 22 | "actual": "len_mod_str", 23 | "expected": "\"13\"" 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /testing/specs/expr_mod.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_mod", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "int_u", 9 | "type": "u4" 10 | }, 11 | { 12 | "id": "int_s", 13 | "type": "s4" 14 | } 15 | ], 16 | "instances": { 17 | "mod_pos_const": { 18 | "value": "9837 % 13" 19 | }, 20 | "mod_neg_const": { 21 | "value": "-9837 % 13" 22 | }, 23 | "mod_pos_seq": { 24 | "value": "int_u % 13" 25 | }, 26 | "mod_neg_seq": { 27 | "value": "int_s % 13" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /testing/tests/enum_long_range_u.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_long_range_u", 3 | "data": "enum_long_range_u.bin", 4 | "asserts": [ 5 | { 6 | "actual": "f1", 7 | "expected": "enum_long_range_u::constants::zero" 8 | }, 9 | { 10 | "actual": "f2", 11 | "expected": "enum_long_range_u::constants::int_max" 12 | }, 13 | { 14 | "actual": "f3", 15 | "expected": "enum_long_range_u::constants::int_over_max" 16 | }, 17 | { 18 | "actual": "f4", 19 | "expected": "enum_long_range_u::constants::long_max" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/tests/expr_sizeof_value_0.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_sizeof_value_0", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "self_sizeof", 7 | "expected": "1 + 4 + 2 + 2" 8 | }, 9 | { 10 | "actual": "sizeof_block", 11 | "expected": "1 + 4 + 2" 12 | }, 13 | { 14 | "actual": "sizeof_block_a", 15 | "expected": 1 16 | }, 17 | { 18 | "actual": "sizeof_block_b", 19 | "expected": 4 20 | }, 21 | { 22 | "actual": "sizeof_block_c", 23 | "expected": 2 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/specs/repeat_until_sized.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "repeat_until_sized", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "records", 9 | "size": 5, 10 | "type": "record", 11 | "repeat": "until", 12 | "repeat-until": "_.marker == 0xaa" 13 | } 14 | ], 15 | "types": { 16 | "record": { 17 | "seq": [ 18 | { 19 | "id": "marker", 20 | "type": "u1" 21 | }, 22 | { 23 | "id": "body", 24 | "type": "u4" 25 | } 26 | ] 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /testing/specs/term_strz.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "term_strz", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "s1", 9 | "type": "strz", 10 | "encoding": "UTF-8", 11 | "terminator": "0x7c" 12 | }, 13 | { 14 | "id": "s2", 15 | "type": "strz", 16 | "encoding": "UTF-8", 17 | "terminator": "0x7c", 18 | "consume": false 19 | }, 20 | { 21 | "id": "s3", 22 | "type": "strz", 23 | "encoding": "UTF-8", 24 | "terminator": "0x40", 25 | "include": true 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /testing/tests/recursive_one.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "recursive_one", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "one", 7 | "expected": "0x50" 8 | }, 9 | { 10 | "actual": "next.as.one", 11 | "expected": "0x41" 12 | }, 13 | { 14 | "actual": "next.as.next.as.one", 15 | "expected": "0x43" 16 | }, 17 | { 18 | "actual": "next.as.next.as.next.as.finisher", 19 | "expected": "0x2d4b" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/specs/expr_int_div.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_int_div", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "int_u", 9 | "type": "u4" 10 | }, 11 | { 12 | "id": "int_s", 13 | "type": "s4" 14 | } 15 | ], 16 | "instances": { 17 | "div_pos_const": { 18 | "value": "9837 / 13" 19 | }, 20 | "div_neg_const": { 21 | "value": "-9837 / 13" 22 | }, 23 | "div_pos_seq": { 24 | "value": "int_u / 13" 25 | }, 26 | "div_neg_seq": { 27 | "value": "int_s / 13" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /testing/tests/nav_root.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nav_root", 3 | "data": "nav.bin", 4 | "asserts": [ 5 | { 6 | "actual": "header.qty_entries", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "header.filename_len", 11 | "expected": 8 12 | }, 13 | { 14 | "actual": "index.entries.size", 15 | "expected": 2 16 | }, 17 | { 18 | "actual": "index.entries[0].filename", 19 | "expected": "\"FIRST___\"" 20 | }, 21 | { 22 | "actual": "index.entries[1].filename", 23 | "expected": "\"SECOND__\"" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/tests/switch_manual_enum_invalid.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "switch_manual_enum_invalid", 3 | "data": "enum_negative.bin", 4 | "asserts": [ 5 | { 6 | "actual": "opcodes.size", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "opcodes[0].code", 11 | "expected": 255 12 | }, 13 | { 14 | "actual": "opcodes[0].body", 15 | "expected": "null" 16 | }, 17 | { 18 | "actual": "opcodes[1].code", 19 | "expected": 1 20 | }, 21 | { 22 | "actual": "opcodes[1].body", 23 | "expected": "null" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/specs/enum_int_range_s.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_int_range_s", 4 | "endian": "be" 5 | }, 6 | "enums": { 7 | "constants": { 8 | "-2147483648": "int_min", 9 | "0": "zero", 10 | "2147483647": "int_max" 11 | } 12 | }, 13 | "seq": [ 14 | { 15 | "id": "f1", 16 | "type": "s4", 17 | "enum": "constants" 18 | }, 19 | { 20 | "id": "f2", 21 | "type": "s4", 22 | "enum": "constants" 23 | }, 24 | { 25 | "id": "f3", 26 | "type": "s4", 27 | "enum": "constants" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /testing/specs/if_values.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "if_values", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "codes", 9 | "type": "code", 10 | "repeat": "expr", 11 | "repeat-expr": 3 12 | } 13 | ], 14 | "types": { 15 | "code": { 16 | "seq": [ 17 | { 18 | "id": "opcode", 19 | "type": "u1" 20 | } 21 | ], 22 | "instances": { 23 | "half_opcode": { 24 | "value": "opcode / 2", 25 | "if": "opcode % 2 == 0" 26 | } 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /testing/specs/position_in_seq.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "position_in_seq", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "numbers", 9 | "type": "u1", 10 | "repeat": "expr", 11 | "repeat-expr": "header.qty_numbers" 12 | } 13 | ], 14 | "types": { 15 | "header_obj": { 16 | "seq": [ 17 | { 18 | "id": "qty_numbers", 19 | "type": "u4" 20 | } 21 | ] 22 | } 23 | }, 24 | "instances": { 25 | "header": { 26 | "pos": "0x10", 27 | "type": "header_obj" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /testing/tests/nav_parent.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nav_parent", 3 | "data": "nav.bin", 4 | "asserts": [ 5 | { 6 | "actual": "header.qty_entries", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "header.filename_len", 11 | "expected": 8 12 | }, 13 | { 14 | "actual": "index.entries.size", 15 | "expected": 2 16 | }, 17 | { 18 | "actual": "index.entries[0].filename", 19 | "expected": "\"FIRST___\"" 20 | }, 21 | { 22 | "actual": "index.entries[1].filename", 23 | "expected": "\"SECOND__\"" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/tests/nav_parent_false.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nav_parent_false", 3 | "data": "nav_parent_codes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "child_size", 7 | "expected": 3 8 | }, 9 | { 10 | "actual": "element_a.foo.code", 11 | "expected": 73 12 | }, 13 | { 14 | "actual": "element_a.foo.more", 15 | "expected": "[0x31, 0x32, 0x33]" 16 | }, 17 | { 18 | "actual": "element_a.bar.foo.code", 19 | "expected": 66 20 | }, 21 | { 22 | "actual": "element_b.foo.code", 23 | "expected": 98 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/specs/process_repeat_usertype.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_repeat_usertype", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "blocks", 9 | "size": 5, 10 | "type": "block", 11 | "repeat": "expr", 12 | "repeat-expr": 2, 13 | "process": "xor(0x9e)" 14 | } 15 | ], 16 | "types": { 17 | "block": { 18 | "seq": [ 19 | { 20 | "id": "a", 21 | "type": "s4" 22 | }, 23 | { 24 | "id": "b", 25 | "type": "s1" 26 | } 27 | ] 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /testing/specs/bytes_pad_term.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "bytes_pad_term" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "str_pad", 8 | "size": 20, 9 | "pad-right": "0x40" 10 | }, 11 | { 12 | "id": "str_term", 13 | "size": 20, 14 | "terminator": "0x40" 15 | }, 16 | { 17 | "id": "str_term_and_pad", 18 | "size": 20, 19 | "terminator": "0x40", 20 | "pad-right": "0x2b" 21 | }, 22 | { 23 | "id": "str_term_include", 24 | "size": 20, 25 | "terminator": "0x40", 26 | "include": true 27 | } 28 | ] 29 | } -------------------------------------------------------------------------------- /testing/specs/repeat_n_struct.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "repeat_n_struct", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "qty", 9 | "type": "u4" 10 | }, 11 | { 12 | "id": "chunks", 13 | "type": "chunk", 14 | "repeat": "expr", 15 | "repeat-expr": "qty" 16 | } 17 | ], 18 | "types": { 19 | "chunk": { 20 | "seq": [ 21 | { 22 | "id": "offset", 23 | "type": "u4" 24 | }, 25 | { 26 | "id": "len", 27 | "type": "u4" 28 | } 29 | ] 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /testing/tests/expr_mod.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_mod", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "int_u", 7 | "expected": 1262698832 8 | }, 9 | { 10 | "actual": "int_s", 11 | "expected": -52947 12 | }, 13 | { 14 | "actual": "mod_pos_const", 15 | "expected": 9 16 | }, 17 | { 18 | "actual": "mod_neg_const", 19 | "expected": 4 20 | }, 21 | { 22 | "actual": "mod_pos_seq", 23 | "expected": 5 24 | }, 25 | { 26 | "actual": "mod_neg_seq", 27 | "expected": 2 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /testing/tests/params_pass_array_usertype.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "params_pass_array_usertype", 3 | "data": "position_to_end.bin", 4 | "asserts": [ 5 | { 6 | "actual": "pass_blocks.bar.size", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "pass_blocks.bar[0].foo", 11 | "expected": 1 12 | }, 13 | { 14 | "actual": "pass_blocks.bar[1].foo", 15 | "expected": 2 16 | }, 17 | { 18 | "actual": "pass_blocks.one", 19 | "expected": "[3]" 20 | }, 21 | { 22 | "actual": "pass_blocks.two", 23 | "expected": "[4, 5]" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/specs/expr_enum.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_enum" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "one", 8 | "type": "u1" 9 | } 10 | ], 11 | "instances": { 12 | "const_dog": { 13 | "value": 4, 14 | "enum": "animal" 15 | }, 16 | "derived_boom": { 17 | "value": "one", 18 | "enum": "animal" 19 | }, 20 | "derived_dog": { 21 | "value": "one - 98", 22 | "enum": "animal" 23 | } 24 | }, 25 | "enums": { 26 | "animal": { 27 | "4": "dog", 28 | "7": "cat", 29 | "12": "chicken", 30 | "0x66": "boom" 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /testing/tests/expr_int_div.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_int_div", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "int_u", 7 | "expected": 1262698832 8 | }, 9 | { 10 | "actual": "int_s", 11 | "expected": -52947 12 | }, 13 | { 14 | "actual": "div_pos_const", 15 | "expected": 756 16 | }, 17 | { 18 | "actual": "div_neg_const", 19 | "expected": -757 20 | }, 21 | { 22 | "actual": "div_pos_seq", 23 | "expected": 97130679 24 | }, 25 | { 26 | "actual": "div_neg_seq", 27 | "expected": -4073 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /testing/tests/nested_same_name2.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nested_same_name2", 3 | "data": "nested_same_name2.bin", 4 | "asserts": [ 5 | { 6 | "actual": "version", 7 | "expected": "0x42" 8 | }, 9 | { 10 | "actual": "main_data.main_size", 11 | "expected": 2 12 | }, 13 | { 14 | "actual": "main_data.foo.data1", 15 | "expected": "[0x11, 0x11, 0x11, 0x11]" 16 | }, 17 | { 18 | "actual": "dummy.dummy_size", 19 | "expected": 3 20 | }, 21 | { 22 | "actual": "dummy.foo.data2", 23 | "expected": "[0x22, 0x22, 0x22, 0x22, 0x22, 0x22]" 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /src/nimitai/identutils.nim: -------------------------------------------------------------------------------- 1 | import strutils 2 | 3 | proc normId*(s: string): string = 4 | result = s 5 | while result[0] == '_': 6 | result.delete(0, 0) 7 | var i = 1 8 | while i < result.len: 9 | if result[i] == '_': 10 | result.delete(i, i) 11 | result[i] = result[i].toUpperAscii 12 | inc i 13 | 14 | proc isParsedId*(s: string): string = 15 | "is" & s.normId.capitalizeAscii 16 | 17 | proc instId*(s: string): string = 18 | s.normId & "Inst" 19 | 20 | proc variantId*(t, f: string): string = 21 | t & "_" & f.capitalizeAscii 22 | 23 | proc variantDiscrId*(t, f: string): string = 24 | variantId(t, f) & "Discr" 25 | -------------------------------------------------------------------------------- /testing/specs/recursive_one.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "recursive_one" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "one", 8 | "type": "u1" 9 | }, 10 | { 11 | "id": "next", 12 | "type": { 13 | "switch-on": "one & 3", 14 | "cases": { 15 | "0": "recursive_one", 16 | "1": "recursive_one", 17 | "2": "recursive_one", 18 | "3": "fini" 19 | } 20 | } 21 | } 22 | ], 23 | "types": { 24 | "fini": { 25 | "seq": [ 26 | { 27 | "id": "finisher", 28 | "type": "u2le" 29 | } 30 | ] 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /testing/tests/bytes_pad_term.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "bytes_pad_term", 3 | "data": "str_pad_term.bin", 4 | "asserts": [ 5 | { 6 | "actual": "str_pad", 7 | "expected": "[0x73, 0x74, 0x72, 0x31]" 8 | }, 9 | { 10 | "actual": "str_term", 11 | "expected": "[0x73, 0x74, 0x72, 0x32, 0x66, 0x6f, 0x6f]" 12 | }, 13 | { 14 | "actual": "str_term_and_pad", 15 | "expected": "[0x73, 0x74, 0x72, 0x2b, 0x2b, 0x2b, 0x33, 0x62, 0x61, 0x72, 0x2b, 0x2b, 0x2b]" 16 | }, 17 | { 18 | "actual": "str_term_include", 19 | "expected": "[0x73, 0x74, 0x72, 0x34, 0x62, 0x61, 0x7a, 0x40]" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /testing/specs/type_ternary_opaque.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "type_ternary_opaque", 4 | "ks-opaque-types": true 5 | }, 6 | "seq": [ 7 | { 8 | "id": "dif_wo_hack", 9 | "size": 12, 10 | "type": "term_strz", 11 | "if": "not is_hack" 12 | }, 13 | { 14 | "id": "dif_with_hack", 15 | "size": 12, 16 | "type": "term_strz", 17 | "process": "xor(0b00000011)", 18 | "if": "is_hack" 19 | } 20 | ], 21 | "instances": { 22 | "is_hack": { 23 | "value": "false" 24 | }, 25 | "dif": { 26 | "value": "not is_hack ? dif_wo_hack : dif_with_hack" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /testing/tests/imports_circular_a.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "imports_circular_a", 3 | "data": "fixed_struct.bin", 4 | "imports": [ 5 | "imports_circular_b" 6 | ], 7 | "asserts": [ 8 | { 9 | "actual": "code", 10 | "expected": "0x50" 11 | }, 12 | { 13 | "actual": "two.initial", 14 | "expected": "0x41" 15 | }, 16 | { 17 | "actual": "two.back_ref.code", 18 | "expected": "0x43" 19 | }, 20 | { 21 | "actual": "two.back_ref.two.initial", 22 | "expected": "0x4b" 23 | }, 24 | { 25 | "actual": "two.back_ref.two.back_ref", 26 | "expected": "null" 27 | } 28 | ] 29 | } -------------------------------------------------------------------------------- /testing/tests/if_values.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "if_values", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "codes[0].opcode", 7 | "expected": 80 8 | }, 9 | { 10 | "actual": "codes[0].half_opcode", 11 | "expected": 40 12 | }, 13 | { 14 | "actual": "codes[1].opcode", 15 | "expected": 65 16 | }, 17 | { 18 | "actual": "codes[1].half_opcode", 19 | "expected": "null" 20 | }, 21 | { 22 | "actual": "codes[2].opcode", 23 | "expected": 67 24 | }, 25 | { 26 | "actual": "codes[2].half_opcode", 27 | "expected": "null" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /testing/tests/index_sizes.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "index_sizes", 3 | "data": "index_sizes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "qty", 7 | "expected": 3 8 | }, 9 | { 10 | "actual": "sizes[0]", 11 | "expected": 1 12 | }, 13 | { 14 | "actual": "sizes[1]", 15 | "expected": 8 16 | }, 17 | { 18 | "actual": "sizes[2]", 19 | "expected": 4 20 | }, 21 | { 22 | "actual": "bufs[0]", 23 | "expected": "\"A\"" 24 | }, 25 | { 26 | "actual": "bufs[1]", 27 | "expected": "\"BBBBBBBB\"" 28 | }, 29 | { 30 | "actual": "bufs[2]", 31 | "expected": "\"CCCC\"" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/specs/bits_seq_endian_combo.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "bits_seq_endian_combo" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "be1", 8 | "type": "b6be" 9 | }, 10 | { 11 | "id": "be2", 12 | "type": "b10be" 13 | }, 14 | { 15 | "id": "le3", 16 | "type": "b8le" 17 | }, 18 | { 19 | "id": "be4", 20 | "type": "b8be" 21 | }, 22 | { 23 | "id": "le5", 24 | "type": "b5le" 25 | }, 26 | { 27 | "id": "le6", 28 | "type": "b6le" 29 | }, 30 | { 31 | "id": "le7", 32 | "type": "b5le" 33 | }, 34 | { 35 | "id": "be8", 36 | "type": "b1be" 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /testing/tests/bcd_user_type_be.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "bcd_user_type_be", 3 | "data": "bcd_user_type_be.bin", 4 | "asserts": [ 5 | { 6 | "actual": "ltr.as_int", 7 | "expected": 12345678 8 | }, 9 | { 10 | "actual": "ltr.as_str", 11 | "expected": "\"12345678\"" 12 | }, 13 | { 14 | "actual": "rtl.as_int", 15 | "expected": 87654321 16 | }, 17 | { 18 | "actual": "rtl.as_str", 19 | "expected": "\"87654321\"" 20 | }, 21 | { 22 | "actual": "leading_zero_ltr.as_int", 23 | "expected": 123456 24 | }, 25 | { 26 | "actual": "leading_zero_ltr.as_str", 27 | "expected": "\"00123456\"" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /testing/tests/bcd_user_type_le.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "bcd_user_type_le", 3 | "data": "bcd_user_type_le.bin", 4 | "asserts": [ 5 | { 6 | "actual": "ltr.as_int", 7 | "expected": 12345678 8 | }, 9 | { 10 | "actual": "ltr.as_str", 11 | "expected": "\"12345678\"" 12 | }, 13 | { 14 | "actual": "rtl.as_int", 15 | "expected": 87654321 16 | }, 17 | { 18 | "actual": "rtl.as_str", 19 | "expected": "\"87654321\"" 20 | }, 21 | { 22 | "actual": "leading_zero_ltr.as_int", 23 | "expected": 123456 24 | }, 25 | { 26 | "actual": "leading_zero_ltr.as_str", 27 | "expected": "\"00123456\"" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /testing/specs/nested_type_param.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "nested_type_param" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "main_seq", 8 | "type": "nested::my_type(5)" 9 | } 10 | ], 11 | "types": { 12 | "nested": { 13 | "types": { 14 | "my_type": { 15 | "params": [ 16 | { 17 | "id": "my_len", 18 | "type": "u4" 19 | } 20 | ], 21 | "seq": [ 22 | { 23 | "id": "body", 24 | "type": "str", 25 | "size": "my_len", 26 | "encoding": "ASCII" 27 | } 28 | ] 29 | } 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /testing/tests/switch_manual_enum_invalid_else.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "switch_manual_enum_invalid_else", 3 | "data": "enum_negative.bin", 4 | "asserts": [ 5 | { 6 | "actual": "opcodes.size", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "opcodes[0].code", 11 | "expected": 255 12 | }, 13 | { 14 | "actual": "opcodes[0].body.as.value", 15 | "expected": 123 16 | }, 17 | { 18 | "actual": "opcodes[1].code", 19 | "expected": 1 20 | }, 21 | { 22 | "actual": "opcodes[1].body.as.value", 23 | "expected": 123 24 | } 25 | ] 26 | } -------------------------------------------------------------------------------- /testing/specs/enum_fancy.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_fancy", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "pet_1", 9 | "type": "u4", 10 | "enum": "animal" 11 | }, 12 | { 13 | "id": "pet_2", 14 | "type": "u4", 15 | "enum": "animal" 16 | } 17 | ], 18 | "enums": { 19 | "animal": { 20 | "4": { 21 | "id": "dog", 22 | "doc": "A member of genus Canis.", 23 | "-orig-id": "MH_CANINE" 24 | }, 25 | "7": { 26 | "id": "cat", 27 | "doc": "Small, typically furry, carnivorous mammal.", 28 | "-orig-id": "MH_FELINE" 29 | }, 30 | "12": "chicken" 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /testing/specs/enum_to_i.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_to_i", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "pet_1", 9 | "type": "u4", 10 | "enum": "animal" 11 | }, 12 | { 13 | "id": "pet_2", 14 | "type": "u4", 15 | "enum": "animal" 16 | } 17 | ], 18 | "enums": { 19 | "animal": { 20 | "4": "dog", 21 | "7": "cat", 22 | "12": "chicken" 23 | } 24 | }, 25 | "instances": { 26 | "pet_1_i": { 27 | "value": "pet_1.to_i" 28 | }, 29 | "pet_1_mod": { 30 | "value": "pet_1.to_i + 0x8000" 31 | }, 32 | "one_lt_two": { 33 | "value": "pet_1.to_i < pet_2.to_i" 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /testing/specs/io_local_var.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "io_local_var" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "skip", 8 | "size": 20 9 | }, 10 | { 11 | "id": "always_null", 12 | "type": "u1", 13 | "if": "mess_up.as._io.pos < 0" 14 | }, 15 | { 16 | "id": "followup", 17 | "type": "u1" 18 | } 19 | ], 20 | "instances": { 21 | "mess_up": { 22 | "io": "_root._io", 23 | "pos": 8, 24 | "size": 2, 25 | "type": { 26 | "switch-on": 2, 27 | "cases": { 28 | "1": "dummy", 29 | "2": "dummy" 30 | } 31 | } 32 | } 33 | }, 34 | "types": { 35 | "dummy": {} 36 | } 37 | } -------------------------------------------------------------------------------- /testing/specs/enum_of_value_inst.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_of_value_inst", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "pet_1", 9 | "type": "u4", 10 | "enum": "animal" 11 | }, 12 | { 13 | "id": "pet_2", 14 | "type": "u4", 15 | "enum": "animal" 16 | } 17 | ], 18 | "enums": { 19 | "animal": { 20 | "4": "dog", 21 | "7": "cat", 22 | "12": "chicken" 23 | } 24 | }, 25 | "instances": { 26 | "pet_3": { 27 | "value": "pet_1 == animal::cat ? 4 : 12", 28 | "enum": "animal" 29 | }, 30 | "pet_4": { 31 | "value": "pet_1 == animal::cat ? animal::dog : animal::chicken" 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /testing/specs/switch_integers.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "switch_integers", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "opcodes", 9 | "type": "opcode", 10 | "repeat": "eos" 11 | } 12 | ], 13 | "types": { 14 | "opcode": { 15 | "seq": [ 16 | { 17 | "id": "code", 18 | "type": "u1" 19 | }, 20 | { 21 | "id": "body", 22 | "type": { 23 | "switch-on": "code", 24 | "cases": { 25 | "1": "u1", 26 | "2": "u2", 27 | "4": "u4", 28 | "8": "u8" 29 | } 30 | } 31 | } 32 | ] 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /testing/tests/index_to_param_eos.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "index_to_param_eos", 3 | "data": "index_sizes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "qty", 7 | "expected": 3 8 | }, 9 | { 10 | "actual": "sizes[0]", 11 | "expected": 1 12 | }, 13 | { 14 | "actual": "sizes[1]", 15 | "expected": 8 16 | }, 17 | { 18 | "actual": "sizes[2]", 19 | "expected": 4 20 | }, 21 | { 22 | "actual": "blocks[0].buf", 23 | "expected": "\"A\"" 24 | }, 25 | { 26 | "actual": "blocks[1].buf", 27 | "expected": "\"BBBBBBBB\"" 28 | }, 29 | { 30 | "actual": "blocks[2].buf", 31 | "expected": "\"CCCC\"" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/tests/index_to_param_expr.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "index_to_param_expr", 3 | "data": "index_sizes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "qty", 7 | "expected": 3 8 | }, 9 | { 10 | "actual": "sizes[0]", 11 | "expected": 1 12 | }, 13 | { 14 | "actual": "sizes[1]", 15 | "expected": 8 16 | }, 17 | { 18 | "actual": "sizes[2]", 19 | "expected": 4 20 | }, 21 | { 22 | "actual": "blocks[0].buf", 23 | "expected": "\"A\"" 24 | }, 25 | { 26 | "actual": "blocks[1].buf", 27 | "expected": "\"BBBBBBBB\"" 28 | }, 29 | { 30 | "actual": "blocks[2].buf", 31 | "expected": "\"CCCC\"" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/tests/index_to_param_until.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "index_to_param_until", 3 | "data": "index_sizes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "qty", 7 | "expected": 3 8 | }, 9 | { 10 | "actual": "sizes[0]", 11 | "expected": 1 12 | }, 13 | { 14 | "actual": "sizes[1]", 15 | "expected": 8 16 | }, 17 | { 18 | "actual": "sizes[2]", 19 | "expected": 4 20 | }, 21 | { 22 | "actual": "blocks[0].buf", 23 | "expected": "\"A\"" 24 | }, 25 | { 26 | "actual": "blocks[1].buf", 27 | "expected": "\"BBBBBBBB\"" 28 | }, 29 | { 30 | "actual": "blocks[2].buf", 31 | "expected": "\"CCCC\"" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/specs/str_pad_term.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "str_pad_term", 4 | "encoding": "UTF-8" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "str_pad", 9 | "type": "str", 10 | "size": 20, 11 | "pad-right": "0x40" 12 | }, 13 | { 14 | "id": "str_term", 15 | "type": "str", 16 | "size": 20, 17 | "terminator": "0x40" 18 | }, 19 | { 20 | "id": "str_term_and_pad", 21 | "type": "str", 22 | "size": 20, 23 | "terminator": "0x40", 24 | "pad-right": "0x2b" 25 | }, 26 | { 27 | "id": "str_term_include", 28 | "type": "str", 29 | "size": 20, 30 | "terminator": "0x40", 31 | "include": true 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/tests/buffered_struct.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "buffered_struct", 3 | "data": "buffered_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "len1", 7 | "expected": "0x10" 8 | }, 9 | { 10 | "actual": "block1.number1", 11 | "expected": "0x42" 12 | }, 13 | { 14 | "actual": "block1.number2", 15 | "expected": "0x43" 16 | }, 17 | { 18 | "actual": "len2", 19 | "expected": "0x8" 20 | }, 21 | { 22 | "actual": "block2.number1", 23 | "expected": "0x44" 24 | }, 25 | { 26 | "actual": "block2.number2", 27 | "expected": "0x45" 28 | }, 29 | { 30 | "actual": "finisher", 31 | "expected": "0xee" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/tests/expr_io_pos.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_io_pos", 3 | "data": "expr_io_pos.bin", 4 | "asserts": [ 5 | { 6 | "actual": "substream1.my_str", 7 | "expected": "\"CURIOSITY\"" 8 | }, 9 | { 10 | "actual": "substream1.body", 11 | "expected": "[0x11, 0x22, 0x33, 0x44]" 12 | }, 13 | { 14 | "actual": "substream1.number", 15 | "expected": "0x42" 16 | }, 17 | { 18 | "actual": "substream2.my_str", 19 | "expected": "\"KILLED\"" 20 | }, 21 | { 22 | "actual": "substream2.body", 23 | "expected": "[0x61, 0x20, 0x63, 0x61, 0x74]" 24 | }, 25 | { 26 | "actual": "substream2.number", 27 | "expected": "0x67" 28 | } 29 | ] 30 | } -------------------------------------------------------------------------------- /testing/specs/params_pass_usertype.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "params_pass_usertype" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "first", 8 | "type": "block" 9 | }, 10 | { 11 | "id": "one", 12 | "type": "param_type(first)" 13 | } 14 | ], 15 | "types": { 16 | "block": { 17 | "seq": [ 18 | { 19 | "id": "foo", 20 | "type": "u1" 21 | } 22 | ] 23 | }, 24 | "param_type": { 25 | "params": [ 26 | { 27 | "id": "foo", 28 | "type": "block" 29 | } 30 | ], 31 | "seq": [ 32 | { 33 | "id": "buf", 34 | "size": "foo.foo" 35 | } 36 | ] 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /testing/specs/nav_parent_override.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "nav_parent_override" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "child_size", 8 | "type": "u1" 9 | }, 10 | { 11 | "id": "child_1", 12 | "type": "child" 13 | }, 14 | { 15 | "id": "mediator_2", 16 | "type": "mediator" 17 | } 18 | ], 19 | "types": { 20 | "mediator": { 21 | "seq": [ 22 | { 23 | "id": "child_2", 24 | "type": "child", 25 | "parent": "_parent" 26 | } 27 | ] 28 | }, 29 | "child": { 30 | "seq": [ 31 | { 32 | "id": "data", 33 | "size": "_parent.child_size" 34 | } 35 | ] 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /testing/specs/str_pad_term_empty.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "str_pad_term_empty", 4 | "encoding": "UTF-8" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "str_pad", 9 | "type": "str", 10 | "size": 20, 11 | "pad-right": "0x40" 12 | }, 13 | { 14 | "id": "str_term", 15 | "type": "str", 16 | "size": 20, 17 | "terminator": "0x40" 18 | }, 19 | { 20 | "id": "str_term_and_pad", 21 | "type": "str", 22 | "size": 20, 23 | "terminator": "0x40", 24 | "pad-right": "0x2b" 25 | }, 26 | { 27 | "id": "str_term_include", 28 | "type": "str", 29 | "size": 20, 30 | "terminator": "0x40", 31 | "include": true 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/specs/switch_integers2.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "switch_integers2", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "code", 9 | "type": "u1" 10 | }, 11 | { 12 | "id": "len", 13 | "type": { 14 | "switch-on": "code", 15 | "cases": { 16 | "1": "u1", 17 | "2": "u2", 18 | "4": "u4", 19 | "8": "u8" 20 | } 21 | } 22 | }, 23 | { 24 | "id": "ham", 25 | "size": "len" 26 | }, 27 | { 28 | "id": "padding", 29 | "type": "u1", 30 | "if": "len > 3" 31 | } 32 | ], 33 | "instances": { 34 | "len_mod_str": { 35 | "value": "(len * 2 - 1).to_s" 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /testing/specs/enum_long_range_u.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_long_range_u", 4 | "endian": "be" 5 | }, 6 | "enums": { 7 | "constants": { 8 | "0": "zero", 9 | "4294967295": "int_max", 10 | "4294967296": "int_over_max", 11 | "9223372036854775807": "long_max" 12 | } 13 | }, 14 | "seq": [ 15 | { 16 | "id": "f1", 17 | "type": "u8", 18 | "enum": "constants" 19 | }, 20 | { 21 | "id": "f2", 22 | "type": "u8", 23 | "enum": "constants" 24 | }, 25 | { 26 | "id": "f3", 27 | "type": "u8", 28 | "enum": "constants" 29 | }, 30 | { 31 | "id": "f4", 32 | "type": "u8", 33 | "enum": "constants" 34 | } 35 | ] 36 | } -------------------------------------------------------------------------------- /testing/tests/if_struct.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "if_struct", 3 | "data": "if_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "op1.opcode", 7 | "expected": "0x53" 8 | }, 9 | { 10 | "actual": "op1.arg_str.str", 11 | "expected": "\"foo\"" 12 | }, 13 | { 14 | "actual": "op2.opcode", 15 | "expected": "0x54" 16 | }, 17 | { 18 | "actual": "op2.arg_tuple.num1", 19 | "expected": "0x42" 20 | }, 21 | { 22 | "actual": "op2.arg_tuple.num2", 23 | "expected": "0x43" 24 | }, 25 | { 26 | "actual": "op3.opcode", 27 | "expected": "0x53" 28 | }, 29 | { 30 | "actual": "op3.arg_str.str", 31 | "expected": "\"bar\"" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/specs/params_pass_array_int.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "params_pass_array_int", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "ints", 9 | "type": "u2", 10 | "repeat": "expr", 11 | "repeat-expr": 3 12 | }, 13 | { 14 | "id": "pass_ints", 15 | "type": "wants_ints(ints)" 16 | }, 17 | { 18 | "id": "pass_ints_calc", 19 | "type": "wants_ints(ints_calc)" 20 | } 21 | ], 22 | "types": { 23 | "wants_ints": { 24 | "params": [ 25 | { 26 | "id": "nums", 27 | "type": "u2[]" 28 | } 29 | ] 30 | } 31 | }, 32 | "instances": { 33 | "ints_calc": { 34 | "value": "[27643, 7]" 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /testing/specs/bits_byte_aligned.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "bits_byte_aligned" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "one", 8 | "type": "b6" 9 | }, 10 | { 11 | "id": "byte_1", 12 | "type": "u1" 13 | }, 14 | { 15 | "id": "two", 16 | "type": "b3" 17 | }, 18 | { 19 | "id": "three", 20 | "type": "b1" 21 | }, 22 | { 23 | "id": "byte_2", 24 | "type": "u1" 25 | }, 26 | { 27 | "id": "four", 28 | "type": "b14" 29 | }, 30 | { 31 | "id": "byte_3", 32 | "size": 1 33 | }, 34 | { 35 | "id": "full_byte", 36 | "type": "b8" 37 | }, 38 | { 39 | "id": "byte_4", 40 | "type": "u1" 41 | } 42 | ] 43 | } -------------------------------------------------------------------------------- /testing/specs/debug_switch_user.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "debug_switch_user", 4 | "endian": "le", 5 | "ks-debug": true 6 | }, 7 | "seq": [ 8 | { 9 | "id": "code", 10 | "type": "u1" 11 | }, 12 | { 13 | "id": "data", 14 | "type": { 15 | "switch-on": "code", 16 | "cases": { 17 | "1": "one", 18 | "2": "two" 19 | } 20 | } 21 | } 22 | ], 23 | "types": { 24 | "one": { 25 | "seq": [ 26 | { 27 | "id": "val", 28 | "type": "s2" 29 | } 30 | ] 31 | }, 32 | "two": { 33 | "seq": [ 34 | { 35 | "id": "val", 36 | "type": "u2" 37 | } 38 | ] 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /testing/specs/expr_io_eof.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_io_eof", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "substream1", 9 | "size": 4, 10 | "type": "one_or_two" 11 | }, 12 | { 13 | "id": "substream2", 14 | "size": 8, 15 | "type": "one_or_two" 16 | } 17 | ], 18 | "types": { 19 | "one_or_two": { 20 | "seq": [ 21 | { 22 | "id": "one", 23 | "type": "u4" 24 | }, 25 | { 26 | "id": "two", 27 | "type": "u4", 28 | "if": "not _io.eof" 29 | } 30 | ], 31 | "instances": { 32 | "reflect_eof": { 33 | "value": "_io.eof" 34 | } 35 | } 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /testing/tests/float_to_i.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "float_to_i", 3 | "data": "floating_points.bin", 4 | "asserts": [ 5 | { 6 | "actual": "single_value", 7 | "expected": 0.5 8 | }, 9 | { 10 | "actual": "double_value", 11 | "expected": 0.25 12 | }, 13 | { 14 | "actual": "single_i", 15 | "expected": 0 16 | }, 17 | { 18 | "actual": "double_i", 19 | "expected": 0 20 | }, 21 | { 22 | "actual": "float1_i", 23 | "expected": 1 24 | }, 25 | { 26 | "actual": "float2_i", 27 | "expected": 1 28 | }, 29 | { 30 | "actual": "float3_i", 31 | "expected": 1 32 | }, 33 | { 34 | "actual": "float4_i", 35 | "expected": -2 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /testing/specs/expr_io_pos.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_io_pos", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "substream1", 9 | "size": 16, 10 | "type": "all_plus_number" 11 | }, 12 | { 13 | "id": "substream2", 14 | "size": 14, 15 | "type": "all_plus_number" 16 | } 17 | ], 18 | "types": { 19 | "all_plus_number": { 20 | "seq": [ 21 | { 22 | "id": "my_str", 23 | "type": "strz", 24 | "encoding": "UTF-8" 25 | }, 26 | { 27 | "id": "body", 28 | "size": "_io.size - _io.pos - 2" 29 | }, 30 | { 31 | "id": "number", 32 | "type": "u2" 33 | } 34 | ] 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /testing/specs/enum_to_i_class_border_1.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_to_i_class_border_1", 4 | "endian": "le", 5 | "imports": [ 6 | "enum_to_i_class_border_2" 7 | ] 8 | }, 9 | "seq": [ 10 | { 11 | "id": "pet_1", 12 | "type": "u4", 13 | "enum": "animal" 14 | }, 15 | { 16 | "id": "pet_2", 17 | "type": "u4", 18 | "enum": "animal" 19 | } 20 | ], 21 | "enums": { 22 | "animal": { 23 | "4": "dog", 24 | "7": "cat", 25 | "12": "chicken" 26 | } 27 | }, 28 | "instances": { 29 | "some_dog": { 30 | "value": 4, 31 | "enum": "animal" 32 | }, 33 | "checker": { 34 | "pos": 0, 35 | "type": "enum_to_i_class_border_2(_root)" 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /testing/specs/multiple_use.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "multiple_use", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "t1", 9 | "type": "type_1" 10 | }, 11 | { 12 | "id": "t2", 13 | "type": "type_2" 14 | } 15 | ], 16 | "types": { 17 | "multi": { 18 | "seq": [ 19 | { 20 | "id": "value", 21 | "type": "s4" 22 | } 23 | ] 24 | }, 25 | "type_1": { 26 | "seq": [ 27 | { 28 | "id": "first_use", 29 | "type": "multi" 30 | } 31 | ] 32 | }, 33 | "type_2": { 34 | "instances": { 35 | "second_use": { 36 | "pos": 0, 37 | "type": "multi" 38 | } 39 | } 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /testing/specs/repeat_until_calc_array_type.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "repeat_until_calc_array_type", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "records", 9 | "size": 5, 10 | "type": "record", 11 | "repeat": "until", 12 | "repeat-until": "_.marker == 0xaa" 13 | } 14 | ], 15 | "types": { 16 | "record": { 17 | "seq": [ 18 | { 19 | "id": "marker", 20 | "type": "u1" 21 | }, 22 | { 23 | "id": "body", 24 | "type": "u4" 25 | } 26 | ] 27 | } 28 | }, 29 | "instances": { 30 | "recs_accessor": { 31 | "value": "records" 32 | }, 33 | "first_rec": { 34 | "value": "recs_accessor.first" 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /testing/tests/instance_std_array.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "instance_std_array", 3 | "data": "instance_std_array.bin", 4 | "asserts": [ 5 | { 6 | "actual": "ofs", 7 | "expected": "0x10" 8 | }, 9 | { 10 | "actual": "qty_entries", 11 | "expected": 3 12 | }, 13 | { 14 | "actual": "entry_size", 15 | "expected": 4 16 | }, 17 | { 18 | "actual": "entries.size", 19 | "expected": 3 20 | }, 21 | { 22 | "actual": "entries[0]", 23 | "expected": "[0x11, 0x11, 0x11, 0x11]" 24 | }, 25 | { 26 | "actual": "entries[1]", 27 | "expected": "[0x22, 0x22, 0x22, 0x22]" 28 | }, 29 | { 30 | "actual": "entries[2]", 31 | "expected": "[0x33, 0x33, 0x33, 0x33]" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/tests/params_pass_array_int.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "params_pass_array_int", 3 | "data": "position_to_end.bin", 4 | "asserts": [ 5 | { 6 | "actual": "pass_ints.nums.size", 7 | "expected": 3 8 | }, 9 | { 10 | "actual": "pass_ints.nums[0]", 11 | "expected": 513 12 | }, 13 | { 14 | "actual": "pass_ints.nums[1]", 15 | "expected": 1027 16 | }, 17 | { 18 | "actual": "pass_ints.nums[2]", 19 | "expected": 1541 20 | }, 21 | { 22 | "actual": "pass_ints_calc.nums.size", 23 | "expected": 2 24 | }, 25 | { 26 | "actual": "pass_ints_calc.nums[0]", 27 | "expected": 27643 28 | }, 29 | { 30 | "actual": "pass_ints_calc.nums[1]", 31 | "expected": 7 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/specs/params_enum.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "params_enum" 4 | }, 5 | "enums": { 6 | "animal": { 7 | "4": "dog", 8 | "7": "cat", 9 | "12": "chicken" 10 | } 11 | }, 12 | "seq": [ 13 | { 14 | "id": "one", 15 | "type": "u1", 16 | "enum": "animal" 17 | }, 18 | { 19 | "id": "invoke_with_param", 20 | "type": "with_param(one)" 21 | } 22 | ], 23 | "types": { 24 | "with_param": { 25 | "params": [ 26 | { 27 | "id": "enumerated_one", 28 | "type": "u1", 29 | "enum": "animal" 30 | } 31 | ], 32 | "instances": { 33 | "is_cat": { 34 | "value": "enumerated_one == animal::cat" 35 | } 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /testing/tests/repeat_until_sized.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "repeat_until_sized", 3 | "data": "repeat_until_process.bin", 4 | "asserts": [ 5 | { 6 | "actual": "records.size", 7 | "expected": 3 8 | }, 9 | { 10 | "actual": "records[0].marker", 11 | "expected": "0xe8" 12 | }, 13 | { 14 | "actual": "records[0].body", 15 | "expected": "0xaaaaaaba" 16 | }, 17 | { 18 | "actual": "records[1].marker", 19 | "expected": "0xfa" 20 | }, 21 | { 22 | "actual": "records[1].body", 23 | "expected": "0xaaaab89e" 24 | }, 25 | { 26 | "actual": "records[2].marker", 27 | "expected": "0xaa" 28 | }, 29 | { 30 | "actual": "records[2].body", 31 | "expected": "0x55555555" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/tests/bits_seq_endian_combo.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "bits_seq_endian_combo", 3 | "data": "process_xor_4.bin", 4 | "asserts": [ 5 | { 6 | "actual": "be1", 7 | "expected": "0b111011" 8 | }, 9 | { 10 | "actual": "be2", 11 | "expected": "0b00_10111011" 12 | }, 13 | { 14 | "actual": "le3", 15 | "expected": "0xA3" 16 | }, 17 | { 18 | "actual": "be4", 19 | "expected": "0x14" 20 | }, 21 | { 22 | "actual": "le5", 23 | "expected": "0b01010" 24 | }, 25 | { 26 | "actual": "le6", 27 | "expected": "0b100100" 28 | }, 29 | { 30 | "actual": "le7", 31 | "expected": "0b11010" 32 | }, 33 | { 34 | "actual": "be8", 35 | "expected": true 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /testing/tests/repeat_until_calc_array_type.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "repeat_until_calc_array_type", 3 | "data": "repeat_until_process.bin", 4 | "asserts": [ 5 | { 6 | "actual": "records.size", 7 | "expected": 3 8 | }, 9 | { 10 | "actual": "records[0].marker", 11 | "expected": 232 12 | }, 13 | { 14 | "actual": "records[0].body", 15 | "expected": 2863311546 16 | }, 17 | { 18 | "actual": "records[1].marker", 19 | "expected": 250 20 | }, 21 | { 22 | "actual": "records[1].body", 23 | "expected": 2863315102 24 | }, 25 | { 26 | "actual": "records[2].marker", 27 | "expected": 170 28 | }, 29 | { 30 | "actual": "records[2].body", 31 | "expected": 1431655765 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/specs/switch_else_only.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "switch_else_only" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "opcode", 8 | "type": "s1" 9 | }, 10 | { 11 | "id": "prim_byte", 12 | "type": { 13 | "switch-on": "opcode", 14 | "cases": { 15 | "_": "s1" 16 | } 17 | } 18 | }, 19 | { 20 | "id": "indicator", 21 | "size": 4 22 | }, 23 | { 24 | "id": "ut", 25 | "type": { 26 | "switch-on": "indicator", 27 | "cases": { 28 | "_": "data" 29 | } 30 | } 31 | } 32 | ], 33 | "types": { 34 | "data": { 35 | "seq": [ 36 | { 37 | "id": "value", 38 | "size": 4 39 | } 40 | ] 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /testing/specs/switch_multi_bool_ops.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "switch_multi_bool_ops", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "opcodes", 9 | "type": "opcode", 10 | "repeat": "eos" 11 | } 12 | ], 13 | "types": { 14 | "opcode": { 15 | "seq": [ 16 | { 17 | "id": "code", 18 | "type": "u1" 19 | }, 20 | { 21 | "id": "body", 22 | "type": { 23 | "switch-on": "( (code > 0) and (code <= 8) and ((code != 10) ? true : false)) ? code : 0", 24 | "cases": { 25 | "1": "u1", 26 | "2": "u2", 27 | "4": "u4", 28 | "8": "u8" 29 | } 30 | } 31 | } 32 | ] 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /testing/specs/type_ternary.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "type_ternary" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "dif_wo_hack", 8 | "size": 1, 9 | "type": "dummy", 10 | "if": "not is_hack" 11 | }, 12 | { 13 | "id": "dif_with_hack", 14 | "size": 1, 15 | "type": "dummy", 16 | "process": "xor(0b00000011)" 17 | } 18 | ], 19 | "types": { 20 | "dummy": { 21 | "seq": [ 22 | { 23 | "id": "value", 24 | "type": "u1" 25 | } 26 | ] 27 | } 28 | }, 29 | "instances": { 30 | "is_hack": { 31 | "value": "true" 32 | }, 33 | "dif": { 34 | "value": "not is_hack ? dif_wo_hack : dif_with_hack" 35 | }, 36 | "dif_value": { 37 | "value": "dif.value" 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /testing/tests/enum_if.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_if", 3 | "data": "if_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "op1.opcode", 7 | "expected": "enum_if::opcodes::a_string" 8 | }, 9 | { 10 | "actual": "op1.arg_str.str", 11 | "expected": "\"foo\"" 12 | }, 13 | { 14 | "actual": "op2.opcode", 15 | "expected": "enum_if::opcodes::a_tuple" 16 | }, 17 | { 18 | "actual": "op2.arg_tuple.num1", 19 | "expected": "0x42" 20 | }, 21 | { 22 | "actual": "op2.arg_tuple.num2", 23 | "expected": "0x43" 24 | }, 25 | { 26 | "actual": "op3.opcode", 27 | "expected": "enum_if::opcodes::a_string" 28 | }, 29 | { 30 | "actual": "op3.arg_str.str", 31 | "expected": "\"bar\"" 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /testing/specs/params_pass_array_str.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "params_pass_array_str", 4 | "encoding": "ascii" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "str_array", 9 | "type": "str", 10 | "size": 2, 11 | "repeat": "expr", 12 | "repeat-expr": 3 13 | }, 14 | { 15 | "id": "pass_str_array", 16 | "type": "wants_strs(str_array)" 17 | }, 18 | { 19 | "id": "pass_str_array_calc", 20 | "type": "wants_strs(str_array_calc)" 21 | } 22 | ], 23 | "types": { 24 | "wants_strs": { 25 | "params": [ 26 | { 27 | "id": "strs", 28 | "type": "str[]" 29 | } 30 | ] 31 | } 32 | }, 33 | "instances": { 34 | "str_array_calc": { 35 | "value": "[\"aB\", \"Cd\"]" 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /testing/tests/nested_types2.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nested_types2", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "one.typed_at_root.value_b", 7 | "expected": 80 8 | }, 9 | { 10 | "actual": "one.typed_here1.value_c", 11 | "expected": 65 12 | }, 13 | { 14 | "actual": "one.typed_here1.typed_here.value_d", 15 | "expected": 67 16 | }, 17 | { 18 | "actual": "one.typed_here1.typed_parent.value_cc", 19 | "expected": 75 20 | }, 21 | { 22 | "actual": "one.typed_here1.typed_root.value_b", 23 | "expected": 45 24 | }, 25 | { 26 | "actual": "one.typed_here2.value_cc", 27 | "expected": 49 28 | }, 29 | { 30 | "actual": "two.value_b", 31 | "expected": -1 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/specs/buffered_struct.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "buffered_struct", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "len1", 9 | "type": "u4" 10 | }, 11 | { 12 | "id": "block1", 13 | "type": "block", 14 | "size": "len1" 15 | }, 16 | { 17 | "id": "len2", 18 | "type": "u4" 19 | }, 20 | { 21 | "id": "block2", 22 | "type": "block", 23 | "size": "len2" 24 | }, 25 | { 26 | "id": "finisher", 27 | "type": "u4" 28 | } 29 | ], 30 | "types": { 31 | "block": { 32 | "seq": [ 33 | { 34 | "id": "number1", 35 | "type": "u4" 36 | }, 37 | { 38 | "id": "number2", 39 | "type": "u4" 40 | } 41 | ] 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /testing/tests/ts_packet_header.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "ts_packet_header", 3 | "data": "ts_packet.bin", 4 | "asserts": [ 5 | { 6 | "actual": "sync_byte", 7 | "expected": "0x47" 8 | }, 9 | { 10 | "actual": "transport_error_indicator", 11 | "expected": false 12 | }, 13 | { 14 | "actual": "payload_unit_start_indicator", 15 | "expected": false 16 | }, 17 | { 18 | "actual": "transport_priority", 19 | "expected": true 20 | }, 21 | { 22 | "actual": "pid", 23 | "expected": 33 24 | }, 25 | { 26 | "actual": "transport_scrambling_control", 27 | "expected": 0 28 | }, 29 | { 30 | "actual": "adaptation_field_control", 31 | "expected": "ts_packet_header::adaptation_field_control_enum::payload_only" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/specs/floating_points.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "floating_points", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "single_value", 9 | "type": "f4" 10 | }, 11 | { 12 | "id": "double_value", 13 | "type": "f8" 14 | }, 15 | { 16 | "id": "single_value_be", 17 | "type": "f4be" 18 | }, 19 | { 20 | "id": "double_value_be", 21 | "type": "f8be" 22 | }, 23 | { 24 | "id": "approximate_value", 25 | "type": "f4" 26 | } 27 | ], 28 | "instances": { 29 | "single_value_plus_int": { 30 | "value": "single_value + 1" 31 | }, 32 | "single_value_plus_float": { 33 | "value": "single_value + 0.5" 34 | }, 35 | "double_value_plus_float": { 36 | "value": "double_value + 0.05" 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /testing/tests/expr_ops_parens.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_ops_parens", 3 | "data": "enum_negative.bin", 4 | "asserts": [ 5 | { 6 | "actual": "i_sum_to_str", 7 | "expected": "\"29\"" 8 | }, 9 | { 10 | "actual": "str_concat_len", 11 | "expected": 10 12 | }, 13 | { 14 | "actual": "str_concat_rev", 15 | "expected": "\"9876543210\"" 16 | }, 17 | { 18 | "actual": "str_concat_substr_2_to_7", 19 | "expected": "\"23456\"" 20 | }, 21 | { 22 | "actual": "str_concat_to_i", 23 | "expected": 123456789 24 | }, 25 | { 26 | "actual": "bool_eq", 27 | "expected": 0 28 | }, 29 | { 30 | "actual": "bool_and", 31 | "expected": 0 32 | }, 33 | { 34 | "actual": "bool_or", 35 | "expected": 1 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /testing/tests/params_pass_array_str.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "params_pass_array_str", 3 | "data": "term_strz.bin", 4 | "asserts": [ 5 | { 6 | "actual": "pass_str_array.strs.size", 7 | "expected": 3 8 | }, 9 | { 10 | "actual": "pass_str_array.strs[0]", 11 | "expected": "\"fo\"" 12 | }, 13 | { 14 | "actual": "pass_str_array.strs[1]", 15 | "expected": "\"o|\"" 16 | }, 17 | { 18 | "actual": "pass_str_array.strs[2]", 19 | "expected": "\"ba\"" 20 | }, 21 | { 22 | "actual": "pass_str_array_calc.strs.size", 23 | "expected": 2 24 | }, 25 | { 26 | "actual": "pass_str_array_calc.strs[0]", 27 | "expected": "\"aB\"" 28 | }, 29 | { 30 | "actual": "pass_str_array_calc.strs[1]", 31 | "expected": "\"Cd\"" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/specs/enum_deep.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_deep", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "pet_1", 9 | "type": "u4", 10 | "enum": "container1::animal" 11 | }, 12 | { 13 | "id": "pet_2", 14 | "type": "u4", 15 | "enum": "container1::container2::animal" 16 | } 17 | ], 18 | "types": { 19 | "container1": { 20 | "enums": { 21 | "animal": { 22 | "4": "dog", 23 | "7": "cat", 24 | "12": "chicken" 25 | } 26 | }, 27 | "types": { 28 | "container2": { 29 | "enums": { 30 | "animal": { 31 | "4": "canary", 32 | "7": "turtle", 33 | "12": "hare" 34 | } 35 | } 36 | } 37 | } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /testing/specs/process_coerce_bytes.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_coerce_bytes" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "records", 8 | "type": "record", 9 | "repeat": "expr", 10 | "repeat-expr": 2 11 | } 12 | ], 13 | "types": { 14 | "record": { 15 | "seq": [ 16 | { 17 | "id": "flag", 18 | "type": "u1" 19 | }, 20 | { 21 | "id": "buf_unproc", 22 | "size": 4, 23 | "if": "flag == 0" 24 | }, 25 | { 26 | "id": "buf_proc", 27 | "size": 4, 28 | "process": "xor(0xaa)", 29 | "if": "flag != 0" 30 | } 31 | ], 32 | "instances": { 33 | "buf": { 34 | "value": "flag == 0 ? buf_unproc : buf_proc" 35 | } 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /testing/specs/index_to_param_eos.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "index_to_param_eos", 4 | "endian": "le", 5 | "encoding": "ASCII" 6 | }, 7 | "seq": [ 8 | { 9 | "id": "qty", 10 | "type": "u4" 11 | }, 12 | { 13 | "id": "sizes", 14 | "type": "u4", 15 | "repeat": "expr", 16 | "repeat-expr": "qty" 17 | }, 18 | { 19 | "id": "blocks", 20 | "type": "block(_index)", 21 | "repeat": "eos" 22 | } 23 | ], 24 | "types": { 25 | "block": { 26 | "params": [ 27 | { 28 | "id": "idx", 29 | "type": "s4" 30 | } 31 | ], 32 | "seq": [ 33 | { 34 | "id": "buf", 35 | "size": "_root.sizes[idx]", 36 | "type": "str", 37 | "encoding": "ASCII" 38 | } 39 | ] 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /testing/specs/nav_parent_switch.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "nav_parent_switch" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "category", 8 | "type": "u1" 9 | }, 10 | { 11 | "id": "content", 12 | "type": { 13 | "switch-on": "category", 14 | "cases": { 15 | "1": "element_1" 16 | } 17 | } 18 | } 19 | ], 20 | "types": { 21 | "element_1": { 22 | "seq": [ 23 | { 24 | "id": "foo", 25 | "type": "u1" 26 | }, 27 | { 28 | "id": "subelement", 29 | "type": "subelement_1" 30 | } 31 | ] 32 | }, 33 | "subelement_1": { 34 | "seq": [ 35 | { 36 | "id": "bar", 37 | "type": "u1", 38 | "if": "_parent.foo == 0x42" 39 | } 40 | ] 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /testing/tests/floating_points.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "floating_points", 3 | "data": "floating_points.bin", 4 | "asserts": [ 5 | { 6 | "actual": "single_value", 7 | "expected": "0.5.as" 8 | }, 9 | { 10 | "actual": "single_value_be", 11 | "expected": "0.5.as" 12 | }, 13 | { 14 | "actual": "double_value", 15 | "expected": 0.25 16 | }, 17 | { 18 | "actual": "double_value_be", 19 | "expected": 0.25 20 | }, 21 | { 22 | "actual": "approximate_value", 23 | "expected": 1.2345 24 | }, 25 | { 26 | "actual": "single_value_plus_int", 27 | "expected": 1.5 28 | }, 29 | { 30 | "actual": "single_value_plus_float", 31 | "expected": 1.0 32 | }, 33 | { 34 | "actual": "double_value_plus_float", 35 | "expected": 0.3 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /testing/specs/instance_user_array.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "instance_user_array", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "ofs", 9 | "type": "u4" 10 | }, 11 | { 12 | "id": "entry_size", 13 | "type": "u4" 14 | }, 15 | { 16 | "id": "qty_entries", 17 | "type": "u4" 18 | } 19 | ], 20 | "types": { 21 | "entry": { 22 | "seq": [ 23 | { 24 | "id": "word1", 25 | "type": "u2" 26 | }, 27 | { 28 | "id": "word2", 29 | "type": "u2" 30 | } 31 | ] 32 | } 33 | }, 34 | "instances": { 35 | "user_entries": { 36 | "pos": "ofs", 37 | "repeat": "expr", 38 | "repeat-expr": "qty_entries", 39 | "size": "entry_size", 40 | "type": "entry", 41 | "if": "ofs > 0" 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /testing/tests/bits_byte_aligned.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "bits_byte_aligned", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "one", 7 | "expected": "0b010100" 8 | }, 9 | { 10 | "actual": "byte_1", 11 | "expected": "0x41" 12 | }, 13 | { 14 | "actual": "two", 15 | "expected": "0b010" 16 | }, 17 | { 18 | "actual": "three", 19 | "expected": false 20 | }, 21 | { 22 | "actual": "byte_2", 23 | "expected": "0x4b" 24 | }, 25 | { 26 | "actual": "four", 27 | "expected": "0b00101101_001100" 28 | }, 29 | { 30 | "actual": "byte_3", 31 | "expected": "[0xff]" 32 | }, 33 | { 34 | "actual": "full_byte", 35 | "expected": "0xff" 36 | }, 37 | { 38 | "actual": "byte_4", 39 | "expected": "0x50" 40 | } 41 | ] 42 | } -------------------------------------------------------------------------------- /testing/README.md: -------------------------------------------------------------------------------- 1 | # Testing infrastructure for nimitai 2 | 3 | The suite is copied and adjusted from the Kaitai Struct project: 4 | * `subjects/`: mere copy of [`kaitai-io/kaitai_struct_tests/src/`](https://github.com/kaitai-io/kaitai_struct_tests/tree/master/src) 5 | * `specs/`: json equivelant of [`kaitai-io/kaitai_struct_tests/formats/`](https://github.com/kaitai-io/kaitai_struct_tests/tree/master/formats) 6 | * `tests/`: json equivelant of [`kaitai-io/kaitai_struct_tests/spec/ks/`](https://github.com/kaitai-io/kaitai_struct_tests/tree/master/spec/ks) 7 | 8 | Periodically these files will be updated with new adjusted copies from Kaitai Struct. 9 | 10 | Two tools are included: 11 | - `gen_suite`: Tries to generate `tests/compiled/*nim `from `tests/*.kst` 12 | - `run_suite`: Compiles and runs all generated `unittest`s 13 | Both programs must be run from the same directory where they resides 14 | -------------------------------------------------------------------------------- /testing/specs/index_to_param_expr.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "index_to_param_expr", 4 | "endian": "le", 5 | "encoding": "ASCII" 6 | }, 7 | "seq": [ 8 | { 9 | "id": "qty", 10 | "type": "u4" 11 | }, 12 | { 13 | "id": "sizes", 14 | "type": "u4", 15 | "repeat": "expr", 16 | "repeat-expr": "qty" 17 | }, 18 | { 19 | "id": "blocks", 20 | "type": "block(_index)", 21 | "repeat": "expr", 22 | "repeat-expr": "qty" 23 | } 24 | ], 25 | "types": { 26 | "block": { 27 | "params": [ 28 | { 29 | "id": "idx", 30 | "type": "s4" 31 | } 32 | ], 33 | "seq": [ 34 | { 35 | "id": "buf", 36 | "size": "_root.sizes[idx]", 37 | "type": "str", 38 | "encoding": "ASCII" 39 | } 40 | ] 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /testing/specs/nested_same_name.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "nested_same_name", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "main_data", 9 | "type": "main" 10 | }, 11 | { 12 | "id": "dummy", 13 | "type": "dummy_obj" 14 | } 15 | ], 16 | "types": { 17 | "main": { 18 | "seq": [ 19 | { 20 | "id": "main_size", 21 | "type": "s4" 22 | }, 23 | { 24 | "id": "foo", 25 | "type": "foo_obj" 26 | } 27 | ], 28 | "types": { 29 | "foo_obj": { 30 | "seq": [ 31 | { 32 | "id": "data", 33 | "size": "_parent.main_size * 2" 34 | } 35 | ] 36 | } 37 | } 38 | }, 39 | "dummy_obj": { 40 | "types": { 41 | "foo": {} 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /testing/specs/index_to_param_until.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "index_to_param_until", 4 | "endian": "le", 5 | "encoding": "ASCII" 6 | }, 7 | "seq": [ 8 | { 9 | "id": "qty", 10 | "type": "u4" 11 | }, 12 | { 13 | "id": "sizes", 14 | "type": "u4", 15 | "repeat": "expr", 16 | "repeat-expr": "qty" 17 | }, 18 | { 19 | "id": "blocks", 20 | "type": "block(_index)", 21 | "repeat": "until", 22 | "repeat-until": "_io.eof" 23 | } 24 | ], 25 | "types": { 26 | "block": { 27 | "params": [ 28 | { 29 | "id": "idx", 30 | "type": "s4" 31 | } 32 | ], 33 | "seq": [ 34 | { 35 | "id": "buf", 36 | "size": "_root.sizes[idx]", 37 | "type": "str", 38 | "encoding": "ASCII" 39 | } 40 | ] 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /testing/specs/switch_repeat_expr.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "switch_repeat_expr", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "code", 9 | "type": "u1" 10 | }, 11 | { 12 | "id": "size", 13 | "type": "u4" 14 | }, 15 | { 16 | "id": "body", 17 | "repeat": "expr", 18 | "repeat-expr": 1, 19 | "size": "size", 20 | "type": { 21 | "switch-on": "code", 22 | "cases": { 23 | "0x11": "one", 24 | "0x22": "two" 25 | } 26 | } 27 | } 28 | ], 29 | "types": { 30 | "one": { 31 | "seq": [ 32 | { 33 | "id": "first", 34 | "size-eos": true 35 | } 36 | ] 37 | }, 38 | "two": { 39 | "seq": [ 40 | { 41 | "id": "second", 42 | "size-eos": true 43 | } 44 | ] 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /testing/specs/params_pass_array_usertype.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "params_pass_array_usertype" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "blocks", 8 | "type": "block", 9 | "repeat": "expr", 10 | "repeat-expr": 2 11 | }, 12 | { 13 | "id": "pass_blocks", 14 | "type": "param_type(blocks)" 15 | } 16 | ], 17 | "types": { 18 | "block": { 19 | "seq": [ 20 | { 21 | "id": "foo", 22 | "type": "u1" 23 | } 24 | ] 25 | }, 26 | "param_type": { 27 | "params": [ 28 | { 29 | "id": "bar", 30 | "type": "block[]" 31 | } 32 | ], 33 | "seq": [ 34 | { 35 | "id": "one", 36 | "size": "bar[0].foo" 37 | }, 38 | { 39 | "id": "two", 40 | "size": "bar[1].foo" 41 | } 42 | ] 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /testing/tests/enum_long_range_s.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "enum_long_range_s", 3 | "data": "enum_long_range_s.bin", 4 | "asserts": [ 5 | { 6 | "actual": "f1", 7 | "expected": "enum_long_range_s::constants::long_min" 8 | }, 9 | { 10 | "actual": "f2", 11 | "expected": "enum_long_range_s::constants::int_below_min" 12 | }, 13 | { 14 | "actual": "f3", 15 | "expected": "enum_long_range_s::constants::int_min" 16 | }, 17 | { 18 | "actual": "f4", 19 | "expected": "enum_long_range_s::constants::zero" 20 | }, 21 | { 22 | "actual": "f5", 23 | "expected": "enum_long_range_s::constants::int_max" 24 | }, 25 | { 26 | "actual": "f6", 27 | "expected": "enum_long_range_s::constants::int_over_max" 28 | }, 29 | { 30 | "actual": "f7", 31 | "expected": "enum_long_range_s::constants::long_max" 32 | } 33 | ] 34 | } -------------------------------------------------------------------------------- /testing/specs/nested_types.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "nested_types" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "one", 8 | "type": "subtype_a" 9 | }, 10 | { 11 | "id": "two", 12 | "type": "subtype_b" 13 | } 14 | ], 15 | "types": { 16 | "subtype_a": { 17 | "seq": [ 18 | { 19 | "id": "typed_at_root", 20 | "type": "subtype_b" 21 | }, 22 | { 23 | "id": "typed_here", 24 | "type": "subtype_c" 25 | } 26 | ], 27 | "types": { 28 | "subtype_c": { 29 | "seq": [ 30 | { 31 | "id": "value_c", 32 | "type": "s1" 33 | } 34 | ] 35 | } 36 | } 37 | }, 38 | "subtype_b": { 39 | "seq": [ 40 | { 41 | "id": "value_b", 42 | "type": "s1" 43 | } 44 | ] 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /testing/tests/switch_integers.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "switch_integers", 3 | "data": "switch_integers.bin", 4 | "asserts": [ 5 | { 6 | "actual": "opcodes.size", 7 | "expected": 4 8 | }, 9 | { 10 | "actual": "opcodes[0].code", 11 | "expected": 1 12 | }, 13 | { 14 | "actual": "opcodes[0].body.c0", 15 | "expected": 7 16 | }, 17 | { 18 | "actual": "opcodes[1].code", 19 | "expected": 2 20 | }, 21 | { 22 | "actual": "opcodes[1].body.c1", 23 | "expected": "0x4040" 24 | }, 25 | { 26 | "actual": "opcodes[2].code", 27 | "expected": 4 28 | }, 29 | { 30 | "actual": "opcodes[2].body.c2", 31 | "expected": 4919 32 | }, 33 | { 34 | "actual": "opcodes[3].code", 35 | "expected": 8 36 | }, 37 | { 38 | "actual": "opcodes[3].body.c3", 39 | "expected": 4919 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /testing/specs/non_standard.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "non_standard", 4 | "endian": "le", 5 | "-vendor-key": "some value", 6 | "-vendor-key2": { 7 | "some": "hash", 8 | "with_more": "values" 9 | }, 10 | "-vendor-key3": [ 11 | "foo", 12 | "bar-" 13 | ] 14 | }, 15 | "vendor-key": "value", 16 | "seq": [ 17 | { 18 | "id": "foo", 19 | "type": "u1", 20 | "-vendor-key": "value" 21 | }, 22 | { 23 | "id": "bar", 24 | "type": { 25 | "switch-on": "foo", 26 | "-vendor-key": "value", 27 | "cases": { 28 | "42": "u2", 29 | "43": "u4" 30 | } 31 | } 32 | } 33 | ], 34 | "instances": { 35 | "vi": { 36 | "value": "foo", 37 | "-vendor-key": "value" 38 | }, 39 | "pi": { 40 | "pos": 0, 41 | "type": "u1", 42 | "-vendor-key": "value" 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /testing/tests/expr_bytes_cmp.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_bytes_cmp", 3 | "data": "fixed_struct.bin", 4 | "asserts": [ 5 | { 6 | "actual": "one", 7 | "expected": "[0x50]" 8 | }, 9 | { 10 | "actual": "two", 11 | "expected": "[0x41, 0x43, 0x4b]" 12 | }, 13 | { 14 | "actual": "is_eq", 15 | "expected": true 16 | }, 17 | { 18 | "actual": "is_ne", 19 | "expected": false 20 | }, 21 | { 22 | "actual": "is_lt", 23 | "expected": true 24 | }, 25 | { 26 | "actual": "is_gt", 27 | "expected": false 28 | }, 29 | { 30 | "actual": "is_le", 31 | "expected": true 32 | }, 33 | { 34 | "actual": "is_ge", 35 | "expected": false 36 | }, 37 | { 38 | "actual": "is_lt2", 39 | "expected": false 40 | }, 41 | { 42 | "actual": "is_gt2", 43 | "expected": true 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /testing/specs/enum_1.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "enum_1", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "main", 9 | "type": "main_obj" 10 | } 11 | ], 12 | "types": { 13 | "main_obj": { 14 | "seq": [ 15 | { 16 | "id": "submain", 17 | "type": "submain_obj" 18 | } 19 | ], 20 | "types": { 21 | "submain_obj": { 22 | "seq": [ 23 | { 24 | "id": "pet_1", 25 | "type": "u4", 26 | "enum": "animal" 27 | }, 28 | { 29 | "id": "pet_2", 30 | "type": "u4", 31 | "enum": "animal" 32 | } 33 | ] 34 | } 35 | }, 36 | "enums": { 37 | "animal": { 38 | "4": "dog", 39 | "7": "cat", 40 | "12": "chicken" 41 | } 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /testing/specs/expr_sizeof_type_1.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_sizeof_type_1", 4 | "endian": "le" 5 | }, 6 | "types": { 7 | "block": { 8 | "seq": [ 9 | { 10 | "id": "a", 11 | "type": "u1" 12 | }, 13 | { 14 | "id": "b", 15 | "type": "u4" 16 | }, 17 | { 18 | "id": "c", 19 | "size": 2 20 | }, 21 | { 22 | "id": "d", 23 | "type": "subblock" 24 | } 25 | ], 26 | "types": { 27 | "subblock": { 28 | "seq": [ 29 | { 30 | "id": "a", 31 | "size": 4 32 | } 33 | ] 34 | } 35 | } 36 | } 37 | }, 38 | "instances": { 39 | "sizeof_block": { 40 | "value": "sizeof" 41 | }, 42 | "sizeof_subblock": { 43 | "value": "sizeof" 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /testing/specs/params_pass_array_struct.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "params_pass_array_struct" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "one", 8 | "type": "foo" 9 | }, 10 | { 11 | "id": "two", 12 | "type": "bar" 13 | }, 14 | { 15 | "id": "pass_structs", 16 | "type": "struct_type(one_two)" 17 | } 18 | ], 19 | "instances": { 20 | "one_two": { 21 | "value": "[one, two]" 22 | } 23 | }, 24 | "types": { 25 | "foo": { 26 | "seq": [ 27 | { 28 | "id": "f", 29 | "type": "u1" 30 | } 31 | ] 32 | }, 33 | "bar": { 34 | "seq": [ 35 | { 36 | "id": "b", 37 | "type": "u1" 38 | } 39 | ] 40 | }, 41 | "struct_type": { 42 | "params": [ 43 | { 44 | "id": "structs", 45 | "type": "struct[]" 46 | } 47 | ] 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /testing/specs/str_encodings.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "str_encodings", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "len_of_1", 9 | "type": "u2" 10 | }, 11 | { 12 | "id": "str1", 13 | "type": "str", 14 | "size": "len_of_1", 15 | "encoding": "ASCII" 16 | }, 17 | { 18 | "id": "len_of_2", 19 | "type": "u2" 20 | }, 21 | { 22 | "id": "str2", 23 | "type": "str", 24 | "size": "len_of_2", 25 | "encoding": "UTF-8" 26 | }, 27 | { 28 | "id": "len_of_3", 29 | "type": "u2" 30 | }, 31 | { 32 | "id": "str3", 33 | "type": "str", 34 | "size": "len_of_3", 35 | "encoding": "SJIS" 36 | }, 37 | { 38 | "id": "len_of_4", 39 | "type": "u2" 40 | }, 41 | { 42 | "id": "str4", 43 | "type": "str", 44 | "size": "len_of_4", 45 | "encoding": "CP437" 46 | } 47 | ] 48 | } -------------------------------------------------------------------------------- /testing/tests/switch_manual_int.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "switch_manual_int", 3 | "data": "switch_opcodes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "opcodes.size", 7 | "expected": 4 8 | }, 9 | { 10 | "actual": "opcodes[0].code", 11 | "expected": 83 12 | }, 13 | { 14 | "actual": "opcodes[0].body.c1.value", 15 | "expected": "\"foobar\"" 16 | }, 17 | { 18 | "actual": "opcodes[1].code", 19 | "expected": 73 20 | }, 21 | { 22 | "actual": "opcodes[1].body.c0.value", 23 | "expected": "0x42" 24 | }, 25 | { 26 | "actual": "opcodes[2].code", 27 | "expected": 73 28 | }, 29 | { 30 | "actual": "opcodes[2].body.c0.value", 31 | "expected": "0x37" 32 | }, 33 | { 34 | "actual": "opcodes[3].code", 35 | "expected": 83 36 | }, 37 | { 38 | "actual": "opcodes[3].body.c1.value", 39 | "expected": "\"\"" 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /testing/tests/switch_manual_int_else.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "switch_manual_int_else", 3 | "data": "switch_opcodes2.bin", 4 | "asserts": [ 5 | { 6 | "actual": "opcodes.size", 7 | "expected": 4 8 | }, 9 | { 10 | "actual": "opcodes[0].code", 11 | "expected": 83 12 | }, 13 | { 14 | "actual": "opcodes[0].body.c1.value", 15 | "expected": "\"foo\"" 16 | }, 17 | { 18 | "actual": "opcodes[1].code", 19 | "expected": 88 20 | }, 21 | { 22 | "actual": "opcodes[1].body.c2.filler", 23 | "expected": "0x42" 24 | }, 25 | { 26 | "actual": "opcodes[2].code", 27 | "expected": 89 28 | }, 29 | { 30 | "actual": "opcodes[2].body.c2.filler", 31 | "expected": "0xcafe" 32 | }, 33 | { 34 | "actual": "opcodes[3].code", 35 | "expected": 73 36 | }, 37 | { 38 | "actual": "opcodes[3].body.c0.value", 39 | "expected": 7 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /testing/specs/expr_bytes_cmp.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_bytes_cmp" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "one", 8 | "size": 1 9 | }, 10 | { 11 | "id": "two", 12 | "size": 3 13 | } 14 | ], 15 | "instances": { 16 | "ack": { 17 | "value": "[65, 67, 75]" 18 | }, 19 | "ack2": { 20 | "value": "[65, 67, 75, 50]" 21 | }, 22 | "hi_val": { 23 | "value": "[0x90, 67]" 24 | }, 25 | "is_eq": { 26 | "value": "two == ack" 27 | }, 28 | "is_ne": { 29 | "value": "two != ack" 30 | }, 31 | "is_lt": { 32 | "value": "two < ack2" 33 | }, 34 | "is_gt": { 35 | "value": "two > ack2" 36 | }, 37 | "is_le": { 38 | "value": "two <= ack2" 39 | }, 40 | "is_ge": { 41 | "value": "two >= ack2" 42 | }, 43 | "is_lt2": { 44 | "value": "one < two" 45 | }, 46 | "is_gt2": { 47 | "value": "hi_val > two" 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /testing/tests/switch_bytearray.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "switch_bytearray", 3 | "data": "switch_opcodes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "opcodes.size", 7 | "expected": 4 8 | }, 9 | { 10 | "actual": "opcodes[0].code", 11 | "expected": "[83]" 12 | }, 13 | { 14 | "actual": "opcodes[0].body.c1.value", 15 | "expected": "\"foobar\"" 16 | }, 17 | { 18 | "actual": "opcodes[1].code", 19 | "expected": "[73]" 20 | }, 21 | { 22 | "actual": "opcodes[1].body.c0.value", 23 | "expected": "0x42" 24 | }, 25 | { 26 | "actual": "opcodes[2].code", 27 | "expected": "[73]" 28 | }, 29 | { 30 | "actual": "opcodes[2].body.c0.value", 31 | "expected": "0x37" 32 | }, 33 | { 34 | "actual": "opcodes[3].code", 35 | "expected": "[83]" 36 | }, 37 | { 38 | "actual": "opcodes[3].body.c1.value", 39 | "expected": "\"\"" 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /testing/specs/combine_bytes.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "combine_bytes" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "bytes_term", 8 | "terminator": "0x7c" 9 | }, 10 | { 11 | "id": "bytes_limit", 12 | "size": 4 13 | }, 14 | { 15 | "id": "bytes_eos", 16 | "size-eos": true 17 | } 18 | ], 19 | "instances": { 20 | "bytes_calc": { 21 | "value": "[0x52, 0x6e, 0x44]" 22 | }, 23 | "term_or_limit": { 24 | "value": "true ? bytes_term : bytes_limit" 25 | }, 26 | "term_or_eos": { 27 | "value": "false ? bytes_term : bytes_eos" 28 | }, 29 | "term_or_calc": { 30 | "value": "true ? bytes_term : bytes_calc" 31 | }, 32 | "limit_or_eos": { 33 | "value": "true ? bytes_limit : bytes_eos" 34 | }, 35 | "limit_or_calc": { 36 | "value": "false ? bytes_limit : bytes_calc" 37 | }, 38 | "eos_or_calc": { 39 | "value": "true ? bytes_eos : bytes_calc" 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /testing/tests/switch_manual_str.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "switch_manual_str", 3 | "data": "switch_opcodes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "opcodes.size", 7 | "expected": 4 8 | }, 9 | { 10 | "actual": "opcodes[0].code", 11 | "expected": "\"S\"" 12 | }, 13 | { 14 | "actual": "opcodes[0].body.c1.value", 15 | "expected": "\"foobar\"" 16 | }, 17 | { 18 | "actual": "opcodes[1].code", 19 | "expected": "\"I\"" 20 | }, 21 | { 22 | "actual": "opcodes[1].body.c0.value", 23 | "expected": "0x42" 24 | }, 25 | { 26 | "actual": "opcodes[2].code", 27 | "expected": "\"I\"" 28 | }, 29 | { 30 | "actual": "opcodes[2].body.c0.value", 31 | "expected": "0x37" 32 | }, 33 | { 34 | "actual": "opcodes[3].code", 35 | "expected": "\"S\"" 36 | }, 37 | { 38 | "actual": "opcodes[3].body.c1.value", 39 | "expected": "\"\"" 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /flow.dot: -------------------------------------------------------------------------------- 1 | digraph G { 2 | rankdir="LR" 3 | node [shape=box]; 4 | 5 | json [label="JSON" fontcolor=white color="#6666ff" fillcolor="#6666ff" 6 | style=filled shape=rarrow] 7 | ast [label="AST" fontcolor=white color="#6666ff" fillcolor="#6666ff" 8 | style=filled] 9 | obj [label="User-defined\nNim Object" fontcolor=white color="#b266ff" 10 | fillcolor="#b266ff" style=filled] 11 | bin [label="Binary" fontcolor=white color="#b266ff" fillcolor="#b266ff" 12 | style=filled shape=larrow] 13 | 14 | json -> ast [style=invis]; 15 | ast -> obj [arrowhead=vee]; 16 | obj -> bin [style=invis]; 17 | bin -> ast [arrowhead=vee constraint=false]; 18 | 19 | subgraph cluster_ct { 20 | json ast; 21 | 22 | label="Spec (compile-time)"; 23 | style=filled; 24 | color=lightgrey; 25 | } 26 | 27 | subgraph cluster_rt { 28 | obj bin; 29 | 30 | label="Data (runtime)"; 31 | style=filled; 32 | color=lightgrey; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /testing/specs/float_to_i.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "float_to_i", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "single_value", 9 | "type": "f4" 10 | }, 11 | { 12 | "id": "double_value", 13 | "type": "f8" 14 | } 15 | ], 16 | "instances": { 17 | "calc_float1": { 18 | "value": 1.234 19 | }, 20 | "calc_float2": { 21 | "value": 1.5 22 | }, 23 | "calc_float3": { 24 | "value": 1.9 25 | }, 26 | "calc_float4": { 27 | "value": -2.7 28 | }, 29 | "single_i": { 30 | "value": "single_value.to_i" 31 | }, 32 | "double_i": { 33 | "value": "double_value.to_i" 34 | }, 35 | "float1_i": { 36 | "value": "calc_float1.to_i" 37 | }, 38 | "float2_i": { 39 | "value": "calc_float2.to_i" 40 | }, 41 | "float3_i": { 42 | "value": "calc_float3.to_i" 43 | }, 44 | "float4_i": { 45 | "value": "calc_float4.to_i" 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /testing/tests/switch_manual_str_else.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "switch_manual_str_else", 3 | "data": "switch_opcodes2.bin", 4 | "asserts": [ 5 | { 6 | "actual": "opcodes.size", 7 | "expected": 4 8 | }, 9 | { 10 | "actual": "opcodes[0].code", 11 | "expected": "\"S\"" 12 | }, 13 | { 14 | "actual": "opcodes[0].body.c1.value", 15 | "expected": "\"foo\"" 16 | }, 17 | { 18 | "actual": "opcodes[1].code", 19 | "expected": "\"X\"" 20 | }, 21 | { 22 | "actual": "opcodes[1].body.c2.filler", 23 | "expected": "0x42" 24 | }, 25 | { 26 | "actual": "opcodes[2].code", 27 | "expected": "\"Y\"" 28 | }, 29 | { 30 | "actual": "opcodes[2].body.c2.filler", 31 | "expected": "0xcafe" 32 | }, 33 | { 34 | "actual": "opcodes[3].code", 35 | "expected": "\"I\"" 36 | }, 37 | { 38 | "actual": "opcodes[3].body.c0.value", 39 | "expected": 7 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /testing/specs/docstrings_docref.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "docstrings_docref" 4 | }, 5 | "doc": "Another one-liner", 6 | "doc-ref": "http://www.example.com/some/path/?even_with=query&more=2", 7 | "seq": [ 8 | { 9 | "id": "one", 10 | "type": "u1", 11 | "doc-ref": "Plain text description of doc ref, page 42" 12 | }, 13 | { 14 | "id": "two", 15 | "type": "u1", 16 | "doc": "Both doc and doc-ref are defined", 17 | "doc-ref": "http://www.example.com/with/url/again" 18 | }, 19 | { 20 | "id": "three", 21 | "type": "u1", 22 | "doc-ref": "http://www.example.com/three Documentation name" 23 | } 24 | ], 25 | "instances": { 26 | "foo": { 27 | "doc-ref": "Doc ref for instance, a plain one", 28 | "value": true 29 | }, 30 | "parse_inst": { 31 | "pos": 0, 32 | "type": "u1", 33 | "doc-ref": "Now this is a really\nlong document ref that\nspans multiple lines.\n" 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /testing/specs/opaque_external_type_02_child.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "opaque_external_type_02_child", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "s1", 9 | "type": "strz", 10 | "encoding": "UTF-8", 11 | "terminator": "0x7C" 12 | }, 13 | { 14 | "id": "s2", 15 | "type": "strz", 16 | "encoding": "UTF-8", 17 | "terminator": "0x7C", 18 | "consume": false 19 | }, 20 | { 21 | "id": "s3", 22 | "type": "opaque_external_type_02_child_child" 23 | } 24 | ], 25 | "types": { 26 | "opaque_external_type_02_child_child": { 27 | "seq": [ 28 | { 29 | "id": "s3", 30 | "type": "strz", 31 | "encoding": "UTF-8", 32 | "terminator": "0x40", 33 | "include": true, 34 | "if": "_root.some_method" 35 | } 36 | ] 37 | } 38 | }, 39 | "instances": { 40 | "some_method": { 41 | "value": "true" 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /testing/tests/expr_bits.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "expr_bits", 3 | "data": "switch_opcodes.bin", 4 | "asserts": [ 5 | { 6 | "actual": "a", 7 | "expected": 2 8 | }, 9 | { 10 | "actual": "enum_seq", 11 | "expected": "expr_bits::items::foo" 12 | }, 13 | { 14 | "actual": "byte_size", 15 | "expected": "[0x66, 0x6f]" 16 | }, 17 | { 18 | "actual": "repeat_expr.size", 19 | "expected": 2 20 | }, 21 | { 22 | "actual": "repeat_expr[0]", 23 | "expected": 111 24 | }, 25 | { 26 | "actual": "repeat_expr[1]", 27 | "expected": 98 28 | }, 29 | { 30 | "actual": "switch_on_type", 31 | "expected": 97 32 | }, 33 | { 34 | "actual": "switch_on_endian.foo", 35 | "expected": 29184 36 | }, 37 | { 38 | "actual": "enum_inst", 39 | "expected": "expr_bits::items::bar" 40 | }, 41 | { 42 | "actual": "inst_pos", 43 | "expected": 111 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /testing/specs/expr_3.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_3" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "one", 8 | "type": "u1" 9 | }, 10 | { 11 | "id": "two", 12 | "type": "str", 13 | "encoding": "ASCII", 14 | "size": 3 15 | } 16 | ], 17 | "instances": { 18 | "three": { 19 | "value": "\"@\" + two" 20 | }, 21 | "four": { 22 | "value": "\"_\" + two + \"_\"" 23 | }, 24 | "is_str_eq": { 25 | "value": "two == \"ACK\"" 26 | }, 27 | "is_str_ne": { 28 | "value": "two != \"ACK\"" 29 | }, 30 | "is_str_lt": { 31 | "value": "two < \"ACK2\"" 32 | }, 33 | "is_str_gt": { 34 | "value": "two > \"ACK2\"" 35 | }, 36 | "is_str_le": { 37 | "value": "two <= \"ACK2\"" 38 | }, 39 | "is_str_ge": { 40 | "value": "two >= \"ACK2\"" 41 | }, 42 | "is_str_lt2": { 43 | "value": "three < two" 44 | }, 45 | "test_not": { 46 | "value": "not false" 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /testing/tests/nav_parent2.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nav_parent2", 3 | "data": "nav_parent2.bin", 4 | "asserts": [ 5 | { 6 | "actual": "ofs_tags", 7 | "expected": 8 8 | }, 9 | { 10 | "actual": "num_tags", 11 | "expected": 2 12 | }, 13 | { 14 | "actual": "tags[0].name", 15 | "expected": "\"RAHC\"" 16 | }, 17 | { 18 | "actual": "tags[0].ofs", 19 | "expected": "0x20" 20 | }, 21 | { 22 | "actual": "tags[0].num_items", 23 | "expected": 3 24 | }, 25 | { 26 | "actual": "tags[0].tag_content.content", 27 | "expected": "\"foo\"" 28 | }, 29 | { 30 | "actual": "tags[1].name", 31 | "expected": "\"RAHC\"" 32 | }, 33 | { 34 | "actual": "tags[1].ofs", 35 | "expected": "0x23" 36 | }, 37 | { 38 | "actual": "tags[1].num_items", 39 | "expected": 6 40 | }, 41 | { 42 | "actual": "tags[1].tag_content.content", 43 | "expected": "\"barbaz\"" 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /testing/tests/nav_parent3.kst: -------------------------------------------------------------------------------- 1 | { 2 | "id": "nav_parent3", 3 | "data": "nav_parent2.bin", 4 | "asserts": [ 5 | { 6 | "actual": "ofs_tags", 7 | "expected": 8 8 | }, 9 | { 10 | "actual": "num_tags", 11 | "expected": 2 12 | }, 13 | { 14 | "actual": "tags[0].name", 15 | "expected": "\"RAHC\"" 16 | }, 17 | { 18 | "actual": "tags[0].ofs", 19 | "expected": "0x20" 20 | }, 21 | { 22 | "actual": "tags[0].num_items", 23 | "expected": 3 24 | }, 25 | { 26 | "actual": "tags[0].tag_content.content", 27 | "expected": "\"foo\"" 28 | }, 29 | { 30 | "actual": "tags[1].name", 31 | "expected": "\"RAHC\"" 32 | }, 33 | { 34 | "actual": "tags[1].ofs", 35 | "expected": "0x23" 36 | }, 37 | { 38 | "actual": "tags[1].num_items", 39 | "expected": 6 40 | }, 41 | { 42 | "actual": "tags[1].tag_content.content", 43 | "expected": "\"barbaz\"" 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /testing/specs/expr_sizeof_value_0.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_sizeof_value_0", 4 | "endian": "le" 5 | }, 6 | "types": { 7 | "block": { 8 | "seq": [ 9 | { 10 | "id": "a", 11 | "type": "u1" 12 | }, 13 | { 14 | "id": "b", 15 | "type": "u4" 16 | }, 17 | { 18 | "id": "c", 19 | "size": 2 20 | } 21 | ] 22 | } 23 | }, 24 | "seq": [ 25 | { 26 | "id": "block1", 27 | "type": "block" 28 | }, 29 | { 30 | "id": "more", 31 | "type": "u2" 32 | } 33 | ], 34 | "instances": { 35 | "self_sizeof": { 36 | "value": "_sizeof" 37 | }, 38 | "sizeof_block": { 39 | "value": "block1._sizeof" 40 | }, 41 | "sizeof_block_a": { 42 | "value": "block1.a._sizeof" 43 | }, 44 | "sizeof_block_b": { 45 | "value": "block1.b._sizeof" 46 | }, 47 | "sizeof_block_c": { 48 | "value": "block1.c._sizeof" 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /testing/specs/expr_bytes_ops.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_bytes_ops" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "one", 8 | "size": 3 9 | } 10 | ], 11 | "instances": { 12 | "two": { 13 | "value": "[0x41, 0x43, 0x4b]" 14 | }, 15 | "one_size": { 16 | "value": "one.size" 17 | }, 18 | "one_first": { 19 | "value": "one.first" 20 | }, 21 | "one_mid": { 22 | "value": "one[1]" 23 | }, 24 | "one_last": { 25 | "value": "one.last" 26 | }, 27 | "one_min": { 28 | "value": "one.min" 29 | }, 30 | "one_max": { 31 | "value": "one.max" 32 | }, 33 | "two_size": { 34 | "value": "two.size" 35 | }, 36 | "two_first": { 37 | "value": "two.first" 38 | }, 39 | "two_mid": { 40 | "value": "two[1]" 41 | }, 42 | "two_last": { 43 | "value": "two.last" 44 | }, 45 | "two_min": { 46 | "value": "two.min" 47 | }, 48 | "two_max": { 49 | "value": "two.max" 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /testing/specs/expr_sizeof_value_sized.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "expr_sizeof_value_sized", 4 | "endian": "le" 5 | }, 6 | "types": { 7 | "block": { 8 | "seq": [ 9 | { 10 | "id": "a", 11 | "type": "u1" 12 | }, 13 | { 14 | "id": "b", 15 | "type": "u4" 16 | }, 17 | { 18 | "id": "c", 19 | "size": 2 20 | } 21 | ] 22 | } 23 | }, 24 | "seq": [ 25 | { 26 | "id": "block1", 27 | "type": "block", 28 | "size": 12 29 | }, 30 | { 31 | "id": "more", 32 | "type": "u2" 33 | } 34 | ], 35 | "instances": { 36 | "self_sizeof": { 37 | "value": "_sizeof" 38 | }, 39 | "sizeof_block": { 40 | "value": "block1._sizeof" 41 | }, 42 | "sizeof_block_a": { 43 | "value": "block1.a._sizeof" 44 | }, 45 | "sizeof_block_b": { 46 | "value": "block1.b._sizeof" 47 | }, 48 | "sizeof_block_c": { 49 | "value": "block1.c._sizeof" 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /testing/specs/process_coerce_switch.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_coerce_switch" 4 | }, 5 | "seq": [ 6 | { 7 | "id": "buf_type", 8 | "type": "u1" 9 | }, 10 | { 11 | "id": "flag", 12 | "type": "u1" 13 | }, 14 | { 15 | "id": "buf_unproc", 16 | "size": 4, 17 | "if": "flag == 0", 18 | "type": { 19 | "switch-on": "buf_type", 20 | "cases": { 21 | "0": "foo" 22 | } 23 | } 24 | }, 25 | { 26 | "id": "buf_proc", 27 | "size": 4, 28 | "process": "xor(0xaa)", 29 | "if": "flag != 0", 30 | "type": { 31 | "switch-on": "buf_type", 32 | "cases": { 33 | "0": "foo" 34 | } 35 | } 36 | } 37 | ], 38 | "instances": { 39 | "buf": { 40 | "value": "flag == 0 ? buf_unproc : buf_proc" 41 | } 42 | }, 43 | "types": { 44 | "foo": { 45 | "seq": [ 46 | { 47 | "id": "bar", 48 | "size": 4 49 | } 50 | ] 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /testing/specs/process_coerce_usertype2.ksj: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "id": "process_coerce_usertype2", 4 | "endian": "le" 5 | }, 6 | "seq": [ 7 | { 8 | "id": "records", 9 | "type": "record", 10 | "repeat": "expr", 11 | "repeat-expr": 2 12 | } 13 | ], 14 | "types": { 15 | "record": { 16 | "seq": [ 17 | { 18 | "id": "flag", 19 | "type": "u1" 20 | }, 21 | { 22 | "id": "buf_unproc", 23 | "type": "foo", 24 | "if": "flag == 0" 25 | }, 26 | { 27 | "id": "buf_proc", 28 | "size": 4, 29 | "type": "foo", 30 | "process": "xor(0xaa)", 31 | "if": "flag != 0" 32 | } 33 | ], 34 | "instances": { 35 | "buf": { 36 | "value": "flag == 0 ? buf_unproc : buf_proc" 37 | } 38 | } 39 | }, 40 | "foo": { 41 | "seq": [ 42 | { 43 | "id": "value", 44 | "type": "u4" 45 | } 46 | ] 47 | } 48 | } 49 | } --------------------------------------------------------------------------------