|
7 | 7 |
|
8 | 8 | use crate::framework::itest;
|
9 | 9 |
|
10 |
| -use godot::global::{Key, KeyModifierMask}; |
| 10 | +use godot::classes::{mesh, window}; |
| 11 | +use godot::global::{InlineAlignment, Key, KeyModifierMask, Orientation}; |
11 | 12 | use godot::obj::{EngineBitfield, EngineEnum};
|
12 | 13 |
|
13 | 14 | #[itest]
|
@@ -46,3 +47,135 @@ fn enum_with_masked_bitfield_from_ord() {
|
46 | 47 | // let back = Key::try_from_ord(31);
|
47 | 48 | // assert_eq!(back, None, "don't deserialize invalid bitmasked enum");
|
48 | 49 | }
|
| 50 | + |
| 51 | +#[itest] |
| 52 | +fn enum_values_class() { |
| 53 | + let expected_modes = [ |
| 54 | + window::Mode::WINDOWED, |
| 55 | + window::Mode::MINIMIZED, |
| 56 | + window::Mode::MAXIMIZED, |
| 57 | + window::Mode::FULLSCREEN, |
| 58 | + window::Mode::EXCLUSIVE_FULLSCREEN, |
| 59 | + ]; |
| 60 | + |
| 61 | + assert_eq!(window::Mode::values(), &expected_modes); |
| 62 | +} |
| 63 | + |
| 64 | +#[itest] |
| 65 | +fn enum_values_global() { |
| 66 | + let expected_orientations = [Orientation::VERTICAL, Orientation::HORIZONTAL]; |
| 67 | + |
| 68 | + assert_eq!(Orientation::values(), &expected_orientations); |
| 69 | +} |
| 70 | + |
| 71 | +#[itest] |
| 72 | +fn enum_values_duplicates() { |
| 73 | + // InlineAlignment has many duplicate ordinals, but values() should return only distinct ones |
| 74 | + // The order matches the declaration order in the JSON API, not ordinal order |
| 75 | + let expected = [ |
| 76 | + (InlineAlignment::TOP_TO, 0, true), |
| 77 | + (InlineAlignment::CENTER_TO, 1, true), |
| 78 | + (InlineAlignment::BASELINE_TO, 3, true), |
| 79 | + (InlineAlignment::BOTTOM_TO, 2, true), |
| 80 | + (InlineAlignment::TO_TOP, 0, false), // duplicate of TOP_TO |
| 81 | + (InlineAlignment::TO_CENTER, 4, true), |
| 82 | + (InlineAlignment::TO_BASELINE, 8, true), |
| 83 | + (InlineAlignment::TO_BOTTOM, 12, true), |
| 84 | + (InlineAlignment::TOP, 0, false), // duplicate of TOP_TO |
| 85 | + (InlineAlignment::CENTER, 5, true), |
| 86 | + (InlineAlignment::BOTTOM, 14, true), |
| 87 | + (InlineAlignment::IMAGE_MASK, 3, false), // duplicate of BASELINE_TO |
| 88 | + (InlineAlignment::TEXT_MASK, 12, false), // duplicate of TO_BOTTOM |
| 89 | + ]; |
| 90 | + |
| 91 | + let all_constants = InlineAlignment::all_constants(); |
| 92 | + let mut expected_distinct_values = vec![]; |
| 93 | + for ((value, ord, is_distinct), c) in expected.into_iter().zip(all_constants) { |
| 94 | + if is_distinct { |
| 95 | + assert_eq!(c.rust_name(), value.as_str()); // First distinct. |
| 96 | + expected_distinct_values.push(value); |
| 97 | + } |
| 98 | + |
| 99 | + assert_eq!(c.value(), value); |
| 100 | + assert_eq!(c.ord(), ord); |
| 101 | + } |
| 102 | + |
| 103 | + assert_eq!(InlineAlignment::values(), &expected_distinct_values); |
| 104 | + |
| 105 | + // Some known duplicates. |
| 106 | + assert_eq!(InlineAlignment::TOP_TO, InlineAlignment::TO_TOP); // ord 0 |
| 107 | + assert_eq!(InlineAlignment::TOP_TO, InlineAlignment::TOP); // ord 0 |
| 108 | + assert_eq!(InlineAlignment::BASELINE_TO, InlineAlignment::IMAGE_MASK); // ord 3 |
| 109 | + assert_eq!(InlineAlignment::TO_BOTTOM, InlineAlignment::TEXT_MASK); // ord 12 |
| 110 | +} |
| 111 | + |
| 112 | +#[itest] |
| 113 | +fn enum_values_max_excluded() { |
| 114 | + let expected_array_types = [ |
| 115 | + mesh::ArrayType::VERTEX, |
| 116 | + mesh::ArrayType::NORMAL, |
| 117 | + mesh::ArrayType::TANGENT, |
| 118 | + mesh::ArrayType::COLOR, |
| 119 | + mesh::ArrayType::TEX_UV, |
| 120 | + mesh::ArrayType::TEX_UV2, |
| 121 | + mesh::ArrayType::CUSTOM0, |
| 122 | + mesh::ArrayType::CUSTOM1, |
| 123 | + mesh::ArrayType::CUSTOM2, |
| 124 | + mesh::ArrayType::CUSTOM3, |
| 125 | + mesh::ArrayType::BONES, |
| 126 | + mesh::ArrayType::WEIGHTS, |
| 127 | + mesh::ArrayType::INDEX, |
| 128 | + ]; |
| 129 | + |
| 130 | + let array_types = mesh::ArrayType::values(); |
| 131 | + assert_eq!(array_types, &expected_array_types); |
| 132 | + assert!( |
| 133 | + !array_types.contains(&mesh::ArrayType::MAX), |
| 134 | + "ArrayType::MAX should be excluded from values()" |
| 135 | + ); |
| 136 | + |
| 137 | + // However, it should still be present in all_constants(). |
| 138 | + let all_constants = mesh::ArrayType::all_constants(); |
| 139 | + assert!( |
| 140 | + all_constants |
| 141 | + .iter() |
| 142 | + .any(|c| c.value() == mesh::ArrayType::MAX), |
| 143 | + "ArrayType::MAX should be present in all_constants()" |
| 144 | + ); |
| 145 | +} |
| 146 | + |
| 147 | +#[itest] |
| 148 | +fn enum_all_constants() { |
| 149 | + let constants = InlineAlignment::all_constants(); |
| 150 | + assert!( |
| 151 | + constants.len() > InlineAlignment::values().len(), |
| 152 | + "all_constants() should include duplicates" |
| 153 | + ); |
| 154 | + |
| 155 | + // Check one known constant. |
| 156 | + let first = constants[0]; |
| 157 | + assert_eq!(first.rust_name(), "TOP_TO"); |
| 158 | + assert_eq!(first.godot_name(), "INLINE_ALIGNMENT_TOP_TO"); |
| 159 | + assert_eq!(first.ord(), 0); |
| 160 | + assert_eq!(first.value(), InlineAlignment::TOP_TO); |
| 161 | + |
| 162 | + // Check specific constants at known indices, with equal ordinals. |
| 163 | + let known_a = constants[2]; |
| 164 | + let known_b = constants[11]; |
| 165 | + |
| 166 | + assert_eq!(known_a.ord(), 3); |
| 167 | + assert_eq!(known_a.rust_name(), "BASELINE_TO"); |
| 168 | + assert_eq!(known_a.godot_name(), "INLINE_ALIGNMENT_BASELINE_TO"); |
| 169 | + assert_eq!(known_a.value(), InlineAlignment::BASELINE_TO); |
| 170 | + |
| 171 | + assert_eq!(known_b.ord(), 3); |
| 172 | + assert_eq!(known_b.rust_name(), "IMAGE_MASK"); |
| 173 | + assert_eq!(known_b.godot_name(), "INLINE_ALIGNMENT_IMAGE_MASK"); |
| 174 | + assert_eq!(known_b.value(), InlineAlignment::IMAGE_MASK); |
| 175 | + |
| 176 | + // "Front-end" values are equal, too. |
| 177 | + assert_eq!( |
| 178 | + InlineAlignment::IMAGE_MASK.ord(), |
| 179 | + InlineAlignment::BASELINE_TO.ord() |
| 180 | + ); |
| 181 | +} |
0 commit comments