mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
test other condition types
This commit is contained in:
parent
7b6b5517d9
commit
523fe10898
|
@ -200,7 +200,7 @@ bool is_valid_color(const std::string &color)
|
|||
new std::vector<std::string>(
|
||||
{
|
||||
"Black",
|
||||
"Green"
|
||||
"Green",
|
||||
"White",
|
||||
"Blue",
|
||||
"Magenta",
|
||||
|
|
108
source/styles/tests/test_number_format.hpp
Normal file
108
source/styles/tests/test_number_format.hpp
Normal 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");
|
||||
}
|
||||
};
|
|
@ -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");
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user