|
| 1 | +/* |
| 2 | + * Copyright (c) godot-rust; Bromeon and contributors. |
| 3 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | + * file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 6 | + */ |
| 7 | + |
| 8 | +use godot::classes::node::DuplicateFlags; |
| 9 | +use godot::obj::EngineBitfield; |
| 10 | + |
| 11 | +use crate::framework::itest; |
| 12 | + |
| 13 | +/// Necessarily since `from_ord` is not `const`. |
| 14 | +fn no_flags() -> DuplicateFlags { |
| 15 | + // Could use `Default::default()` here. Until it is broken by `!1630`, funnily enough. |
| 16 | + DuplicateFlags::from_ord(0) |
| 17 | +} |
| 18 | + |
| 19 | +const SIGNALS: DuplicateFlags = DuplicateFlags::SIGNALS; |
| 20 | +const GROUPS: DuplicateFlags = DuplicateFlags::GROUPS; |
| 21 | +const USE_INSTANTIATION: DuplicateFlags = DuplicateFlags::USE_INSTANTIATION; |
| 22 | + |
| 23 | +#[itest] |
| 24 | +fn bitfield_ops_with() { |
| 25 | + let no_flags = no_flags(); |
| 26 | + |
| 27 | + assert_eq!(no_flags.with(USE_INSTANTIATION), USE_INSTANTIATION); |
| 28 | + |
| 29 | + assert_eq!( |
| 30 | + GROUPS.with(SIGNALS), |
| 31 | + DuplicateFlags::from_ord(GROUPS.ord() | SIGNALS.ord()) |
| 32 | + ); |
| 33 | + |
| 34 | + assert_eq!(GROUPS.with(GROUPS), GROUPS); |
| 35 | + |
| 36 | + assert_eq!(GROUPS.with(GROUPS.with(SIGNALS)), GROUPS.with(SIGNALS)); |
| 37 | + |
| 38 | + let with_then_with = GROUPS.with(SIGNALS).with(USE_INSTANTIATION); |
| 39 | + assert!(with_then_with.is_set(GROUPS)); |
| 40 | + assert!(with_then_with.is_set(SIGNALS)); |
| 41 | + assert!(with_then_with.is_set(USE_INSTANTIATION)); |
| 42 | + |
| 43 | + assert_eq!(GROUPS.with(no_flags), GROUPS); |
| 44 | +} |
| 45 | + |
| 46 | +#[itest] |
| 47 | +fn bitfield_ops_without() { |
| 48 | + let no_flags = no_flags(); |
| 49 | + |
| 50 | + assert_eq!(USE_INSTANTIATION.without(USE_INSTANTIATION), no_flags); |
| 51 | + |
| 52 | + assert_eq!(SIGNALS.with(GROUPS).without(SIGNALS), GROUPS); |
| 53 | + |
| 54 | + assert_eq!(GROUPS.without(SIGNALS), GROUPS); |
| 55 | + |
| 56 | + assert_eq!( |
| 57 | + SIGNALS |
| 58 | + .with(GROUPS) |
| 59 | + .without(SIGNALS.with(USE_INSTANTIATION)), |
| 60 | + GROUPS |
| 61 | + ); |
| 62 | + |
| 63 | + let without_then_without = GROUPS |
| 64 | + .with(SIGNALS) |
| 65 | + .with(USE_INSTANTIATION) |
| 66 | + .without(SIGNALS) |
| 67 | + .without(USE_INSTANTIATION); |
| 68 | + assert!(without_then_without.is_set(GROUPS)); |
| 69 | + assert!(!without_then_without.is_set(SIGNALS)); |
| 70 | + assert!(!without_then_without.is_set(USE_INSTANTIATION)); |
| 71 | + |
| 72 | + assert_eq!(GROUPS.without(no_flags), GROUPS); |
| 73 | +} |
0 commit comments