mirror of
https://github.com/Noratrieb/mono-fmt.git
synced 2026-01-16 08:15:04 +01:00
Only eval args once
This commit is contained in:
parent
58e90857d2
commit
b5f6318fce
3 changed files with 65 additions and 15 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use std::cell::Cell;
|
||||
|
||||
#[macro_use]
|
||||
extern crate mono_fmt;
|
||||
|
||||
|
|
@ -17,3 +19,13 @@ fn test_pointer_formats_data_pointer() {
|
|||
assert_eq!(format!("{s:p}"), format!("{:p}", s.as_ptr()));
|
||||
assert_eq!(format!("{b:p}"), format!("{:p}", b.as_ptr()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn only_eval_once() {
|
||||
let evil = Cell::new(0);
|
||||
let _ = format!("{0} {0}", {
|
||||
evil.set(evil.get() + 1);
|
||||
0
|
||||
});
|
||||
assert_eq!(evil.get(), 1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue