From 7b84ef15283c8244feaae0fd17698c5e71eba316 Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Fri, 20 Oct 2023 07:03:33 +0000 Subject: [PATCH] tests: Add new tests for derive Debug There are two new things added: 1. OpenEnum which mimics the failing build scenario 2. Struct which embeds that enum inside it and also derive Debug on top of it. By doing so we verify first of all the code compiles with multiple derive attributes and secondly the embedded debug derives works as expected. Signed-off-by: Jinank Jain --- tests/derives.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/derives.rs diff --git a/tests/derives.rs b/tests/derives.rs new file mode 100644 index 0000000..cecf82b --- /dev/null +++ b/tests/derives.rs @@ -0,0 +1,42 @@ +// Copyright © 2023 Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +extern crate open_enum; +use open_enum::*; + +#[open_enum] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(u32)] +pub enum Color3 { + Red = 0x0, + White = 0x1, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub struct EmbeddedColor { + pub color: Color3, +} + +#[test] +fn embedded_enum_struct() { + let test_struct = EmbeddedColor { color: Color3::Red }; + + assert_eq!(test_struct.color, Color3::Red); + + let expected_debug_str = "EmbeddedColor { color: Red }"; + let debug_str = format!("{:?}", test_struct); + + assert_eq!(expected_debug_str, debug_str); +} +