Boost logo

Boost Users :

Subject: [Boost-users] Ideas for UT needed
From: Olaf Peter (ope-devel_at_[hidden])
Date: 2013-02-13 14:00:31


Hello,

for my project I use the ideas used on spirit's conjure2 example. Now I
like to do some test with the lexer/grammar using boost::test. The
example uses sequentially initializing all iterators, lexer and grammar.
I like to put this into the fixture but I run into the problem that the
error_handler requires begin/end of iterator.

---8<--- original from conjure2 main
     typedef std::string::const_iterator base_iterator_type;
     typedef client::lexer::conjure_tokens<base_iterator_type>
                                                   lexer_type;
     typedef lexer_type::iterator_type iterator_type;

     lexer_type lexer; // Our lexer

     base_iterator_type first = source_code.begin();
     base_iterator_type last = source_code.end();

     iterator_type iter = lexer.begin(first, last);
     iterator_type end = lexer.end();

     client::error_handler<base_iterator_type, iterator_type>
         error_handler(first, last); // Our error handler
     client::parser::function<iterator_type, lexer_type>
         function(error_handler, lexer); // Our parser
--->8---

My fixture looks so far:

---8<---
     typedef std::string::const_iterator base_iterator_type;
     typedef my_tokens<base_iterator_type> lexer_type;
     typedef lexer_type::iterator_type iterator_type;
     typedef error_handler<base_iterator_type, iterator_type>
                                             error_handler_type;

     struct fixture
            : private boost::base_from_member<error_handler_type>,
              private boost::base_from_member<lexer_type>,
              my_grammar<iterator_type, lexer_type>
     {
        typedef boost::base_from_member<lexer_type> lexer_base;
         typedef boost::base_from_member<error_handler_type>
                                                 error_handler_base;
        typedef my_grammar<iterator_type, lexer_type> grammar_base;

        fixture() : grammar_base(error_handler_base::member,
                                 lexer_base::member) {

        }

     };
--->8---

error_handler_base::member requires therefore the iterators first/last.
How to give them? In the UT I have further a "test" function object so I
can use e.g. it like here:

---8<---
BOOST_FIXTURE_TEST_SUITE(parameter_test, fixture)

BOOST_AUTO_TEST_CASE(my_test) {

     BOOST_CHECK(test(rule_to_test,
                     "input to parse",
                     "expected output"));
}

--->8---

The next problem is related to the original use case. conjure2 is design
as a compiler: initialize, analyse, generate and exit - no reuse of the
grammar. I like to instance the grammar once (static) and use it several
times using the qi::parse function. Since the iterators are fixed, they
can't be changed later to point to other sources, isn't it? Is this the
right approach for my problem?

Thanks,
Olaf


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net