[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master b6a43b5 5/6: Test input-sequence keywords-onl
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master b6a43b5 5/6: Test input-sequence keywords-only switch [401] |
Date: |
Tue, 31 Jan 2017 21:20:57 +0000 (UTC) |
branch: master
commit b6a43b55d28497a3001ed532412d994f5191f6ee
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Test input-sequence keywords-only switch [401]
---
input_seq_test.cpp | 35 +++++++++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)
diff --git a/input_seq_test.cpp b/input_seq_test.cpp
index 866658f..417f011 100644
--- a/input_seq_test.cpp
+++ b/input_seq_test.cpp
@@ -38,9 +38,10 @@ void check
,std::vector<std::string> const& k = std::vector<std::string>()
,std::vector<std::string> const& c = std::vector<std::string>()
,std::string const& w = std::string()
+ ,bool o = false
)
{
- InputSequence const seq(e, n, 90, 95, 0, 2002, k, w);
+ InputSequence const seq(e, n, 90, 95, 0, 2002, k, w, o);
std::vector<double> const& v(seq.linear_number_representation());
bool const bv = v == std::vector<double>(d, d + n);
@@ -104,6 +105,7 @@ int test_main(int, char*[])
// e: expression
// k: extra keywords
// w: default keyword
+ // o: keywords only
// An all-blank string is treated as zero.
{
@@ -317,7 +319,8 @@ int test_main(int, char*[])
BOOST_TEST_EQUAL("0", InputSequence(v).mathematical_representation());
}
- // Test (enumerative) extra keywords.
+ // Test (enumerative) extra keywords, and keywords-only switch
+ // (with input it allows).
{
int const n = 9;
strvec const c {"a", "a", "ccc", "ccc", "b", "b", "b", "b", "b"};
@@ -325,6 +328,11 @@ int test_main(int, char*[])
std::string const e("a[0, 2); ccc [2, 4);b[4, 6);");
strvec const k{"not_used", "a", "b", "c", "cc", "ccc"};
check(__FILE__, __LINE__, d, n, e, "", k, c);
+ // Toggle keywords-only switch on: same result.
+ bool const o = true;
+ check(__FILE__, __LINE__, d, n, e, "", k, c, "", o);
+ // Toggle keywords-only switch explicitly off: same result.
+ check(__FILE__, __LINE__, d, n, e, "", k, c, "", false);
}
// Test numbers mixed with (enumerative) extra keywords.
@@ -349,6 +357,27 @@ int test_main(int, char*[])
check(__FILE__, __LINE__, d, n, e, "", k, c, w);
}
+ // Test keywords-only switch with input it forbids.
+ // SOMEDAY !! It is not ideal for construction to succeed and give
+ // a vector of zeros. Instead, the ctor should throw what is now
+ // made available (only on demand) as formatted_diagnostics().
+ {
+ int const n = 10;
+ strvec const c {"x", "x", "x", "x", "x", "x", "x", "x", "x", "x"};
+ double const d[n] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
+ char const* x =
+ "Expected keyword chosen from { a b x }."
+ " Current token 'number' at position 21.\n"
+ "Expected ';'."
+ " Current token '[' at position 23.\n"
+ ;
+ std::string const e("b [0, 2); a [3, 4); 5 [4, 6); a; 7");
+ strvec const k{"a", "b", "x"};
+ std::string w("x");
+ bool const o = true;
+ check(__FILE__, __LINE__, d, n, e, x, k, c, w, o);
+ }
+
// Duration keywords: {retirement, maturity}
{
int const n = 10;
@@ -363,8 +392,6 @@ int test_main(int, char*[])
BOOST_TEST(e_maturity == i[1].end_mode );
}
-// TODO ?? Also test keywords-only switch.
-
return 0;
}
- [lmi-commits] [lmi] master updated (d040068 -> 2286e57), Greg Chicares, 2017/01/31
- [lmi-commits] [lmi] master ca6ff86 1/6: Improve documentation, Greg Chicares, 2017/01/31
- [lmi-commits] [lmi] master 9d19cdc 3/6: Resolve a marked defect: need not check input for NaN [403], Greg Chicares, 2017/01/31
- [lmi-commits] [lmi] master 5c76c96 2/6: Initialize local POD variables at point of declaration [404], Greg Chicares, 2017/01/31
- [lmi-commits] [lmi] master b6a43b5 5/6: Test input-sequence keywords-only switch [401],
Greg Chicares <=
- [lmi-commits] [lmi] master 2286e57 6/6: Transliterate some unit-test examples for concinnity, Greg Chicares, 2017/01/31
- [lmi-commits] [lmi] master 4ecdb09 4/6: Resolve a marked defect: duration keywords already tested [402], Greg Chicares, 2017/01/31