Skip to content

Commit 7779cd6

Browse files
committed
More tests
1 parent 7365278 commit 7779cd6

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

sdk/log/crate/src/lib.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,54 @@ mod tests {
252252

253253
logger.append_with_args(u64::MAX, &[Argument::Precision(u8::MAX)]);
254254
assert!(&*logger == "0.00000000000000000@".as_bytes());
255+
256+
// 255 precision + leading 0 + decimal point
257+
let mut logger = Logger::<257>::default();
258+
logger.append_with_args(u64::MAX, &[Argument::Precision(u8::MAX)]);
259+
assert!(logger.starts_with("0.00000000000000".as_bytes()));
260+
assert!(logger.ends_with("18446744073709551615".as_bytes()));
261+
262+
logger.clear();
263+
264+
logger.append_with_args(u32::MAX, &[Argument::Precision(u8::MAX)]);
265+
assert!(logger.starts_with("0.00000000000000".as_bytes()));
266+
assert!(logger.ends_with("4294967295".as_bytes()));
267+
268+
logger.clear();
269+
270+
logger.append_with_args(u16::MAX, &[Argument::Precision(u8::MAX)]);
271+
assert!(logger.starts_with("0.00000000000000".as_bytes()));
272+
assert!(logger.ends_with("65535".as_bytes()));
273+
274+
logger.clear();
275+
276+
logger.append_with_args(u8::MAX, &[Argument::Precision(u8::MAX)]);
277+
assert!(logger.starts_with("0.00000000000000".as_bytes()));
278+
assert!(logger.ends_with("255".as_bytes()));
279+
280+
// 255 precision + sign + leading 0 + decimal point
281+
let mut logger = Logger::<258>::default();
282+
logger.append_with_args(i64::MIN, &[Argument::Precision(u8::MAX)]);
283+
assert!(logger.starts_with("-0.00000000000000".as_bytes()));
284+
assert!(logger.ends_with("9223372036854775808".as_bytes()));
285+
286+
logger.clear();
287+
288+
logger.append_with_args(i32::MIN, &[Argument::Precision(u8::MAX)]);
289+
assert!(logger.starts_with("-0.00000000000000".as_bytes()));
290+
assert!(logger.ends_with("2147483648".as_bytes()));
291+
292+
logger.clear();
293+
294+
logger.append_with_args(i16::MIN, &[Argument::Precision(u8::MAX)]);
295+
assert!(logger.starts_with("-0.00000000000000".as_bytes()));
296+
assert!(logger.ends_with("32768".as_bytes()));
297+
298+
logger.clear();
299+
300+
logger.append_with_args(i8::MIN, &[Argument::Precision(u8::MAX)]);
301+
assert!(logger.starts_with("-0.00000000000000".as_bytes()));
302+
assert!(logger.ends_with("128".as_bytes()));
255303
}
256304

257305
#[test]

0 commit comments

Comments
 (0)