/*
* 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());
}