Debian Codegraph @

tests/digit_tests.rs

raw symbols SCIP
1 #![cfg(any(
2 feature = "parse-floats",
3 feature = "parse-integers",
4 feature = "write-floats",
5 feature = "write-integers",
6 ))]
7
8 use lexical_utilrust-analyzer cargo lexical-util 1.0.7 crate/::digitrust-analyzer cargo lexical-util 1.0.7 digit/;
9
10 #[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
11 fn char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(c: u8, radix: u32, expected: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u32>) {
12 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(digitrust-analyzer cargo lexical-util 1.0.7 digit/::char_to_digit_construst-analyzer cargo lexical-util 1.0.7 digit/char_to_digit_const().(c, radix), expected);
13 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(digitrust-analyzer cargo lexical-util 1.0.7 digit/::char_to_digitrust-analyzer cargo lexical-util 1.0.7 digit/char_to_digit().(c, radix), expected);
14 }
15
16 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
17 #[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
18 fn char_to_digit_testrust-analyzer cargo lexical-util 1.0.7 char_to_digit_test().() {
19 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'0', 2, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0));
20 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'1', 2, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
21 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'9', 2, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
22 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'A', 2, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
23 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'Z', 2, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
24
25 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'0', 10, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0));
26 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'1', 10, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
27 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'9', 10, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(9));
28 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'A', 10, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
29 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'Z', 10, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
30
31 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'0', 16, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0));
32 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'1', 16, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(1));
33 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'9', 16, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(9));
34 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'A', 16, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(10));
35 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(b'Z', 16, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
36
37 // char_to_digit doesn't care about the radix.
38 // check some more comprehensive cases.
39 for c in b'0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'9' {
40 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(c, 10, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().b'0' as u32));
41 }
42 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x29, 10, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
43 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x3A, 10, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
44 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x59, 10, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
45
46 for c in b'0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'8' {
47 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(c, 9, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().b'0' as u32));
48 }
49 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x29, 9, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
50 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x39, 9, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
51 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x3A, 9, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
52 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x59, 9, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
53
54 for c in b'0'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'9' {
55 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(c, 16, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().b'0' as u32));
56 }
57 for c in b'a'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'f' {
58 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(c, 16, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().b'a' as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().10));
59 }
60 for c in b'A'..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#b'F' {
61 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(c, 16, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(c as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().b'A' as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().10));
62 }
63 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x29, 16, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
64 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x40, 16, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
65 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x3A, 16, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
66 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x59, 16, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
67 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x41, 16, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(10));
68 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x47, 16, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
69 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x5A, 16, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
70 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x61, 16, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(10));
71 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x67, 16, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
72 char_to_digitrust-analyzer cargo lexical-util 1.0.7 char_to_digit().(0x7A, 16, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
73 }
74
75 #[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
76 fn char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(c: u8, radix: u32, expected: bool) {
77 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(digitrust-analyzer cargo lexical-util 1.0.7 digit/::char_is_digit_construst-analyzer cargo lexical-util 1.0.7 digit/char_is_digit_const().(c, radix), expected);
78 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(digitrust-analyzer cargo lexical-util 1.0.7 digit/::char_is_digitrust-analyzer cargo lexical-util 1.0.7 digit/char_is_digit().(c, radix), expected);
79 }
80
81 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
82 #[cfg(any(feature = "parse-floats", feature = "parse-integers"))]
83 fn char_is_digit_const_testrust-analyzer cargo lexical-util 1.0.7 char_is_digit_const_test().() {
84 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'0', 2, true);
85 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'1', 2, true);
86 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'9', 2, false);
87 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'A', 2, false);
88 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'Z', 2, false);
89
90 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'0', 10, true);
91 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'1', 10, true);
92 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'9', 10, true);
93 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'A', 10, false);
94 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'Z', 10, false);
95
96 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'0', 16, true);
97 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'1', 16, true);
98 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'9', 16, true);
99 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'A', 16, true);
100 char_is_digitrust-analyzer cargo lexical-util 1.0.7 char_is_digit().(b'Z', 16, false);
101 }
102
103 #[cfg(any(feature = "write-floats", feature = "write-integers"))]
104 fn digit_to_charrust-analyzer cargo lexical-util 1.0.7 digit_to_char().(digit: u32, radix: u32, expected: u8) {
105 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(digitrust-analyzer cargo lexical-util 1.0.7 digit/::digit_to_char_construst-analyzer cargo lexical-util 1.0.7 digit/digit_to_char_const().(digit, radix), expected);
106 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(digitrust-analyzer cargo lexical-util 1.0.7 digit/::digit_to_charrust-analyzer cargo lexical-util 1.0.7 digit/digit_to_char().(digit), expected);
107 }
108
109 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
110 #[cfg(any(feature = "write-floats", feature = "write-integers"))]
111 fn digit_to_char_const_testrust-analyzer cargo lexical-util 1.0.7 digit_to_char_const_test().() {
112 digit_to_charrust-analyzer cargo lexical-util 1.0.7 digit_to_char().(9, 10, b'9');
113 digit_to_charrust-analyzer cargo lexical-util 1.0.7 digit_to_char().(10, 36, b'A');
114 digit_to_charrust-analyzer cargo lexical-util 1.0.7 digit_to_char().(11, 36, b'B');
115 }