Skip to content

Commit 37aec95

Browse files
committed
Add tests
1 parent 788ef5d commit 37aec95

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

sdk/log/crate/src/lib.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,47 @@ mod tests {
199199

200200
logger.clear();
201201

202-
// This should have no effect.
202+
// This should have no effect since it is a string.
203203
logger.append_with_args("0123456789", &[Argument::Precision(2)]);
204204
assert!(&*logger == "0123456789".as_bytes());
205+
206+
// Setting a precision equal to or greater than the maximum digits should have
207+
// no effect. The value used will be capped at the maximum digits - 1.
208+
let mut l1 = Logger::<50>::default();
209+
let mut l2 = Logger::<50>::default();
210+
211+
l1.append_with_args(2u8, &[Argument::Precision(u8::MAX)]);
212+
assert_eq!(&*l1, "0.02".as_bytes());
213+
// same as 2 precision
214+
l2.append_with_args(2u8, &[Argument::Precision(2)]);
215+
assert_eq!(&*l1, &*l2);
216+
217+
l1.clear();
218+
l2.clear();
219+
220+
l1.append_with_args(2u16, &[Argument::Precision(u8::MAX)]);
221+
assert_eq!(&*l1, "0.0002".as_bytes());
222+
// same as 4 precision
223+
l2.append_with_args(2u16, &[Argument::Precision(4)]);
224+
assert_eq!(&*l1, &*l2);
225+
226+
l1.clear();
227+
l2.clear();
228+
229+
l1.append_with_args(2u32, &[Argument::Precision(u8::MAX)]);
230+
assert_eq!(&*l1, "0.000000002".as_bytes());
231+
// same as 9 precision
232+
l2.append_with_args(2u32, &[Argument::Precision(9)]);
233+
assert_eq!(&*l1, &*l2);
234+
235+
l1.clear();
236+
l2.clear();
237+
238+
l1.append_with_args(2u64, &[Argument::Precision(u8::MAX)]);
239+
assert_eq!(&*l1, "0.0000000000000000002".as_bytes());
240+
// same as 19 precision
241+
l2.append_with_args(2u64, &[Argument::Precision(19)]);
242+
assert_eq!(&*l1, &*l2);
205243
}
206244

207245
#[test]

0 commit comments

Comments
 (0)