c++ - Unit-tests for Boost.Spirit -


I'm new to Boost.Dear and Boost. I should know how you verify the correctness of your grammar. Below is a simplified version of how I do this, and I am pretty sure that this is a better way:

In case of each test there is a pair of two strings in which the text is parsed and expected The result is delimited by a semicolon.

Parsing functions performs actual parsing and gives the string that should be equivalent to the expected result.

  std :: string parse (std :: string const and line) {std :: string name; Full hours; & Lt; & Gt; Top_release = ...; // Rule 'name' and 'hours' parse_info & lt; & Gt; Info = parse (line.c_str (), top_rule); If (info.full) {std :: stringstream sstr; Sstr & lt; & Lt; Name & lt; & Lt; "," & Lt; & Lt; Hours; Return sstr.str (); } Return "Parser failed."; } BOOST_AUTO_TEST_SUITE (test site) BOOST_AUTO_TEST_CASE (Tests) {BOOST_CHECK_EQUAL (Pars ("Tom works for 10 hours."), "Tom; 10"); } BOOST_AUTO_TEST_SUITE_END ()  

In general, your attitude sounds good to me. Group class of tests in the work with descriptive names, e.g. TestInvalidGrammar, TestErrorHandling, TestNestedGrammar etc and have been called from the main.

I'm sure you read the documentation, but check that it helps.


Comments