Menu

[076713]: / testsrc / RepStringStreamTest.cpp  Maximize  Restore  History

Download this file

75 lines (59 with data), 1.9 kB

 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
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Copyright (c) 2013 Jason Lenthe <lenthe@comcast.net>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <gtest/gtest.h>
#include <RepStringStream.hpp>
using namespace std;
TEST(RepStringStreamTest, Test1Param)
{
RepStringStream s("1 {*} 2");
s << "foo";
ASSERT_EQ("1 foo 2", s.str());
}
TEST(RepStringStreamTest, Test2Param)
{
RepStringStream s(" {*} foo {*}");
s << "1" << "2";
ASSERT_EQ(" 1 foo 2", s.str());
}
TEST(RepStringStreamTest, Test3Param)
{
RepStringStream s("{*}{*} foo {*}");
s << "1" << "2" << "3";
ASSERT_EQ("12 foo 3", s.str());
}
TEST(RepStringStreamTest, TestIncompleteSplitPattern)
{
RepStringStream s("foo {{*}");
s << "1";
ASSERT_EQ("foo {1", s.str());
}
TEST(RepStringStreamTest, TestNoReplacements)
{
RepStringStream s("blahblah");
ASSERT_THROW(s << "foo", RepStringStreamException);
}
TEST(RepStringStreamTest, TestWithFormat)
{
RepStringStream s(" {*} ");
s << fixed << setprecision(10) << 5.0;
ASSERT_EQ(" 5.0000000000 ", s.str());
}
TEST(RepStringStreamTest ,TestWithUnusedReplacements)
{
RepStringStream s("{*}{*} foo {*} foo");
s << 1 << 2;
ASSERT_EQ("12 foo ", s.str());
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.