copybook-codepage 0.4.3

Codepage and unmappable-character policy types for copybook-rs.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
#![cfg_attr(not(test), deny(clippy::unwrap_used, clippy::expect_used))]
// SPDX-License-Identifier: AGPL-3.0-or-later
//! Codepage domain types and helpers.
//!
//! This crate contains codepage-related enums and codepage-specific constants
//! used by charset and numeric handling.

#[cfg(feature = "clap")]
use clap::ValueEnum;
use serde::{Deserialize, Serialize};
use std::str::FromStr;

/// Character encoding specification
///
/// # Examples
///
/// ```
/// use copybook_codepage::Codepage;
///
/// let cp = Codepage::CP037;
/// assert!(cp.is_ebcdic());
/// assert_eq!(cp.code_page_number(), Some(37));
/// assert_eq!(cp.description(), "EBCDIC Code Page 037 (US/Canada)");
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "clap", derive(ValueEnum))]
pub enum Codepage {
    /// ASCII encoding
    ASCII,
    /// EBCDIC Code Page 037 (US/Canada)
    #[cfg_attr(feature = "clap", value(name = "cp037"))]
    CP037,
    /// EBCDIC Code Page 273 (Germany/Austria)
    #[cfg_attr(feature = "clap", value(name = "cp273"))]
    CP273,
    /// EBCDIC Code Page 500 (International)
    #[cfg_attr(feature = "clap", value(name = "cp500"))]
    CP500,
    /// EBCDIC Code Page 1047 (Open Systems)
    #[cfg_attr(feature = "clap", value(name = "cp1047"))]
    CP1047,
    /// EBCDIC Code Page 1140 (US/Canada with Euro)
    #[cfg_attr(feature = "clap", value(name = "cp1140"))]
    CP1140,
}

impl Codepage {
    /// Check if this is an ASCII codepage
    #[must_use]
    #[inline]
    pub const fn is_ascii(self) -> bool {
        matches!(self, Self::ASCII)
    }

    /// Check if this is an EBCDIC codepage
    #[must_use]
    #[inline]
    pub const fn is_ebcdic(self) -> bool {
        !self.is_ascii()
    }

    /// Get the numeric code page identifier
    #[must_use]
    #[inline]
    pub const fn code_page_number(self) -> Option<u16> {
        match self {
            Self::ASCII => None,
            Self::CP037 => Some(37),
            Self::CP273 => Some(273),
            Self::CP500 => Some(500),
            Self::CP1047 => Some(1047),
            Self::CP1140 => Some(1140),
        }
    }

    /// Get a human-readable description of the codepage
    #[must_use]
    #[inline]
    pub const fn description(self) -> &'static str {
        match self {
            Self::ASCII => "ASCII encoding",
            Self::CP037 => "EBCDIC Code Page 037 (US/Canada)",
            Self::CP273 => "EBCDIC Code Page 273 (Germany/Austria)",
            Self::CP500 => "EBCDIC Code Page 500 (International)",
            Self::CP1047 => "EBCDIC Code Page 1047 (Open Systems)",
            Self::CP1140 => "EBCDIC Code Page 1140 (US/Canada with Euro)",
        }
    }
}

impl std::fmt::Display for Codepage {
    #[inline]
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::ASCII => write!(f, "ascii"),
            Self::CP037 => write!(f, "cp037"),
            Self::CP273 => write!(f, "cp273"),
            Self::CP500 => write!(f, "cp500"),
            Self::CP1047 => write!(f, "cp1047"),
            Self::CP1140 => write!(f, "cp1140"),
        }
    }
}

impl FromStr for Codepage {
    type Err = std::convert::Infallible;

    #[inline]
    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
        Ok(match s.to_lowercase().as_str() {
            "ascii" => Self::ASCII,
            "cp273" => Self::CP273,
            "cp500" => Self::CP500,
            "cp1047" => Self::CP1047,
            "cp1140" => Self::CP1140,
            // Default to CP037 for backward compatibility
            _ => Self::CP037,
        })
    }
}

/// Policy for handling unmappable characters during decode
///
/// # Examples
///
/// ```
/// use copybook_codepage::UnmappablePolicy;
///
/// let policy = UnmappablePolicy::Replace;
/// assert_eq!(format!("{policy}"), "replace");
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "clap", derive(ValueEnum))]
pub enum UnmappablePolicy {
    /// Error on unmappable characters
    #[cfg_attr(feature = "clap", value(name = "error"))]
    Error,
    /// Replace with U+FFFD
    #[cfg_attr(feature = "clap", value(name = "replace"))]
    Replace,
    /// Skip unmappable characters
    #[cfg_attr(feature = "clap", value(name = "skip"))]
    Skip,
}

impl std::fmt::Display for UnmappablePolicy {
    #[inline]
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Error => write!(f, "error"),
            Self::Replace => write!(f, "replace"),
            Self::Skip => write!(f, "skip"),
        }
    }
}

impl FromStr for UnmappablePolicy {
    type Err = std::convert::Infallible;

    #[inline]
    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
        Ok(match s.to_lowercase().as_str() {
            "replace" => Self::Replace,
            "skip" => Self::Skip,
            _ => Self::Error, // Default to Error for backward compatibility
        })
    }
}

// Zoned decimal sign tables map the zone nibble (high 4 bits) to sign info.
static EBCDIC_ZONED_SIGNS: [(bool, bool); 16] = [
    (false, false), // 0x0_: unsigned
    (false, false), // 0x1_: unsigned
    (false, false), // 0x2_: unsigned
    (false, false), // 0x3_: unsigned
    (false, false), // 0x4_: unsigned
    (false, false), // 0x5_: unsigned
    (false, false), // 0x6_: unsigned
    (false, false), // 0x7_: unsigned
    (false, false), // 0x8_: unsigned
    (false, false), // 0x9_: unsigned
    (false, false), // 0xA_: unsigned
    (false, false), // 0xB_: unsigned
    (true, false),  // 0xC_: positive
    (true, true),   // 0xD_: negative
    (false, false), // 0xE_: unsigned
    (true, false),  // 0xF_: positive (default)
];

// ASCII overpunch requires byte-level logic, so zoned table is intentionally
// unsigned to avoid accidental misuse in ASCII code paths.
static ASCII_ZONED_SIGNS: [(bool, bool); 16] = [(false, false); 16];

/// Get zoned decimal sign table for a codepage.
#[must_use]
#[inline]
pub fn get_zoned_sign_table(codepage: Codepage) -> &'static [(bool, bool); 16] {
    match codepage {
        Codepage::ASCII => &ASCII_ZONED_SIGNS,
        _ => &EBCDIC_ZONED_SIGNS,
    }
}

/// Get the space byte value for a codepage.
///
/// Returns `0x20` for ASCII, `0x40` for all EBCDIC codepages.
#[must_use]
#[inline]
pub const fn space_byte(codepage: Codepage) -> u8 {
    match codepage {
        Codepage::ASCII => 0x20,
        Codepage::CP037
        | Codepage::CP273
        | Codepage::CP500
        | Codepage::CP1047
        | Codepage::CP1140 => 0x40,
    }
}

#[cfg(test)]
#[allow(clippy::expect_used, clippy::unwrap_used)]
mod tests {
    use super::*;

    #[test]
    fn test_space_byte_ascii() {
        assert_eq!(space_byte(Codepage::ASCII), 0x20);
    }

    #[test]
    fn test_space_byte_ebcdic() {
        assert_eq!(space_byte(Codepage::CP037), 0x40);
        assert_eq!(space_byte(Codepage::CP273), 0x40);
        assert_eq!(space_byte(Codepage::CP500), 0x40);
        assert_eq!(space_byte(Codepage::CP1047), 0x40);
        assert_eq!(space_byte(Codepage::CP1140), 0x40);
    }

    #[test]
    fn test_codepage_is_ascii() {
        assert!(Codepage::ASCII.is_ascii());
        assert!(!Codepage::CP037.is_ascii());
    }

    #[test]
    fn test_codepage_is_ebcdic() {
        assert!(!Codepage::ASCII.is_ebcdic());
        assert!(Codepage::CP037.is_ebcdic());
    }

    #[test]
    fn test_codepage_code_page_number() {
        assert_eq!(Codepage::ASCII.code_page_number(), None);
        assert_eq!(Codepage::CP037.code_page_number(), Some(37));
        assert_eq!(Codepage::CP1140.code_page_number(), Some(1140));
    }

    #[test]
    fn test_codepage_from_str_defaults_to_cp037() {
        assert_eq!(
            <Codepage as std::str::FromStr>::from_str("unknown").unwrap(),
            Codepage::CP037
        );
    }

    #[test]
    fn test_unmappable_policy_from_str_defaults_to_error() {
        assert_eq!(
            <UnmappablePolicy as std::str::FromStr>::from_str("unknown").unwrap(),
            UnmappablePolicy::Error
        );
    }

    #[test]
    fn test_get_zoned_sign_table_ascii_is_unsigned() {
        let table = get_zoned_sign_table(Codepage::ASCII);
        assert!(table.iter().all(|entry| *entry == (false, false)));
    }

    #[test]
    fn test_get_zoned_sign_table_ebcdic_has_signed_entries() {
        let table = get_zoned_sign_table(Codepage::CP037);
        assert_eq!(table[0xC], (true, false));
        assert_eq!(table[0xD], (true, true));
        assert_eq!(table[0xF], (true, false));
    }

    // --- Codepage::description tests ---

    #[test]
    fn test_codepage_description_all_variants() {
        assert_eq!(Codepage::ASCII.description(), "ASCII encoding");
        assert_eq!(
            Codepage::CP037.description(),
            "EBCDIC Code Page 037 (US/Canada)"
        );
        assert_eq!(
            Codepage::CP273.description(),
            "EBCDIC Code Page 273 (Germany/Austria)"
        );
        assert_eq!(
            Codepage::CP500.description(),
            "EBCDIC Code Page 500 (International)"
        );
        assert_eq!(
            Codepage::CP1047.description(),
            "EBCDIC Code Page 1047 (Open Systems)"
        );
        assert_eq!(
            Codepage::CP1140.description(),
            "EBCDIC Code Page 1140 (US/Canada with Euro)"
        );
    }

    // --- Codepage Display tests ---

    #[test]
    fn test_codepage_display_all_variants() {
        assert_eq!(format!("{}", Codepage::ASCII), "ascii");
        assert_eq!(format!("{}", Codepage::CP037), "cp037");
        assert_eq!(format!("{}", Codepage::CP273), "cp273");
        assert_eq!(format!("{}", Codepage::CP500), "cp500");
        assert_eq!(format!("{}", Codepage::CP1047), "cp1047");
        assert_eq!(format!("{}", Codepage::CP1140), "cp1140");
    }

    // --- Codepage FromStr tests ---

    #[test]
    fn test_codepage_from_str_all_valid_variants() {
        assert_eq!(
            <Codepage as std::str::FromStr>::from_str("ascii").unwrap(),
            Codepage::ASCII
        );
        assert_eq!(
            <Codepage as std::str::FromStr>::from_str("cp273").unwrap(),
            Codepage::CP273
        );
        assert_eq!(
            <Codepage as std::str::FromStr>::from_str("cp500").unwrap(),
            Codepage::CP500
        );
        assert_eq!(
            <Codepage as std::str::FromStr>::from_str("cp1047").unwrap(),
            Codepage::CP1047
        );
        assert_eq!(
            <Codepage as std::str::FromStr>::from_str("cp1140").unwrap(),
            Codepage::CP1140
        );
    }

    #[test]
    fn test_codepage_from_str_case_insensitive() {
        assert_eq!(
            <Codepage as std::str::FromStr>::from_str("ASCII").unwrap(),
            Codepage::ASCII
        );
        assert_eq!(
            <Codepage as std::str::FromStr>::from_str("CP273").unwrap(),
            Codepage::CP273
        );
        assert_eq!(
            <Codepage as std::str::FromStr>::from_str("Cp500").unwrap(),
            Codepage::CP500
        );
    }

    #[test]
    fn test_codepage_from_str_empty_string_defaults_to_cp037() {
        assert_eq!(
            <Codepage as std::str::FromStr>::from_str("").unwrap(),
            Codepage::CP037
        );
    }

    // --- Codepage is_ebcdic exhaustive ---

    #[test]
    fn test_codepage_is_ebcdic_all_variants() {
        assert!(!Codepage::ASCII.is_ebcdic());
        assert!(Codepage::CP037.is_ebcdic());
        assert!(Codepage::CP273.is_ebcdic());
        assert!(Codepage::CP500.is_ebcdic());
        assert!(Codepage::CP1047.is_ebcdic());
        assert!(Codepage::CP1140.is_ebcdic());
    }

    // --- Codepage code_page_number exhaustive ---

    #[test]
    fn test_codepage_code_page_number_all_variants() {
        assert_eq!(Codepage::ASCII.code_page_number(), None);
        assert_eq!(Codepage::CP037.code_page_number(), Some(37));
        assert_eq!(Codepage::CP273.code_page_number(), Some(273));
        assert_eq!(Codepage::CP500.code_page_number(), Some(500));
        assert_eq!(Codepage::CP1047.code_page_number(), Some(1047));
        assert_eq!(Codepage::CP1140.code_page_number(), Some(1140));
    }

    // --- UnmappablePolicy Display tests ---

    #[test]
    fn test_unmappable_policy_display_all_variants() {
        assert_eq!(format!("{}", UnmappablePolicy::Error), "error");
        assert_eq!(format!("{}", UnmappablePolicy::Replace), "replace");
        assert_eq!(format!("{}", UnmappablePolicy::Skip), "skip");
    }

    // --- UnmappablePolicy FromStr tests ---

    #[test]
    fn test_unmappable_policy_from_str_all_valid() {
        assert_eq!(
            <UnmappablePolicy as std::str::FromStr>::from_str("replace").unwrap(),
            UnmappablePolicy::Replace
        );
        assert_eq!(
            <UnmappablePolicy as std::str::FromStr>::from_str("skip").unwrap(),
            UnmappablePolicy::Skip
        );
        assert_eq!(
            <UnmappablePolicy as std::str::FromStr>::from_str("error").unwrap(),
            UnmappablePolicy::Error
        );
    }

    #[test]
    fn test_unmappable_policy_from_str_case_insensitive() {
        assert_eq!(
            <UnmappablePolicy as std::str::FromStr>::from_str("REPLACE").unwrap(),
            UnmappablePolicy::Replace
        );
        assert_eq!(
            <UnmappablePolicy as std::str::FromStr>::from_str("SKIP").unwrap(),
            UnmappablePolicy::Skip
        );
    }

    // --- Zoned sign table exhaustive ---

    #[test]
    fn test_get_zoned_sign_table_ebcdic_unsigned_nibbles() {
        let table = get_zoned_sign_table(Codepage::CP037);
        for (i, &entry) in table.iter().enumerate().take(0xB + 1) {
            assert_eq!(entry, (false, false), "Expected unsigned at nibble 0x{i:X}");
        }
        assert_eq!(table[0xE], (false, false));
    }

    #[test]
    fn test_get_zoned_sign_table_all_ebcdic_codepages_same() {
        let cp037 = get_zoned_sign_table(Codepage::CP037);
        let cp273 = get_zoned_sign_table(Codepage::CP273);
        let cp500 = get_zoned_sign_table(Codepage::CP500);
        let cp1047 = get_zoned_sign_table(Codepage::CP1047);
        let cp1140 = get_zoned_sign_table(Codepage::CP1140);
        assert_eq!(cp037, cp273);
        assert_eq!(cp037, cp500);
        assert_eq!(cp037, cp1047);
        assert_eq!(cp037, cp1140);
    }

    // --- Serde round-trip ---

    #[test]
    fn test_codepage_serde_roundtrip() {
        let cp = Codepage::CP037;
        let json = serde_json::to_string(&cp).unwrap();
        let deserialized: Codepage = serde_json::from_str(&json).unwrap();
        assert_eq!(cp, deserialized);
    }

    #[test]
    fn test_unmappable_policy_serde_roundtrip() {
        let policy = UnmappablePolicy::Replace;
        let json = serde_json::to_string(&policy).unwrap();
        let deserialized: UnmappablePolicy = serde_json::from_str(&json).unwrap();
        assert_eq!(policy, deserialized);
    }

    // --- Additional coverage ---

    #[test]
    fn test_codepage_clone_preserves_value() {
        let cp = Codepage::CP500;
        let cloned = cp;
        assert_eq!(cp, cloned);
    }

    #[test]
    fn test_codepage_eq_different_variants() {
        assert_ne!(Codepage::ASCII, Codepage::CP037);
        assert_ne!(Codepage::CP037, Codepage::CP273);
        assert_ne!(Codepage::CP273, Codepage::CP500);
        assert_ne!(Codepage::CP500, Codepage::CP1047);
        assert_ne!(Codepage::CP1047, Codepage::CP1140);
    }

    #[test]
    fn test_codepage_debug_format() {
        let debug = format!("{:?}", Codepage::CP037);
        assert_eq!(debug, "CP037");
        let debug = format!("{:?}", Codepage::ASCII);
        assert_eq!(debug, "ASCII");
    }

    #[test]
    fn test_codepage_serde_all_variants_roundtrip() {
        let variants = [
            Codepage::ASCII,
            Codepage::CP037,
            Codepage::CP273,
            Codepage::CP500,
            Codepage::CP1047,
            Codepage::CP1140,
        ];
        for cp in variants {
            let json = serde_json::to_string(&cp).unwrap();
            let deserialized: Codepage = serde_json::from_str(&json).unwrap();
            assert_eq!(cp, deserialized, "Roundtrip failed for {cp}");
        }
    }

    #[test]
    fn test_codepage_from_str_cp037_explicit() {
        // cp037 should match explicitly, not just as default
        assert_eq!(
            <Codepage as std::str::FromStr>::from_str("cp037").unwrap(),
            Codepage::CP037
        );
    }

    #[test]
    fn test_codepage_display_roundtrip_via_from_str() {
        let variants = [
            Codepage::ASCII,
            Codepage::CP273,
            Codepage::CP500,
            Codepage::CP1047,
            Codepage::CP1140,
        ];
        for cp in variants {
            let displayed = cp.to_string();
            let parsed: Codepage = displayed.parse().unwrap();
            assert_eq!(cp, parsed, "Display/FromStr roundtrip failed for {cp}");
        }
    }

    #[test]
    fn test_unmappable_policy_clone_preserves_value() {
        let policy = UnmappablePolicy::Skip;
        let cloned = policy;
        assert_eq!(policy, cloned);
    }

    #[test]
    fn test_unmappable_policy_debug_format() {
        assert_eq!(format!("{:?}", UnmappablePolicy::Error), "Error");
        assert_eq!(format!("{:?}", UnmappablePolicy::Replace), "Replace");
        assert_eq!(format!("{:?}", UnmappablePolicy::Skip), "Skip");
    }

    #[test]
    fn test_unmappable_policy_serde_all_variants_roundtrip() {
        let variants = [
            UnmappablePolicy::Error,
            UnmappablePolicy::Replace,
            UnmappablePolicy::Skip,
        ];
        for policy in variants {
            let json = serde_json::to_string(&policy).unwrap();
            let deserialized: UnmappablePolicy = serde_json::from_str(&json).unwrap();
            assert_eq!(policy, deserialized, "Roundtrip failed for {policy}");
        }
    }

    #[test]
    fn test_unmappable_policy_eq_different_variants() {
        assert_ne!(UnmappablePolicy::Error, UnmappablePolicy::Replace);
        assert_ne!(UnmappablePolicy::Replace, UnmappablePolicy::Skip);
        assert_ne!(UnmappablePolicy::Skip, UnmappablePolicy::Error);
    }

    #[test]
    fn test_unmappable_policy_from_str_empty_defaults_to_error() {
        assert_eq!(
            <UnmappablePolicy as std::str::FromStr>::from_str("").unwrap(),
            UnmappablePolicy::Error
        );
    }

    #[test]
    fn test_space_byte_consistency_with_is_ebcdic() {
        let variants = [
            Codepage::ASCII,
            Codepage::CP037,
            Codepage::CP273,
            Codepage::CP500,
            Codepage::CP1047,
            Codepage::CP1140,
        ];
        for cp in variants {
            if cp.is_ebcdic() {
                assert_eq!(space_byte(cp), 0x40, "EBCDIC {cp} should have space 0x40");
            } else {
                assert_eq!(space_byte(cp), 0x20, "ASCII should have space 0x20");
            }
        }
    }

    #[test]
    fn test_codepage_is_ascii_and_is_ebcdic_mutually_exclusive() {
        let variants = [
            Codepage::ASCII,
            Codepage::CP037,
            Codepage::CP273,
            Codepage::CP500,
            Codepage::CP1047,
            Codepage::CP1140,
        ];
        for cp in variants {
            assert_ne!(
                cp.is_ascii(),
                cp.is_ebcdic(),
                "is_ascii and is_ebcdic must be mutually exclusive for {cp}"
            );
        }
    }

    #[test]
    fn test_get_zoned_sign_table_ebcdic_positive_nibble_f() {
        let table = get_zoned_sign_table(Codepage::CP037);
        // 0xF_ is unsigned/positive default
        let (is_signed, is_negative) = table[0xF];
        assert!(is_signed);
        assert!(!is_negative);
    }

    #[test]
    fn test_get_zoned_sign_table_ebcdic_negative_nibble_d() {
        let table = get_zoned_sign_table(Codepage::CP037);
        let (is_signed, is_negative) = table[0xD];
        assert!(is_signed);
        assert!(is_negative);
    }
}