#include "UserTestTraits.hpp" #include "t002lexer.hpp" #include #include #include #include using namespace Antlr3Test; using namespace std; int testValid(string const& data); int testIteratorInterface(string const& data); int testMalformedInput(string const& data); static t002lexer *lxr; static t002lexerTokens::Tokens ExpectedTokens[] = { t002lexerTokens::ZERO, t002lexerTokens::ONE, t002lexerTokens::EOF_TOKEN }; int main (int argc, char *argv[]) { testValid("01"); testIteratorInterface("01"); testMalformedInput("2"); return 0; } int testValid(string const& data) { t002lexerTraits::InputStreamType* input = new t002lexerTraits::InputStreamType((const ANTLR_UINT8 *)data.c_str(), ANTLR_ENC_8BIT, data.length(), //strlen(data.c_str()), (ANTLR_UINT8*)"t002"); if (lxr == NULL) lxr = new t002lexer(input); else lxr->setCharStream(input); std::cout << "testValid: \"" << data << '"' <nextToken(); std::cout << token->getText() << '\t' << (token->getType() == ExpectedTokens[i] ? "OK" : "Fail") << std::endl; } delete lxr; lxr = NULL; delete input; return 0; } int testIteratorInterface(string const& data) { t002lexerTraits::InputStreamType* input = new t002lexerTraits::InputStreamType((const ANTLR_UINT8 *)data.c_str(), ANTLR_ENC_8BIT, data.length(), //strlen(data.c_str()), (ANTLR_UINT8*)"t002"); if (lxr == NULL) lxr = new t002lexer(input); else lxr->setCharStream(input); std::cout << "testIteratorInterface: \"" << data << '"' <get_tokSource()); t002lexerTraits::CommonTokenType const *token0 = tstream->_LT(1); t002lexerTraits::CommonTokenType const *token1 = tstream->_LT(2); t002lexerTraits::CommonTokenType const *token2 = tstream->_LT(3); std::cout << token0->getText() << std::endl; std::cout << token1->getText() << std::endl; std::cout << token2->getText() << std::endl; delete tstream; delete lxr; lxr = NULL; delete input; return 0; } int testMalformedInput(string const& data) { t002lexerTraits::InputStreamType* input = new t002lexerTraits::InputStreamType((const ANTLR_UINT8 *)data.c_str(), ANTLR_ENC_8BIT, data.length(), //strlen(data.c_str()), (ANTLR_UINT8*)"t002"); if (lxr == NULL) lxr = new t002lexer(input); else lxr->setCharStream(input); std::cout << "testMalformedInput: \"" << data << '"' <nextToken(); std::cout << token0->getText() << std::endl; delete lxr; lxr = NULL; delete input; return 0; }