Skip to content

Commit

Permalink
tests: Add new tests for derive Debug
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jinankjain authored and Jinank Jain committed Nov 12, 2023
1 parent d0ad45d commit 7b84ef1
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/derives.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 7b84ef1

Please sign in to comment.