1use crate::value::r#type::Type;
5
6pub fn value_max<'a>(value: Type) -> &'a str {
7 match value {
8 Type::Boolean => unreachable!(),
9 Type::Float4 => "+3.4e38",
10 Type::Float8 => "+1.8e308",
11 Type::Int1 => "127",
12 Type::Int2 => "32_767",
13 Type::Int4 => "2_147_483_647",
14 Type::Int8 => "9_223_372_036_854_775_807",
15 Type::Int16 => "170_141_183_460_469_231_731_687_303_715_884_105_727",
16 Type::Utf8 => unreachable!(),
17 Type::Uint1 => "255",
18 Type::Uint2 => "65_535",
19 Type::Uint4 => "4_294_967_295",
20 Type::Uint8 => "18_446_744_073_709_551_615",
21 Type::Uint16 => "340_282_366_920_938_463_463_374_607_431_768_211_455",
22 Type::Date => unreachable!(),
23 Type::DateTime => unreachable!(),
24 Type::Time => unreachable!(),
25 Type::Duration => unreachable!(),
26 Type::IdentityId => unreachable!(),
27 Type::Uuid4 => unreachable!(),
28 Type::Uuid7 => unreachable!(),
29 Type::Blob => unreachable!(),
30 Type::Int => "unlimited",
31 Type::Uint => "unlimited",
32 Type::Decimal {
33 ..
34 } => "unlimited",
35 Type::Option(_) => unreachable!(),
36 Type::Any => unreachable!(),
37 Type::DictionaryId => unreachable!(),
38 Type::List(_) => unreachable!(),
39 Type::Record(_) => unreachable!(),
40 Type::Tuple(_) => unreachable!(),
41 }
42}
43
44pub fn value_range<'a>(value: Type) -> &'a str {
45 match value {
46 Type::Boolean => unreachable!(),
47 Type::Float4 => "-3.4e38 to +3.4e38",
48 Type::Float8 => "-1.8e308 to +1.8e308",
49 Type::Int1 => "-128 to 127",
50 Type::Int2 => "-32_768 to 32_767",
51 Type::Int4 => "-2_147_483_648 to 2_147_483_647",
52 Type::Int8 => "-9_223_372_036_854_775_808 to 9_223_372_036_854_775_807",
53 Type::Int16 => {
54 "-170_141_183_460_469_231_731_687_303_715_884_105_728 to 170_141_183_460_469_231_731_687_303_715_884_105_727"
55 }
56 Type::Utf8 => unreachable!(),
57 Type::Uint1 => "0 to 255",
58 Type::Uint2 => "0 to 65_535",
59 Type::Uint4 => "0 to 4_294_967_295",
60 Type::Uint8 => "0 to 18_446_744_073_709_551_615",
61 Type::Uint16 => "0 to 340_282_366_920_938_463_463_374_607_431_768_211_455",
62 Type::Date => unreachable!(),
63 Type::DateTime => unreachable!(),
64 Type::Time => unreachable!(),
65 Type::Duration => unreachable!(),
66 Type::IdentityId => unreachable!(),
67 Type::Uuid4 => unreachable!(),
68 Type::Uuid7 => unreachable!(),
69 Type::Blob => unreachable!(),
70 Type::Int => "unlimited",
71 Type::Uint => "unlimited",
72 Type::Decimal {
73 ..
74 } => "unlimited",
75 Type::Option(_) => unreachable!(),
76 Type::Any => unreachable!(),
77 Type::DictionaryId => unreachable!(),
78 Type::List(_) => unreachable!(),
79 Type::Record(_) => unreachable!(),
80 Type::Tuple(_) => unreachable!(),
81 }
82}
83
84#[cfg(test)]
85pub mod tests {
86
87 mod value_max {
88 use crate::{error::util::value_max, value::r#type::Type};
89
90 #[test]
91 fn test_signed_ints() {
92 assert_eq!(value_max(Type::Int1), "127");
93 assert_eq!(value_max(Type::Int2), "32_767");
94 assert_eq!(value_max(Type::Int4), "2_147_483_647");
95 assert_eq!(value_max(Type::Int8), "9_223_372_036_854_775_807");
96 assert_eq!(value_max(Type::Int16), "170_141_183_460_469_231_731_687_303_715_884_105_727");
97 }
98
99 #[test]
100 fn test_unsigned_ints() {
101 assert_eq!(value_max(Type::Uint1), "255");
102 assert_eq!(value_max(Type::Uint2), "65_535");
103 assert_eq!(value_max(Type::Uint4), "4_294_967_295");
104 assert_eq!(value_max(Type::Uint8), "18_446_744_073_709_551_615");
105 assert_eq!(value_max(Type::Uint16), "340_282_366_920_938_463_463_374_607_431_768_211_455");
106 }
107
108 #[test]
109 fn test_floats() {
110 assert_eq!(value_max(Type::Float4), "+3.4e38");
111 assert_eq!(value_max(Type::Float8), "+1.8e308");
112 }
113 }
114
115 mod value_range {
116 use crate::{error::util::value_range, value::r#type::Type};
117
118 #[test]
119 fn test_signed_ints() {
120 assert_eq!(value_range(Type::Int1), "-128 to 127");
121 assert_eq!(value_range(Type::Int2), "-32_768 to 32_767");
122 assert_eq!(value_range(Type::Int4), "-2_147_483_648 to 2_147_483_647");
123 assert_eq!(value_range(Type::Int8), "-9_223_372_036_854_775_808 to 9_223_372_036_854_775_807");
124 assert_eq!(
125 value_range(Type::Int16),
126 "-170_141_183_460_469_231_731_687_303_715_884_105_728 to 170_141_183_460_469_231_731_687_303_715_884_105_727"
127 );
128 }
129
130 #[test]
131 fn test_unsigned_ints() {
132 assert_eq!(value_range(Type::Uint1), "0 to 255");
133 assert_eq!(value_range(Type::Uint2), "0 to 65_535");
134 assert_eq!(value_range(Type::Uint4), "0 to 4_294_967_295");
135 assert_eq!(value_range(Type::Uint8), "0 to 18_446_744_073_709_551_615");
136 assert_eq!(
137 value_range(Type::Uint16),
138 "0 to 340_282_366_920_938_463_463_374_607_431_768_211_455"
139 );
140 }
141
142 #[test]
143 fn test_floats() {
144 assert_eq!(value_range(Type::Float4), "-3.4e38 to +3.4e38");
145 assert_eq!(value_range(Type::Float8), "-1.8e308 to +1.8e308");
146 }
147 }
148}