1
#[allow(unused_imports)]
2
pub use super::*;
3
#[cfg(test)]
4
mod autotest_generated {
5
    use super::*;
6

            
7
    fn offsets(top: f32, left: f32, right: f32, bottom: f32) -> ResolvedOffsets {
8
        ResolvedOffsets {
9
            top,
10
            left,
11
            right,
12
            bottom,
13
        }
14
    }
15

            
16
    fn glyph(index: u32, x: f32, y: f32, w: f32, h: f32) -> GlyphInstance {
17
        GlyphInstance {
18
            index,
19
            point: LogicalPosition::new(x, y),
20
            size: LogicalSize::new(w, h),
21
        }
22
    }
23

            
24
    // --- ResolvedOffsets::zero (constructor) ---
25

            
26
    #[test]
27
    fn zero_is_all_zeroes_and_usable_in_const_context() {
28
        const Z: ResolvedOffsets = ResolvedOffsets::zero();
29
        assert_eq!(Z.top, 0.0);
30
        assert_eq!(Z.left, 0.0);
31
        assert_eq!(Z.right, 0.0);
32
        assert_eq!(Z.bottom, 0.0);
33
        // Positive zero, not -0.0: sign leaks through `f32::signum` in layout math.
34
        assert!(Z.top.is_sign_positive());
35
        assert!(Z.left.is_sign_positive());
36
        assert!(Z.right.is_sign_positive());
37
        assert!(Z.bottom.is_sign_positive());
38
    }
39

            
40
    #[test]
41
    fn zero_matches_default_and_is_neutral_for_totals() {
42
        assert_eq!(ResolvedOffsets::zero(), ResolvedOffsets::default());
43
        assert_eq!(ResolvedOffsets::zero().total_vertical(), 0.0);
44
        assert_eq!(ResolvedOffsets::zero().total_horizontal(), 0.0);
45
    }
46

            
47
    // --- ResolvedOffsets::total_vertical / total_horizontal (getters) ---
48

            
49
    #[test]
50
    fn totals_sum_only_their_own_axis() {
51
        let o = offsets(1.0, 20.0, 300.0, 4000.0);
52
        assert_eq!(o.total_vertical(), 4001.0); // top + bottom
53
        assert_eq!(o.total_horizontal(), 320.0); // left + right
54
                                                 // Perturbing one axis must not move the other.
55
        let o2 = offsets(1.0, -20.0, -300.0, 4000.0);
56
        assert_eq!(o2.total_vertical(), o.total_vertical());
57
        assert_eq!(o2.total_horizontal(), -320.0);
58
    }
59

            
60
    #[test]
61
    fn totals_handle_negative_and_cancelling_offsets() {
62
        let o = offsets(-5.0, -2.5, 2.5, 5.0);
63
        assert_eq!(o.total_vertical(), 0.0);
64
        assert_eq!(o.total_horizontal(), 0.0);
65
    }
66

            
67
    #[test]
68
    fn totals_saturate_to_infinity_instead_of_wrapping() {
69
        let o = offsets(f32::MAX, f32::MAX, f32::MAX, f32::MAX);
70
        assert!(o.total_vertical().is_infinite() && o.total_vertical().is_sign_positive());
71
        assert!(o.total_horizontal().is_infinite() && o.total_horizontal().is_sign_positive());
72

            
73
        let o = offsets(f32::MIN, f32::MIN, f32::MIN, f32::MIN);
74
        assert!(o.total_vertical().is_infinite() && o.total_vertical().is_sign_negative());
75
        assert!(o.total_horizontal().is_infinite() && o.total_horizontal().is_sign_negative());
76
    }
77

            
78
    #[test]
79
    fn totals_of_opposing_infinities_are_nan_not_a_panic() {
80
        let o = offsets(
81
            f32::INFINITY,
82
            f32::INFINITY,
83
            f32::NEG_INFINITY,
84
            f32::NEG_INFINITY,
85
        );
86
        assert!(o.total_vertical().is_nan());
87
        assert!(o.total_horizontal().is_nan());
88
    }
89

            
90
    #[test]
91
    fn totals_propagate_nan() {
92
        let o = offsets(f32::NAN, 1.0, 2.0, 10.0);
93
        assert!(o.total_vertical().is_nan());
94
        assert_eq!(o.total_horizontal(), 3.0); // unaffected axis stays finite
95

            
96
        let o = offsets(1.0, f32::NAN, 2.0, 10.0);
97
        assert_eq!(o.total_vertical(), 11.0);
98
        assert!(o.total_horizontal().is_nan());
99
    }
100

            
101
    #[test]
102
    fn totals_on_subnormals_do_not_flush_to_a_wrong_value() {
103
        let o = offsets(f32::MIN_POSITIVE, f32::MIN_POSITIVE, 0.0, 0.0);
104
        assert_eq!(o.total_vertical(), f32::MIN_POSITIVE);
105
        assert_eq!(o.total_horizontal(), f32::MIN_POSITIVE);
106
    }
107

            
108
    #[test]
109
    fn totals_are_pure_getters() {
110
        let o = offsets(3.0, 7.0, 11.0, 13.0);
111
        let before = o;
112
        let _ = o.total_vertical();
113
        let _ = o.total_horizontal();
114
        assert_eq!(o, before);
115
        // Repeated calls are deterministic.
116
        let (v1, v2) = (o.total_vertical(), o.total_vertical());
117
        let (h1, h2) = (o.total_horizontal(), o.total_horizontal());
118
        assert_eq!(v1, v2);
119
        assert_eq!(h1, h2);
120
    }
121

            
122
    // --- GlyphInstance::scale_for_dpi (numeric) ---
123

            
124
    #[test]
125
    fn scale_for_dpi_by_one_is_identity_and_never_touches_the_glyph_index() {
126
        let mut g = glyph(u32::MAX, 1.5, -2.5, 3.5, 4.5);
127
        g.scale_for_dpi(1.0);
128
        assert_eq!(g.index, u32::MAX);
129
        assert_eq!(g.point.x, 1.5);
130
        assert_eq!(g.point.y, -2.5);
131
        assert_eq!(g.size.width, 3.5);
132
        assert_eq!(g.size.height, 4.5);
133
    }
134

            
135
    #[test]
136
    fn scale_for_dpi_by_zero_collapses_to_zero_and_preserves_sign() {
137
        let mut g = glyph(7, 10.0, -10.0, 20.0, -20.0);
138
        g.scale_for_dpi(0.0);
139
        assert_eq!(g.index, 7);
140
        assert_eq!(g.point.x, 0.0);
141
        assert_eq!(g.point.y, 0.0);
142
        assert!(g.point.x.is_sign_positive());
143
        assert!(g.point.y.is_sign_negative()); // -10.0 * 0.0 == -0.0
144
        assert_eq!(g.size.width, 0.0);
145
        assert_eq!(g.size.height, 0.0);
146
    }
147

            
148
    #[test]
149
    fn scale_for_dpi_negative_factor_mirrors_deterministically() {
150
        let mut g = glyph(1, 2.0, -4.0, 8.0, -16.0);
151
        g.scale_for_dpi(-2.0);
152
        assert_eq!(g.point.x, -4.0);
153
        assert_eq!(g.point.y, 8.0);
154
        assert_eq!(g.size.width, -16.0);
155
        assert_eq!(g.size.height, 32.0);
156
    }
157

            
158
    #[test]
159
    fn scale_for_dpi_round_trips_for_exact_binary_factors() {
160
        let original = glyph(42, 12.0, -6.5, 100.0, 0.25);
161
        let mut g = original;
162
        g.scale_for_dpi(4.0);
163
        g.scale_for_dpi(0.25);
164
        assert_eq!(g.index, original.index);
165
        assert_eq!(g.point.x, original.point.x);
166
        assert_eq!(g.point.y, original.point.y);
167
        assert_eq!(g.size.width, original.size.width);
168
        assert_eq!(g.size.height, original.size.height);
169
    }
170

            
171
    #[test]
172
    fn scale_for_dpi_overflows_to_infinity_rather_than_wrapping() {
173
        let mut g = glyph(0, f32::MAX, -f32::MAX, f32::MAX, f32::MAX);
174
        g.scale_for_dpi(2.0);
175
        assert!(g.point.x.is_infinite() && g.point.x.is_sign_positive());
176
        assert!(g.point.y.is_infinite() && g.point.y.is_sign_negative());
177
        assert!(g.size.width.is_infinite());
178
        assert!(g.size.height.is_infinite());
179
    }
180

            
181
    #[test]
182
    fn scale_for_dpi_underflows_to_zero_rather_than_panicking() {
183
        let mut g = glyph(
184
            0,
185
            f32::MIN_POSITIVE,
186
            f32::MIN_POSITIVE,
187
            f32::MIN_POSITIVE,
188
            1.0,
189
        );
190
        g.scale_for_dpi(f32::MIN_POSITIVE);
191
        assert_eq!(g.point.x, 0.0);
192
        assert_eq!(g.point.y, 0.0);
193
        assert_eq!(g.size.width, 0.0);
194
        assert_eq!(g.size.height, f32::MIN_POSITIVE);
195
    }
196

            
197
    #[test]
198
    fn scale_for_dpi_with_nan_factor_poisons_all_coordinates_without_panicking() {
199
        let mut g = glyph(3, 1.0, 2.0, 3.0, 4.0);
200
        g.scale_for_dpi(f32::NAN);
201
        assert_eq!(g.index, 3);
202
        assert!(g.point.x.is_nan());
203
        assert!(g.point.y.is_nan());
204
        assert!(g.size.width.is_nan());
205
        assert!(g.size.height.is_nan());
206
    }
207

            
208
    #[test]
209
    fn scale_for_dpi_with_infinite_factor_is_defined_at_zero_and_nonzero_coords() {
210
        // finite non-zero * inf == inf (sign-correct)
211
        let mut g = glyph(0, 1.0, -1.0, 2.0, -2.0);
212
        g.scale_for_dpi(f32::INFINITY);
213
        assert!(g.point.x.is_infinite() && g.point.x.is_sign_positive());
214
        assert!(g.point.y.is_infinite() && g.point.y.is_sign_negative());
215
        assert!(g.size.width.is_infinite() && g.size.width.is_sign_positive());
216
        assert!(g.size.height.is_infinite() && g.size.height.is_sign_negative());
217

            
218
        // 0 * inf == NaN, per IEEE-754 — must not panic, must not silently become 0.
219
        let mut g = glyph(0, 0.0, 0.0, 0.0, 0.0);
220
        g.scale_for_dpi(f32::INFINITY);
221
        assert!(g.point.x.is_nan());
222
        assert!(g.size.width.is_nan());
223

            
224
        // -inf flips signs.
225
        let mut g = glyph(0, 1.0, 1.0, 1.0, 1.0);
226
        g.scale_for_dpi(f32::NEG_INFINITY);
227
        assert!(g.point.x.is_infinite() && g.point.x.is_sign_negative());
228
        assert!(g.size.height.is_infinite() && g.size.height.is_sign_negative());
229
    }
230

            
231
    #[test]
232
    fn scale_for_dpi_on_default_glyph_is_a_no_op_for_finite_factors() {
233
        let mut g = GlyphInstance::default();
234
        g.scale_for_dpi(1_000_000.0);
235
        assert_eq!(g.index, 0);
236
        assert_eq!(g.point.x, 0.0);
237
        assert_eq!(g.point.y, 0.0);
238
        assert_eq!(g.size.width, 0.0);
239
        assert_eq!(g.size.height, 0.0);
240
    }
241

            
242
    #[test]
243
    fn glyph_equality_stays_reflexive_after_a_nan_scale() {
244
        // `LogicalPosition`/`LogicalSize` quantize NaN to a single sentinel, so
245
        // `GlyphInstance: Eq` must remain reflexive even with poisoned coords.
246
        let mut g = glyph(9, 1.0, 2.0, 3.0, 4.0);
247
        g.scale_for_dpi(f32::NAN);
248
        let same = g;
249
        assert_eq!(g, same);
250
        // A NaN glyph must not compare equal to the origin glyph.
251
        assert_ne!(g, glyph(9, 0.0, 0.0, 0.0, 0.0));
252
    }
253
}