From e315595c366277491a476286bce04dd3859674e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 18 Jan 2009 08:52:20 +0000 Subject: [PATCH] Tokenizer: Added unit test to check that define is tokenized correctly --- test/testtokenize.cpp | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 294a28eff..5ca49b48e 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -37,6 +37,8 @@ private: void run() { + TEST_CASE(define1); + TEST_CASE(longtok); TEST_CASE(inlineasm); @@ -81,6 +83,48 @@ private: } + std::string tokenizeAndStringify(const char code[]) + { + // tokenize.. + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + std::ostringstream ostr; + for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) + { + ostr << tok->str(); + + // Append newlines + if ( tok->next() ) + { + if ( tok->linenr() != tok->next()->linenr() ) + { + for (int i=tok->linenr();i < tok->next()->linenr();++i) + ostr << "\n"; + } + else + { + ostr << " "; + } + } + } + + return ostr.str(); + } + + + + void define1() + { + const char code[] = "#define AAA(a) a*a\n\n" + " AAA(5)\n\n"; + const char expected[] = "# define AAA ( a ) a * a\n\n" + "AAA ( 5 )"; + ASSERT_EQUALS( expected, tokenizeAndStringify(code) ); + } + + void longtok() { std::string filedata(10000, 'a');