From 973659d9a1f8679ab67144660915cad015ea633a Mon Sep 17 00:00:00 2001 From: "johannes@debussy" Date: Tue, 5 Nov 2013 11:57:00 +0100 Subject: Fixed variable name --- doc/ledger3.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ledger3.texi b/doc/ledger3.texi index 4e544ef3..e95640e8 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -7410,7 +7410,7 @@ The market value of a posting, or an account without its children. The net gain (market value minus cost basis), for a posting or an account without its children. It is the same as @samp{v-b}. -@item l +@item depth The depth (``level'') of an account. If an account has one parent, it's depth is one. -- cgit v1.2.3 From 71f1adad647d5ec4f2e69970543758d7f49f1340 Mon Sep 17 00:00:00 2001 From: "johannes@debussy" Date: Tue, 5 Nov 2013 14:56:13 +0100 Subject: first try for implementing --depth for register --- src/filters.cc | 32 +++++++++++++++++++++++++------- src/filters.h | 32 ++++++++++++++------------------ 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/filters.cc b/src/filters.cc index fadd5b5a..02f0e79b 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -449,13 +449,16 @@ void collapse_posts::report_subtotal() DEBUG("filters.collapse", "earliest date = " << earliest_date); DEBUG("filters.collapse", "latest date = " << latest_date); - handle_value(/* value= */ subtotal, - /* account= */ totals_account, - /* xact= */ &xact, - /* temps= */ temps, - /* handler= */ handler, - /* date= */ latest_date, - /* act_date_p= */ false); + foreach (post_t * post, component_posts) { + handle_value(/* value= */ subtotal, + /* account= */ find_totals_account(post->account), + /* xact= */ &xact, + /* temps= */ temps, + /* handler= */ handler, + /* date= */ latest_date, + /* act_date_p= */ false); + } + } component_posts.clear(); @@ -466,6 +469,21 @@ void collapse_posts::report_subtotal() count = 0; } +account_t* collapse_posts::find_totals_account(account_t* account) +{ + unsigned short depth=2; + if(account->depth==depth) + { + string name=account->fullname(); + account_t*& acc = totals_accounts[name]; + if(acc==NULL) + acc= &temps.create_account(name); + return acc; + } + //recurse + return find_totals_account(account->parent); +} + void collapse_posts::operator()(post_t& post) { // If we've reached a new xact, report on the subtotal diff --git a/src/filters.h b/src/filters.h index f256707b..f05ddaa1 100644 --- a/src/filters.h +++ b/src/filters.h @@ -421,18 +421,18 @@ public: class collapse_posts : public item_handler { - expr_t& amount_expr; - predicate_t display_predicate; - predicate_t only_predicate; - value_t subtotal; - std::size_t count; - xact_t * last_xact; - post_t * last_post; - temporaries_t temps; - account_t * totals_account; - bool only_collapse_if_zero; - std::list component_posts; - report_t& report; + expr_t& amount_expr; + predicate_t display_predicate; + predicate_t only_predicate; + value_t subtotal; + std::size_t count; + xact_t * last_xact; + post_t * last_post; + temporaries_t temps; + std::map totals_accounts; + bool only_collapse_if_zero; + std::list component_posts; + report_t& report; collapse_posts(); @@ -448,17 +448,13 @@ public: only_predicate(_only_predicate), count(0), last_xact(NULL), last_post(NULL), only_collapse_if_zero(_only_collapse_if_zero), report(_report) { - create_accounts(); TRACE_CTOR(collapse_posts, "post_handler_ptr, ..."); } virtual ~collapse_posts() { TRACE_DTOR(collapse_posts); handler.reset(); } - - void create_accounts() { - totals_account = &temps.create_account(_("")); - } + account_t* find_totals_account(account_t* account); virtual void flush() { report_subtotal(); @@ -480,7 +476,7 @@ public: last_post = NULL; temps.clear(); - create_accounts(); + totals_accounts.clear(); component_posts.clear(); item_handler::clear(); -- cgit v1.2.3 From a2d29dda5f514b84b503037195ca8a79a7969f7d Mon Sep 17 00:00:00 2001 From: "johannes@debussy" Date: Tue, 5 Nov 2013 15:58:52 +0100 Subject: first implementation of --depth for register --- src/filters.cc | 27 ++++++++++++--------------- src/filters.h | 31 +++++++++++++++++-------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/filters.cc b/src/filters.cc index 02f0e79b..f7321438 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -448,10 +448,10 @@ void collapse_posts::report_subtotal() DEBUG("filters.collapse", "Pseudo-xact date = " << *xact._date); DEBUG("filters.collapse", "earliest date = " << earliest_date); DEBUG("filters.collapse", "latest date = " << latest_date); - - foreach (post_t * post, component_posts) { - handle_value(/* value= */ subtotal, - /* account= */ find_totals_account(post->account), + + foreach (totals_map::value_type& pat, totals) { + handle_value(/* value= */ pat.second, + /* account= */ &temps.create_account(pat.first), /* xact= */ &xact, /* temps= */ temps, /* handler= */ handler, @@ -461,6 +461,7 @@ void collapse_posts::report_subtotal() } + totals.clear(); component_posts.clear(); last_xact = NULL; @@ -469,19 +470,14 @@ void collapse_posts::report_subtotal() count = 0; } -account_t* collapse_posts::find_totals_account(account_t* account) +value_t& collapse_posts::find_totals(account_t* account) { - unsigned short depth=2; + unsigned short depth=3; if(account->depth==depth) - { - string name=account->fullname(); - account_t*& acc = totals_accounts[name]; - if(acc==NULL) - acc= &temps.create_account(name); - return acc; - } - //recurse - return find_totals_account(account->parent); + return totals[account->fullname()]; + + //else recurse + return find_totals(account->parent); } void collapse_posts::operator()(post_t& post) @@ -493,6 +489,7 @@ void collapse_posts::operator()(post_t& post) report_subtotal(); post.add_to_value(subtotal, amount_expr); + post.add_to_value(find_totals(post.account), amount_expr); component_posts.push_back(&post); diff --git a/src/filters.h b/src/filters.h index f05ddaa1..d6e1b6fc 100644 --- a/src/filters.h +++ b/src/filters.h @@ -421,18 +421,21 @@ public: class collapse_posts : public item_handler { - expr_t& amount_expr; - predicate_t display_predicate; - predicate_t only_predicate; - value_t subtotal; - std::size_t count; - xact_t * last_xact; - post_t * last_post; - temporaries_t temps; - std::map totals_accounts; - bool only_collapse_if_zero; - std::list component_posts; - report_t& report; + + typedef std::map totals_map; + + expr_t& amount_expr; + predicate_t display_predicate; + predicate_t only_predicate; + value_t subtotal; + std::size_t count; + xact_t * last_xact; + post_t * last_post; + temporaries_t temps; + totals_map totals; + bool only_collapse_if_zero; + std::list component_posts; + report_t& report; collapse_posts(); @@ -454,7 +457,7 @@ public: TRACE_DTOR(collapse_posts); handler.reset(); } - account_t* find_totals_account(account_t* account); + value_t& find_totals(account_t* account); virtual void flush() { report_subtotal(); @@ -476,7 +479,7 @@ public: last_post = NULL; temps.clear(); - totals_accounts.clear(); + totals.clear(); component_posts.clear(); item_handler::clear(); -- cgit v1.2.3 From 658029d39f8594c7f3bf75fb8f7ca9fb2081b473 Mon Sep 17 00:00:00 2001 From: "johannes@debussy" Date: Tue, 5 Nov 2013 16:13:37 +0100 Subject: first implementation of --depth for register --- src/filters.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/filters.cc b/src/filters.cc index f7321438..2b4fe1bf 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -473,6 +473,10 @@ void collapse_posts::report_subtotal() value_t& collapse_posts::find_totals(account_t* account) { unsigned short depth=3; + + if(depth==0) + return totals[_("")]; + if(account->depth==depth) return totals[account->fullname()]; -- cgit v1.2.3 From 53572549d35c6907f4e76798cfba018f502de501 Mon Sep 17 00:00:00 2001 From: tripun Date: Fri, 15 Aug 2014 16:45:40 +0530 Subject: add t_value unit test --- test/unit/CMakeLists.txt | 2 +- test/unit/t_value.cc | 0 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 test/unit/t_value.cc diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 23bb0ea4..8d13d2d6 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -9,7 +9,7 @@ if (BUILD_LIBRARY) add_executable(UtilTests t_times.cc) add_ledger_test(UtilTests) - add_executable(MathTests t_amount.cc t_commodity.cc t_balance.cc t_expr.cc) + add_executable(MathTests t_amount.cc t_commodity.cc t_balance.cc t_expr.cc t_value.cc) add_ledger_test(MathTests) set_target_properties(check PROPERTIES DEPENDS LedgerUtilTests) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc new file mode 100644 index 00000000..e69de29b -- cgit v1.2.3 From b8cb110720c4034db2b0e8a61acc965ff2bc8c59 Mon Sep 17 00:00:00 2001 From: tripun Date: Sat, 16 Aug 2014 19:36:36 +0530 Subject: initialize value fixture --- test/unit/t_value.cc | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index e69de29b..96d644a6 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -0,0 +1,37 @@ +#define BOOST_TEST_DYN_LINK + +#include + +#include + +#include "value.h" + +using namespace ledger; + +struct value_fixture { + value_fixture() { + times_initialize(); + amount_t::initialize(); + value_t::initialize(); + + + // Cause the display precision for dollars to be initialized to 2. + amount_t x1("$1.00"); + BOOST_CHECK(x1); + + amount_t::stream_fullstrings = true; // make reports from UnitTests accurate + } + + ~value_fixture() + { + amount_t::stream_fullstrings = false; + amount_t::shutdown(); + times_shutdown(); + value_t::shutdown(); + } +}; + +BOOST_FIXTURE_TEST_SUITE(value, value_fixture) + +BOOST_AUTO_TEST_SUITE_END() + -- cgit v1.2.3 From 66478aa89416509c28ecf8a3886a232c2351cf48 Mon Sep 17 00:00:00 2001 From: tripun Date: Sun, 17 Aug 2014 16:20:30 +0530 Subject: add constructors unit test for value --- test/unit/t_value.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index 96d644a6..88d1f9fd 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -33,5 +33,40 @@ struct value_fixture { BOOST_FIXTURE_TEST_SUITE(value, value_fixture) +BOOST_AUTO_TEST_CASE(testConstructors) +{ + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_t(NULL))); + value_t v4(date_t(parse_date("2014/08/14"))); + value_t v5(2L); + value_t v6(4UL); + value_t v7(1.00); + value_t v8(amount_t("4 GBP")); + value_t v9(balance_t("3 EUR")); + value_t v10(mask_t("regex")); + value_t v11(new value_t::sequence_t()); + value_t v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment",true); + value_t v15(string("tag"),true); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 6c7a951a2da1e2aeb395930b573b1bc0f531efaa Mon Sep 17 00:00:00 2001 From: tripun Date: Sun, 17 Aug 2014 16:30:14 +0530 Subject: add assignment unit test for value --- test/unit/t_value.cc | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index 88d1f9fd..b6068652 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -68,5 +68,40 @@ BOOST_AUTO_TEST_CASE(testConstructors) BOOST_CHECK(v15.valid()); } +BOOST_AUTO_TEST_CASE(testAssignment) +{ + value_t v1; + value_t v2 = true; + value_t v3 = boost::posix_time::from_time_t(time_t(NULL)); + value_t v4 = date_t(parse_date("2014/08/14")); + value_t v5 = -2L; + value_t v6 = 4UL; + value_t v7 = 1.00; + value_t v8 = amount_t("4 GBP"); + value_t v9 = balance_t("3 EUR"); + value_t v10 = mask_t("regex"); + value_t v11 = new value_t::sequence_t(); + value_t v12 = new value_t(string("$1")); + value_t v13 = new value_t("2 CAD"); + value_t v14 = new value_t("comment",true); + value_t v15 = new value_t(string("tag"),true); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 2e5520a5cfcbcd17a4eebbc5a180fe465796fe55 Mon Sep 17 00:00:00 2001 From: tripun Date: Sun, 17 Aug 2014 18:53:30 +0530 Subject: add unit test of equality for value --- test/unit/t_value.cc | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index b6068652..8d398214 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -103,5 +103,69 @@ BOOST_AUTO_TEST_CASE(testAssignment) BOOST_CHECK(v15.valid()); } +BOOST_AUTO_TEST_CASE(testEquality) +{ + struct tm localtime; + strptime("10 February 2010", "%d %b %Y", &localtime); + time_t time_var = mktime(&localtime); + + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_var)); + value_t v4(date_t(parse_date("2014/08/14"))); + value_t v5(2L); + value_t v6(2UL); + value_t v7(1.00); + value_t v8(amount_t("4 GBP")); + value_t v9(balance_t("4 GBP")); + value_t v10(mask_t("regex")); + value_t v11(new value_t::sequence_t()); + value_t v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment",true); + value_t v15(string("comment"),true); + value_t v16; + + BOOST_CHECK_EQUAL(v1, value_t()); + BOOST_CHECK_EQUAL(v2, value_t(true)); + BOOST_CHECK_EQUAL(v3, value_t(boost::posix_time::from_time_t(time_var))); + BOOST_CHECK(!(v4 == value_t(date_t(parse_date("2014/08/15"))))); + + value_t v19(amount_t("2")); + value_t v20(balance_t("2")); + BOOST_CHECK_EQUAL(v5, v6); + BOOST_CHECK_EQUAL(v5, v19); + BOOST_CHECK_EQUAL(v5, v20); + BOOST_CHECK(v19 == v5); + BOOST_CHECK(v19 == v20); + BOOST_CHECK(v19 == value_t(amount_t("2"))); + BOOST_CHECK(v20 == v5); + BOOST_CHECK(v20 == v19); + BOOST_CHECK(v20 == value_t(balance_t(2L))); + BOOST_CHECK(v14 == v15); + BOOST_CHECK(v10 == value_t(mask_t("regex"))); + BOOST_CHECK(v11 == value_t(new value_t::sequence_t())); + + BOOST_CHECK_THROW(v8 == v10, value_error); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); + BOOST_CHECK(v19.valid()); + BOOST_CHECK(v20.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 2eac1ef328bf8dc7d5f36606d4547a233ab60708 Mon Sep 17 00:00:00 2001 From: tripun Date: Sun, 17 Aug 2014 22:53:30 +0530 Subject: add unit test Addition for value --- test/unit/t_value.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index 8d398214..fbf8c25e 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -167,5 +167,107 @@ BOOST_AUTO_TEST_CASE(testEquality) BOOST_CHECK(v20.valid()); } +BOOST_AUTO_TEST_CASE(testAddition) +{ + struct tm localtime; + strptime("10 February 2010 00:00:00", "%d %b %Y %H:%M:%S", &localtime); + time_t time_var = mktime(&localtime); + + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_var)); + value_t v4(date_t(parse_date("2014/08/14"))); + value_t v5(2L); + value_t v6(2UL); + value_t v7(1.00); + value_t v8(amount_t("4 GBP")); + value_t v9(balance_t("4 GBP")); + value_t v10(mask_t("regex")); + value_t v11(new value_t::sequence_t()); + value_t v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment", true); + value_t v15(string("comment"), true); + value_t v16(amount_t("2")); + + v14 += v15; + BOOST_CHECK_EQUAL(v14, value_t(string("commentcomment"), true)); + v14 += v12; + BOOST_CHECK_EQUAL(v14, value_t(string("commentcomment$1.00"), true)); + + v3 += value_t(2L); + strptime("10 February 2010 00:00:02", "%d %b %Y %H:%M:%S", &localtime); + BOOST_CHECK_EQUAL(v3, value_t(boost::posix_time::from_time_t(mktime(&localtime)))); + v3 += value_t(amount_t("2")); + strptime("10 February 2010 00:00:04", "%d %b %Y %H:%M:%S", &localtime); + BOOST_CHECK_EQUAL(v3, value_t(boost::posix_time::from_time_t(mktime(&localtime)))); + + v4 += value_t(2L); + BOOST_CHECK_EQUAL(v4, value_t(date_t(parse_date("2014/08/16")))); + v4 += value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v4, value_t(date_t(parse_date("2014/08/18")))); + + v5 += value_t(2L); + BOOST_CHECK_EQUAL(v5, value_t(4L)); + v5 += value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v5, value_t(amount_t("6"))); + v5 += v8; + + v16 += value_t(2L); + v16 += value_t(amount_t("2")); + v16 += v8; + BOOST_CHECK_EQUAL(v5, v16); + + v8 += value_t("6"); + BOOST_CHECK_EQUAL(v8, v16); + + value_t v17(6L); + v17 += value_t(amount_t("4 GBP")); + BOOST_CHECK_EQUAL(v8, v17); + + value_t v18(6L); + v18 += v9; + value_t v19(amount_t("6")); + v19 += v9; + BOOST_CHECK_EQUAL(v18, v19); + + v9 += value_t(2L); + v9 += value_t(amount_t("4")); + v9 += v19; + v18 += v19; + BOOST_CHECK_EQUAL(v9, v18); + + value_t v20(new value_t::sequence_t()); + v11.push_back(value_t(2L)); + v11.push_back(value_t("4 GBP")); + v20.push_back(value_t(2L)); + BOOST_CHECK_THROW(v11 += v20,value_error); + BOOST_CHECK_THROW(v10 += v8, value_error); + + v20 += value_t("4 GBP"); + BOOST_CHECK_EQUAL(v11, v20); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); + BOOST_CHECK(v16.valid()); + BOOST_CHECK(v17.valid()); + BOOST_CHECK(v18.valid()); + BOOST_CHECK(v19.valid()); + BOOST_CHECK(v20.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 580cb42c81644f46a36a51482aae203380cf3f6e Mon Sep 17 00:00:00 2001 From: tripun Date: Sun, 17 Aug 2014 22:55:09 +0530 Subject: add whitespaces --- test/unit/t_value.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index fbf8c25e..a90523ee 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -48,8 +48,8 @@ BOOST_AUTO_TEST_CASE(testConstructors) value_t v11(new value_t::sequence_t()); value_t v12(string("$1")); value_t v13("2 CAD"); - value_t v14("comment",true); - value_t v15(string("tag"),true); + value_t v14("comment", true); + value_t v15(string("tag"), true); BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); @@ -122,8 +122,8 @@ BOOST_AUTO_TEST_CASE(testEquality) value_t v11(new value_t::sequence_t()); value_t v12(string("$1")); value_t v13("2 CAD"); - value_t v14("comment",true); - value_t v15(string("comment"),true); + value_t v14("comment", true); + value_t v15(string("comment"), true); value_t v16; BOOST_CHECK_EQUAL(v1, value_t()); -- cgit v1.2.3 From 1834ba568a8d743684e75f29fc644e5342b22b7f Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 00:17:14 +0530 Subject: add unit test subtraction for value --- test/unit/t_value.cc | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index a90523ee..d884730e 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -269,5 +269,98 @@ BOOST_AUTO_TEST_CASE(testAddition) BOOST_CHECK(v20.valid()); } +BOOST_AUTO_TEST_CASE(testSubtraction) +{ + struct tm localtime; + strptime("10 February 2010 00:00:04", "%d %b %Y %H:%M:%S", &localtime); + time_t time_var = mktime(&localtime); + + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_var)); + value_t v4(date_t(parse_date("2014/08/18"))); + value_t v5(6L); + value_t v6(6UL); + value_t v7(1.00); + value_t v8(amount_t("4 GBP")); + value_t v9(balance_t("4 GBP")); + value_t v10(mask_t("regex")); + value_t v11(new value_t::sequence_t()); + value_t v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment", true); + value_t v15(string("comment"), true); + value_t v16(amount_t("6")); + + v3 -= value_t(2L); + strptime("10 February 2010 00:00:02", "%d %b %Y %H:%M:%S", &localtime); + BOOST_CHECK_EQUAL(v3, value_t(boost::posix_time::from_time_t(mktime(&localtime)))); + v3 -= value_t(amount_t("2")); + strptime("10 February 2010 00:00:00", "%d %b %Y %H:%M:%S", &localtime); + BOOST_CHECK_EQUAL(v3, value_t(boost::posix_time::from_time_t(mktime(&localtime)))); + + v4 -= value_t(2L); + BOOST_CHECK_EQUAL(v4, value_t(date_t(parse_date("2014/08/16")))); + v4 -= value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v4, value_t(date_t(parse_date("2014/08/14")))); + + v5 -= value_t(2L); + BOOST_CHECK_EQUAL(v5, value_t(4L)); + v5 -= value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v5, value_t(amount_t("2"))); + v5 -= v8; + + v16 -= value_t(2L); + v16 -= value_t(amount_t("2")); + v16 -= v8; + BOOST_CHECK_EQUAL(v5, v16); + + v8 -= value_t("2"); + BOOST_CHECK_EQUAL(-v8, v16); + + value_t v18(6L); + v18 -= v9; + value_t v19(amount_t("6")); + v19 -= v9; + BOOST_CHECK_EQUAL(v18, v19); + + v9 -= value_t(-2L); + v9 -= value_t(amount_t("-10")); + v9 -= value_t(amount_t("12 GBP")); + v9 -= v19; + BOOST_CHECK_EQUAL(v9, v18); + v18 -=v19; + BOOST_CHECK_EQUAL(v18, value_t("0")); + + value_t v20(new value_t::sequence_t()); + value_t v21(2L); + value_t v22("4 GBP"); + v11.push_back(v21); + v11.push_back(v22); + v20.push_back(v21); + BOOST_CHECK_THROW(v11 -= v20,value_error); + BOOST_CHECK_THROW(v10 -= v8, value_error); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); + BOOST_CHECK(v16.valid()); + BOOST_CHECK(v18.valid()); + BOOST_CHECK(v19.valid()); + BOOST_CHECK(v20.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 90f2ca8049b483d6641cc3c86879b3aa88b9f431 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 00:44:50 +0530 Subject: add Multiplication unit test for value --- test/unit/t_value.cc | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index d884730e..a662f786 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -362,5 +362,84 @@ BOOST_AUTO_TEST_CASE(testSubtraction) BOOST_CHECK(v20.valid()); } +BOOST_AUTO_TEST_CASE(testMultiplication) +{ + struct tm localtime; + strptime("10 February 2010 00:00:00", "%d %b %Y %H:%M:%S", &localtime); + time_t time_var = mktime(&localtime); + + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_var)); + value_t v4(date_t(parse_date("2014/08/14"))); + value_t v5(2L); + value_t v6(2UL); + value_t v7(1.00); + value_t v8(amount_t("4 GBP")); + value_t v9(balance_t("4 GBP")); + value_t v10(mask_t("regex")); + value_t v11(new value_t::sequence_t()); + value_t v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment", true); + value_t v15(string("comment"), true); + value_t v16(amount_t("2")); + + v14 *= value_t(2L); + BOOST_CHECK_EQUAL(v14, value_t(string("commentcomment"), true)); + + v5 *= value_t(2L); + BOOST_CHECK_EQUAL(v5, value_t(4L)); + v5 *= value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v5, value_t(amount_t("8"))); + + v16 *= value_t(2L); + v16 *= value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v5, v16); + + v8 *= v9; + BOOST_CHECK_EQUAL(v8, value_t("16 GBP")); + + value_t v17(v9); + v9 *= value_t(2L); + BOOST_CHECK_EQUAL(v9, value_t("8 GBP")); + v17 += value_t(2L); + v17 *= value_t(2L); + value_t v18("8 GBP"); + v18 += value_t(4L); + BOOST_CHECK_EQUAL(v17, v18); + + value_t v20(new value_t::sequence_t()); + v11.push_back(value_t(2L)); + v11.push_back(value_t("4 GBP")); + v20.push_back(value_t(2L)); + v20 += value_t("4 GBP"); + v20.push_back(value_t(2L)); + v20 += value_t("4 GBP"); + v11 *= value_t(2L); + BOOST_CHECK_EQUAL(v11, v20); + + BOOST_CHECK_THROW(v10 += v8, value_error); + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); + BOOST_CHECK(v16.valid()); + BOOST_CHECK(v17.valid()); + BOOST_CHECK(v18.valid()); + BOOST_CHECK(v20.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 3a87b949960f92b67377c1ed8e9e02657b452b3f Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 00:48:49 +0530 Subject: remove some statements until sequence multiplication run-time error is fixed --- test/unit/t_value.cc | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index a662f786..81338cb2 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -409,16 +409,6 @@ BOOST_AUTO_TEST_CASE(testMultiplication) v18 += value_t(4L); BOOST_CHECK_EQUAL(v17, v18); - value_t v20(new value_t::sequence_t()); - v11.push_back(value_t(2L)); - v11.push_back(value_t("4 GBP")); - v20.push_back(value_t(2L)); - v20 += value_t("4 GBP"); - v20.push_back(value_t(2L)); - v20 += value_t("4 GBP"); - v11 *= value_t(2L); - BOOST_CHECK_EQUAL(v11, v20); - BOOST_CHECK_THROW(v10 += v8, value_error); BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); @@ -438,7 +428,6 @@ BOOST_AUTO_TEST_CASE(testMultiplication) BOOST_CHECK(v16.valid()); BOOST_CHECK(v17.valid()); BOOST_CHECK(v18.valid()); - BOOST_CHECK(v20.valid()); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 66d89d92f20740d008338bade3dc4b195cbf3692 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 01:14:36 +0530 Subject: add Division unit test for value --- test/unit/t_value.cc | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index 81338cb2..dfbd94d1 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -430,5 +430,68 @@ BOOST_AUTO_TEST_CASE(testMultiplication) BOOST_CHECK(v18.valid()); } +BOOST_AUTO_TEST_CASE(testDivision) +{ + struct tm localtime; + strptime("10 February 2010 00:00:00", "%d %b %Y %H:%M:%S", &localtime); + time_t time_var = mktime(&localtime); + + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_var)); + value_t v4(date_t(parse_date("2014/08/14"))); + value_t v5(8L); + value_t v6(2UL); + value_t v7(1.00); + value_t v8(amount_t("4 GBP")); + value_t v9(balance_t("4 GBP")); + value_t v10(mask_t("regex")); + value_t v11(new value_t::sequence_t()); + value_t v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment", true); + value_t v15(string("comment"), true); + value_t v16(amount_t("8")); + + v5 /= value_t(2L); + BOOST_CHECK_EQUAL(v5, value_t(4L)); + v5 /= value_t(amount_t("8")); + BOOST_CHECK_EQUAL(v5, value_t(amount_t("2"))); + + v16 /= value_t(2L); + v16 /= value_t(amount_t("2")); + BOOST_CHECK_EQUAL(v5, v16); + + v8 /= v9; + v8 /= value_t(balance_t(2L)); + BOOST_CHECK_EQUAL(v8, value_t("0.5 GBP")); + + value_t v17(v9); + v9 /= value_t(2L); + BOOST_CHECK_EQUAL(v9, value_t("2 GBP")); + v17 /= value_t("2 GBP"); + v17 /= value_t("2"); + BOOST_CHECK_EQUAL(v17, value_t(balance_t("1 GBP"))); + + BOOST_CHECK_THROW(v10 /= v8, value_error); + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); + BOOST_CHECK(v16.valid()); + BOOST_CHECK(v17.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From e0f2e0ad29204632ffd3be8575173184314932f3 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 01:24:52 +0530 Subject: check Type unit test for value --- test/unit/t_value.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index dfbd94d1..a14ac167 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -493,5 +493,55 @@ BOOST_AUTO_TEST_CASE(testDivision) BOOST_CHECK(v17.valid()); } +BOOST_AUTO_TEST_CASE(testType) +{ + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_t(NULL))); + value_t v4(date_t(parse_date("2014/08/14"))); + value_t v5(2L); + value_t v6(4UL); + value_t v7(1.00); + value_t v8(amount_t("4 GBP")); + value_t v9(balance_t("3 EUR")); + value_t v10(mask_t("regex")); + value_t v11(new value_t::sequence_t()); + value_t v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment", true); + value_t v15(string("tag"), true); + + BOOST_CHECK(v2.is_boolean()); + BOOST_CHECK(v3.is_datetime()); + BOOST_CHECK(v4.is_date()); + BOOST_CHECK(v5.is_long()); + BOOST_CHECK(v6.is_amount()); + BOOST_CHECK(v7.is_amount()); + BOOST_CHECK(v8.is_amount()); + BOOST_CHECK(v9.is_balance()); + BOOST_CHECK(v10.is_mask()); + BOOST_CHECK(v11.is_boolean()); + BOOST_CHECK(v12.is_amount()); + BOOST_CHECK(v13.is_amount()); + BOOST_CHECK(v14.is_string()); + BOOST_CHECK(v15.is_string()); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 43511a58c11f0643eebd9cafa6fb4e9ba298a438 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 01:53:06 +0530 Subject: add test for zero for value --- test/unit/t_value.cc | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index a14ac167..c9b93272 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -526,6 +526,63 @@ BOOST_AUTO_TEST_CASE(testType) BOOST_CHECK(v14.is_string()); BOOST_CHECK(v15.is_string()); + v11.push_back(v6); + BOOST_CHECK(v11.is_sequence()); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); +} + +BOOST_AUTO_TEST_CASE(testForZero) +{ + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_t(NULL))); + value_t v4(date_t(0)); + value_t v5(2L); + value_t v6(0UL); + value_t v7(1.00); + value_t v8(amount_t("4 GBP")); + value_t v9(balance_t("0")); + value_t v10(mask_t("")); + value_t v11(new value_t::sequence_t()); + value_t v12(string("$1")); + value_t v13("2 CAD"); + value_t v14("comment", true); + value_t v15(string(""), true); + + BOOST_CHECK(v1.is_null()); + BOOST_CHECK(v2.is_nonzero()); + BOOST_CHECK(!v3.is_zero()); + BOOST_CHECK(v4.is_nonzero()); + BOOST_CHECK(v5.is_nonzero()); + BOOST_CHECK(v6.is_realzero()); + BOOST_CHECK(v7.is_nonzero()); + BOOST_CHECK(v8.is_nonzero()); + BOOST_CHECK(v9.is_zero()); + BOOST_CHECK_THROW(v10.is_zero(), value_error); + BOOST_CHECK(v11.is_nonzero()); + BOOST_CHECK(v12.is_nonzero()); + BOOST_CHECK(v13.is_nonzero()); + BOOST_CHECK(v14.is_nonzero()); + BOOST_CHECK(v15.is_zero()); + + v11.push_back(v6); + BOOST_CHECK(v11.is_nonzero()); + BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); BOOST_CHECK(v3.valid()); -- cgit v1.2.3 From f1c3f36e3bf45c9e74359bd64ff91f1aa4a5f525 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 01:57:19 +0530 Subject: minor additions --- test/unit/t_value.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index c9b93272..eae71ea9 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -511,6 +511,7 @@ BOOST_AUTO_TEST_CASE(testType) value_t v14("comment", true); value_t v15(string("tag"), true); + BOOST_CHECK(v1.is_null()); BOOST_CHECK(v2.is_boolean()); BOOST_CHECK(v3.is_datetime()); BOOST_CHECK(v4.is_date()); -- cgit v1.2.3 From c87dd21912b1ecd4cab3aba7de2e5412ce54281b Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 02:33:26 +0530 Subject: add unit test Negation for value --- test/unit/t_value.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index eae71ea9..2fbfda3f 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -601,5 +601,51 @@ BOOST_AUTO_TEST_CASE(testForZero) BOOST_CHECK(v15.valid()); } +BOOST_AUTO_TEST_CASE(testNegation) +{ + value_t v1; + value_t v2(true); + value_t v3(boost::posix_time::from_time_t(time_t(NULL))); + value_t v4(date_t(parse_date("2014/08/09"))); + value_t v5(2L); + value_t v6(0UL); + value_t v7(1.00); + value_t v8(amount_t("4 GBP")); + value_t v9(balance_t("4 GBP")); + value_t v10(mask_t("")); + value_t v11(new value_t::sequence_t()); + value_t v12(string("$1")); + value_t v13("$-1"); + value_t v14("comment", true); + value_t v15(string("comment"), true); + + BOOST_CHECK_THROW(v1.negated(), value_error); + BOOST_CHECK_EQUAL(v2.negated(), value_t(false)); + v5.in_place_negate(); + BOOST_CHECK_EQUAL(v5, value_t(-2L)); + v8.in_place_negate(); + v9.in_place_negate(); + BOOST_CHECK_EQUAL(v8, v9); + BOOST_CHECK_THROW(v10.negated(), value_error); + BOOST_CHECK_EQUAL(-v12, v13); + BOOST_CHECK_THROW(-v14, value_error); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(v4.valid()); + BOOST_CHECK(v5.valid()); + BOOST_CHECK(v6.valid()); + BOOST_CHECK(v7.valid()); + BOOST_CHECK(v8.valid()); + BOOST_CHECK(v9.valid()); + BOOST_CHECK(v10.valid()); + BOOST_CHECK(v11.valid()); + BOOST_CHECK(v12.valid()); + BOOST_CHECK(v13.valid()); + BOOST_CHECK(v14.valid()); + BOOST_CHECK(v15.valid()); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From 04d541ed44b189ccdd8ebfc78f4752903c737ca9 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 22:13:11 +0530 Subject: add test for sequenc_t in value_t --- test/unit/t_value.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index 2fbfda3f..b0b9b382 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -167,6 +167,38 @@ BOOST_AUTO_TEST_CASE(testEquality) BOOST_CHECK(v20.valid()); } +BOOST_AUTO_TEST_CASE(testSequence) +{ + value_t::sequence_t s1; + value_t v1(s1); + BOOST_CHECK(v1.is_sequence()); + v1.push_back(value_t(2L)); + v1.push_back(value_t("3 GBP")); + + value_t v2("3 GBP"); + value_t seq(v1); + const value_t v3(seq); + value_t::sequence_t::iterator i = std::find(seq.begin(), seq.end(), v2); + if (i != seq.end()) + BOOST_CHECK(v2 == *i); + value_t::sequence_t::const_iterator j = std::find(v3.begin(), v3.end(), v2); + if (j != v3.end()) + BOOST_CHECK(v2 == *j); + BOOST_CHECK(v2 == seq[1]); + BOOST_CHECK(v2 == v3[1]); + v1.pop_back(); + v1.pop_back(); + v1.push_front(v2); + v1.push_front(value_t(2L)); + BOOST_CHECK(v2 == v1[1]); + BOOST_CHECK(seq == v1); + + BOOST_CHECK(v1.valid()); + BOOST_CHECK(v2.valid()); + BOOST_CHECK(v3.valid()); + BOOST_CHECK(seq.valid()); +} + BOOST_AUTO_TEST_CASE(testAddition) { struct tm localtime; -- cgit v1.2.3 From cb39ea25080a65ebc67d42d24f9de72c7b49bea2 Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 23:23:58 +0530 Subject: add case for addition to void --- src/value.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/value.cc b/src/value.cc index 70a8ab43..2c62f4e1 100644 --- a/src/value.cc +++ b/src/value.cc @@ -341,6 +341,10 @@ value_t& value_t::operator+=(const value_t& val) } switch (type()) { + case VOID: + *this = value_t(val); + return *this; + case DATETIME: switch (val.type()) { case INTEGER: -- cgit v1.2.3 From b2bd337c31b1bf2481f643967b6670ada9d3cb2e Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 23:24:25 +0530 Subject: add additional tests for sequence_t and fix the old ones --- test/unit/t_value.cc | 72 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index b0b9b382..ad400daa 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -35,6 +35,7 @@ BOOST_FIXTURE_TEST_SUITE(value, value_fixture) BOOST_AUTO_TEST_CASE(testConstructors) { + value_t::sequence_t s1; value_t v1; value_t v2(true); value_t v3(boost::posix_time::from_time_t(time_t(NULL))); @@ -45,7 +46,7 @@ BOOST_AUTO_TEST_CASE(testConstructors) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("3 EUR")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -70,6 +71,7 @@ BOOST_AUTO_TEST_CASE(testConstructors) BOOST_AUTO_TEST_CASE(testAssignment) { + value_t::sequence_t s1; value_t v1; value_t v2 = true; value_t v3 = boost::posix_time::from_time_t(time_t(NULL)); @@ -80,7 +82,7 @@ BOOST_AUTO_TEST_CASE(testAssignment) value_t v8 = amount_t("4 GBP"); value_t v9 = balance_t("3 EUR"); value_t v10 = mask_t("regex"); - value_t v11 = new value_t::sequence_t(); + value_t v11 = s1; value_t v12 = new value_t(string("$1")); value_t v13 = new value_t("2 CAD"); value_t v14 = new value_t("comment",true); @@ -108,6 +110,7 @@ BOOST_AUTO_TEST_CASE(testEquality) struct tm localtime; strptime("10 February 2010", "%d %b %Y", &localtime); time_t time_var = mktime(&localtime); + value_t::sequence_t s1; value_t v1; value_t v2(true); @@ -119,7 +122,7 @@ BOOST_AUTO_TEST_CASE(testEquality) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("4 GBP")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -144,7 +147,7 @@ BOOST_AUTO_TEST_CASE(testEquality) BOOST_CHECK(v20 == value_t(balance_t(2L))); BOOST_CHECK(v14 == v15); BOOST_CHECK(v10 == value_t(mask_t("regex"))); - BOOST_CHECK(v11 == value_t(new value_t::sequence_t())); + BOOST_CHECK(v11 == value_t(s1)); BOOST_CHECK_THROW(v8 == v10, value_error); @@ -204,6 +207,7 @@ BOOST_AUTO_TEST_CASE(testAddition) struct tm localtime; strptime("10 February 2010 00:00:00", "%d %b %Y %H:%M:%S", &localtime); time_t time_var = mktime(&localtime); + value_t::sequence_t s1; value_t v1; value_t v2(true); @@ -215,7 +219,7 @@ BOOST_AUTO_TEST_CASE(testAddition) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("4 GBP")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -269,15 +273,18 @@ BOOST_AUTO_TEST_CASE(testAddition) v18 += v19; BOOST_CHECK_EQUAL(v9, v18); - value_t v20(new value_t::sequence_t()); - v11.push_back(value_t(2L)); - v11.push_back(value_t("4 GBP")); - v20.push_back(value_t(2L)); + value_t v20(s1); + v11 += value_t(2L); + v11 += value_t("4 GBP"); BOOST_CHECK_THROW(v11 += v20,value_error); BOOST_CHECK_THROW(v10 += v8, value_error); + v20 += value_t(2L); v20 += value_t("4 GBP"); BOOST_CHECK_EQUAL(v11, v20); + v11 += v20; + v20 += v20; + BOOST_CHECK_EQUAL(v11, v20); BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); @@ -306,6 +313,7 @@ BOOST_AUTO_TEST_CASE(testSubtraction) struct tm localtime; strptime("10 February 2010 00:00:04", "%d %b %Y %H:%M:%S", &localtime); time_t time_var = mktime(&localtime); + value_t::sequence_t s1; value_t v1; value_t v2(true); @@ -317,7 +325,7 @@ BOOST_AUTO_TEST_CASE(testSubtraction) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("4 GBP")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -364,15 +372,25 @@ BOOST_AUTO_TEST_CASE(testSubtraction) v18 -=v19; BOOST_CHECK_EQUAL(v18, value_t("0")); - value_t v20(new value_t::sequence_t()); + value_t v20(s1); value_t v21(2L); value_t v22("4 GBP"); v11.push_back(v21); v11.push_back(v22); - v20.push_back(v21); BOOST_CHECK_THROW(v11 -= v20,value_error); BOOST_CHECK_THROW(v10 -= v8, value_error); + v20.push_back(v21); + v20.push_back(v22); + v11 -= v20; + value_t v23(s1); + v23.push_back(value_t(0L)); + v23.push_back(value_t("0")); + BOOST_CHECK_EQUAL(v11, v23); + v20 -= v21; + v20 -= v22; + BOOST_CHECK_EQUAL(v20, value_t(s1)); + BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); BOOST_CHECK(v3.valid()); @@ -399,6 +417,7 @@ BOOST_AUTO_TEST_CASE(testMultiplication) struct tm localtime; strptime("10 February 2010 00:00:00", "%d %b %Y %H:%M:%S", &localtime); time_t time_var = mktime(&localtime); + value_t::sequence_t s1; value_t v1; value_t v2(true); @@ -410,7 +429,7 @@ BOOST_AUTO_TEST_CASE(testMultiplication) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("4 GBP")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -441,6 +460,14 @@ BOOST_AUTO_TEST_CASE(testMultiplication) v18 += value_t(4L); BOOST_CHECK_EQUAL(v17, v18); + value_t v20(s1); + v11.push_back(value_t(2L)); + v11.push_back(value_t("2 GBP")); + v20.push_back(value_t(4L)); + v20.push_back(value_t("4 GBP")); + v11 *= value_t(2L); + BOOST_CHECK_EQUAL(v11 ,v20); + BOOST_CHECK_THROW(v10 += v8, value_error); BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); @@ -467,6 +494,7 @@ BOOST_AUTO_TEST_CASE(testDivision) struct tm localtime; strptime("10 February 2010 00:00:00", "%d %b %Y %H:%M:%S", &localtime); time_t time_var = mktime(&localtime); + value_t::sequence_t s1; value_t v1; value_t v2(true); @@ -478,7 +506,7 @@ BOOST_AUTO_TEST_CASE(testDivision) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("4 GBP")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -527,6 +555,7 @@ BOOST_AUTO_TEST_CASE(testDivision) BOOST_AUTO_TEST_CASE(testType) { + value_t::sequence_t s1; value_t v1; value_t v2(true); value_t v3(boost::posix_time::from_time_t(time_t(NULL))); @@ -537,7 +566,7 @@ BOOST_AUTO_TEST_CASE(testType) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("3 EUR")); value_t v10(mask_t("regex")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -553,15 +582,12 @@ BOOST_AUTO_TEST_CASE(testType) BOOST_CHECK(v8.is_amount()); BOOST_CHECK(v9.is_balance()); BOOST_CHECK(v10.is_mask()); - BOOST_CHECK(v11.is_boolean()); + BOOST_CHECK(v11.is_sequence()); BOOST_CHECK(v12.is_amount()); BOOST_CHECK(v13.is_amount()); BOOST_CHECK(v14.is_string()); BOOST_CHECK(v15.is_string()); - v11.push_back(v6); - BOOST_CHECK(v11.is_sequence()); - BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); BOOST_CHECK(v3.valid()); @@ -581,6 +607,7 @@ BOOST_AUTO_TEST_CASE(testType) BOOST_AUTO_TEST_CASE(testForZero) { + value_t::sequence_t s1; value_t v1; value_t v2(true); value_t v3(boost::posix_time::from_time_t(time_t(NULL))); @@ -591,7 +618,7 @@ BOOST_AUTO_TEST_CASE(testForZero) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("0")); value_t v10(mask_t("")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("2 CAD"); value_t v14("comment", true); @@ -607,7 +634,7 @@ BOOST_AUTO_TEST_CASE(testForZero) BOOST_CHECK(v8.is_nonzero()); BOOST_CHECK(v9.is_zero()); BOOST_CHECK_THROW(v10.is_zero(), value_error); - BOOST_CHECK(v11.is_nonzero()); + BOOST_CHECK(v11.is_zero()); BOOST_CHECK(v12.is_nonzero()); BOOST_CHECK(v13.is_nonzero()); BOOST_CHECK(v14.is_nonzero()); @@ -635,6 +662,7 @@ BOOST_AUTO_TEST_CASE(testForZero) BOOST_AUTO_TEST_CASE(testNegation) { + value_t::sequence_t s1; value_t v1; value_t v2(true); value_t v3(boost::posix_time::from_time_t(time_t(NULL))); @@ -645,7 +673,7 @@ BOOST_AUTO_TEST_CASE(testNegation) value_t v8(amount_t("4 GBP")); value_t v9(balance_t("4 GBP")); value_t v10(mask_t("")); - value_t v11(new value_t::sequence_t()); + value_t v11(s1); value_t v12(string("$1")); value_t v13("$-1"); value_t v14("comment", true); -- cgit v1.2.3 From 9a9d55499ea1a4ca5c2b9efe48d149b8cd2e01df Mon Sep 17 00:00:00 2001 From: tripun Date: Mon, 18 Aug 2014 23:28:18 +0530 Subject: fix minor issues --- test/unit/t_value.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/unit/t_value.cc b/test/unit/t_value.cc index ad400daa..e8367bbe 100644 --- a/test/unit/t_value.cc +++ b/test/unit/t_value.cc @@ -83,10 +83,10 @@ BOOST_AUTO_TEST_CASE(testAssignment) value_t v9 = balance_t("3 EUR"); value_t v10 = mask_t("regex"); value_t v11 = s1; - value_t v12 = new value_t(string("$1")); - value_t v13 = new value_t("2 CAD"); - value_t v14 = new value_t("comment",true); - value_t v15 = new value_t(string("tag"),true); + value_t v12 = value_t(string("$1")); + value_t v13 = value_t("2 CAD"); + value_t v14 = value_t("comment", true); + value_t v15 = value_t(string("tag"), true); BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); @@ -181,12 +181,15 @@ BOOST_AUTO_TEST_CASE(testSequence) value_t v2("3 GBP"); value_t seq(v1); const value_t v3(seq); + value_t::sequence_t::iterator i = std::find(seq.begin(), seq.end(), v2); if (i != seq.end()) BOOST_CHECK(v2 == *i); + value_t::sequence_t::const_iterator j = std::find(v3.begin(), v3.end(), v2); if (j != v3.end()) BOOST_CHECK(v2 == *j); + BOOST_CHECK(v2 == seq[1]); BOOST_CHECK(v2 == v3[1]); v1.pop_back(); @@ -468,7 +471,7 @@ BOOST_AUTO_TEST_CASE(testMultiplication) v11 *= value_t(2L); BOOST_CHECK_EQUAL(v11 ,v20); - BOOST_CHECK_THROW(v10 += v8, value_error); + BOOST_CHECK_THROW(v10 *= v8, value_error); BOOST_CHECK(v1.valid()); BOOST_CHECK(v2.valid()); BOOST_CHECK(v3.valid()); -- cgit v1.2.3 From a468fdca0eb380e6ea3d954d98b5995a45decbc9 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Sat, 10 Jan 2015 16:16:05 +0100 Subject: Replace utfcpp submodule with partial subtree * Remove utfcpp submodule * Squashed 'lib/utfcpp/' content from commit 63cd498 git-subtree-dir: lib/utfcpp git-subtree-split: 63cd4984464e875546b4a91918be7355357a3a68 * Merge commit '82003f30ba8ba436cf7cef380155f50ed4242b37' as 'lib/utfcpp' * Remove needless utfcpp subtree files * Change include path to utfcpp Signed-off-by: Alexis Hildebrandt --- .gitmodules | 3 - CMakeLists.txt | 2 +- lib/utfcpp | 1 - lib/utfcpp/v2_0/LICENSE | 23 +++ lib/utfcpp/v2_0/buildrelease.pl | 18 ++ lib/utfcpp/v2_0/samples/Makefile | 5 + lib/utfcpp/v2_0/samples/docsample.cpp | 52 +++++ lib/utfcpp/v2_0/source/utf8.h | 34 ++++ lib/utfcpp/v2_0/source/utf8/checked.h | 327 +++++++++++++++++++++++++++++++ lib/utfcpp/v2_0/source/utf8/core.h | 329 ++++++++++++++++++++++++++++++++ lib/utfcpp/v2_0/source/utf8/unchecked.h | 228 ++++++++++++++++++++++ 11 files changed, 1017 insertions(+), 5 deletions(-) delete mode 160000 lib/utfcpp create mode 100644 lib/utfcpp/v2_0/LICENSE create mode 100755 lib/utfcpp/v2_0/buildrelease.pl create mode 100644 lib/utfcpp/v2_0/samples/Makefile create mode 100644 lib/utfcpp/v2_0/samples/docsample.cpp create mode 100644 lib/utfcpp/v2_0/source/utf8.h create mode 100644 lib/utfcpp/v2_0/source/utf8/checked.h create mode 100644 lib/utfcpp/v2_0/source/utf8/core.h create mode 100644 lib/utfcpp/v2_0/source/utf8/unchecked.h diff --git a/.gitmodules b/.gitmodules index ff480831..e69de29b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "lib/utfcpp"] - path = lib/utfcpp - url = http://github.com/ledger/utfcpp.git diff --git a/CMakeLists.txt b/CMakeLists.txt index b7e7e920..285b7b6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,7 +242,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) # add the binary tree to the search path for include files so that we will # find TutorialConfig.h include_directories("${PROJECT_SOURCE_DIR}/lib") -include_directories("${PROJECT_SOURCE_DIR}/lib/utfcpp/source") +include_directories("${PROJECT_SOURCE_DIR}/lib/utfcpp/v2_0/source") include_directories("${PROJECT_BINARY_DIR}") configure_file( diff --git a/lib/utfcpp b/lib/utfcpp deleted file mode 160000 index 2233ec93..00000000 --- a/lib/utfcpp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2233ec933f5661c7050b94d3b14f5f9f51ae3d55 diff --git a/lib/utfcpp/v2_0/LICENSE b/lib/utfcpp/v2_0/LICENSE new file mode 100644 index 00000000..36b7cd93 --- /dev/null +++ b/lib/utfcpp/v2_0/LICENSE @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/lib/utfcpp/v2_0/buildrelease.pl b/lib/utfcpp/v2_0/buildrelease.pl new file mode 100755 index 00000000..ed3a17bb --- /dev/null +++ b/lib/utfcpp/v2_0/buildrelease.pl @@ -0,0 +1,18 @@ +#! /usr/bin/perl + +$release_files = 'source/utf8.h source/utf8/core.h source/utf8/checked.h source/utf8/unchecked.h doc/utf8cpp.html doc/ReleaseNotes'; + +# First get the latest version +`svn update`; + +# Then construct the name of the zip file +$argc = @ARGV; +if ($argc > 0) { + $zip_name = $ARGV[0]; +} +else { + $zip_name = "utf8"; +} + +# Zip the files to an archive +`zip $zip_name $release_files`; diff --git a/lib/utfcpp/v2_0/samples/Makefile b/lib/utfcpp/v2_0/samples/Makefile new file mode 100644 index 00000000..6cdd3c85 --- /dev/null +++ b/lib/utfcpp/v2_0/samples/Makefile @@ -0,0 +1,5 @@ +CC = g++ +CFLAGS = -g -Wall -pedantic + +docsample: docsample.cpp ../source/utf8.h + $(CC) $(CFLAGS) docsample.cpp -odocsample diff --git a/lib/utfcpp/v2_0/samples/docsample.cpp b/lib/utfcpp/v2_0/samples/docsample.cpp new file mode 100644 index 00000000..6f8953b9 --- /dev/null +++ b/lib/utfcpp/v2_0/samples/docsample.cpp @@ -0,0 +1,52 @@ +#include "../source/utf8.h" +#include +#include +#include +#include + + +using namespace std; + +int main(int argc, char** argv) +{ + if (argc != 2) { + cout << "\nUsage: docsample filename\n"; + return 0; + } + const char* test_file_path = argv[1]; + // Open the test file (must be UTF-8 encoded) + ifstream fs8(test_file_path); + if (!fs8.is_open()) { + cout << "Could not open " << test_file_path << endl; + return 0; + } + + unsigned line_count = 1; + string line; + // Play with all the lines in the file + while (getline(fs8, line)) { + // check for invalid utf-8 (for a simple yes/no check, there is also utf8::is_valid function) + string::iterator end_it = utf8::find_invalid(line.begin(), line.end()); + if (end_it != line.end()) { + cout << "Invalid UTF-8 encoding detected at line " << line_count << "\n"; + cout << "This part is fine: " << string(line.begin(), end_it) << "\n"; + } + // Get the line length (at least for the valid part) + int length = utf8::distance(line.begin(), end_it); + cout << "Length of line " << line_count << " is " << length << "\n"; + + // Convert it to utf-16 + vector utf16line; + utf8::utf8to16(line.begin(), end_it, back_inserter(utf16line)); + // And back to utf-8; + string utf8line; + utf8::utf16to8(utf16line.begin(), utf16line.end(), back_inserter(utf8line)); + // Confirm that the conversion went OK: + if (utf8line != string(line.begin(), end_it)) + cout << "Error in UTF-16 conversion at line: " << line_count << "\n"; + + line_count++; + } + + return 0; +} diff --git a/lib/utfcpp/v2_0/source/utf8.h b/lib/utfcpp/v2_0/source/utf8.h new file mode 100644 index 00000000..4e445140 --- /dev/null +++ b/lib/utfcpp/v2_0/source/utf8.h @@ -0,0 +1,34 @@ +// Copyright 2006 Nemanja Trifunovic + +/* +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +*/ + + +#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 +#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731 + +#include "utf8/checked.h" +#include "utf8/unchecked.h" + +#endif // header guard diff --git a/lib/utfcpp/v2_0/source/utf8/checked.h b/lib/utfcpp/v2_0/source/utf8/checked.h new file mode 100644 index 00000000..13311551 --- /dev/null +++ b/lib/utfcpp/v2_0/source/utf8/checked.h @@ -0,0 +1,327 @@ +// Copyright 2006 Nemanja Trifunovic + +/* +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +*/ + + +#ifndef UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 +#define UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 + +#include "core.h" +#include + +namespace utf8 +{ + // Base for the exceptions that may be thrown from the library + class exception : public ::std::exception { + }; + + // Exceptions that may be thrown from the library functions. + class invalid_code_point : public exception { + uint32_t cp; + public: + invalid_code_point(uint32_t cp) : cp(cp) {} + virtual const char* what() const throw() { return "Invalid code point"; } + uint32_t code_point() const {return cp;} + }; + + class invalid_utf8 : public exception { + uint8_t u8; + public: + invalid_utf8 (uint8_t u) : u8(u) {} + virtual const char* what() const throw() { return "Invalid UTF-8"; } + uint8_t utf8_octet() const {return u8;} + }; + + class invalid_utf16 : public exception { + uint16_t u16; + public: + invalid_utf16 (uint16_t u) : u16(u) {} + virtual const char* what() const throw() { return "Invalid UTF-16"; } + uint16_t utf16_word() const {return u16;} + }; + + class not_enough_room : public exception { + public: + virtual const char* what() const throw() { return "Not enough space"; } + }; + + /// The library API - functions intended to be called by the users + + template + octet_iterator append(uint32_t cp, octet_iterator result) + { + if (!utf8::internal::is_code_point_valid(cp)) + throw invalid_code_point(cp); + + if (cp < 0x80) // one octet + *(result++) = static_cast(cp); + else if (cp < 0x800) { // two octets + *(result++) = static_cast((cp >> 6) | 0xc0); + *(result++) = static_cast((cp & 0x3f) | 0x80); + } + else if (cp < 0x10000) { // three octets + *(result++) = static_cast((cp >> 12) | 0xe0); + *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); + *(result++) = static_cast((cp & 0x3f) | 0x80); + } + else { // four octets + *(result++) = static_cast((cp >> 18) | 0xf0); + *(result++) = static_cast(((cp >> 12) & 0x3f) | 0x80); + *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); + *(result++) = static_cast((cp & 0x3f) | 0x80); + } + return result; + } + + template + output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement) + { + while (start != end) { + octet_iterator sequence_start = start; + internal::utf_error err_code = utf8::internal::validate_next(start, end); + switch (err_code) { + case internal::UTF8_OK : + for (octet_iterator it = sequence_start; it != start; ++it) + *out++ = *it; + break; + case internal::NOT_ENOUGH_ROOM: + throw not_enough_room(); + case internal::INVALID_LEAD: + out = utf8::append (replacement, out); + ++start; + break; + case internal::INCOMPLETE_SEQUENCE: + case internal::OVERLONG_SEQUENCE: + case internal::INVALID_CODE_POINT: + out = utf8::append (replacement, out); + ++start; + // just one replacement mark for the sequence + while (start != end && utf8::internal::is_trail(*start)) + ++start; + break; + } + } + return out; + } + + template + inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out) + { + static const uint32_t replacement_marker = utf8::internal::mask16(0xfffd); + return utf8::replace_invalid(start, end, out, replacement_marker); + } + + template + uint32_t next(octet_iterator& it, octet_iterator end) + { + uint32_t cp = 0; + internal::utf_error err_code = utf8::internal::validate_next(it, end, cp); + switch (err_code) { + case internal::UTF8_OK : + break; + case internal::NOT_ENOUGH_ROOM : + throw not_enough_room(); + case internal::INVALID_LEAD : + case internal::INCOMPLETE_SEQUENCE : + case internal::OVERLONG_SEQUENCE : + throw invalid_utf8(*it); + case internal::INVALID_CODE_POINT : + throw invalid_code_point(cp); + } + return cp; + } + + template + uint32_t peek_next(octet_iterator it, octet_iterator end) + { + return utf8::next(it, end); + } + + template + uint32_t prior(octet_iterator& it, octet_iterator start) + { + // can't do much if it == start + if (it == start) + throw not_enough_room(); + + octet_iterator end = it; + // Go back until we hit either a lead octet or start + while (utf8::internal::is_trail(*(--it))) + if (it == start) + throw invalid_utf8(*it); // error - no lead byte in the sequence + return utf8::peek_next(it, end); + } + + /// Deprecated in versions that include "prior" + template + uint32_t previous(octet_iterator& it, octet_iterator pass_start) + { + octet_iterator end = it; + while (utf8::internal::is_trail(*(--it))) + if (it == pass_start) + throw invalid_utf8(*it); // error - no lead byte in the sequence + octet_iterator temp = it; + return utf8::next(temp, end); + } + + template + void advance (octet_iterator& it, distance_type n, octet_iterator end) + { + for (distance_type i = 0; i < n; ++i) + utf8::next(it, end); + } + + template + typename std::iterator_traits::difference_type + distance (octet_iterator first, octet_iterator last) + { + typename std::iterator_traits::difference_type dist; + for (dist = 0; first < last; ++dist) + utf8::next(first, last); + return dist; + } + + template + octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result) + { + while (start != end) { + uint32_t cp = utf8::internal::mask16(*start++); + // Take care of surrogate pairs first + if (utf8::internal::is_lead_surrogate(cp)) { + if (start != end) { + uint32_t trail_surrogate = utf8::internal::mask16(*start++); + if (utf8::internal::is_trail_surrogate(trail_surrogate)) + cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET; + else + throw invalid_utf16(static_cast(trail_surrogate)); + } + else + throw invalid_utf16(static_cast(cp)); + + } + // Lone trail surrogate + else if (utf8::internal::is_trail_surrogate(cp)) + throw invalid_utf16(static_cast(cp)); + + result = utf8::append(cp, result); + } + return result; + } + + template + u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result) + { + while (start != end) { + uint32_t cp = utf8::next(start, end); + if (cp > 0xffff) { //make a surrogate pair + *result++ = static_cast((cp >> 10) + internal::LEAD_OFFSET); + *result++ = static_cast((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN); + } + else + *result++ = static_cast(cp); + } + return result; + } + + template + octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result) + { + while (start != end) + result = utf8::append(*(start++), result); + + return result; + } + + template + u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result) + { + while (start != end) + (*result++) = utf8::next(start, end); + + return result; + } + + // The iterator class + template + class iterator : public std::iterator { + octet_iterator it; + octet_iterator range_start; + octet_iterator range_end; + public: + iterator () {} + explicit iterator (const octet_iterator& octet_it, + const octet_iterator& range_start, + const octet_iterator& range_end) : + it(octet_it), range_start(range_start), range_end(range_end) + { + if (it < range_start || it > range_end) + throw std::out_of_range("Invalid utf-8 iterator position"); + } + // the default "big three" are OK + octet_iterator base () const { return it; } + uint32_t operator * () const + { + octet_iterator temp = it; + return utf8::next(temp, range_end); + } + bool operator == (const iterator& rhs) const + { + if (range_start != rhs.range_start || range_end != rhs.range_end) + throw std::logic_error("Comparing utf-8 iterators defined with different ranges"); + return (it == rhs.it); + } + bool operator != (const iterator& rhs) const + { + return !(operator == (rhs)); + } + iterator& operator ++ () + { + utf8::next(it, range_end); + return *this; + } + iterator operator ++ (int) + { + iterator temp = *this; + utf8::next(it, range_end); + return temp; + } + iterator& operator -- () + { + utf8::prior(it, range_start); + return *this; + } + iterator operator -- (int) + { + iterator temp = *this; + utf8::prior(it, range_start); + return temp; + } + }; // class iterator + +} // namespace utf8 + +#endif //header guard + + diff --git a/lib/utfcpp/v2_0/source/utf8/core.h b/lib/utfcpp/v2_0/source/utf8/core.h new file mode 100644 index 00000000..693d388c --- /dev/null +++ b/lib/utfcpp/v2_0/source/utf8/core.h @@ -0,0 +1,329 @@ +// Copyright 2006 Nemanja Trifunovic + +/* +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +*/ + + +#ifndef UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 +#define UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 + +#include + +namespace utf8 +{ + // The typedefs for 8-bit, 16-bit and 32-bit unsigned integers + // You may need to change them to match your system. + // These typedefs have the same names as ones from cstdint, or boost/cstdint + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; + +// Helper code - not intended to be directly called by the library users. May be changed at any time +namespace internal +{ + // Unicode constants + // Leading (high) surrogates: 0xd800 - 0xdbff + // Trailing (low) surrogates: 0xdc00 - 0xdfff + const uint16_t LEAD_SURROGATE_MIN = 0xd800u; + const uint16_t LEAD_SURROGATE_MAX = 0xdbffu; + const uint16_t TRAIL_SURROGATE_MIN = 0xdc00u; + const uint16_t TRAIL_SURROGATE_MAX = 0xdfffu; + const uint16_t LEAD_OFFSET = LEAD_SURROGATE_MIN - (0x10000 >> 10); + const uint32_t SURROGATE_OFFSET = 0x10000u - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN; + + // Maximum valid value for a Unicode code point + const uint32_t CODE_POINT_MAX = 0x0010ffffu; + + template + inline uint8_t mask8(octet_type oc) + { + return static_cast(0xff & oc); + } + template + inline uint16_t mask16(u16_type oc) + { + return static_cast(0xffff & oc); + } + template + inline bool is_trail(octet_type oc) + { + return ((utf8::internal::mask8(oc) >> 6) == 0x2); + } + + template + inline bool is_lead_surrogate(u16 cp) + { + return (cp >= LEAD_SURROGATE_MIN && cp <= LEAD_SURROGATE_MAX); + } + + template + inline bool is_trail_surrogate(u16 cp) + { + return (cp >= TRAIL_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX); + } + + template + inline bool is_surrogate(u16 cp) + { + return (cp >= LEAD_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX); + } + + template + inline bool is_code_point_valid(u32 cp) + { + return (cp <= CODE_POINT_MAX && !utf8::internal::is_surrogate(cp)); + } + + template + inline typename std::iterator_traits::difference_type + sequence_length(octet_iterator lead_it) + { + uint8_t lead = utf8::internal::mask8(*lead_it); + if (lead < 0x80) + return 1; + else if ((lead >> 5) == 0x6) + return 2; + else if ((lead >> 4) == 0xe) + return 3; + else if ((lead >> 3) == 0x1e) + return 4; + else + return 0; + } + + template + inline bool is_overlong_sequence(uint32_t cp, octet_difference_type length) + { + if (cp < 0x80) { + if (length != 1) + return true; + } + else if (cp < 0x800) { + if (length != 2) + return true; + } + else if (cp < 0x10000) { + if (length != 3) + return true; + } + + return false; + } + + enum utf_error {UTF8_OK, NOT_ENOUGH_ROOM, INVALID_LEAD, INCOMPLETE_SEQUENCE, OVERLONG_SEQUENCE, INVALID_CODE_POINT}; + + /// Helper for get_sequence_x + template + utf_error increase_safely(octet_iterator& it, octet_iterator end) + { + if (++it == end) + return NOT_ENOUGH_ROOM; + + if (!utf8::internal::is_trail(*it)) + return INCOMPLETE_SEQUENCE; + + return UTF8_OK; + } + + #define UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(IT, END) {utf_error ret = increase_safely(IT, END); if (ret != UTF8_OK) return ret;} + + /// get_sequence_x functions decode utf-8 sequences of the length x + template + utf_error get_sequence_1(octet_iterator& it, octet_iterator end, uint32_t& code_point) + { + if (it == end) + return NOT_ENOUGH_ROOM; + + code_point = utf8::internal::mask8(*it); + + return UTF8_OK; + } + + template + utf_error get_sequence_2(octet_iterator& it, octet_iterator end, uint32_t& code_point) + { + if (it == end) + return NOT_ENOUGH_ROOM; + + code_point = utf8::internal::mask8(*it); + + UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) + + code_point = ((code_point << 6) & 0x7ff) + ((*it) & 0x3f); + + return UTF8_OK; + } + + template + utf_error get_sequence_3(octet_iterator& it, octet_iterator end, uint32_t& code_point) + { + if (it == end) + return NOT_ENOUGH_ROOM; + + code_point = utf8::internal::mask8(*it); + + UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) + + code_point = ((code_point << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff); + + UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) + + code_point += (*it) & 0x3f; + + return UTF8_OK; + } + + template + utf_error get_sequence_4(octet_iterator& it, octet_iterator end, uint32_t& code_point) + { + if (it == end) + return NOT_ENOUGH_ROOM; + + code_point = utf8::internal::mask8(*it); + + UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) + + code_point = ((code_point << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff); + + UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) + + code_point += (utf8::internal::mask8(*it) << 6) & 0xfff; + + UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end) + + code_point += (*it) & 0x3f; + + return UTF8_OK; + } + + #undef UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR + + template + utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t& code_point) + { + // Save the original value of it so we can go back in case of failure + // Of course, it does not make much sense with i.e. stream iterators + octet_iterator original_it = it; + + uint32_t cp = 0; + // Determine the sequence length based on the lead octet + typedef typename std::iterator_traits::difference_type octet_difference_type; + const octet_difference_type length = utf8::internal::sequence_length(it); + + // Get trail octets and calculate the code point + utf_error err = UTF8_OK; + switch (length) { + case 0: + return INVALID_LEAD; + case 1: + err = utf8::internal::get_sequence_1(it, end, cp); + break; + case 2: + err = utf8::internal::get_sequence_2(it, end, cp); + break; + case 3: + err = utf8::internal::get_sequence_3(it, end, cp); + break; + case 4: + err = utf8::internal::get_sequence_4(it, end, cp); + break; + } + + if (err == UTF8_OK) { + // Decoding succeeded. Now, security checks... + if (utf8::internal::is_code_point_valid(cp)) { + if (!utf8::internal::is_overlong_sequence(cp, length)){ + // Passed! Return here. + code_point = cp; + ++it; + return UTF8_OK; + } + else + err = OVERLONG_SEQUENCE; + } + else + err = INVALID_CODE_POINT; + } + + // Failure branch - restore the original value of the iterator + it = original_it; + return err; + } + + template + inline utf_error validate_next(octet_iterator& it, octet_iterator end) { + uint32_t ignored; + return utf8::internal::validate_next(it, end, ignored); + } + +} // namespace internal + + /// The library API - functions intended to be called by the users + + // Byte order mark + const uint8_t bom[] = {0xef, 0xbb, 0xbf}; + + template + octet_iterator find_invalid(octet_iterator start, octet_iterator end) + { + octet_iterator result = start; + while (result != end) { + utf8::internal::utf_error err_code = utf8::internal::validate_next(result, end); + if (err_code != internal::UTF8_OK) + return result; + } + return result; + } + + template + inline bool is_valid(octet_iterator start, octet_iterator end) + { + return (utf8::find_invalid(start, end) == end); + } + + template + inline bool starts_with_bom (octet_iterator it, octet_iterator end) + { + return ( + ((it != end) && (utf8::internal::mask8(*it++)) == bom[0]) && + ((it != end) && (utf8::internal::mask8(*it++)) == bom[1]) && + ((it != end) && (utf8::internal::mask8(*it)) == bom[2]) + ); + } + + //Deprecated in release 2.3 + template + inline bool is_bom (octet_iterator it) + { + return ( + (utf8::internal::mask8(*it++)) == bom[0] && + (utf8::internal::mask8(*it++)) == bom[1] && + (utf8::internal::mask8(*it)) == bom[2] + ); + } +} // namespace utf8 + +#endif // header guard + + diff --git a/lib/utfcpp/v2_0/source/utf8/unchecked.h b/lib/utfcpp/v2_0/source/utf8/unchecked.h new file mode 100644 index 00000000..cb242716 --- /dev/null +++ b/lib/utfcpp/v2_0/source/utf8/unchecked.h @@ -0,0 +1,228 @@ +// Copyright 2006 Nemanja Trifunovic + +/* +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +*/ + + +#ifndef UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 +#define UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731 + +#include "core.h" + +namespace utf8 +{ + namespace unchecked + { + template + octet_iterator append(uint32_t cp, octet_iterator result) + { + if (cp < 0x80) // one octet + *(result++) = static_cast(cp); + else if (cp < 0x800) { // two octets + *(result++) = static_cast((cp >> 6) | 0xc0); + *(result++) = static_cast((cp & 0x3f) | 0x80); + } + else if (cp < 0x10000) { // three octets + *(result++) = static_cast((cp >> 12) | 0xe0); + *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); + *(result++) = static_cast((cp & 0x3f) | 0x80); + } + else { // four octets + *(result++) = static_cast((cp >> 18) | 0xf0); + *(result++) = static_cast(((cp >> 12) & 0x3f)| 0x80); + *(result++) = static_cast(((cp >> 6) & 0x3f) | 0x80); + *(result++) = static_cast((cp & 0x3f) | 0x80); + } + return result; + } + + template + uint32_t next(octet_iterator& it) + { + uint32_t cp = utf8::internal::mask8(*it); + typename std::iterator_traits::difference_type length = utf8::internal::sequence_length(it); + switch (length) { + case 1: + break; + case 2: + it++; + cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f); + break; + case 3: + ++it; + cp = ((cp << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff); + ++it; + cp += (*it) & 0x3f; + break; + case 4: + ++it; + cp = ((cp << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff); + ++it; + cp += (utf8::internal::mask8(*it) << 6) & 0xfff; + ++it; + cp += (*it) & 0x3f; + break; + } + ++it; + return cp; + } + + template + uint32_t peek_next(octet_iterator it) + { + return utf8::unchecked::next(it); + } + + template + uint32_t prior(octet_iterator& it) + { + while (utf8::internal::is_trail(*(--it))) ; + octet_iterator temp = it; + return utf8::unchecked::next(temp); + } + + // Deprecated in versions that include prior, but only for the sake of consistency (see utf8::previous) + template + inline uint32_t previous(octet_iterator& it) + { + return utf8::unchecked::prior(it); + } + + template + void advance (octet_iterator& it, distance_type n) + { + for (distance_type i = 0; i < n; ++i) + utf8::unchecked::next(it); + } + + template + typename std::iterator_traits::difference_type + distance (octet_iterator first, octet_iterator last) + { + typename std::iterator_traits::difference_type dist; + for (dist = 0; first < last; ++dist) + utf8::unchecked::next(first); + return dist; + } + + template + octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result) + { + while (start != end) { + uint32_t cp = utf8::internal::mask16(*start++); + // Take care of surrogate pairs first + if (utf8::internal::is_lead_surrogate(cp)) { + uint32_t trail_surrogate = utf8::internal::mask16(*start++); + cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET; + } + result = utf8::unchecked::append(cp, result); + } + return result; + } + + template + u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result) + { + while (start < end) { + uint32_t cp = utf8::unchecked::next(start); + if (cp > 0xffff) { //make a surrogate pair + *result++ = static_cast((cp >> 10) + internal::LEAD_OFFSET); + *result++ = static_cast((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN); + } + else + *result++ = static_cast(cp); + } + return result; + } + + template + octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result) + { + while (start != end) + result = utf8::unchecked::append(*(start++), result); + + return result; + } + + template + u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result) + { + while (start < end) + (*result++) = utf8::unchecked::next(start); + + return result; + } + + // The iterator class + template + class iterator : public std::iterator { + octet_iterator it; + public: + iterator () {} + explicit iterator (const octet_iterator& octet_it): it(octet_it) {} + // the default "big three" are OK + octet_iterator base () const { return it; } + uint32_t operator * () const + { + octet_iterator temp = it; + return utf8::unchecked::next(temp); + } + bool operator == (const iterator& rhs) const + { + return (it == rhs.it); + } + bool operator != (const iterator& rhs) const + { + return !(operator == (rhs)); + } + iterator& operator ++ () + { + ::std::advance(it, utf8::internal::sequence_length(it)); + return *this; + } + iterator operator ++ (int) + { + iterator temp = *this; + ::std::advance(it, utf8::internal::sequence_length(it)); + return temp; + } + iterator& operator -- () + { + utf8::unchecked::prior(it); + return *this; + } + iterator operator -- (int) + { + iterator temp = *this; + utf8::unchecked::prior(it); + return temp; + } + }; // class iterator + + } // namespace utf8::unchecked +} // namespace utf8 + + +#endif // header guard + -- cgit v1.2.3 From cc0b32d9bc26f9345de3d89b540841bc2b8ad593 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Mon, 12 Jan 2015 10:02:31 +0100 Subject: [acprep] Remove obsoleted submodule phase Signed-off-by: Alexis Hildebrandt --- acprep | 8 -------- 1 file changed, 8 deletions(-) diff --git a/acprep b/acprep index 9e661aad..f569e460 100755 --- a/acprep +++ b/acprep @@ -490,17 +490,10 @@ class PrepareBuild(CommandLineApp): # Update local files with the latest information # ######################################################################### - def phase_submodule(self, *args): - self.log.info('Executing phase: submodule') - if self.git_working_tree(): - self.execute('git', 'submodule', 'init') - self.execute('git', 'submodule', 'update') - def phase_pull(self, *args): self.log.info('Executing phase: pull') if self.git_working_tree(): self.execute('git', 'pull') - self.phase_submodule() ######################################################################### # Automatic installation of build dependencies # @@ -860,7 +853,6 @@ class PrepareBuild(CommandLineApp): def phase_config(self, *args): self.log.info('Executing phase: config') - self.phase_submodule() self.phase_configure(*args) if self.should_clean: self.phase_clean() -- cgit v1.2.3 From 1d7dd3e082be8a046f21d4a2d51026ac3c1f7c14 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Sun, 11 Jan 2015 12:10:00 +0100 Subject: [cmake] Add FindUtfcpp.cmake it will look for utfcpp in the standard system paths, UTFCPP_PATH, and lib/utfcpp/v2_0/source. This allows the use of utfcpp in: * standard locations such as /usr/include on distributions shipping utfcpp * custom locations for users via UTFCPP_PATH * the source tree using the default location of the utfcpp git submodule, .i.e lib/utfcpp/v2_0 Signed-off-by: Alexis Hildebrandt --- CMakeLists.txt | 16 +++++++++++++--- cmake/FindUtfcpp.cmake | 30 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 cmake/FindUtfcpp.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 285b7b6b..538a26c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,9 @@ set(Ledger_VERSION_MINOR 1) set(Ledger_VERSION_PATCH 0) set(Ledger_VERSION_DATE 20141005) +# Point CMake at any custom modules we may ship +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") + enable_testing() add_definitions(-std=c++11) @@ -236,13 +239,20 @@ endmacro(add_ledger_library_dependencies _target) ######################################################################## +include(FindUtfcpp) +if (UTFCPP_FOUND) + include_directories("${UTFCPP_INCLUDE_DIR}") +else() + message(FATAL_ERROR "Missing required header file: utf8.h\n" + "Define UTFCPP_PATH or install utfcpp locally into the source tree below lib/utfcpp/." + ) +endif() + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) # add the binary tree to the search path for include files so that we will -# find TutorialConfig.h -include_directories("${PROJECT_SOURCE_DIR}/lib") -include_directories("${PROJECT_SOURCE_DIR}/lib/utfcpp/v2_0/source") +# find system.hh include_directories("${PROJECT_BINARY_DIR}") configure_file( diff --git a/cmake/FindUtfcpp.cmake b/cmake/FindUtfcpp.cmake new file mode 100644 index 00000000..185a8d88 --- /dev/null +++ b/cmake/FindUtfcpp.cmake @@ -0,0 +1,30 @@ +# - Try to find utfcpp +# Once done, this will define +# +# UTFCPP_FOUND - system has utfcpp's utf8.h +# UTFCPP_PATH - the utfcpp include directories + +include(CheckCXXSourceCompiles) + +set(UTFCPP_FOUND FALSE) + +find_path(UTFCPP_INCLUDE_DIR + NAMES utf8.h + HINTS "${UTFCPP_PATH}" "${PROJECT_SOURCE_DIR}/lib/utfcpp/v2_0/source" +) + +if (UTFCPP_INCLUDE_DIR) + set(CMAKE_REQUIRED_INCLUDES "${UTFCPP_INCLUDE_DIR}") + set(UTFCPP_FOUND TRUE) +endif() + +check_cxx_source_compiles(" +#include +#include \"utf8.h\" + +int main(int argc, char** argv) { + std::string input = std::string(\"utfcpp\"); + const char * p = input.c_str(); + std::size_t len = input.length(); + utf8::is_valid(p, p + len); +}" HAVE_WORKING_UTFCPP) -- cgit v1.2.3 From 6e82b29073541e1f48a283f38e4b47629ca8495a Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Sun, 11 Jan 2015 12:21:23 +0100 Subject: Remove duplicate utfcpp LICENSE file already present in utfcpp git subtree [ci skip] Signed-off-by: Alexis Hildebrandt --- doc/LICENSE-utfcpp | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 doc/LICENSE-utfcpp diff --git a/doc/LICENSE-utfcpp b/doc/LICENSE-utfcpp deleted file mode 100644 index 1751a003..00000000 --- a/doc/LICENSE-utfcpp +++ /dev/null @@ -1,23 +0,0 @@ -Copyright 2006 Nemanja Trifunovic - -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -- cgit v1.2.3 From 967a76193eb241ea99ae7d99d1f813590fa12ae3 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Mon, 12 Jan 2015 11:26:23 +0100 Subject: [acprep]: Add libutfcpp-dev dependency [ci skip] Signed-off-by: Alexis Hildebrandt --- acprep | 2 ++ 1 file changed, 2 insertions(+) diff --git a/acprep b/acprep index f569e460..6c3cdb86 100755 --- a/acprep +++ b/acprep @@ -562,6 +562,7 @@ class PrepareBuild(CommandLineApp): 'libedit-dev', 'texinfo', 'lcov', + 'libutfcpp-dev', 'sloccount' ] + BoostInfo().dependencies('ubuntu-trusty') elif re.search('saucy', info): @@ -599,6 +600,7 @@ class PrepareBuild(CommandLineApp): 'libedit-dev', 'texinfo', 'lcov', + 'libutfcpp-dev', 'sloccount' ] + BoostInfo().dependencies('ubuntu-precise') else: -- cgit v1.2.3 From 249527c985a9580a5a17ceab8f4488b855a8569c Mon Sep 17 00:00:00 2001 From: "Tim D. Smith" Date: Sat, 9 May 2015 20:01:32 -0700 Subject: link ledger executable to Python Since the ledger executable embeds the Python interpreter, it does need an explicit link to a Python framework on OS X after all. --- src/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a368d378..570a6592 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -273,6 +273,9 @@ if (BUILD_LIBRARY) add_executable(ledger main.cc global.cc) target_link_libraries(ledger libledger) + if (APPLE AND HAVE_BOOST_PYTHON) + target_link_libraries(ledger ${PYTHON_LIBRARIES}) + endif() install(TARGETS libledger DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES ${LEDGER_INCLUDES} -- cgit v1.2.3 From bcaca24de4264f89a94069701361988007e22e58 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 27 Jul 2015 20:37:16 +0100 Subject: Convert boost::optional objects to bool explicitly. Fixes #417. --- src/account.h | 6 +----- src/item.h | 6 +----- src/parser.h | 2 +- src/post.h | 6 +----- src/times.h | 6 +----- 5 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/account.h b/src/account.h index 7fae93e1..7de4e560 100644 --- a/src/account.h +++ b/src/account.h @@ -261,11 +261,7 @@ public: mutable optional xdata_; bool has_xdata() const { -#if BOOST_VERSION >= 105600 - return xdata_ != NULL; -#else - return xdata_; -#endif + return static_cast(xdata_); } void clear_xdata(); xdata_t& xdata() { diff --git a/src/item.h b/src/item.h index ba812175..dbba53a8 100644 --- a/src/item.h +++ b/src/item.h @@ -174,11 +174,7 @@ public: static bool use_aux_date; virtual bool has_date() const { -#if BOOST_VERSION >= 105600 - return _date != NULL; -#else - return _date; -#endif + return static_cast(_date); } virtual date_t date() const { diff --git a/src/parser.h b/src/parser.h index e46fc719..25c4a7e3 100644 --- a/src/parser.h +++ b/src/parser.h @@ -118,7 +118,7 @@ public: ptr_op_t parse(std::istream& in, const parse_flags_t& flags = PARSE_DEFAULT, - const optional& original_string = NULL); + const optional& original_string = boost::none); }; } // namespace ledger diff --git a/src/post.h b/src/post.h index 0fb45e90..5f22fa3c 100644 --- a/src/post.h +++ b/src/post.h @@ -205,11 +205,7 @@ public: mutable optional xdata_; bool has_xdata() const { -#if BOOST_VERSION >= 105600 - return xdata_ != NULL; -#else - return xdata_; -#endif + return static_cast(xdata_); } void clear_xdata() { xdata_ = none; diff --git a/src/times.h b/src/times.h index 421d1462..e1a9e847 100644 --- a/src/times.h +++ b/src/times.h @@ -500,11 +500,7 @@ public: void stabilize(const optional& date = none); bool is_valid() const { -#if BOOST_VERSION >= 105600 - return start != NULL; -#else - return start; -#endif + return static_cast(start); } /** Find the current or next period containing date. Returns false if -- cgit v1.2.3 From a1cb25ad2d9a98ea9ec0bb3ee27fe3cde6046434 Mon Sep 17 00:00:00 2001 From: Johann Klähn Date: Sun, 10 May 2015 13:41:26 +0200 Subject: fix build for boost 1.58 --- src/filters.cc | 2 +- src/iterators.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/filters.cc b/src/filters.cc index 2f97a0e5..b6530c04 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -707,7 +707,7 @@ namespace { insert_prices_in_map(price_map_t& _all_prices) : all_prices(_all_prices) {} - void operator()(datetime_t& date, const amount_t& price) { + void operator()(const datetime_t& date, const amount_t& price) { all_prices.insert(price_map_t::value_type(date, price)); } }; diff --git a/src/iterators.cc b/src/iterators.cc index 21bec5d9..0225e210 100644 --- a/src/iterators.cc +++ b/src/iterators.cc @@ -96,7 +96,7 @@ namespace { TRACE_DTOR(create_price_xact); } - void operator()(datetime_t& date, const amount_t& price) { + void operator()(const datetime_t& date, const amount_t& price) { xact_t * xact; string symbol = price.commodity().symbol(); -- cgit v1.2.3 From 844796972acdcaf16e96a90e96ed354438f70a3a Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Tue, 28 Jul 2015 16:26:30 +0200 Subject: [travis] Switch to container-based build using plain cmake and make --- .travis.yml | 58 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9128c24e..03d5c720 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,32 +2,60 @@ # provides GNU GCC 4.6, which does not support -std=c++11 GNU GCC 4.8 is installed # NOTE: Please validate this file after editing it using -# Travis WebLint http://lint.travis-ci.org/ -# or travis-yaml https://github.com/travis-ci/travis-yaml +# Travis WebLint https://lint.travis-ci.org/ +# or travis-lint https://github.com/travis-ci/travis-lint language: cpp compiler: - clang - gcc +sudo: false +cache: + apt: true + +matrix: + include: + - os: linux + compiler: clang + - os: linux + compiler: g++-4.8 + - os: osx + compiler: clang + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + - boost-latest + packages: + - gcc-4.8 + - g++-4.8 + - libgmp-dev + - libmpfr-dev + - libedit-dev + - libboost1.55-dev + - libboost-test1.55-dev + - libboost-regex1.55-dev + - libboost-python1.55-dev + - libboost-system1.55-dev + - libboost-date-time1.55-dev + - libboost-iostreams1.55-dev + - libboost-filesystem1.55-dev + - libboost-serialization1.55-dev before_install: - # Add software package repositories with recent versions of gcc and boost - - sudo add-apt-repository ppa:ubuntu-toolchain-r/test --yes - - sudo add-apt-repository ppa:boost-latest/ppa --yes - - sudo apt-get update -qq - -install: - # Install GNU GCC 4.8 required by use of C++11 - - if [ "$CXX" = "g++" ]; then sudo apt-get install -qq g++-4.8 gcc-4.8; fi - - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi - # Install Ledger dependencies - - sudo apt-get install -qq libboost1.55 libgmp-dev libmpfr-dev libeditline-dev + - if [[ "${TRAVIS_OS_NAME}" == osx ]]; then brew update; fi + +install: + - if [[ "${TRAVIS_OS_NAME}" == osx ]]; then for formula in gmp mpfr boost boost-python; do brew outdated $formula || brew install $formula; done; fi before_script: - - ./acprep debug make --python + #- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi + - cmake . -DUSE_PYTHON=ON + - make script: - - ./acprep check --jobs $(nproc) -- --output-on-failure + - make test - PYTHONPATH=. python python/demo.py notifications: -- cgit v1.2.3 From f0f4d7e66f9adf5610aaf6d65c160621a79c10da Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Tue, 28 Jul 2015 20:35:56 +0200 Subject: [travis] Remove multi-os build configuration --- .travis.yml | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 03d5c720..fee32bef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,15 +13,6 @@ sudo: false cache: apt: true -matrix: - include: - - os: linux - compiler: clang - - os: linux - compiler: g++-4.8 - - os: osx - compiler: clang - addons: apt: sources: @@ -43,14 +34,8 @@ addons: - libboost-filesystem1.55-dev - libboost-serialization1.55-dev -before_install: - - if [[ "${TRAVIS_OS_NAME}" == osx ]]; then brew update; fi - -install: - - if [[ "${TRAVIS_OS_NAME}" == osx ]]; then for formula in gmp mpfr boost boost-python; do brew outdated $formula || brew install $formula; done; fi - before_script: - #- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi + - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi - cmake . -DUSE_PYTHON=ON - make -- cgit v1.2.3 From f5d59159f1aac6e5c24476d085de3f9033c52edb Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Tue, 28 Jul 2015 20:54:44 +0200 Subject: [tests] Fix Util and Math tests on Mac OS X by explicitly linking the testing targets against Python --- test/unit/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 23bb0ea4..654bda5f 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -7,9 +7,15 @@ include_directories(${PROJECT_SOURCE_DIR}/src) if (BUILD_LIBRARY) add_executable(UtilTests t_times.cc) + if (CMAKE_SYSTEM_NAME STREQUAL Darwin AND HAVE_BOOST_PYTHON) + target_link_libraries(UtilTests ${PYTHON_LIBRARIES}) + endif() add_ledger_test(UtilTests) add_executable(MathTests t_amount.cc t_commodity.cc t_balance.cc t_expr.cc) + if (CMAKE_SYSTEM_NAME STREQUAL Darwin AND HAVE_BOOST_PYTHON) + target_link_libraries(MathTests ${PYTHON_LIBRARIES}) + endif() add_ledger_test(MathTests) set_target_properties(check PROPERTIES DEPENDS LedgerUtilTests) -- cgit v1.2.3 From d0fba947ade223dfa351c49ac15c6939c35b5f89 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Tue, 28 Jul 2015 20:55:56 +0200 Subject: [cmake] Use CMAKE_SYSTEM_NAME to test the platform. APPLE and CMAKE_HOST_APPLE only check the host system, whereas CMAKE_SYSTEM_NAME checks the target system when cross-compiling. --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6166780c..3c8c36ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -225,7 +225,7 @@ macro(add_ledger_library_dependencies _target) target_link_libraries(${_target} ${INTL_LIB}) endif() if (HAVE_BOOST_PYTHON) - if(APPLE) + if(CMAKE_SYSTEM_NAME STREQUAL Darwin) # Don't link directly to a Python framework on OS X, to avoid segfaults # when the module is imported from a different interpreter target_link_libraries(${_target} ${Boost_LIBRARIES}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 570a6592..8ed6e51a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -273,7 +273,7 @@ if (BUILD_LIBRARY) add_executable(ledger main.cc global.cc) target_link_libraries(ledger libledger) - if (APPLE AND HAVE_BOOST_PYTHON) + if (CMAKE_SYSTEM_NAME STREQUAL Darwin AND HAVE_BOOST_PYTHON) target_link_libraries(ledger ${PYTHON_LIBRARIES}) endif() @@ -297,7 +297,7 @@ print(s.get_python_lib(True, prefix=''))" if (PYTHON_SITE_PACKAGES) if (WIN32 AND NOT CYGWIN) set(_ledger_python_module_name "ledger.pyd") - elseif(CMAKE_HOST_APPLE) + elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin) set(_ledger_python_module_name "ledger.so") else() set(_ledger_python_module_name "ledger${CMAKE_SHARED_LIBRARY_SUFFIX}") -- cgit v1.2.3 From 68ecc043cc69917582d81ac3514372bc3f690e0b Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Tue, 28 Jul 2015 22:07:10 +0200 Subject: [tests] Allow string continuation in documentation in long documentation examples. --- test/DocTests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/DocTests.py b/test/DocTests.py index ac681bc2..7af7abc3 100755 --- a/test/DocTests.py +++ b/test/DocTests.py @@ -108,6 +108,7 @@ class DocTests: validate_command = False try: command = example[self.testin_token][self.testin_token] + command = re.sub(r'\\\n', '', command) except KeyError: if self.validate_dat_token in example: command = '$ ledger bal' -- cgit v1.2.3 From 69fa2fc671e7a02d416270d1d68df71a0f096714 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Tue, 28 Jul 2015 22:43:16 +0200 Subject: [tests] Remove compiler warnings for unit tests warning: relational comparison result unused [-Wunused-comparison] BOOST_CHECK_THROW(x6 < x7, amount_error); ~~~^~~~ --- test/unit/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 654bda5f..b440d2ed 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -13,6 +13,7 @@ if (BUILD_LIBRARY) add_ledger_test(UtilTests) add_executable(MathTests t_amount.cc t_commodity.cc t_balance.cc t_expr.cc) + set_source_files_properties(t_amount.cc PROPERTIES COMPILE_FLAGS "-Wno-unused-comparison") if (CMAKE_SYSTEM_NAME STREQUAL Darwin AND HAVE_BOOST_PYTHON) target_link_libraries(MathTests ${PYTHON_LIBRARIES}) endif() -- cgit v1.2.3 From c4db52614e75e1c564ab4591e1dc5240d33a2293 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Tue, 28 Jul 2015 23:01:48 +0200 Subject: [travis] Run documentation checks as reports which are allowed to fail instead of strict tests. --- .travis.yml | 6 +++++- test/CMakeLists.txt | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index fee32bef..c573057d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,13 +36,17 @@ addons: before_script: - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi - - cmake . -DUSE_PYTHON=ON + - cmake . -DUSE_PYTHON=ON -DBUILD_DEBUG=ON - make script: - make test - PYTHONPATH=. python python/demo.py +after_script: + - python test/CheckTexinfo.py -l ledger -s . + - python test/CheckManpage.py -l ledger -s . + notifications: email: on_success: change diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6eb9f956..0e7d5f2c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -47,7 +47,9 @@ if (PYTHONINTERP_FOUND) set_target_properties(check PROPERTIES DEPENDS ${_class}Test_${TestFile_Name}) endforeach() - list(APPEND CheckOptions CheckManpage CheckTexinfo CheckBaselineTests) + # CheckManpage and CheckTexinfo are disabled, since they do not work + # reliably yet, instead they are being run as a Travis CI report. + list(APPEND CheckOptions CheckBaselineTests) #CheckManpage CheckTexinfo foreach(_class ${CheckOptions}) add_test(NAME ${_class} COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/test/${_class}.py -- cgit v1.2.3 From b60a12a6cef6338a3a2fb731d77496f4752f6ce6 Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Tue, 28 Jul 2015 17:30:00 -0400 Subject: Add missing known functions to test --- test/CheckOptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CheckOptions.py b/test/CheckOptions.py index 5059a289..e4a1fdc3 100755 --- a/test/CheckOptions.py +++ b/test/CheckOptions.py @@ -83,7 +83,7 @@ class CheckOptions (object): self.missing_functions.add(function) else: functions.remove(function) - known_functions = ['tag', 'has_tag'] + known_functions = ['tag', 'has_tag', 'meta', 'has_meta'] self.unknown_functions = {function for function in functions if function not in known_functions} if len(self.missing_options): -- cgit v1.2.3 From 2c8c6524bd2e5cc8436341947989f05c7028f72f Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Tue, 28 Jul 2015 17:31:14 -0400 Subject: Improve --explicit test case Since --explicit tells ledger to require pre-declarations to establish "known-ness" (rather than taking it from cleared transactions), make sure the transactions are cleared. --- test/baseline/opt-explicit.test | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/baseline/opt-explicit.test b/test/baseline/opt-explicit.test index defae179..20b74913 100644 --- a/test/baseline/opt-explicit.test +++ b/test/baseline/opt-explicit.test @@ -2,16 +2,18 @@ account Assets:Cash account Expenses:Phone account Expenses:Rent commodity GBP +tag bar -2012-03-20 Phone +2012-03-20 * Phone + ; :bar: Expenses:Phone 20.00 GBP Assets:Cash -2012-03-21 Rent +2012-03-21 * Rent Expenses:Rent 550.00 GBP Assets:Cash -2012-03-22 Food +2012-03-22 * Food ; :food: Expenses:Food 20.00 EUR Assets:Cash @@ -27,8 +29,8 @@ test bal --explicit --strict -------------------- 0 __ERROR__ -Warning: "$FILE", line 16: Unknown account 'Expenses:Food' -Warning: "$FILE", line 16: Unknown commodity 'EUR' -Warning: "$FILE", line 17: Unknown metadata tag 'food' +Warning: "$FILE", line 18: Unknown account 'Expenses:Food' +Warning: "$FILE", line 18: Unknown commodity 'EUR' +Warning: "$FILE", line 19: Unknown metadata tag 'food' end test -- cgit v1.2.3 From 1cf473ca50415dd4667b145b466994489ff57d1a Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Tue, 28 Jul 2015 17:32:36 -0400 Subject: Add Debian testing and sid to install instructions --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5e2c6a07..e6296517 100644 --- a/README.md +++ b/README.md @@ -147,9 +147,9 @@ Or, for Ubuntu 12.04: Debian squeeze (6.0): the version of boost in squeeze is too old for ledger and unfortunately no backport is available at the moment. -Debian 7 (wheezy) and Debian 8 (jessie) contain all components needed to -build ledger. You can install all required build dependencies using the -following command: +Debian 7 (wheezy), Debian 8 (jessie), Debian testing (stretch) and Debian +unstable (sid) contain all components needed to build ledger. You can +install all required build dependencies using the following command: $ sudo apt-get install build-essential cmake autopoint texinfo python-dev \ zlib1g-dev libbz2-dev libgmp3-dev gettext libmpfr-dev \ -- cgit v1.2.3 From e65ead2770a6135ca8714c793cdcc53b3d3f0afd Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Tue, 28 Jul 2015 17:40:05 -0400 Subject: Document --explicit --- doc/ledger.1 | 5 ++++- doc/ledger3.texi | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/doc/ledger.1 b/doc/ledger.1 index b674cb6a..7b0cc642 100644 --- a/doc/ledger.1 +++ b/doc/ledger.1 @@ -574,7 +574,10 @@ posting occurring in that period. Display values in terms of the given .Ar COMMODITY . The latest available price is used. -.\".It Fl \-explicit +.It Fl \-explicit +Direct Ledger to require pre-declarations for entities (such as accounts, +commodities and tags) rather than taking entities from cleared +transactions as defined. .It Fl \-file Ar FILE Read journal data from .Ar FILE . diff --git a/doc/ledger3.texi b/doc/ledger3.texi index e70210ab..78db34bf 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -5970,8 +5970,10 @@ Direct Ledger to download prices. @c @option{--getquote @var{FILE}}. @item --explicit -@c see test/baseline/opt-explicit.test -@value{FIXME:UNDOCUMENTED} +Direct Ledger to require pre-declarations for entities (such as accounts, +commodities and tags) rather than taking entities from cleared +transactions as defined. This option is useful in combination with +@option{--strict} or @option{--pedantic}. @item --file @var{FILE} @itemx -f @var{FILE} -- cgit v1.2.3 From 852ece54fe9f2b035cbdf729a71ad9f4feee0111 Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Tue, 28 Jul 2015 17:46:13 -0400 Subject: Add baseline test for --no-revalued option --- test/baseline/opt-no-revalued.test | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/baseline/opt-no-revalued.test diff --git a/test/baseline/opt-no-revalued.test b/test/baseline/opt-no-revalued.test new file mode 100644 index 00000000..487ffa30 --- /dev/null +++ b/test/baseline/opt-no-revalued.test @@ -0,0 +1,58 @@ +2009/01/01 Sample 1a + Assets:Brokerage:Stocks 100 S + Assets:Brokerage:Cash -100 P + +P 2009/01/01 00:00:00 S 2 P + +2009/02/01 Sample 2a + Assets:Brokerage:Stocks 100 S @ 1 P + Assets:Brokerage:Cash + +P 2009/02/01 00:00:00 S 4 P + +2009/03/01 Sample 3a + Assets:Brokerage:Stocks 100 S @@ 100 P + Assets:Brokerage:Cash + +P 2009/03/01 00:00:00 S 8 P + +2009/04/01 Sample 4a + Assets:Brokerage:Cash 100 P + Assets:Brokerage:Stocks -100 S {1 P} + +P 2009/04/01 00:00:00 S 16 P + +; In this usage case, the top amount is always secondary +; 2010/01/01 Sample 1b +; Assets:Brokerage:Cash -100 P +; Assets:Brokerage:Stocks 100 S +; +; P 2010/01/01 00:00:00 S 2 P + +2010/02/01 Sample 2b + Assets:Brokerage:Cash + Assets:Brokerage:Stocks 100 S @ 1 P + +P 2010/02/01 00:00:00 S 4 P + +2010/03/01 Sample 3b + Assets:Brokerage:Cash + Assets:Brokerage:Stocks 100 S @@ 100 P + +P 2010/03/01 00:00:00 S 8 P + +2010/04/01 Sample 4b + Assets:Brokerage:Stocks -100 S {1 P} + Assets:Brokerage:Cash 100 P + +P 2010/04/01 00:00:00 S 16 P + +test reg --market --no-revalued stocks +09-Jan-01 Sample 1a Asset:Brokerage:Stocks 200 P 200 P +09-Feb-01 Sample 2a Asset:Brokerage:Stocks 400 P 800 P +09-Mar-01 Sample 3a Asset:Brokerage:Stocks 800 P 2400 P +09-Apr-01 Sample 4a Asset:Brokerage:Stocks -1600 P 3200 P +10-Feb-01 Sample 2b Asset:Brokerage:Stocks 400 P 1200 P +10-Mar-01 Sample 3b Asset:Brokerage:Stocks 800 P 3200 P +10-Apr-01 Sample 4b Asset:Brokerage:Stocks -1600 P 4800 P +end test -- cgit v1.2.3 From 94d4f5c1952c9fe013ad763b991c841a632a9366 Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Tue, 28 Jul 2015 17:50:13 -0400 Subject: Document --no-revalued --- doc/ledger.1 | 4 ++++ doc/ledger3.texi | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/doc/ledger.1 b/doc/ledger.1 index 7b0cc642..e93af550 100644 --- a/doc/ledger.1 +++ b/doc/ledger.1 @@ -719,6 +719,10 @@ Aliases are completely ignored. Suppress any color TTY output. .It Fl \-no-pager Disables the pager on TTY output. +.It Fl \-no-revalued +Stop Ledger from showing + +postings. .It Fl \-no-rounding Don't output .Qq Li diff --git a/doc/ledger3.texi b/doc/ledger3.texi index 78db34bf..21f8f91f 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -6538,6 +6538,10 @@ Suppress any color TTY output. @item --no-pager Direct output to stdout, avoiding pager program. +@item --no-revalued +Stop Ledger from showing @code{} postings. This option is useful +in combination with the @option{--exchange} or @option{--market} option. + @item --no-rounding Don't output @samp{} postings. Note that this will cause the running total to often not add up! Its main use is for -- cgit v1.2.3 From c3f0d23f66620e263ee50e47f2bdb0ec6bb8740d Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Tue, 28 Jul 2015 17:52:18 -0400 Subject: Use .Nm to refer to ledger in the man page Thanks to Alexis for the suggestion. --- doc/ledger.1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/ledger.1 b/doc/ledger.1 index e93af550..2a3fd5c0 100644 --- a/doc/ledger.1 +++ b/doc/ledger.1 @@ -575,7 +575,9 @@ Display values in terms of the given .Ar COMMODITY . The latest available price is used. .It Fl \-explicit -Direct Ledger to require pre-declarations for entities (such as accounts, +Direct +.Nm +to require pre-declarations for entities (such as accounts, commodities and tags) rather than taking entities from cleared transactions as defined. .It Fl \-file Ar FILE @@ -720,7 +722,9 @@ Suppress any color TTY output. .It Fl \-no-pager Disables the pager on TTY output. .It Fl \-no-revalued -Stop Ledger from showing +Stop +.Nm +from showing postings. .It Fl \-no-rounding -- cgit v1.2.3 From 3a0e41dd0307348da173a569ec05e71b68c63e7d Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Tue, 28 Jul 2015 18:18:57 -0400 Subject: Document some changes in NEWS --- doc/NEWS | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/NEWS b/doc/NEWS index 45596ddc..eaabc459 100644 --- a/doc/NEWS +++ b/doc/NEWS @@ -1,5 +1,27 @@ Ledger NEWS +* 3.x.x + +- Added a --no-revalued option + +- Improved Embedded Python Support + +- Fixed parsing of transactions with single-character payees and comments + +- Fixed sorting for option --auto-match + +- Fixed treatment of "year 2015" and "Y2014" directives + +- Fixed crash when using --trace 10 or above + +- Build fix for boost 1.56 + +- Build fix for Cygwin + +- Fixed Util and Math tests on Mac OS X + +- Various documentation improvements + * 3.1 - Changed the definition of cost basis to preserve the original cost basis -- cgit v1.2.3 From 60c387fed76c90054ca6d1218955d621ef82854f Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Tue, 28 Jul 2015 18:25:37 -0400 Subject: Update NEWS --- doc/NEWS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/NEWS b/doc/NEWS index eaabc459..94c0946a 100644 --- a/doc/NEWS +++ b/doc/NEWS @@ -8,6 +8,8 @@ - Fixed parsing of transactions with single-character payees and comments +- Fixed crash when using -M with empty result + - Fixed sorting for option --auto-match - Fixed treatment of "year 2015" and "Y2014" directives -- cgit v1.2.3 From dd3d28f7b62784b0393aa6cb099cc51d9e512b33 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Wed, 29 Jul 2015 15:38:32 +0200 Subject: [tests] Remove empty baseline test files. The --generated and --verify-memory options are already ignored by CheckBaselineTests.py The --no-pager and --no-rounding options currently fail and need a proper baseline test or be ignored in CheckBaselineTests.py. --- test/baseline/opt-generated.test | 0 test/baseline/opt-no-pager.test | 0 test/baseline/opt-no-rounding.test | 0 test/baseline/opt-verify-memory.test | 0 4 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/baseline/opt-generated.test delete mode 100644 test/baseline/opt-no-pager.test delete mode 100644 test/baseline/opt-no-rounding.test delete mode 100644 test/baseline/opt-verify-memory.test diff --git a/test/baseline/opt-generated.test b/test/baseline/opt-generated.test deleted file mode 100644 index e69de29b..00000000 diff --git a/test/baseline/opt-no-pager.test b/test/baseline/opt-no-pager.test deleted file mode 100644 index e69de29b..00000000 diff --git a/test/baseline/opt-no-rounding.test b/test/baseline/opt-no-rounding.test deleted file mode 100644 index e69de29b..00000000 diff --git a/test/baseline/opt-verify-memory.test b/test/baseline/opt-verify-memory.test deleted file mode 100644 index e69de29b..00000000 -- cgit v1.2.3 From 3d1c59aa811bf9e961fef2f7a219a532b71a2ba2 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Thu, 30 Jul 2015 13:35:32 +0200 Subject: [tests] Add baseline test for --cleared-format --- test/baseline/opt-cleared-format.test | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/baseline/opt-cleared-format.test b/test/baseline/opt-cleared-format.test index e69de29b..9100a636 100644 --- a/test/baseline/opt-cleared-format.test +++ b/test/baseline/opt-cleared-format.test @@ -0,0 +1,20 @@ +test tags --file test/input/drewr3.dat --cleared-format '%-30(account) %15(get_at(total_expr, 0)) %15(get_at(total_expr, 1))\n%/' +Assets $ -3,804.00 $ 775.00 +Assets:Checking $ 1,396.00 $ 775.00 +Assets:Checking:Business $ 30.00 0 +Assets:Savings $ -5,200.00 0 +Equity:Opening Balances $ -1,000.00 $ -1,000.00 +Expenses $ 6,654.00 $ 225.00 +Expenses:Auto $ 5,500.00 0 +Expenses:Books $ 20.00 0 +Expenses:Escrow $ 300.00 0 +Expenses:Food:Groceries $ 334.00 $ 225.00 +Expenses:Interest:Mortgage $ 500.00 0 +Income $ -2,030.00 0 +Income:Salary $ -2,000.00 0 +Income:Sales $ -30.00 0 +Liabilities $ -63.60 0 +Liabilities:MasterCard $ -20.00 0 +Liabilities:Mortgage:Principal $ 200.00 0 +Liabilities:Tithe $ -243.60 0 +end test -- cgit v1.2.3 From 76f057c14c1ab3255478ba9e8f305bf961f8ed71 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 30 Jul 2015 14:05:53 -0700 Subject: Re-indent some code that was indented incorrectly --- src/session.cc | 83 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/src/session.cc b/src/session.cc index 7736023d..b4fb4eb8 100644 --- a/src/session.cc +++ b/src/session.cc @@ -127,47 +127,14 @@ std::size_t session_t::read_data(const string& master_account) if (HANDLED(value_expr_)) journal->value_expr = HANDLER(value_expr_).str(); - if (price_db_path) { - if (exists(*price_db_path)) { - parsing_context.push(*price_db_path); - parsing_context.get_current().journal = journal.get(); - try { - if (journal->read(parsing_context) > 0) - throw_(parse_error, _("Transactions not allowed in price history file")); - } - catch (...) { - parsing_context.pop(); - throw; - } - parsing_context.pop(); - } - } - - foreach (const path& pathname, HANDLER(file_).data_files) { - if (pathname == "-" || pathname == "/dev/stdin") { - // To avoid problems with stdin and pipes, etc., we read the entire - // file in beforehand into a memory buffer, and then parcel it out - // from there. - std::ostringstream buffer; - - while (std::cin.good() && ! std::cin.eof()) { - char line[8192]; - std::cin.read(line, 8192); - std::streamsize count = std::cin.gcount(); - buffer.write(line, count); - } - buffer.flush(); - - shared_ptr stream(new std::istringstream(buffer.str())); - parsing_context.push(stream); - } else { - parsing_context.push(pathname); - } + if (price_db_path) { + if (exists(*price_db_path)) { + parsing_context.push(*price_db_path); parsing_context.get_current().journal = journal.get(); - parsing_context.get_current().master = acct; try { - xact_count += journal->read(parsing_context); + if (journal->read(parsing_context) > 0) + throw_(parse_error, _("Transactions not allowed in price history file")); } catch (...) { parsing_context.pop(); @@ -175,10 +142,44 @@ std::size_t session_t::read_data(const string& master_account) } parsing_context.pop(); } + } + + foreach (const path& pathname, HANDLER(file_).data_files) { + if (pathname == "-" || pathname == "/dev/stdin") { + // To avoid problems with stdin and pipes, etc., we read the entire + // file in beforehand into a memory buffer, and then parcel it out + // from there. + std::ostringstream buffer; + + while (std::cin.good() && ! std::cin.eof()) { + char line[8192]; + std::cin.read(line, 8192); + std::streamsize count = std::cin.gcount(); + buffer.write(line, count); + } + buffer.flush(); + + shared_ptr stream(new std::istringstream(buffer.str())); + parsing_context.push(stream); + } else { + parsing_context.push(pathname); + } + + parsing_context.get_current().journal = journal.get(); + parsing_context.get_current().master = acct; + try { + xact_count += journal->read(parsing_context); + } + catch (...) { + parsing_context.pop(); + throw; + } + parsing_context.pop(); + } - DEBUG("ledger.read", "xact_count [" << xact_count - << "] == journal->xacts.size() [" << journal->xacts.size() << "]"); - assert(xact_count == journal->xacts.size()); + DEBUG("ledger.read", "xact_count [" << xact_count + << "] == journal->xacts.size() [" << journal->xacts.size() << "]"); + assert(xact_count == journal->xacts.size()); if (populated_data_files) HANDLER(file_).data_files.clear(); -- cgit v1.2.3 From 89c3eaa3881d34d81eb195aef33e53ca42766397 Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Thu, 30 Jul 2015 17:38:38 -0400 Subject: Update documentation to reflect was changed to --- doc/ledger.1 | 2 +- doc/ledger3.texi | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ledger.1 b/doc/ledger.1 index 2a3fd5c0..0445c237 100644 --- a/doc/ledger.1 +++ b/doc/ledger.1 @@ -729,7 +729,7 @@ from showing postings. .It Fl \-no-rounding Don't output -.Qq Li +.Qq Li postings. Note that this will cause the running total to often not add up! Its main use is for .Fl \-amount-data Pq Fl j diff --git a/doc/ledger3.texi b/doc/ledger3.texi index 21f8f91f..1226a66f 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -6543,7 +6543,7 @@ Stop Ledger from showing @code{} postings. This option is useful in combination with the @option{--exchange} or @option{--market} option. @item --no-rounding -Don't output @samp{} postings. Note that this will cause the +Don't output @samp{} postings. Note that this will cause the running total to often not add up! Its main use is for @option{--amount-data (-j)} and @option{--total-data (-J)} reports. -- cgit v1.2.3 From 61995d6a200b2d277c9fe6746be20d07690763c2 Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Thu, 30 Jul 2015 17:41:40 -0400 Subject: Add test for --no-rounding --- test/baseline/opt-no-rounding.test | 81 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 test/baseline/opt-no-rounding.test diff --git a/test/baseline/opt-no-rounding.test b/test/baseline/opt-no-rounding.test new file mode 100644 index 00000000..5d0758c6 --- /dev/null +++ b/test/baseline/opt-no-rounding.test @@ -0,0 +1,81 @@ +2012-01-01 * Opening balance + Assets:Current 17.43 EUR + Assets:Investments 200 "LU02" @ 24.77 EUR + Assets:Investments 58 "LU02" @ 24.79900855 EUR + Equity:Opening balance + +2012-01-01 * Opening balance + Assets:Pension 785.44 GBP + Assets:Pension 97.0017 "H2" @ 5.342999720204 GBP + Assets:Pension 4.3441 "H1" @ 5.289999915108 GBP + Equity:Opening balance + +2012-01-01 * Opening balance: misc + Assets:Piggy bank 3.51 GBP + Equity:Opening balance + +2012-01-01 * Opening balance + Assets:Rewards 9836 AAdvantage + Equity:Opening balance + +2012-01-03 * Receivable + Assets:Current + Assets:Receivable -161.06 EUR + Assets:Receivable -9.99 GBP @@ 11.65 EUR + +2012-01-27 * Test + Income:Test -2759.50 GBP + Income:Test -110.76 GBP + Assets:Foo 345.57 GBP + Expenses:Test 16.47 GBP + Expenses:Test 6.33 GBP + Expenses:Test 261.39 GBP + Assets:Current + +test reg -X EUR -H --no-rounding +12-Jan-01 Opening balance Assets:Current 17.43 EUR 17.43 EUR + Assets:Investments 4959.80 EUR 4977.23 EUR + Assets:Investments 1438.34 EUR 6415.57 EUR + Equity:Opening balance -6409.77 EUR 5.80 EUR +12-Jan-01 Opening balance Assets:Pension 785.44 GBP 5.80 EUR + 785.44 GBP + Assets:Pension 97.0017 H2 5.80 EUR + 785.44 GBP + 97.0017 H2 + Assets:Pension 4.3441 H1 5.80 EUR + 785.44 GBP + 4.3441 H1 + 97.0017 H2 + Equity:Opening balance -1326.70 GBP 5.80 EUR + -541.26 GBP + 4.3441 H1 + 97.0017 H2 +12-Jan-01 Opening balance: misc Assets:Piggy bank 3.51 GBP 5.80 EUR + -537.75 GBP + 4.3441 H1 + 97.0017 H2 + Equity:Opening balance -3.51 GBP 5.80 EUR + -541.26 GBP + 4.3441 H1 + 97.0017 H2 +12-Jan-01 Opening balance Assets:Rewards 9836 AAdvantage 9836 AAdvantage + 5.80 EUR + -541.26 GBP + 4.3441 H1 + 97.0017 H2 + Equity:Opening balance -9836 AAdvantage 5.80 EUR + -541.26 GBP + 4.3441 H1 + 97.0017 H2 +12-Jan-03 Commodities revalued 0 5.80 EUR +12-Jan-03 Receivable Assets:Current 172.71 EUR 178.51 EUR + Assets:Receivable -161.06 EUR 17.45 EUR + Assets:Receivable -11.65 EUR 5.80 EUR +12-Jan-27 Test Income:Test -3218.04 EUR -3212.23 EUR + Income:Test -129.16 EUR -3341.40 EUR + Assets:Foo 402.99 EUR -2938.41 EUR + Expenses:Test 19.21 EUR -2919.20 EUR + Expenses:Test 7.38 EUR -2911.82 EUR + Expenses:Test 304.82 EUR -2606.99 EUR + Assets:Current 2612.80 EUR 5.80 EUR +end test -- cgit v1.2.3 From 4e12580789523afb6c3b582c925eef44fad04488 Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Thu, 30 Jul 2015 17:44:32 -0400 Subject: Add test for --value-expr See John's email "A solution to the commodity pricing problem" on how this works: https://groups.google.com/forum/#!topic/ledger-cli/gpOW50XtCTo --- test/baseline/opt-value-expr.test | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/test/baseline/opt-value-expr.test b/test/baseline/opt-value-expr.test index e69de29b..c71be26e 100644 --- a/test/baseline/opt-value-expr.test +++ b/test/baseline/opt-value-expr.test @@ -0,0 +1,48 @@ + +D 1000.00 EUR +D 1000.00 USD +D 1000.00 DM + +2015-01-01 * Buy 2 FOO + Assets:Investments 2 FOO @@ 20.00 EUR + Assets:Cash -20.00 EUR + +2015-05-01 * Buy 2 FOO + Expenses:Food 20.00 USD + ; Just to be silly, always valuate *these* $20 as 30 DM, no matter what + ; the user asks for with -V or -X + ; VALUE:: 30 DM + Assets:Cash -20.00 USD + +P 2015-05-01 USD 20 DM + +P 2015-06-01 USD 22 DM + +test bal assets:investments -V --value-expr "25.00 EUR" + 50.00 EUR Assets:Investments +end test + +test bal assets:investments -G --value-expr "date < [March 2015] ? 22.00 EUR : 25.00 EUR" --now "2015-02-20" + 24.00 EUR Assets:Investments +end test + +test bal assets:investments -G --value-expr "date < [March 2015] ? 22.00 EUR : 25.00 EUR" --now "2015-03-20" + 30.00 EUR Assets:Investments +end test + +test bal expenses:food + 20.00 USD Expenses:Food +end test + +test bal expenses:food -V + 600.00 DM Expenses:Food +end test + +test bal expenses:food -X "DM" --now "2015-05-02" + 600.00 DM Expenses:Food +end test + +test bal expenses:food -X "DM" --now "2015-06-02" + 600.00 DM Expenses:Food +end test + -- cgit v1.2.3 From 09f61ded0ff9217acdc0f05a27c71f958103fe1b Mon Sep 17 00:00:00 2001 From: Martin Michlmayr Date: Thu, 30 Jul 2015 18:06:48 -0400 Subject: Fix description --- test/baseline/opt-value-expr.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/baseline/opt-value-expr.test b/test/baseline/opt-value-expr.test index c71be26e..8b68a80e 100644 --- a/test/baseline/opt-value-expr.test +++ b/test/baseline/opt-value-expr.test @@ -7,7 +7,7 @@ D 1000.00 DM Assets:Investments 2 FOO @@ 20.00 EUR Assets:Cash -20.00 EUR -2015-05-01 * Buy 2 FOO +2015-05-01 * Spend on food Expenses:Food 20.00 USD ; Just to be silly, always valuate *these* $20 as 30 DM, no matter what ; the user asks for with -V or -X -- cgit v1.2.3 From 3008a6a6bed9dcc98981d4c66e978eb6eacf1e02 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Fri, 31 Jul 2015 00:25:53 +0200 Subject: [tests] Fix typo in --cleared option baseline test --- test/baseline/opt-cleared-format.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/baseline/opt-cleared-format.test b/test/baseline/opt-cleared-format.test index 9100a636..4d3ea267 100644 --- a/test/baseline/opt-cleared-format.test +++ b/test/baseline/opt-cleared-format.test @@ -1,4 +1,4 @@ -test tags --file test/input/drewr3.dat --cleared-format '%-30(account) %15(get_at(total_expr, 0)) %15(get_at(total_expr, 1))\n%/' +test cleared --file test/input/drewr3.dat --cleared-format "%-30(account) %15(get_at(total_expr, 0)) %15(get_at(total_expr, 1))\n%/" Assets $ -3,804.00 $ 775.00 Assets:Checking $ 1,396.00 $ 775.00 Assets:Checking:Business $ 30.00 0 -- cgit v1.2.3 From 81ee98c17c96aed21d437457e4917fe6a3a8c47b Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Wed, 29 Jul 2015 00:21:08 +0200 Subject: [travis] Add multi-os build configuration and use a custom build of boost. --- .travis.yml | 66 ++++++++++++++++++++++++++++++++++-------- tools/travis-before_install.sh | 16 ++++++++++ tools/travis-install.sh | 22 ++++++++++++++ 3 files changed, 92 insertions(+), 12 deletions(-) create mode 100755 tools/travis-before_install.sh create mode 100755 tools/travis-install.sh diff --git a/.travis.yml b/.travis.yml index c573057d..abfa903b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,35 +7,75 @@ language: cpp compiler: - - clang - gcc + - clang +os: + - linux + - osx sudo: false cache: apt: true +env: + global: + # Boost version to use. + - BOOST_VERSION="1.58.0" + # List of required boost libraries to build + - BOOST_LIBS="date_time,filesystem,iostreams,python,regex,system,test" + # List of required Homebrew formulae to install + - BREWS="gmp,mpfr" + +matrix: + exclude: + - os: linux + compiler: clang + # Compiling ledger on Linux with clang + # either crashes clang or results in a ledger binary that crashes with SIGSEGV. + - os: osx + compiler: gcc + # On Mac OS X building ledger with GNU GCC 4.8 fails due to + # undefined symbols, maybe because boost was not being built with g++-4.8. + # Undefined symbols for architecture x86_64: + # "boost::re_detail::perl_matcher >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)", referenced from: + # boost::re_detail::perl_matcher >, boost::regex_traits > >::perl_matcher(char const*, char const*, boost::match_results > >&, boost::basic_regex > > const&, boost::regex_constants::_match_flags, char const*) in main.cc.o + # boost::re_detail::perl_matcher >, boost::regex_traits > >::perl_matcher(char const*, char const*, boost::match_results > >&, boost::basic_regex > > const&, boost::regex_constants::_match_flags, char const*) in global.cc.o + # "boost::re_detail::perl_matcher >, boost::regex_traits > >::find()", referenced from: + # bool boost::regex_search > >(char const*, char const*, boost::basic_regex > > const&, boost::regex_constants::_match_flags) in main.cc.o + # bool boost::regex_search > >(char const*, char const*, boost::basic_regex > > const&, boost::regex_constants::_match_flags) in global.cc.o + addons: apt: sources: - ubuntu-toolchain-r-test - - boost-latest + #- boost-latest packages: - gcc-4.8 - g++-4.8 - libgmp-dev - libmpfr-dev - libedit-dev - - libboost1.55-dev - - libboost-test1.55-dev - - libboost-regex1.55-dev - - libboost-python1.55-dev - - libboost-system1.55-dev - - libboost-date-time1.55-dev - - libboost-iostreams1.55-dev - - libboost-filesystem1.55-dev - - libboost-serialization1.55-dev + #- libboost1.55-dev + #- libboost-test1.55-dev + #- libboost-regex1.55-dev + #- libboost-python1.55-dev + #- libboost-system1.55-dev + #- libboost-date-time1.55-dev + #- libboost-iostreams1.55-dev + #- libboost-filesystem1.55-dev + #- libboost-serialization1.55-dev + +before_install: + - if [ -n "${BOOST_VERSION}" ]; then export BOOST_ROOT="${TRAVIS_BUILD_DIR}/../boost-trunk"; export CMAKE_MODULE_PATH="${BOOST_ROOT}"; fi + - if [ "${CXX}" = "g++" ]; then export CXX="$(which g++-4.8)"; export CC="$(which gcc-4.8)"; fi + - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then export DYLD_LIBRARY_PATH="${BOOST_ROOT}/lib"; fi + # c++ is a symlink to clang++, but the compiler behaves differently when invoked as c++ + - if [ "${TRAVIS_OS_NAME}" = "osx" -a "${CXX}" = "clang++" ]; then export CXX="$(which c++)"; export CC="$(which cc)"; fi + - tools/travis-before_install.sh + +install: + - tools/travis-install.sh before_script: - - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi - cmake . -DUSE_PYTHON=ON -DBUILD_DEBUG=ON - make @@ -44,6 +84,8 @@ script: - PYTHONPATH=. python python/demo.py after_script: + # These scripts are run for informational purposes and + # should be reintegrated into CTest once they reliably verify the documentation. - python test/CheckTexinfo.py -l ledger -s . - python test/CheckManpage.py -l ledger -s . diff --git a/tools/travis-before_install.sh b/tools/travis-before_install.sh new file mode 100755 index 00000000..fe010945 --- /dev/null +++ b/tools/travis-before_install.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +#set -x +set -e +set -o pipefail + +if [ "${TRAVIS_OS_NAME}" = "osx" ]; then + brew update +fi + +if [ -n "${BOOST_VERSION}" ]; then + mkdir -p $BOOST_ROOT + wget --no-verbose --output-document=- \ + http://sourceforge.net/projects/boost/files/boost/${BOOST_VERSION}/boost_${BOOST_VERSION//./_}.tar.bz2/download \ + | tar jxf - --strip-components=1 -C "${BOOST_ROOT}" +fi diff --git a/tools/travis-install.sh b/tools/travis-install.sh new file mode 100755 index 00000000..4e8bdc48 --- /dev/null +++ b/tools/travis-install.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +#set -x +set -e +set -o pipefail + +if [ "${TRAVIS_OS_NAME}" = "osx" ]; then + for formula in $(echo "${BREWS//,/ }"); do + echo "Checking ${formula} formula" + brew outdated "${formula}" \ + || (brew unlink "${formula}" + brew install "${formula}" + ) + done +fi + +if [ -d "${BOOST_ROOT}" ]; then + (cd "${BOOST_ROOT}" + ./bootstrap.sh --with-libraries="${BOOST_LIBS}" + ./b2 threading=multi --prefix="${BOOST_ROOT}" -d0 install + ) +fi -- cgit v1.2.3 From 0364e598e3eb76b0226f9dfb9a247f1f96d5c781 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Fri, 31 Jul 2015 10:51:20 +0200 Subject: [doc] Update status badges in README [ci skip] --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e6296517..759fa26a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ -[![Build Status](https://img.shields.io/travis/ledger/ledger/master.svg?&style=flat)](https://travis-ci.org/ledger/ledger) +[![Build Status master](https://img.shields.io/travis/ledger/ledger/master.svg?label=master&style=flat)](https://travis-ci.org/ledger/ledger) +[![Build Status next](https://img.shields.io/travis/ledger/ledger/next.svg?label=next&style=flat)](https://travis-ci.org/ledger/ledger) [![Status](https://img.shields.io/badge/status-active-brightgreen.svg?style=flat)](https://github.com/ledger/ledger/pulse/monthly) [![License](https://img.shields.io/badge/license-BSD-blue.svg?style=flat)](http://opensource.org/licenses/BSD-3-Clause) -[![GitHub tag](https://img.shields.io/github/tag/ledger/ledger.svg?style=flat)](https://github.com/ledger/ledger/releases) +[![GitHub release](https://img.shields.io/github/release/ledger/ledger.svg?style=flat)](https://github.com/ledger/ledger/releases) # Ledger: Command-Line Accounting -- cgit v1.2.3 From 1ef946a9b9b45698fd0fc603c196c58072fb735c Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Fri, 31 Jul 2015 10:29:51 +0200 Subject: [travis] Fix Travis CI builds Add multi-os build configuration and use a custom build of boost. --- .travis.yml | 92 +++++++++++++++++++++++++++++++++++------- tools/travis-before_install.sh | 17 ++++++++ tools/travis-install.sh | 23 +++++++++++ 3 files changed, 117 insertions(+), 15 deletions(-) create mode 100755 tools/travis-before_install.sh create mode 100755 tools/travis-install.sh diff --git a/.travis.yml b/.travis.yml index 59501f68..5f026e6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,30 +7,92 @@ language: cpp compiler: - - clang - gcc + - clang +os: + - linux + - osx +sudo: false +cache: + apt: true + +env: + global: + # Boost version to use: + # _MIN is used when building the master branch + # _MAX is used when building any other branch + - BOOST_VERSION_MIN="1.49.0" + - BOOST_VERSION_MAX="1.58.0" + # List of required boost libraries to build + - BOOST_LIBS="date_time,filesystem,iostreams,python,regex,system,test" + # List of required Homebrew formulae to install + - BREWS="gmp,mpfr" + +matrix: + exclude: + - os: linux + compiler: clang + # Compiling ledger on Linux with clang + # either crashes clang or results in a ledger binary that crashes with SIGSEGV. + - os: osx + compiler: gcc + # On Mac OS X building ledger with GNU GCC 4.8 fails due to + # undefined symbols, maybe because boost was not being built with g++-4.8. + # Undefined symbols for architecture x86_64: + # "boost::re_detail::perl_matcher >, boost::regex_traits > >::construct_init(boost::basic_regex > > const&, boost::regex_constants::_match_flags)", referenced from: + # boost::re_detail::perl_matcher >, boost::regex_traits > >::perl_matcher(char const*, char const*, boost::match_results > >&, boost::basic_regex > > const&, boost::regex_constants::_match_flags, char const*) in main.cc.o + # boost::re_detail::perl_matcher >, boost::regex_traits > >::perl_matcher(char const*, char const*, boost::match_results > >&, boost::basic_regex > > const&, boost::regex_constants::_match_flags, char const*) in global.cc.o + # "boost::re_detail::perl_matcher >, boost::regex_traits > >::find()", referenced from: + # bool boost::regex_search > >(char const*, char const*, boost::basic_regex > > const&, boost::regex_constants::_match_flags) in main.cc.o + # bool boost::regex_search > >(char const*, char const*, boost::basic_regex > > const&, boost::regex_constants::_match_flags) in global.cc.o + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + #- boost-latest + packages: + - gcc-4.8 + - g++-4.8 + - libgmp-dev + - libmpfr-dev + - libedit-dev + #- libboost1.55-dev + #- libboost-test1.55-dev + #- libboost-regex1.55-dev + #- libboost-python1.55-dev + #- libboost-system1.55-dev + #- libboost-date-time1.55-dev + #- libboost-iostreams1.55-dev + #- libboost-filesystem1.55-dev + #- libboost-serialization1.55-dev before_install: - # Add software package repositories with recent versions of gcc and boost - - sudo add-apt-repository ppa:ubuntu-toolchain-r/test --yes - - sudo add-apt-repository ppa:boost-latest/ppa --yes - - sudo apt-get update -qq - -install: - # Install GNU GCC 4.8 required by use of C++11 - - sudo apt-get install -qq g++-4.8 gcc-4.8 - - export CXX="g++-4.8" CC="gcc-4.8" - # Install Ledger dependencies - - sudo apt-get install -qq libboost1.55 libgmp-dev libmpfr-dev libeditline-dev + - if [ "${TRAVIS_BRANCH}" = "master" ]; then export BOOST_VERSION="${BOOST_VERSION_MIN}"; else export BOOST_VERSION="${BOOST_VERSION_MAX}"; fi + - if [ -n "${BOOST_VERSION}" ]; then export BOOST_ROOT="${TRAVIS_BUILD_DIR}/../boost-trunk"; export CMAKE_MODULE_PATH="${BOOST_ROOT}"; fi + - if [ "${CXX}" = "g++" ]; then export CXX="$(which g++-4.8)"; export CC="$(which gcc-4.8)"; fi + - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then export DYLD_LIBRARY_PATH="${BOOST_ROOT}/lib"; fi + # c++ is a symlink to clang++, but the compiler behaves differently when invoked as c++ + - if [ "${TRAVIS_OS_NAME}" = "osx" -a "${CXX}" = "clang++" ]; then export CXX="$(which c++)"; export CC="$(which cc)"; fi + - tools/travis-before_install.sh + +install: + - tools/travis-install.sh before_script: - - export JOBS=2 - - ./acprep opt make --jobs $JOBS --python + - cmake . -DUSE_PYTHON=ON -DBUILD_DEBUG=ON + - make script: - - ./acprep check --jobs $JOBS -- --output-on-failure + - make test - PYTHONPATH=. python python/demo.py +after_script: + # These scripts are run for informational purposes and + # should be reintegrated into CTest once they reliably verify the documentation. + - python test/CheckTexinfo.py -l ledger -s . + - python test/CheckManpage.py -l ledger -s . + notifications: email: on_success: change diff --git a/tools/travis-before_install.sh b/tools/travis-before_install.sh new file mode 100755 index 00000000..a1800021 --- /dev/null +++ b/tools/travis-before_install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +#set -x +set -e +set -o pipefail + +if [ "${TRAVIS_OS_NAME}" = "osx" ]; then + brew update +fi + +if [ -n "${BOOST_VERSION}" ]; then + echo "Downloading boost ${BOOST_VERSION}" + mkdir -p $BOOST_ROOT + wget --no-verbose --output-document=- \ + http://sourceforge.net/projects/boost/files/boost/${BOOST_VERSION}/boost_${BOOST_VERSION//./_}.tar.bz2/download \ + | tar jxf - --strip-components=1 -C "${BOOST_ROOT}" +fi diff --git a/tools/travis-install.sh b/tools/travis-install.sh new file mode 100755 index 00000000..b5039d5c --- /dev/null +++ b/tools/travis-install.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +#set -x +set -e +set -o pipefail + +if [ "${TRAVIS_OS_NAME}" = "osx" ]; then + for formula in $(echo "${BREWS//,/ }"); do + echo "Checking ${formula} formula" + brew outdated "${formula}" \ + || (brew unlink "${formula}" + brew install "${formula}" + ) + done +fi + +if [ -d "${BOOST_ROOT}" ]; then + echo "Installing boost ${BOOST_VERSION} in ${BOOST_ROOT}" + (cd "${BOOST_ROOT}" + ./bootstrap.sh --with-libraries="${BOOST_LIBS}" + ./b2 threading=multi --prefix="${BOOST_ROOT}" -d0 install + ) +fi -- cgit v1.2.3 From 523413d8f14d3896ed3ffc2cd4e3fcd585044fef Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Fri, 31 Jul 2015 13:00:10 +0200 Subject: [travis] Use boost 1.49.0 for master branch builds and boost 1.58.0 for all other branches. --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index abfa903b..06ead752 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,11 @@ cache: env: global: - # Boost version to use. - - BOOST_VERSION="1.58.0" + # Boost version to use: + # _MIN is used when building the master branch + # _MAX is used when building any other branch + - BOOST_VERSION_MIN="1.49.0" + - BOOST_VERSION_MAX="1.58.0" # List of required boost libraries to build - BOOST_LIBS="date_time,filesystem,iostreams,python,regex,system,test" # List of required Homebrew formulae to install @@ -65,6 +68,7 @@ addons: #- libboost-serialization1.55-dev before_install: + - if [ "${TRAVIS_BRANCH}" = "master" ]; then export BOOST_VERSION="${BOOST_VERSION_MIN}"; else export BOOST_VERSION="${BOOST_VERSION_MAX}"; fi - if [ -n "${BOOST_VERSION}" ]; then export BOOST_ROOT="${TRAVIS_BUILD_DIR}/../boost-trunk"; export CMAKE_MODULE_PATH="${BOOST_ROOT}"; fi - if [ "${CXX}" = "g++" ]; then export CXX="$(which g++-4.8)"; export CC="$(which gcc-4.8)"; fi - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then export DYLD_LIBRARY_PATH="${BOOST_ROOT}/lib"; fi -- cgit v1.2.3 From 5bb4f2f593f34e6ce7f98bb59d5c0d30c5e377fb Mon Sep 17 00:00:00 2001 From: thdox Date: Fri, 27 Jun 2014 21:17:57 +0200 Subject: untabify --- src/emacs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/emacs.h b/src/emacs.h index fef7a882..b89ce9f4 100644 --- a/src/emacs.h +++ b/src/emacs.h @@ -72,7 +72,7 @@ public: out.flush(); } virtual void operator()(post_t& post); - virtual string escape_string(string raw); + virtual string escape_string(string raw); }; } // namespace ledger -- cgit v1.2.3 From f0a329db26d4fb1aa34289712278206dadc2d8d2 Mon Sep 17 00:00:00 2001 From: thdox Date: Fri, 27 Jun 2014 21:44:36 +0200 Subject: regression test file for bug 1057 --- test/regress/1057.test | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 test/regress/1057.test diff --git a/test/regress/1057.test b/test/regress/1057.test new file mode 100644 index 00000000..13af78e5 --- /dev/null +++ b/test/regress/1057.test @@ -0,0 +1,11 @@ +2014/04/03 www.amazon.fr + Dépense:Loisir:Ordi:Matériel 101,50 € ; disque dur portable 2,5" 2000 Go + Dépense:Maison:Service:Poste + * Passif:Crédit:BanqueAccord -171,63 € + +test -f test/regress/1057.test emacs +(("$sourcepath/test/regress/1057.test" 1 (21308 34912 0) nil "www.amazon.fr" + (2 "Dépense:Loisir:Ordi:Matériel" "101,50 €" nil " disque dur portable 2,5\" 2000 Go") + (3 "Dépense:Maison:Service:Poste" "70,13 €" nil) + (4 "Passif:Crédit:BanqueAccord" "-171,63 €" t))) +end test -- cgit v1.2.3 From 48bd8e94ded49354c7e028709236c45a5895bcbb Mon Sep 17 00:00:00 2001 From: thdox Date: Sat, 28 Jun 2014 09:30:44 +0200 Subject: Modification to help fix issue when compiling with travis -(("/home/travis/build/ledger/ledger/test/regress/1057.test" 1 (21308 34912 0) nil "www.amazon.fr" +(("/home/travis/build/ledger/ledger/test/regress/1057.test" 1 (21308 42112 0) nil "www.amazon.fr" --- test/regress/1057.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/regress/1057.test b/test/regress/1057.test index 13af78e5..94d82767 100644 --- a/test/regress/1057.test +++ b/test/regress/1057.test @@ -3,7 +3,7 @@ Dépense:Maison:Service:Poste * Passif:Crédit:BanqueAccord -171,63 € -test -f test/regress/1057.test emacs +test -f test/regress/1057.test --now=2014/06/27 emacs (("$sourcepath/test/regress/1057.test" 1 (21308 34912 0) nil "www.amazon.fr" (2 "Dépense:Loisir:Ordi:Matériel" "101,50 €" nil " disque dur portable 2,5\" 2000 Go") (3 "Dépense:Maison:Service:Poste" "70,13 €" nil) -- cgit v1.2.3 From 4cad4b327d462b0115bea44a219a5a32f4b19bfc Mon Sep 17 00:00:00 2001 From: thdox Date: Wed, 25 Feb 2015 19:03:29 +0100 Subject: Revert "Disable three tests preventing Jenkins from succeeding" This reverts commit 8d1067c89c1c283accfeebb1ff35276b8eb35749. --- test/baseline/cmd-convert.test | 35 +++++++++++++++++++++++++++ test/baseline/cmd-convert.test.disable | 35 --------------------------- test/baseline/opt-file.test | 12 ++++++++++ test/baseline/opt-file.test.disable | 12 ---------- test/regress/25A099C9.test | 43 ++++++++++++++++++++++++++++++++++ test/regress/25A099C9.test.disable | 43 ---------------------------------- 6 files changed, 90 insertions(+), 90 deletions(-) create mode 100644 test/baseline/cmd-convert.test delete mode 100644 test/baseline/cmd-convert.test.disable create mode 100644 test/baseline/opt-file.test delete mode 100644 test/baseline/opt-file.test.disable create mode 100644 test/regress/25A099C9.test delete mode 100644 test/regress/25A099C9.test.disable diff --git a/test/baseline/cmd-convert.test b/test/baseline/cmd-convert.test new file mode 100644 index 00000000..d444da52 --- /dev/null +++ b/test/baseline/cmd-convert.test @@ -0,0 +1,35 @@ + +test -f /dev/null --input-date-format "%m/%d/%Y" convert test/baseline/cmd-convert1.dat +2011/12/12=2011/12/13 * (100) Test ;test + Expenses:Unknown $10 + Equity:Unknown $-10 = $20 + +2011/12/12=2011/12/12 * + Expenses:Unknown $10 + Equity:Unknown +end test + +test -f /dev/null --input-date-format "%m/%d/%Y" convert test/baseline/cmd-convert2.dat +2011/01/01 * test + Expenses:Unknown 20.00 EUR + Equity:Unknown +end test + +test -f /dev/null --input-date-format "%m/%d/%Y" convert test/baseline/cmd-convert3.dat -> 1 +__ERROR__ +While parsing file "$sourcepath/test/baseline/cmd-convert3.dat", line 1: +While parsing CSV line: + 01/01/2011,, + +Error: No quantity specified for amount +end test + +test -f /dev/null convert test/baseline/cmd-convert4.dat -> 1 +__ERROR__ +While parsing file "$sourcepath/test/baseline/cmd-convert4.dat", line 1: +While parsing CSV line: + bogus,$10, + +Error: Invalid date: bogus +end test + diff --git a/test/baseline/cmd-convert.test.disable b/test/baseline/cmd-convert.test.disable deleted file mode 100644 index d444da52..00000000 --- a/test/baseline/cmd-convert.test.disable +++ /dev/null @@ -1,35 +0,0 @@ - -test -f /dev/null --input-date-format "%m/%d/%Y" convert test/baseline/cmd-convert1.dat -2011/12/12=2011/12/13 * (100) Test ;test - Expenses:Unknown $10 - Equity:Unknown $-10 = $20 - -2011/12/12=2011/12/12 * - Expenses:Unknown $10 - Equity:Unknown -end test - -test -f /dev/null --input-date-format "%m/%d/%Y" convert test/baseline/cmd-convert2.dat -2011/01/01 * test - Expenses:Unknown 20.00 EUR - Equity:Unknown -end test - -test -f /dev/null --input-date-format "%m/%d/%Y" convert test/baseline/cmd-convert3.dat -> 1 -__ERROR__ -While parsing file "$sourcepath/test/baseline/cmd-convert3.dat", line 1: -While parsing CSV line: - 01/01/2011,, - -Error: No quantity specified for amount -end test - -test -f /dev/null convert test/baseline/cmd-convert4.dat -> 1 -__ERROR__ -While parsing file "$sourcepath/test/baseline/cmd-convert4.dat", line 1: -While parsing CSV line: - bogus,$10, - -Error: Invalid date: bogus -end test - diff --git a/test/baseline/opt-file.test b/test/baseline/opt-file.test new file mode 100644 index 00000000..66d0ab1b --- /dev/null +++ b/test/baseline/opt-file.test @@ -0,0 +1,12 @@ +test -f opt-file-does-not-exist.dat bal -> 1 +__ERROR__ +Error: Cannot read journal file "$sourcepath/opt-file-does-not-exist.dat" +end test + +test -f test/baseline/opt-file1.dat -f test/baseline/opt-file2.dat bal + 10 A + -10 C +-------------------- + 0 +end test + diff --git a/test/baseline/opt-file.test.disable b/test/baseline/opt-file.test.disable deleted file mode 100644 index 66d0ab1b..00000000 --- a/test/baseline/opt-file.test.disable +++ /dev/null @@ -1,12 +0,0 @@ -test -f opt-file-does-not-exist.dat bal -> 1 -__ERROR__ -Error: Cannot read journal file "$sourcepath/opt-file-does-not-exist.dat" -end test - -test -f test/baseline/opt-file1.dat -f test/baseline/opt-file2.dat bal - 10 A - -10 C --------------------- - 0 -end test - diff --git a/test/regress/25A099C9.test b/test/regress/25A099C9.test new file mode 100644 index 00000000..e511c799 --- /dev/null +++ b/test/regress/25A099C9.test @@ -0,0 +1,43 @@ +test -f test/garbage-input.dat reg -> 20 +__ERROR__ +While parsing file "$sourcepath/test/garbage-input.dat", line 2: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 33: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 37: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 66: +Error: No quantity specified for amount +While parsing file "$sourcepath/test/garbage-input.dat", line 69: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 83: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 93: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 99: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 121: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 132: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 711: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 741: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 749: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 752: +Error: Invalid date/time: line amount_t amoun +While parsing file "$sourcepath/test/garbage-input.dat", line 758: +Error: Invalid date/time: line string amount_ +While parsing file "$sourcepath/test/garbage-input.dat", line 764: +Error: Invalid date/time: line string amount_ +While parsing file "$sourcepath/test/garbage-input.dat", line 770: +Error: Invalid date/time: line string amount_ +While parsing file "$sourcepath/test/garbage-input.dat", line 776: +Error: Invalid date/time: line std::ostream& +While parsing file "$sourcepath/test/garbage-input.dat", line 783: +Error: Invalid date/time: line std::istream& +While parsing file "$sourcepath/test/garbage-input.dat", line 789: +Error: Unexpected whitespace at beginning of line +end test diff --git a/test/regress/25A099C9.test.disable b/test/regress/25A099C9.test.disable deleted file mode 100644 index e511c799..00000000 --- a/test/regress/25A099C9.test.disable +++ /dev/null @@ -1,43 +0,0 @@ -test -f test/garbage-input.dat reg -> 20 -__ERROR__ -While parsing file "$sourcepath/test/garbage-input.dat", line 2: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 33: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 37: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 66: -Error: No quantity specified for amount -While parsing file "$sourcepath/test/garbage-input.dat", line 69: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 83: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 93: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 99: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 121: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 132: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 711: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 741: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 749: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 752: -Error: Invalid date/time: line amount_t amoun -While parsing file "$sourcepath/test/garbage-input.dat", line 758: -Error: Invalid date/time: line string amount_ -While parsing file "$sourcepath/test/garbage-input.dat", line 764: -Error: Invalid date/time: line string amount_ -While parsing file "$sourcepath/test/garbage-input.dat", line 770: -Error: Invalid date/time: line string amount_ -While parsing file "$sourcepath/test/garbage-input.dat", line 776: -Error: Invalid date/time: line std::ostream& -While parsing file "$sourcepath/test/garbage-input.dat", line 783: -Error: Invalid date/time: line std::istream& -While parsing file "$sourcepath/test/garbage-input.dat", line 789: -Error: Unexpected whitespace at beginning of line -end test -- cgit v1.2.3 From 89119c68cac4c7d3bc91a083283e5d1e6580264a Mon Sep 17 00:00:00 2001 From: thdox Date: Wed, 25 Feb 2015 19:13:59 +0100 Subject: Whitespace fix for cmd-convert.test --- test/baseline/cmd-convert.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/baseline/cmd-convert.test b/test/baseline/cmd-convert.test index d444da52..8ee5bb2e 100644 --- a/test/baseline/cmd-convert.test +++ b/test/baseline/cmd-convert.test @@ -17,7 +17,7 @@ end test test -f /dev/null --input-date-format "%m/%d/%Y" convert test/baseline/cmd-convert3.dat -> 1 __ERROR__ -While parsing file "$sourcepath/test/baseline/cmd-convert3.dat", line 1: +While parsing file "$sourcepath/test/baseline/cmd-convert3.dat", line 1: While parsing CSV line: 01/01/2011,, @@ -26,7 +26,7 @@ end test test -f /dev/null convert test/baseline/cmd-convert4.dat -> 1 __ERROR__ -While parsing file "$sourcepath/test/baseline/cmd-convert4.dat", line 1: +While parsing file "$sourcepath/test/baseline/cmd-convert4.dat", line 1: While parsing CSV line: bogus,$10, -- cgit v1.2.3 From 4451452db37ca76b950c124428f022e4f908148f Mon Sep 17 00:00:00 2001 From: thdox Date: Wed, 25 Feb 2015 19:25:37 +0100 Subject: Fix test file regress/25A099C9.test. --- test/regress/25A099C9.test | 84 ++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/test/regress/25A099C9.test b/test/regress/25A099C9.test index e511c799..cfc0eabd 100644 --- a/test/regress/25A099C9.test +++ b/test/regress/25A099C9.test @@ -1,43 +1,61 @@ -test -f test/garbage-input.dat reg -> 20 +test -f test/garbage-input.dat reg -> 29 __ERROR__ -While parsing file "$sourcepath/test/garbage-input.dat", line 2: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 33: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 37: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 66: +While parsing file "$sourcepath/test/garbage-input.dat", line 1: +Error: Directive '/*' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 32: +Error: Directive '/**' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 36: +Error: Directive '/**' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 66: Error: No quantity specified for amount -While parsing file "$sourcepath/test/garbage-input.dat", line 69: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 83: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 93: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 99: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 121: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 132: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 711: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 741: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 749: -Error: Unexpected whitespace at beginning of line -While parsing file "$sourcepath/test/garbage-input.dat", line 752: +While parsing file "$sourcepath/test/garbage-input.dat", line 69: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 78: +Error: Directive '};' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 82: +Error: Directive '/**' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 93: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 97: +Error: Directive '{' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 98: +Error: Directive 'public:' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 120: +Error: Directive 'protected:' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 131: +Error: Directive 'public:' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 711: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 740: +Error: Directive 'private:' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 749: +Error: Unexpected whitespace at beginning of line +While parsing file "$sourcepath/test/garbage-input.dat", line 750: +Error: Directive '};' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 752: Error: Invalid date/time: line amount_t amoun -While parsing file "$sourcepath/test/garbage-input.dat", line 758: +While parsing file "$sourcepath/test/garbage-input.dat", line 756: +Error: Directive '}' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 758: Error: Invalid date/time: line string amount_ -While parsing file "$sourcepath/test/garbage-input.dat", line 764: +While parsing file "$sourcepath/test/garbage-input.dat", line 762: +Error: Directive '}' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 764: Error: Invalid date/time: line string amount_ -While parsing file "$sourcepath/test/garbage-input.dat", line 770: +While parsing file "$sourcepath/test/garbage-input.dat", line 768: +Error: Directive '}' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 770: Error: Invalid date/time: line string amount_ -While parsing file "$sourcepath/test/garbage-input.dat", line 776: +While parsing file "$sourcepath/test/garbage-input.dat", line 774: +Error: Directive '}' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 776: Error: Invalid date/time: line std::ostream& -While parsing file "$sourcepath/test/garbage-input.dat", line 783: +While parsing file "$sourcepath/test/garbage-input.dat", line 782: +Error: Directive '}' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 783: Error: Invalid date/time: line std::istream& -While parsing file "$sourcepath/test/garbage-input.dat", line 789: +While parsing file "$sourcepath/test/garbage-input.dat", line 786: +Error: Directive '}' requires an argument +While parsing file "$sourcepath/test/garbage-input.dat", line 789: Error: Unexpected whitespace at beginning of line end test -- cgit v1.2.3 From fb5a1bed5cd0584eba23aeb7eeea1d5a60b37e45 Mon Sep 17 00:00:00 2001 From: thdox Date: Wed, 25 Feb 2015 19:27:39 +0100 Subject: Add --file to tested options. --- test/CheckBaselineTests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/CheckBaselineTests.py b/test/CheckBaselineTests.py index f0eb2646..570b93be 100755 --- a/test/CheckBaselineTests.py +++ b/test/CheckBaselineTests.py @@ -23,7 +23,6 @@ class CheckBaselineTests (CheckOptions): 'args-only', 'debug', 'download', - 'file', 'force-color', 'force-pager', 'generated', -- cgit v1.2.3 From 0273fbedc6df42f5339622c94c41c67f14f0da80 Mon Sep 17 00:00:00 2001 From: thdox Date: Sat, 18 Apr 2015 22:19:39 +0200 Subject: Add command directives to concepts and commands indexes. --- doc/ledger3.texi | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/doc/ledger3.texi b/doc/ledger3.texi index 1226a66f..72c1165d 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -2105,6 +2105,7 @@ the syntax @code{[ACTUAL_DATE]} or @code{[=EFFECTIVE_DATE]} or @item P @findex --download @findex P +@cindex historical prices Specifies a historical price for a commodity. These are usually found in a pricing history file (see the @option{--download (-Q)} option). The syntax is: @@ -2114,6 +2115,9 @@ P DATE SYMBOL PRICE @end smallexample @item = +@findex = +@cindex automated transaction +@cindex transaction, automated An automated transaction. A value expression must appear after the equal sign. @@ -2124,17 +2128,23 @@ posting is matched by the value expression (@pxref{Automated Transactions}). @item ~ +@findex ~ +@cindex periodic transaction +@cindex transaction, periodic A periodic transaction. A period expression must appear after the tilde. After this initial line there should be a set of one or more postings, just as if it were a normal transaction. @item ; # % | * +@findex comment +@cindex comments A line beginning with a semicolon, pound, percent, bar or asterisk indicates a comment, and is ignored. Comments will not be returned in a ``print'' response. @item indented ; +@cindex tags If the semicolon is indented and occurs inside a transaction, it is parsed as a persistent note for its preceding category. These notes or tags can be used to augment the reporting and filtering capabilities of @@ -2154,6 +2164,8 @@ Command directives must occur at the beginning of a line. Use of @samp{!} and @samp{@@} is deprecated. @item account +@findex account +@cindex pre-declare account Pre-declare valid account names. This only has an effect if @option{--strict} or @option{--pedantic} is used (see below). The @code{account} directive supports several optional sub-directives, if @@ -2203,6 +2215,7 @@ used as the ``balancing account'' for any future transactions that contain only a single posting. @item apply account +@findex apply account @c instance_t::master_account_directive Sets the root for all accounts following this directive. Ledger supports a hierarchical tree of accounts. It may be convenient to @@ -2225,6 +2238,8 @@ Would result in all postings going into until an @samp{end apply account} directive was found. @item alias +@findex alias +@cindex account, alias @c instance_t::alias_directive Define an alias for an account name. If you have a deeply nested tree of accounts, it may be convenient to define an alias, for example: @@ -2276,6 +2291,8 @@ The option @option{--no-aliases} completely disables alias expansion. All accounts are read verbatim as they are in the ledger file. @item assert +@findex assert +@cindex assertions @c instance_t::assert_directive An assertion can throw an error if a condition is not met during Ledger's run. @@ -2286,6 +2303,8 @@ assert @item bucket @anchor{bucket} +@findex bucket +@cindex bucket @c instance_t::default_account_directive Defines the default account to use for balancing transactions. Normally, each transaction has at least two postings, which must @@ -2311,6 +2330,7 @@ bucket Assets:Checking @item capture @c instance_t::account_mapping_directive +@findex capture @findex print @findex register @@ -2328,6 +2348,8 @@ Ledger will display the mapped payees in @command{print} and @command{register} reports. @item check +@findex check +@cindex assertions @c instance_t::check_directive in textual.cc A check issues a warning if a condition is not met during Ledger's run. @@ -2337,10 +2359,14 @@ check @end smallexample @item comment +@findex comment +@cindex comments @c instance_t::comment_directive in textual.cc Start a block comment, closed by @code{end comment}. @item commodity +@findex commodity +@cindex pre-declare commodity Pre-declare commodity names. This only has an effect if @option{--strict} or @option{--pedantic} is used (see below). @@ -2375,6 +2401,7 @@ should never be auto-downloaded. The @code{default} sub-directive marks this as the ``default'' commodity. @item define +@findex define @c instance_t::define_directive in textual.cc Allows you to define value expressions for future use. For example: @@ -2389,13 +2416,17 @@ define var_name=$100 The posting will have a cost of $400. @item end +@findex end @c instance_t::end_directive in textual.cc Closes block commands like @code{tag} or @code{comment}. @item expr +@findex expr @c instance_t::expr_directive in textual.cc @item fixed +@findex fixed +@cindex fixated prices @c instance_t::fixed_directive in textual.cc A fixed block is used to set fixated prices (@pxref{Fixated prices and @@ -2437,10 +2468,12 @@ For the moment, users may wish to study before using the @code{fixed} directive in production. @item include +@findex include @c instance_t::include_directive in textual.cc Include the stated file as if it were part of the current file. @item payee +@findex payee @c instance_t::payee_alias_mapping_directive in textual.cc @c instance_t::payee_uuid_mapping_directive in textual.cc @findex print @@ -2475,6 +2508,7 @@ Ledger will display the mapped payees in @command{print} and @command{register} reports. @item apply tag +@findex apply tag @c instance_t::tag_directive in textual.cc Allows you to designate a block of transactions and assign the same tag to all. Tags can have values and may be nested. @@ -2532,6 +2566,8 @@ is the equivalent of: @c track. @item tag +@findex tag +@cindex pre-declare tag Pre-declares tag names. This only has an effect if @option{--strict} or @option{--pedantic} is used (see below). @@ -2558,11 +2594,14 @@ but a string if typed metadata is used!). Such checks or assertions are not called if no value is given. @item test +@findex test +@cindex comments @c instance_t::comment_directive in textual.cc This is a synonym for @code{comment} and must be closed by an @code{end} tag. @item year +@findex year @anchor{year} @c instance_t::year_directive in textual.cc Denotes the year used for all subsequent transactions that give a date @@ -2580,10 +2619,12 @@ alone, for backwards compatibility with older Ledger versions. @item A @findex A +@findex bucket @xref{bucket}. @item Y @findex Y +@findex year @xref{year}. @item N SYMBOL @@ -2601,7 +2642,6 @@ N SYMBOL @item D AMOUNT @findex xact @findex D - Specifies the default commodity to use, by specifying an amount in the expected format. The @command{xact} command will use this commodity as the default when none other can be determined. This command may be used -- cgit v1.2.3 From 54de245a50fcd9a3fc90cf4bc0e6e6de7c370956 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Mon, 3 Aug 2015 13:09:28 +0200 Subject: [doc] Minor spelling correction [ci skip] --- doc/ledger3.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ledger3.texi b/doc/ledger3.texi index 1226a66f..eeae7ad3 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -8113,7 +8113,7 @@ Render the given @var{expression} as a string, applying the proper ANSI escape codes to display it in the given @var{color} if @var{bool} is true. It typically checks the value of the option @option{--color}. Since ANSI escape codes include non-printable character sequences, such as escape @kbd{^[} -the following example may not appear as the final result on the commandline. +the following example may not appear as the final result on the command-line. @smallexample @c command:4D836EE,with_input:3406FC1 $ ledger -f expr.dat --format "%(ansify_if(account, blue, options.color))\n" reg @end smallexample -- cgit v1.2.3 From a24910b3740b572db15fda4bd574222090e16d79 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 4 Aug 2015 14:47:44 -0700 Subject: Whitespace cleanup --- src/CMakeLists.txt | 8 ++++---- src/filters.cc | 6 +++--- src/filters.h | 2 +- src/history.cc | 2 +- src/pool.h | 4 ++-- src/pyinterp.h | 2 +- src/select.cc | 2 +- src/strptime.cc | 2 +- src/value.h | 2 +- src/views.h | 2 +- src/wcwidth.cc | 2 +- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8ed6e51a..65e58edb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -152,7 +152,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") -Wno-unused-parameter -Wno-c++98-compat -fno-limit-debug-info) - + macro(ADD_PCH_RULE _header_filename _src_list _other_srcs) set(_pch_filename "${_header_filename}.pch") @@ -188,7 +188,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} ${_args} DEPENDS ${_header_filename}) endmacro(ADD_PCH_RULE _header_filename _src_list _other_srcs) - + elseif(CMAKE_CXX_COMPILER MATCHES "g\\+\\+") set(GXX_WARNING_FLAGS -pedantic @@ -210,7 +210,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") -Wno-strict-aliasing) add_definitions(${GXX_WARNING_FLAGS}) - + macro(ADD_PCH_RULE _header_filename _src_list _other_srcs) set(_gch_filename "${_header_filename}.gch") @@ -247,7 +247,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug") COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1} ${_args} DEPENDS ${_header_filename}) endmacro(ADD_PCH_RULE _header_filename _src_list _other_srcs) - + else() macro(ADD_PCH_RULE _header_filename _src_list _other_srcs) endmacro(ADD_PCH_RULE _header_filename _src_list _other_srcs) diff --git a/src/filters.cc b/src/filters.cc index d9fb64b0..ef713f1f 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -448,7 +448,7 @@ void collapse_posts::report_subtotal() DEBUG("filters.collapse", "Pseudo-xact date = " << *xact._date); DEBUG("filters.collapse", "earliest date = " << earliest_date); DEBUG("filters.collapse", "latest date = " << latest_date); - + foreach (totals_map::value_type& pat, totals) { handle_value(/* value= */ pat.second, /* account= */ &temps.create_account(pat.first), @@ -476,10 +476,10 @@ value_t& collapse_posts::find_totals(account_t* account) if(depth==0) return totals[_("")]; - + if(account->depth==depth) return totals[account->fullname()]; - + //else recurse return find_totals(account->parent); } diff --git a/src/filters.h b/src/filters.h index 9b745235..e3dc19d8 100644 --- a/src/filters.h +++ b/src/filters.h @@ -423,7 +423,7 @@ class collapse_posts : public item_handler { typedef std::map totals_map; - + expr_t& amount_expr; predicate_t display_predicate; predicate_t only_predicate; diff --git a/src/history.cc b/src/history.cc index e3c459f3..8772d18c 100644 --- a/src/history.cc +++ b/src/history.cc @@ -475,7 +475,7 @@ commodity_history_impl_t::find_price(const commodity_t& source, #endif vertex_descriptor v = tv; - for (vertex_descriptor u = predecessorMap[v]; + for (vertex_descriptor u = predecessorMap[v]; u != v; v = u, u = predecessorMap[v]) { diff --git a/src/pool.h b/src/pool.h index 2e9d93f1..fcc54b86 100644 --- a/src/pool.h +++ b/src/pool.h @@ -78,8 +78,8 @@ public: commodity_t * default_commodity; bool keep_base; // --base - optional price_db; // --price-db= - long quote_leeway; // --leeway= + optional price_db; // --price-db= + long quote_leeway; // --leeway= bool get_quotes; // --download function diff --git a/src/pyinterp.h b/src/pyinterp.h index 32becbf6..fe86573a 100644 --- a/src/pyinterp.h +++ b/src/pyinterp.h @@ -77,7 +77,7 @@ public: if (name != "__main__") main_module->define_global(name, mod->module_object); return mod; - } + } python_interpreter_t() : session_t(), is_initialized(false) { TRACE_CTOR(python_interpreter_t, ""); diff --git a/src/select.cc b/src/select.cc index 81800f16..1141df04 100644 --- a/src/select.cc +++ b/src/select.cc @@ -396,7 +396,7 @@ value_t select_command(call_scope_t& args) #if 0 query_t query; keep_details_t keeper(true, true, true); - expr_t::ptr_op_t expr = + expr_t::ptr_op_t expr = query.parse_args(string_value(arg).to_sequence(), keeper, false, true); report.HANDLER(limit_).on("#select", query.get_query(query_t::QUERY_LIMIT)); #else diff --git a/src/strptime.cc b/src/strptime.cc index b64af96b..b31954f4 100644 --- a/src/strptime.cc +++ b/src/strptime.cc @@ -85,7 +85,7 @@ static char* _strptime(const char *s, const char *format, struct tm *tm) { if (tm->tm_wday == -1) return NULL; s += len; break; - + // month name. case 'b': case 'B': diff --git a/src/value.h b/src/value.h index 810d34f9..c9084e03 100644 --- a/src/value.h +++ b/src/value.h @@ -435,7 +435,7 @@ public: return temp; } void in_place_roundto(int places); - + value_t truncated() const { value_t temp(*this); temp.in_place_truncate(); diff --git a/src/views.h b/src/views.h index 2be3d978..603b28da 100644 --- a/src/views.h +++ b/src/views.h @@ -235,7 +235,7 @@ public: optional note() const { return ptr()->note; } - + bool has_tag(const string& tag) const { return ptr()->has_tag(tag); } diff --git a/src/wcwidth.cc b/src/wcwidth.cc index c23f83d7..75cd76be 100644 --- a/src/wcwidth.cc +++ b/src/wcwidth.cc @@ -195,7 +195,7 @@ int mk_wcwidth(boost::uint32_t ucs) /* if we arrive here, ucs is not a combining or C0/C1 control character */ - return 1 + + return 1 + (ucs >= 0x1100 && (ucs <= 0x115f || /* Hangul Jamo init. consonants */ ucs == 0x2329 || ucs == 0x232a || -- cgit v1.2.3 From 69de980aebf83e83971eb2b791e8676a0141f00a Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 4 Aug 2015 14:54:06 -0700 Subject: Revert "--depth for register" --- doc/ledger3.texi | 2 +- src/filters.cc | 33 +++++++-------------------------- src/filters.h | 13 +++++++------ 3 files changed, 15 insertions(+), 33 deletions(-) diff --git a/doc/ledger3.texi b/doc/ledger3.texi index 4dc3f48f..62869a29 100644 --- a/doc/ledger3.texi +++ b/doc/ledger3.texi @@ -7740,7 +7740,7 @@ The market value of a posting or an account, without its children. The net gain (market value minus cost basis), for a posting or an account, without its children. It is the same as @samp{v-b}. -@item depth +@item l The depth (``level'') of an account. If an account has one parent, its depth is one. diff --git a/src/filters.cc b/src/filters.cc index fd30c966..2f97a0e5 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -448,20 +448,16 @@ void collapse_posts::report_subtotal() DEBUG("filters.collapse", "Pseudo-xact date = " << *xact._date); DEBUG("filters.collapse", "earliest date = " << earliest_date); DEBUG("filters.collapse", "latest date = " << latest_date); - - foreach (totals_map::value_type& pat, totals) { - handle_value(/* value= */ pat.second, - /* account= */ &temps.create_account(pat.first), - /* xact= */ &xact, - /* temps= */ temps, - /* handler= */ handler, - /* date= */ latest_date, - /* act_date_p= */ false); - } + handle_value(/* value= */ subtotal, + /* account= */ totals_account, + /* xact= */ &xact, + /* temps= */ temps, + /* handler= */ handler, + /* date= */ latest_date, + /* act_date_p= */ false); } - totals.clear(); component_posts.clear(); last_xact = NULL; @@ -470,20 +466,6 @@ void collapse_posts::report_subtotal() count = 0; } -value_t& collapse_posts::find_totals(account_t* account) -{ - unsigned short depth=3; - - if(depth==0) - return totals[_("")]; - - if(account->depth==depth) - return totals[account->fullname()]; - - //else recurse - return find_totals(account->parent); -} - void collapse_posts::operator()(post_t& post) { // If we've reached a new xact, report on the subtotal @@ -493,7 +475,6 @@ void collapse_posts::operator()(post_t& post) report_subtotal(); post.add_to_value(subtotal, amount_expr); - post.add_to_value(find_totals(post.account), amount_expr); component_posts.push_back(&post); diff --git a/src/filters.h b/src/filters.h index 9b745235..1404b38e 100644 --- a/src/filters.h +++ b/src/filters.h @@ -421,9 +421,6 @@ public: class collapse_posts : public item_handler { - - typedef std::map totals_map; - expr_t& amount_expr; predicate_t display_predicate; predicate_t only_predicate; @@ -432,7 +429,7 @@ class collapse_posts : public item_handler xact_t * last_xact; post_t * last_post; temporaries_t temps; - totals_map totals; + account_t * totals_account; bool only_collapse_if_zero; std::list component_posts; report_t& report; @@ -451,13 +448,17 @@ public: only_predicate(_only_predicate), count(0), last_xact(NULL), last_post(NULL), only_collapse_if_zero(_only_collapse_if_zero), report(_report) { + create_accounts(); TRACE_CTOR(collapse_posts, "post_handler_ptr, ..."); } virtual ~collapse_posts() { TRACE_DTOR(collapse_posts); handler.reset(); } - value_t& find_totals(account_t* account); + + void create_accounts() { + totals_account = &temps.create_account(_("")); + } virtual void flush() { report_subtotal(); @@ -479,7 +480,7 @@ public: last_post = NULL; temps.clear(); - totals.clear(); + create_accounts(); component_posts.clear(); item_handler::clear(); -- cgit v1.2.3 From 8d351d1b4c0c0c602c1ea6d17276496391dde572 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Wed, 5 Aug 2015 00:09:01 +0200 Subject: [tests] Ignore --revalued-total in baseline tests --- test/CheckBaselineTests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/CheckBaselineTests.py b/test/CheckBaselineTests.py index 570b93be..8659d1b5 100755 --- a/test/CheckBaselineTests.py +++ b/test/CheckBaselineTests.py @@ -32,6 +32,7 @@ class CheckBaselineTests (CheckOptions): 'no-pager', 'options', 'price-exp', + 'revalued-total', 'seed', 'trace', 'verbose', -- cgit v1.2.3 From 80fa6e402aff4c123f4d54ba7e5db5682ef6ab0a Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Wed, 5 Aug 2015 00:13:32 +0200 Subject: [travis] Configure coverity scan --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index 06ead752..991cb755 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,8 @@ env: - BOOST_LIBS="date_time,filesystem,iostreams,python,regex,system,test" # List of required Homebrew formulae to install - BREWS="gmp,mpfr" + # Encrypted COVERITY_SCAN_TOKEN + - secure: "mYNxD1B8WNSvUeKzInehZ7syi2g1jH2ymeSQxoeKKD2duq3pvNWPdZdc4o9MlWQcAqcz58rhFZRIpuEWCnP0LbbJaG+MyuemMn9uAmg9Y4gFpMsBPHuTdf8pO3rDex+tkrr9puEJFgL+QV/TehxO6NDDpx7UdYvJb+4aZD/auYI=" matrix: exclude: @@ -47,6 +49,13 @@ matrix: # bool boost::regex_search > >(char const*, char const*, boost::basic_regex > > const&, boost::regex_constants::_match_flags) in global.cc.o addons: + coverity_scan: + project: + name: "ledger/ledger" + description: "Build submitted via Travis CI>" + build_command_prepend: "cmake . -DUSE_PYTHON=ON -DBUILD_DEBUG=ON -DCLANG_GCOV=ON" + build_command: "make" + branch_pattern: coverity_scan apt: sources: - ubuntu-toolchain-r-test -- cgit v1.2.3 From eff53dbf9d6ea6319a61c4c7905cdd51bbaa464a Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Wed, 5 Aug 2015 00:20:52 +0200 Subject: [travis] Rename coverity scan branch Fix typo --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 991cb755..6ae2d8d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,10 +52,10 @@ addons: coverity_scan: project: name: "ledger/ledger" - description: "Build submitted via Travis CI>" + description: "Build submitted via Travis CI" build_command_prepend: "cmake . -DUSE_PYTHON=ON -DBUILD_DEBUG=ON -DCLANG_GCOV=ON" build_command: "make" - branch_pattern: coverity_scan + branch_pattern: coverity apt: sources: - ubuntu-toolchain-r-test -- cgit v1.2.3 From b213372d9cf5fa18726d3496e53c1aa7a3c61243 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Wed, 5 Aug 2015 09:49:28 +0200 Subject: [travis] Enable verbose failures --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6ae2d8d1..98b0ab82 100644 --- a/.travis.yml +++ b/.travis.yml @@ -93,7 +93,7 @@ before_script: - make script: - - make test + - ctest --output-on-failure - PYTHONPATH=. python python/demo.py after_script: -- cgit v1.2.3