From 0ac83365291af6260a45730bd24a0c0d98d9d8fd Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sun, 17 Jul 2011 21:59:43 +0000 Subject: More variant unit tests, signed and unsigned chars are no formatted as numbers, while chars are formatted as characters. --- src/formatter.cpp | 6 ++++-- src/unit/variant.unit | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/formatter.cpp b/src/formatter.cpp index 17fb311..61a059a 100644 --- a/src/formatter.cpp +++ b/src/formatter.cpp @@ -351,7 +351,8 @@ Bu::Formatter &Bu::operator<<( Bu::Formatter &f, const Bu::String &sStr ) Bu::Formatter &Bu::operator<<( Bu::Formatter &f, signed char c ) { - f.write( (char *)&c, 1 ); + f.ifmt( c ); + //f.write( (char *)&c, 1 ); return f; } @@ -363,7 +364,8 @@ Bu::Formatter &Bu::operator<<( Bu::Formatter &f, char c ) Bu::Formatter &Bu::operator<<( Bu::Formatter &f, unsigned char c ) { - f.write( (char *)&c, 1 ); + f.ifmt( c ); + //f.write( (char *)&c, 1 ); return f; } diff --git a/src/unit/variant.unit b/src/unit/variant.unit index 1654c4f..4fd5e26 100644 --- a/src/unit/variant.unit +++ b/src/unit/variant.unit @@ -10,6 +10,18 @@ #include "bu/membuf.h" #include "bu/formatter.h" #include "bu/string.h" +#include "bu/sio.h" + +using namespace Bu; + +Bu::String mkastring() +{ + Bu::String a = "s"; + a += "tu"; + a += "f"; + a += "f"; + return a; +} suite Variant { @@ -29,6 +41,21 @@ suite Variant Bu::Formatter f( mb ); f << v; unitTest( mb.getString() == v.get() ); + } + test stringForamtting + { + Bu::String s1; + s1 = "hello"; + int32_t i1, i2; + i1 = 32; + i2 = 0; + Bu::String out = Bu::String("%1-%2-%3-%4.odp"). + arg( s1.getStr() ). + arg( mkastring().getStr() ). + arg( i1, Fmt(2).fill('0') ). + arg( i2, Fmt(2).fill('0') ); + sio << sio.nl << out << sio.nl; + unitTest( out == "hello-stuff-32-00.odp" ); } } -- cgit v1.2.3