From 65d75b8fe3105f00ab2e01537d568d4587167582 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 20 Nov 2023 17:25:48 -0800 Subject: [PATCH] Add RangeFrom and RangeTo tests --- test_suite/tests/test_de.rs | 40 ++++++++++++++++++++++++++++++++++++ test_suite/tests/test_ser.rs | 32 +++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/test_suite/tests/test_de.rs b/test_suite/tests/test_de.rs index b7d82ecf..3ca0fde3 100644 --- a/test_suite/tests/test_de.rs +++ b/test_suite/tests/test_de.rs @@ -1898,6 +1898,46 @@ fn test_range_inclusive() { ); } +#[test] +fn test_range_from() { + test( + 1u32.., + &[ + Token::Struct { + name: "RangeFrom", + len: 1, + }, + Token::Str("start"), + Token::U32(1), + Token::StructEnd, + ], + ); + test( + 1u32.., + &[Token::Seq { len: Some(1) }, Token::U32(1), Token::SeqEnd], + ); +} + +#[test] +fn test_range_to() { + test( + ..2u32, + &[ + Token::Struct { + name: "RangeTo", + len: 1, + }, + Token::Str("end"), + Token::U32(2), + Token::StructEnd, + ], + ); + test( + ..2u32, + &[Token::Seq { len: Some(1) }, Token::U32(2), Token::SeqEnd], + ); +} + #[test] fn test_bound() { test( diff --git a/test_suite/tests/test_ser.rs b/test_suite/tests/test_ser.rs index 81fc9ea7..71ec3bc5 100644 --- a/test_suite/tests/test_ser.rs +++ b/test_suite/tests/test_ser.rs @@ -500,6 +500,38 @@ fn test_range_inclusive() { ); } +#[test] +fn test_range_from() { + assert_ser_tokens( + &(1u32..), + &[ + Token::Struct { + name: "RangeFrom", + len: 1, + }, + Token::Str("start"), + Token::U32(1), + Token::StructEnd, + ], + ); +} + +#[test] +fn test_range_to() { + assert_ser_tokens( + &(..2u32), + &[ + Token::Struct { + name: "RangeTo", + len: 1, + }, + Token::Str("end"), + Token::U32(2), + Token::StructEnd, + ], + ); +} + #[test] fn test_bound() { assert_ser_tokens(