xlnt/source/styles/tests/test_number_style.hpp
2016-06-18 23:07:22 +01:00

54 lines
1.4 KiB
C++

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