diff options
author | Mike Buland <eichlan@xagasoft.com> | 2011-07-17 21:59:43 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2011-07-17 21:59:43 +0000 |
commit | 0ac83365291af6260a45730bd24a0c0d98d9d8fd (patch) | |
tree | 6ad8b9bf67fc7e8953aecdd313714cf7fae35c59 /src | |
parent | 0bc7562c218376b44a3eb87db0e310df0b1d0036 (diff) | |
download | libbu++-0ac83365291af6260a45730bd24a0c0d98d9d8fd.tar.gz libbu++-0ac83365291af6260a45730bd24a0c0d98d9d8fd.tar.bz2 libbu++-0ac83365291af6260a45730bd24a0c0d98d9d8fd.tar.xz libbu++-0ac83365291af6260a45730bd24a0c0d98d9d8fd.zip |
More variant unit tests, signed and unsigned chars are no formatted as numbers,
while chars are formatted as characters.
Diffstat (limited to 'src')
-rw-r--r-- | src/formatter.cpp | 6 | ||||
-rw-r--r-- | src/unit/variant.unit | 27 |
2 files changed, 31 insertions, 2 deletions
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 ) | |||
351 | 351 | ||
352 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, signed char c ) | 352 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, signed char c ) |
353 | { | 353 | { |
354 | f.write( (char *)&c, 1 ); | 354 | f.ifmt<signed char>( c ); |
355 | //f.write( (char *)&c, 1 ); | ||
355 | return f; | 356 | return f; |
356 | } | 357 | } |
357 | 358 | ||
@@ -363,7 +364,8 @@ Bu::Formatter &Bu::operator<<( Bu::Formatter &f, char c ) | |||
363 | 364 | ||
364 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, unsigned char c ) | 365 | Bu::Formatter &Bu::operator<<( Bu::Formatter &f, unsigned char c ) |
365 | { | 366 | { |
366 | f.write( (char *)&c, 1 ); | 367 | f.ifmt<unsigned char>( c ); |
368 | //f.write( (char *)&c, 1 ); | ||
367 | return f; | 369 | return f; |
368 | } | 370 | } |
369 | 371 | ||
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 @@ | |||
10 | #include "bu/membuf.h" | 10 | #include "bu/membuf.h" |
11 | #include "bu/formatter.h" | 11 | #include "bu/formatter.h" |
12 | #include "bu/string.h" | 12 | #include "bu/string.h" |
13 | #include "bu/sio.h" | ||
14 | |||
15 | using namespace Bu; | ||
16 | |||
17 | Bu::String mkastring() | ||
18 | { | ||
19 | Bu::String a = "s"; | ||
20 | a += "tu"; | ||
21 | a += "f"; | ||
22 | a += "f"; | ||
23 | return a; | ||
24 | } | ||
13 | 25 | ||
14 | suite Variant | 26 | suite Variant |
15 | { | 27 | { |
@@ -29,6 +41,21 @@ suite Variant | |||
29 | Bu::Formatter f( mb ); | 41 | Bu::Formatter f( mb ); |
30 | f << v; | 42 | f << v; |
31 | unitTest( mb.getString() == v.get<Bu::String>() ); | 43 | unitTest( mb.getString() == v.get<Bu::String>() ); |
44 | } | ||
32 | 45 | ||
46 | test stringForamtting | ||
47 | { | ||
48 | Bu::String s1; | ||
49 | s1 = "hello"; | ||
50 | int32_t i1, i2; | ||
51 | i1 = 32; | ||
52 | i2 = 0; | ||
53 | Bu::String out = Bu::String("%1-%2-%3-%4.odp"). | ||
54 | arg( s1.getStr() ). | ||
55 | arg( mkastring().getStr() ). | ||
56 | arg( i1, Fmt(2).fill('0') ). | ||
57 | arg( i2, Fmt(2).fill('0') ); | ||
58 | sio << sio.nl << out << sio.nl; | ||
59 | unitTest( out == "hello-stuff-32-00.odp" ); | ||
33 | } | 60 | } |
34 | } | 61 | } |