diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-05-02 11:01:58 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-05-02 12:02:32 +1000 |
| commit | 8d359e4385052f012d8d0c2e57a0bcfe54462d44 (patch) | |
| tree | a7f4846473a0601fb69fbdbe01106b57e8e46c35 /compiler/rustc_serialize | |
| parent | b4ba2f0bf469da7a5fea38f2ef2a9bd069736eba (diff) | |
Move some `Encodable`/`Decodable` tests.
Round-trip encoding/decoding of many types is tested in `compiler/rustc_serialize/tests/opaque.rs`. There is also a small amount of encoding/decoding testing in three files in `tests/ui-fulldeps`. There is no obvious reason why these three files are necessary. They were originally added in 2014. Maybe it wasn't possible for a proc macro to run in a unit test back then? This commit just moves the testing from those three files into the unit test.
Diffstat (limited to 'compiler/rustc_serialize')
| -rw-r--r-- | compiler/rustc_serialize/tests/opaque.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/compiler/rustc_serialize/tests/opaque.rs b/compiler/rustc_serialize/tests/opaque.rs index 5e7dd18aa84..7a7db99b168 100644 --- a/compiler/rustc_serialize/tests/opaque.rs +++ b/compiler/rustc_serialize/tests/opaque.rs @@ -251,3 +251,42 @@ fn test_tuples() { check_round_trip(vec![(1234567isize, 100000000000000u64, 99999999999999i64)]); check_round_trip(vec![(String::new(), "some string".to_string())]); } + +#[test] +fn test_unit_like_struct() { + #[derive(Encodable, Decodable, PartialEq, Debug)] + struct UnitLikeStruct; + + check_round_trip(vec![UnitLikeStruct]); +} + +#[test] +fn test_box() { + #[derive(Encodable, Decodable, PartialEq, Debug)] + struct A { + foo: Box<[bool]>, + } + + let obj = A { foo: Box::new([true, false]) }; + check_round_trip(vec![obj]); +} + +#[test] +fn test_cell() { + use std::cell::{Cell, RefCell}; + + #[derive(Encodable, Decodable, PartialEq, Debug)] + struct A { + baz: isize, + } + + #[derive(Encodable, Decodable, PartialEq, Debug)] + struct B { + foo: Cell<bool>, + bar: RefCell<A>, + } + + let obj = B { foo: Cell::new(true), bar: RefCell::new(A { baz: 2 }) }; + check_round_trip(vec![obj]); +} + |
