Skip to content

Commit e1577c3

Browse files
author
Michael Ward
committed
[Rust] updated rust tests
1 parent 7bb5448 commit e1577c3

File tree

9 files changed

+141
-61
lines changed

9 files changed

+141
-61
lines changed

rust/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ issue_987 = { path = "../generated/rust/issue987" }
1919
issue_1028 = { path = "../generated/rust/issue1028" }
2020
issue_1057 = { path = "../generated/rust/issue1057" }
2121
issue_1066 = { path = "../generated/rust/issue1066" }
22-
baseline_bigendian = { path = "../generated/rust/baseline-bigendian" }
23-
nested_composite_name = { path = "../generated/rust/nested-composite-name" }
22+
baseline_bigendian = { path = "../generated/rust/baseline_bigendian" }
23+
nested_composite_name = { path = "../generated/rust/nested_composite_name" }
2424
sbe_tests = { path = "../generated/rust/sbe_tests" }
2525
fixed_sized_primitive_array = { path = "../generated/rust/fixed_sized_primitive_array" }
2626

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,60 @@
1+
use examples_baseline::boost_type::BoostType;
12
use BoostType::{NullVal, KERS, NITROUS, SUPERCHARGER, TURBO};
2-
use examples_baseline::{
3-
boost_type::BoostType,
4-
};
53

64
#[test]
75
fn test_boost_type_from_str() -> Result<(), ()> {
8-
assert_eq!("TURBO".parse::<BoostType>()?, TURBO, "Parse \"TURBO\" as BoostType");
9-
assert_eq!("SUPERCHARGER".parse::<BoostType>()?, SUPERCHARGER, "Parse \"SUPERCHARGER\" as BoostType");
10-
assert_eq!("NITROUS".parse::<BoostType>()?, NITROUS, "Parse \"NITROUS\" as BoostType");
11-
assert_eq!("KERS".parse::<BoostType>()?, KERS, "Parse \"KERS\" as BoostType");
6+
assert_eq!(
7+
"TURBO".parse::<BoostType>()?,
8+
TURBO,
9+
"Parse \"TURBO\" as BoostType"
10+
);
11+
assert_eq!(
12+
"SUPERCHARGER".parse::<BoostType>()?,
13+
SUPERCHARGER,
14+
"Parse \"SUPERCHARGER\" as BoostType"
15+
);
16+
assert_eq!(
17+
"NITROUS".parse::<BoostType>()?,
18+
NITROUS,
19+
"Parse \"NITROUS\" as BoostType"
20+
);
21+
assert_eq!(
22+
"KERS".parse::<BoostType>()?,
23+
KERS,
24+
"Parse \"KERS\" as BoostType"
25+
);
1226

13-
assert_eq!("Turbo".parse::<BoostType>()?, NullVal, "Parse \"Turbo\" as BoostType");
14-
assert_eq!("Supercharger".parse::<BoostType>()?, NullVal, "Parse \"Supercharger\" as BoostType");
15-
assert_eq!("Nitrous".parse::<BoostType>()?, NullVal, "Parse \"Nitrous\" as BoostType");
16-
assert_eq!("Kers".parse::<BoostType>()?, NullVal, "Parse \"Kers\" as BoostType");
27+
assert_eq!(
28+
"Turbo".parse::<BoostType>()?,
29+
NullVal,
30+
"Parse \"Turbo\" as BoostType"
31+
);
32+
assert_eq!(
33+
"Supercharger".parse::<BoostType>()?,
34+
NullVal,
35+
"Parse \"Supercharger\" as BoostType"
36+
);
37+
assert_eq!(
38+
"Nitrous".parse::<BoostType>()?,
39+
NullVal,
40+
"Parse \"Nitrous\" as BoostType"
41+
);
42+
assert_eq!(
43+
"Kers".parse::<BoostType>()?,
44+
NullVal,
45+
"Parse \"Kers\" as BoostType"
46+
);
1747

18-
assert_eq!("AA".parse::<BoostType>()?, NullVal, "Parse \"AA\" as BoostType");
19-
assert_eq!("".parse::<BoostType>().unwrap(), NullVal, "Parse \"\" as BoostType");
48+
assert_eq!(
49+
"AA".parse::<BoostType>()?,
50+
NullVal,
51+
"Parse \"AA\" as BoostType"
52+
);
53+
assert_eq!(
54+
"".parse::<BoostType>().unwrap(),
55+
NullVal,
56+
"Parse \"\" as BoostType"
57+
);
2058

2159
Ok(())
2260
}

rust/tests/baseline_enum_into.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
1-
use examples_baseline::{
2-
boost_type::BoostType,
3-
};
1+
use examples_baseline::boost_type::BoostType;
42

53
#[test]
64
fn test_boost_type_from_str() -> Result<(), ()> {
7-
assert_eq!(<BoostType as Into<u8>>::into(BoostType::TURBO), 84_u8, "BoostType::TURBO into value");
8-
assert_eq!(<BoostType as Into<u8>>::into(BoostType::SUPERCHARGER), 83_u8, "BoostType::SUPERCHARGER into value");
9-
assert_eq!(<BoostType as Into<u8>>::into(BoostType::NITROUS), 78_u8, "BoostType::NITROUS into value");
10-
assert_eq!(<BoostType as Into<u8>>::into(BoostType::KERS), 75_u8, "BoostType::KERS into value");
11-
assert_eq!(<BoostType as Into<u8>>::into(BoostType::NullVal), 0_u8, "BoostType::NullVal into value");
5+
assert_eq!(
6+
<BoostType as Into<u8>>::into(BoostType::TURBO),
7+
84_u8,
8+
"BoostType::TURBO into value"
9+
);
10+
assert_eq!(
11+
<BoostType as Into<u8>>::into(BoostType::SUPERCHARGER),
12+
83_u8,
13+
"BoostType::SUPERCHARGER into value"
14+
);
15+
assert_eq!(
16+
<BoostType as Into<u8>>::into(BoostType::NITROUS),
17+
78_u8,
18+
"BoostType::NITROUS into value"
19+
);
20+
assert_eq!(
21+
<BoostType as Into<u8>>::into(BoostType::KERS),
22+
75_u8,
23+
"BoostType::KERS into value"
24+
);
25+
assert_eq!(
26+
<BoostType as Into<u8>>::into(BoostType::NullVal),
27+
0_u8,
28+
"BoostType::NullVal into value"
29+
);
1230

1331
Ok(())
1432
}

rust/tests/baseline_enum_to_str.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1-
use examples_baseline::{
2-
boost_type::BoostType,
3-
};
1+
use examples_baseline::boost_type::BoostType;
42

53
#[test]
64
fn test_boost_type_from_str() -> Result<(), ()> {
7-
assert_eq!(format!("{}", BoostType::TURBO), "TURBO", "Display \"TURBO\"");
8-
assert_eq!(format!("{}", BoostType::SUPERCHARGER), "SUPERCHARGER", "Display \"SUPERCHARGER\"");
9-
assert_eq!(format!("{}", BoostType::NITROUS), "NITROUS", "Display \"NITROUS\"");
5+
assert_eq!(
6+
format!("{}", BoostType::TURBO),
7+
"TURBO",
8+
"Display \"TURBO\""
9+
);
10+
assert_eq!(
11+
format!("{}", BoostType::SUPERCHARGER),
12+
"SUPERCHARGER",
13+
"Display \"SUPERCHARGER\""
14+
);
15+
assert_eq!(
16+
format!("{}", BoostType::NITROUS),
17+
"NITROUS",
18+
"Display \"NITROUS\""
19+
);
1020
assert_eq!(format!("{}", BoostType::KERS), "KERS", "Display \"KERS\"");
11-
assert_eq!(format!("{}", BoostType::NullVal), "NullVal", "Display \"NullVal\"");
21+
assert_eq!(
22+
format!("{}", BoostType::NullVal),
23+
"NullVal",
24+
"Display \"NullVal\""
25+
);
1226

1327
Ok(())
1428
}

rust/tests/baseline_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,4 @@ fn test_issue_1018() {
272272
assert_eq!(1, examples_baseline::SBE_SCHEMA_ID);
273273
assert_eq!(0, examples_baseline::SBE_SCHEMA_VERSION);
274274
assert_eq!("5.2", examples_baseline::SBE_SEMANTIC_VERSION);
275-
}
275+
}

rust/tests/big_endian_test.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
use baseline_bigendian::car_codec::{CarDecoder, CarEncoder, SBE_TEMPLATE_ID};
12
use baseline_bigendian::{
23
boolean_type::BooleanType,
34
boost_type::BoostType,
4-
car_codec::{
5-
encoder::{AccelerationEncoder, FuelFiguresEncoder, PerformanceFiguresEncoder},
6-
*,
7-
},
5+
car_codec::encoder::{AccelerationEncoder, FuelFiguresEncoder, PerformanceFiguresEncoder},
86
message_header_codec,
97
message_header_codec::MessageHeaderDecoder,
108
model::Model,

rust/tests/fixed_sized_primitive_array.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,28 +337,32 @@ fn test_encode_then_decode_non_u8_signed_primitive_slice() {
337337
DemoDecoder::fixed_16_i8,
338338
DemoEncoder::fixed_16_i8_end,
339339
DemoDecoder::fixed_16_i8_end,
340-
i8, i8::from_le_bytes([uninit])
340+
i8,
341+
i8::from_le_bytes([uninit])
341342
);
342343
run_encode_then_decode_for_array_of_signed_len_16!(
343344
DemoEncoder::fixed_16_i16_from_iter,
344345
DemoDecoder::fixed_16_i16,
345346
DemoEncoder::fixed_16_i16_end,
346347
DemoDecoder::fixed_16_i16_end,
347-
i16, i16::from_le_bytes([uninit, uninit])
348+
i16,
349+
i16::from_le_bytes([uninit, uninit])
348350
);
349351
run_encode_then_decode_for_array_of_signed_len_16!(
350352
DemoEncoder::fixed_16_i32_from_iter,
351353
DemoDecoder::fixed_16_i32,
352354
DemoEncoder::fixed_16_i32_end,
353355
DemoDecoder::fixed_16_i32_end,
354-
i32, i32::from_le_bytes([uninit, uninit, uninit, uninit])
356+
i32,
357+
i32::from_le_bytes([uninit, uninit, uninit, uninit])
355358
);
356359
run_encode_then_decode_for_array_of_signed_len_16!(
357360
DemoEncoder::fixed_16_i64_from_iter,
358361
DemoDecoder::fixed_16_i64,
359362
DemoEncoder::fixed_16_i64_end,
360363
DemoDecoder::fixed_16_i64_end,
361-
i64, i64::from_le_bytes([uninit, uninit, uninit, uninit, uninit, uninit, uninit, uninit])
364+
i64,
365+
i64::from_le_bytes([uninit, uninit, uninit, uninit, uninit, uninit, uninit, uninit])
362366
);
363367
}
364368

rust/tests/issue_987_test.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
use issue_987::{
2-
issue_987_codec::{Issue987Decoder, Issue987Encoder, SBE_BLOCK_LENGTH, SBE_SCHEMA_ID, SBE_SCHEMA_VERSION, SBE_TEMPLATE_ID}, message_header_codec::MessageHeaderDecoder, *
2+
issue_987_codec::{
3+
Issue987Decoder, Issue987Encoder, SBE_BLOCK_LENGTH, SBE_SCHEMA_ID, SBE_SCHEMA_VERSION,
4+
SBE_TEMPLATE_ID,
5+
},
6+
message_header_codec::MessageHeaderDecoder,
7+
*,
38
};
49

510
fn create_encoder(buffer: &mut Vec<u8>, off: usize) -> Issue987Encoder {
Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<messageSchema package="SBE tests"
3-
id="4"
4-
semanticVersion="5.2"
5-
description="Unit Test"
6-
byteOrder="littleEndian">
7-
<types>
8-
<composite name="messageHeader" description="Message identifiers and length of message root">
9-
<type name="blockLength" primitiveType="uint16"/>
10-
<type name="templateId" primitiveType="uint16"/>
11-
<type name="schemaId" primitiveType="uint16"/>
12-
<type name="version" primitiveType="uint16"/>
13-
</composite>
14-
<composite name="varDataEncoding" semanticType="Length">
15-
<type name="length" primitiveType="uint8" semanticType="Length"/>
16-
<type name="varData" primitiveType="char" semanticType="data"/>
17-
</composite>
18-
</types>
19-
<message name="TestMessage1" id="1" description="TestMessage">
20-
<data type="varDataEncoding" name="encryptedNewPassword" id="1404"/>
21-
</message>
22-
</messageSchema>
2+
<sbe:messageSchema
3+
xmlns:sbe="http://fixprotocol.io/2016/sbe"
4+
package="SBE tests"
5+
id="4"
6+
version="1"
7+
semanticVersion="5.2"
8+
description="Unit Test"
9+
byteOrder="littleEndian">
10+
<types>
11+
<composite name="messageHeader" description="Message identifiers and length of message root">
12+
<type name="blockLength" primitiveType="uint16"/>
13+
<type name="templateId" primitiveType="uint16"/>
14+
<type name="schemaId" primitiveType="uint16"/>
15+
<type name="version" primitiveType="uint16"/>
16+
</composite>
17+
<composite name="varDataEncoding" semanticType="Length">
18+
<type name="length" primitiveType="uint8" semanticType="Length"/>
19+
<type name="varData" primitiveType="char" semanticType="data"/>
20+
</composite>
21+
</types>
22+
<sbe:message name="TestMessage1" id="1" description="TestMessage">
23+
<data type="varDataEncoding" name="encryptedNewPassword" id="1404"/>
24+
</sbe:message>
25+
</sbe:messageSchema>

0 commit comments

Comments
 (0)