mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Printable values passed to the Formatter as pointers, will print as if passed by value. Pointers are rendered with "0x" prefix when passed to '%s'.
This commit is contained in:
20
test/unit/stdlib/core/formatter.c3
Normal file
20
test/unit/stdlib/core/formatter.c3
Normal file
@@ -0,0 +1,20 @@
|
||||
module std::core::formatter_test;
|
||||
|
||||
import std;
|
||||
|
||||
struct Foo (Printable) { int a; }
|
||||
fn usz! Foo.to_format(&self, Formatter *f) @dynamic
|
||||
{
|
||||
return f.printf("Foo[%d]", self.a);
|
||||
}
|
||||
|
||||
fn void test_ref() @test
|
||||
{
|
||||
Foo* f = &&Foo{ 8 };
|
||||
Foo* f0 = null;
|
||||
int* a = (void*)(uptr)0x40;
|
||||
int* b = null;
|
||||
String s = string::new_format("%s %s %s %s %s", a, b, f0, f, *f);
|
||||
defer free(s);
|
||||
assert(s == "0x40 0x0 (null) Foo[8] Foo[8]");
|
||||
}
|
||||
@@ -19,7 +19,7 @@ fn void test_print_null()
|
||||
ZString w = "hello";
|
||||
String s = string::new_format("%s %s %s", z, w, y);
|
||||
defer free(s);
|
||||
assert(s == "(null) hello (null)");
|
||||
assert(s == "(null) hello 0x0");
|
||||
}
|
||||
|
||||
fn void test_strip()
|
||||
|
||||
Reference in New Issue
Block a user