remove unneeded number formats and finish testing number format

This commit is contained in:
Thomas Fussell 2016-07-21 20:15:53 -04:00
parent 007619fb79
commit ffeb1b1046
5 changed files with 46 additions and 56 deletions

View File

@ -47,7 +47,7 @@ public:
static const number_format percentage();
static const number_format percentage_00();
static const number_format date_yyyymmdd2();
static const number_format date_yyyymmdd();
static const number_format date_yymmdd();
static const number_format date_ddmmyyyy();
static const number_format date_dmyslash();
static const number_format date_dmyminus();
@ -65,13 +65,6 @@ public:
static const number_format date_time4();
static const number_format date_time5();
static const number_format date_time6();
static const number_format date_time7();
static const number_format date_time8();
static const number_format date_timedelta();
static const number_format date_yyyymmddslash();
static const number_format currency_usd_simple();
static const number_format currency_usd();
static const number_format currency_eur_simple();
static number_format from_builtin_id(std::size_t builtin_id);

View File

@ -383,7 +383,7 @@ XLNT_FUNCTION void cell::set_value(timedelta t)
{
d_->type_ = type::numeric;
d_->value_numeric_ = t.to_number();
set_number_format(number_format::date_timedelta());
set_number_format(number_format("[hh]:mm:ss"));
}
row_t cell::get_row() const

View File

@ -1593,7 +1593,7 @@ std::string number_formatter::format_number(const format_code &format, long doub
break;
case template_part::template_type::bad:
throw std::runtime_error("bad state");
throw std::runtime_error("bad format");
}
}

View File

@ -124,7 +124,7 @@ const number_format number_format::date_yyyymmdd2()
return *format;
}
const number_format number_format::date_yyyymmdd()
const number_format number_format::date_yymmdd()
{
static const number_format *format = new number_format("yy-mm-dd");
return *format;
@ -138,13 +138,13 @@ const number_format number_format::date_ddmmyyyy()
const number_format number_format::date_dmyslash()
{
static const number_format *format = new number_format("d/m/y");
static const number_format *format = new number_format("d/m/yy");
return *format;
}
const number_format number_format::date_dmyminus()
{
static const number_format *format = new number_format("d-m-y");
static const number_format *format = new number_format("d-m-yy");
return *format;
}
@ -156,7 +156,7 @@ const number_format number_format::date_dmminus()
const number_format number_format::date_myminus()
{
static const number_format *format = new number_format("m-y");
static const number_format *format = new number_format("m-yy");
return *format;
}
@ -232,48 +232,6 @@ const number_format number_format::date_time6()
return *format;
}
const number_format number_format::date_time7()
{
static const number_format *format = new number_format("i:s.S");
return *format;
}
const number_format number_format::date_time8()
{
static const number_format *format = new number_format("h:mm:ss@");
return *format;
}
const number_format number_format::date_timedelta()
{
static const number_format *format = new number_format("[hh]:mm:ss");
return *format;
}
const number_format number_format::date_yyyymmddslash()
{
static const number_format *format = new number_format("yy/mm/dd@");
return *format;
}
const number_format number_format::currency_usd_simple()
{
static const number_format *format = new number_format("\"$\"#,##0.00_-");
return *format;
}
const number_format number_format::currency_usd()
{
static const number_format *format = new number_format("$#,##0_-");
return *format;
}
const number_format number_format::currency_eur_simple()
{
static const number_format *format = new number_format("[$EUR ]#,##0.00_-");
return *format;
}
number_format::number_format() : number_format(general())
{
}

View File

@ -10,6 +10,21 @@
class test_number_format : public CxxTest::TestSuite
{
public:
void test_basic()
{
xlnt::number_format no_id("#\\x\\y\\z");
TS_ASSERT_THROWS(no_id.get_id(), std::runtime_error);
xlnt::number_format id("General", 200);
TS_ASSERT_EQUALS(id.get_id(), 200);
TS_ASSERT_EQUALS(id.get_format_string(), "General");
xlnt::number_format general(0);
TS_ASSERT_EQUALS(general, xlnt::number_format::general());
TS_ASSERT_EQUALS(general.get_id(), 0);
TS_ASSERT_EQUALS(general.get_format_string(), "General");
}
void test_simple_format()
{
xlnt::number_format nf;
@ -800,4 +815,28 @@ public:
{
format_and_test(xlnt::number_format::text(), {{"42503.1234", "-42503.1234", "0", "text"}});
}
// yy-mm-dd
void test_builtin_format_date_yyyymmdd()
{
format_and_test(xlnt::number_format::date_yymmdd(), {{"16-05-13", "###########", "00-01-00", "text"}});
}
// d/m/y
void test_builtin_format_date_dmyslash()
{
format_and_test(xlnt::number_format::date_dmyslash(), {{"13/5/16", "###########", "0/1/00", "text"}});
}
// d-m-y
void test_builtin_format_date_dmyminus()
{
format_and_test(xlnt::number_format::date_dmyminus(), {{"13-5-16", "###########", "0-1-00", "text"}});
}
// d-m
void test_builtin_format_date_dmminus()
{
format_and_test(xlnt::number_format::date_dmminus(), {{"13-5", "###########", "0-1", "text"}});
}
};