summaryrefslogtreecommitdiff
path: root/src/unit/variant.unit
blob: 68c7be5138935a51b338b8049d63ae7ecd092736 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// vim: syntax=cpp
/*
 * Copyright (C) 2007-2012 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/variant.h"
#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
{
    test construction
    {
        Bu::Variant v( 55 );
        v.get<int>();

        Bu::Variant v2( v );
        v2.get<int>();
    }

    test formatting
    {
        Bu::Variant v("hello");
        Bu::MemBuf mb;
        Bu::Formatter f( mb );
        f << v;
        unitTest( mb.getString() == v.get<Bu::String>() );
    }

    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" );
    }
}