Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Rust] encoding primitive arrays now supports slice instead of array (issue #1021) #1040

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ tasks.register('generateRustTestCodecs', JavaExec) {
'sbe-tool/src/test/resources/issue984.xml',
'sbe-tool/src/test/resources/issue987.xml',
'sbe-tool/src/test/resources/issue1028.xml',
'sbe-tool/src/test/resources/fixed-sized-primitive-array-types.xml',
'sbe-tool/src/test/resources/example-bigendian-test-schema.xml',
'sbe-tool/src/test/resources/nested-composite-name.xml',
]
Expand Down
1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ issue_987 = { path = "../generated/rust/issue987" }
issue_1028 = { path = "../generated/rust/issue1028" }
baseline_bigendian = { path = "../generated/rust/baseline-bigendian" }
nested_composite_name = { path = "../generated/rust/nested-composite-name" }
fixed_sized_primitive_array = { path = "../generated/rust/fixed_sized_primitive_array" }

[dev-dependencies]
criterion = "0.5"
Expand Down
21 changes: 11 additions & 10 deletions rust/tests/baseline_enum_from_str.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use BoostType::{NullVal, KERS, NITROUS, SUPERCHARGER, TURBO};
use examples_baseline::{
boost_type::BoostType,
};

#[test]
fn test_boost_type_from_str() -> Result<(), ()> {
assert_eq!("TURBO".parse::<BoostType>()?, BoostType::TURBO, "Parse \"TURBO\" as BoostType");
assert_eq!("SUPERCHARGER".parse::<BoostType>()?, BoostType::SUPERCHARGER, "Parse \"SUPERCHARGER\" as BoostType");
assert_eq!("NITROUS".parse::<BoostType>()?, BoostType::NITROUS, "Parse \"NITROUS\" as BoostType");
assert_eq!("KERS".parse::<BoostType>()?, BoostType::KERS, "Parse \"KERS\" as BoostType");
assert_eq!("TURBO".parse::<BoostType>()?, TURBO, "Parse \"TURBO\" as BoostType");
assert_eq!("SUPERCHARGER".parse::<BoostType>()?, SUPERCHARGER, "Parse \"SUPERCHARGER\" as BoostType");
assert_eq!("NITROUS".parse::<BoostType>()?, NITROUS, "Parse \"NITROUS\" as BoostType");
assert_eq!("KERS".parse::<BoostType>()?, KERS, "Parse \"KERS\" as BoostType");

assert_eq!("Turbo".parse::<BoostType>()?, BoostType::NullVal, "Parse \"Turbo\" as BoostType");
assert_eq!("Supercharger".parse::<BoostType>()?, BoostType::NullVal, "Parse \"Supercharger\" as BoostType");
assert_eq!("Nitrous".parse::<BoostType>()?, BoostType::NullVal, "Parse \"Nitrous\" as BoostType");
assert_eq!("Kers".parse::<BoostType>()?, BoostType::NullVal, "Parse \"Kers\" as BoostType");
assert_eq!("Turbo".parse::<BoostType>()?, NullVal, "Parse \"Turbo\" as BoostType");
assert_eq!("Supercharger".parse::<BoostType>()?, NullVal, "Parse \"Supercharger\" as BoostType");
assert_eq!("Nitrous".parse::<BoostType>()?, NullVal, "Parse \"Nitrous\" as BoostType");
assert_eq!("Kers".parse::<BoostType>()?, NullVal, "Parse \"Kers\" as BoostType");

assert_eq!("AA".parse::<BoostType>()?, BoostType::NullVal, "Parse \"AA\" as BoostType");
assert_eq!("".parse::<BoostType>().unwrap(), BoostType::NullVal, "Parse \"\" as BoostType");
assert_eq!("AA".parse::<BoostType>()?, NullVal, "Parse \"AA\" as BoostType");
assert_eq!("".parse::<BoostType>().unwrap(), NullVal, "Parse \"\" as BoostType");

Ok(())
}
4 changes: 2 additions & 2 deletions rust/tests/extension_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fn encode_car_from_scratch() -> SbeResult<(usize, Vec<u8>)> {
car.available(BooleanType::T);
car.code(Model::A);
car.some_numbers(&[0, 1, 2, 3]);
car.vehicle_code(&[97, 98, 99, 100, 101, 102]); // abcdef
car.vehicle_code_from_iter(b"abcdef_extra_is_ignored".into_iter().copied()); // abcdef

extras.set_cruise_control(true);
extras.set_sports_pack(true);
Expand All @@ -197,7 +197,7 @@ fn encode_car_from_scratch() -> SbeResult<(usize, Vec<u8>)> {
let mut engine = car.engine_encoder();
engine.capacity(2000);
engine.num_cylinders(4);
engine.manufacturer_code(&[49, 50, 51]); // 123
engine.manufacturer_code(b"123");
engine.efficiency(35);
engine.booster_enabled(BooleanType::T);
let mut booster = engine.booster_encoder();
Expand Down
Loading
Loading