test other condition types

This commit is contained in:
Thomas Fussell 2016-06-19 21:50:41 +01:00
parent 7b6b5517d9
commit 523fe10898
3 changed files with 109 additions and 54 deletions

View File

@ -200,7 +200,7 @@ bool is_valid_color(const std::string &color)
new std::vector<std::string>(
{
"Black",
"Green"
"Green",
"White",
"Blue",
"Magenta",

View File

@ -0,0 +1,108 @@
#pragma once
#include <iostream>
#include <cxxtest/TestSuite.h>
#include "pugixml.hpp"
#include <xlnt/xlnt.hpp>
class test_number_format : public CxxTest::TestSuite
{
public:
void test_simple_date()
{
auto date = xlnt::date(2016, 6, 18);
auto date_number = date.to_number(xlnt::calendar::windows_1900);
xlnt::number_format nf = xlnt::number_format::date_ddmmyyyy();
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "18/06/16");
}
void test_simple_time()
{
auto time = xlnt::time(20, 15, 10);
auto time_number = time.to_number();
xlnt::number_format nf = xlnt::number_format::date_time2();
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "8:15:10 PM");
}
void test_text_section_string()
{
xlnt::number_format nf;
nf.set_format_string("General;General;General;[Green]\"a\"@\"b\"");
auto formatted = nf.format("text");
TS_ASSERT_EQUALS(formatted, "atextb");
}
void test_conditional_format()
{
xlnt::number_format nf;
nf.set_format_string("[>5]\"first\"General;[>3]\"second\"General;\"third\"General");
auto formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "first6");
formatted = nf.format(4, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "second4");
formatted = nf.format(5, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "second5");
formatted = nf.format(3, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third3");
formatted = nf.format(2, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third2");
nf.set_format_string("[>=5]\"first\"General;[>=3]\"second\"General;\"third\"General");
formatted = nf.format(5, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "first5");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "first6");
formatted = nf.format(4, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "second4");
formatted = nf.format(3, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "second3");
formatted = nf.format(2, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third2");
nf.set_format_string("[<1]\"first\"General;[<5]\"second\"General;\"third\"General");
formatted = nf.format(0, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "first0");
formatted = nf.format(1, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "second1");
formatted = nf.format(5, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third5");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third6");
nf.set_format_string("[<=1]\"first\"General;[<=5]\"second\"General;\"third\"General");
formatted = nf.format(-1000, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "first-1000");
formatted = nf.format(0, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "first0");
formatted = nf.format(1, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "first1");
formatted = nf.format(4, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "second4");
formatted = nf.format(5, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "second5");
formatted = nf.format(6, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third6");
formatted = nf.format(1000, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third1000");
nf.set_format_string("[=1]\"first\"General;[=2]\"second\"General;\"third\"General");
formatted = nf.format(1, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "first1");
formatted = nf.format(2, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "second2");
formatted = nf.format(3, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third3");
formatted = nf.format(0, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "third0");
}
};

View File

@ -1,53 +0,0 @@
#pragma once
#include <iostream>
#include <cxxtest/TestSuite.h>
#include "pugixml.hpp"
#include <xlnt/xlnt.hpp>
class test_number_style : public CxxTest::TestSuite
{
public:
void test_simple_date()
{
auto date = xlnt::date(2016, 6, 18);
auto date_number = date.to_number(xlnt::calendar::windows_1900);
xlnt::number_format nf = xlnt::number_format::date_ddmmyyyy();
auto formatted = nf.format(date_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "18/06/16");
}
void test_simple_time()
{
auto time = xlnt::time(20, 15, 10);
auto time_number = time.to_number();
xlnt::number_format nf = xlnt::number_format::date_time2();
auto formatted = nf.format(time_number, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "8:15:10 PM");
}
void test_text_section_string()
{
xlnt::number_format nf;
nf.set_format_string("General;General;General;[Magenta]\"a\"@\"b\"");
auto formatted = nf.format("text");
TS_ASSERT_EQUALS(formatted, "atextb");
}
void test_conditional_format()
{
xlnt::number_format nf;
nf.set_format_string("[>5]\"first\"General;[>3]\"second\"General;\"third\"General");
auto formatted = nf.format(4, xlnt::calendar::windows_1900);
TS_ASSERT_EQUALS(formatted, "second4");
}
};