pre_lex.test.cc

Go to the documentation of this file.
00001 /*
00002    The lestes compiler suite
00003    Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy
00004    Copyright (C) 2002, 2003, 2004, 2005 Petr Zika
00005    Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala
00006    Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina
00007    Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda
00008    Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar
00009    Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas
00010 
00011    This program is free software; you can redistribute it and/or modify
00012    it under the terms of the GNU General Public License as published by
00013    the Free Software Foundation; version 2 of the License.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    See the full text of the GNU General Public License version 2, and
00021    the limitations in the file doc/LICENSE.
00022 
00023    By accepting the license the licensee waives any and all claims
00024    against the copyright holder(s) related in whole or in part to the
00025    work, its use, and/or the inability to use it.
00026  
00027  */
00028 /*! \file
00029   Unit test for pre_lex class.
00030   \author pt
00031 */
00032 
00033 #include <lestes/common.hh>
00034 #include <lestes/lang/cplus/lex/ucn_token.hh>
00035 #include <lestes/lang/cplus/lex/pre_lex.hh>
00036 #include <lestes/lang/cplus/lex/string_source.hh>
00037 #include <lestes/lang/cplus/lex/encoder_host.hh>
00038 #include <lestes/lang/cplus/lex/simple_location.hh>
00039 #include <lestes/std/vector.hh>
00040 
00041 #include <iostream>
00042 
00043 package(lestes);
00044 package(lang);
00045 package(cplus);
00046 package(lex);
00047 
00048 typedef vector< srp<simple_location> > vec_loc;
00049 
00050 void pre_lex_test(void)
00051 {
00052         char inp[] = "abc$@`\n?""?""?""?""?=?""?/?""?(?""?)?""?!?""?<?""?>?""?-?""?'?""?+\\\nx\n";
00053         char ouv[] = "abc$@`\n?""?""?#\\[]|{}~^?""?+x\n";
00054         ulint out[] = {
00055                 ucn_token::TOK_BASIC,
00056                 ucn_token::TOK_BASIC,
00057                 ucn_token::TOK_BASIC,
00058                 
00059                 ucn_token::TOK_TRANSLATED,
00060                 ucn_token::TOK_TRANSLATED,
00061                 ucn_token::TOK_TRANSLATED,
00062                 
00063                 ucn_token::TOK_BASIC,
00064                 
00065                 ucn_token::TOK_BASIC,
00066                 ucn_token::TOK_BASIC,
00067                 ucn_token::TOK_BASIC,
00068 
00069                 ucn_token::TOK_BASIC,
00070                 ucn_token::TOK_BASIC,
00071                 ucn_token::TOK_BASIC,
00072                 ucn_token::TOK_BASIC,
00073                 ucn_token::TOK_BASIC,
00074                 ucn_token::TOK_BASIC,
00075                 ucn_token::TOK_BASIC,
00076                 ucn_token::TOK_BASIC,
00077                 ucn_token::TOK_BASIC,
00078 
00079                 ucn_token::TOK_BASIC,
00080                 ucn_token::TOK_BASIC,
00081                 ucn_token::TOK_BASIC,
00082 
00083                 ucn_token::TOK_BASIC,
00084                 
00085                 ucn_token::TOK_BASIC,
00086         };
00087 
00088         ptr<vec_loc> loc = vec_loc::create();
00089 
00090         loc->push_back(simple_location::create(1,1));
00091         loc->push_back(simple_location::create(1,2));
00092         loc->push_back(simple_location::create(1,3));
00093         loc->push_back(simple_location::create(1,4));
00094         loc->push_back(simple_location::create(1,5));
00095         loc->push_back(simple_location::create(1,6));
00096         loc->push_back(simple_location::create(1,7));
00097                 
00098         loc->push_back(simple_location::create(2,1));
00099         loc->push_back(simple_location::create(2,2));
00100         loc->push_back(simple_location::create(2,3));
00101                 
00102         loc->push_back(simple_location::create(2,4));      
00103         loc->push_back(simple_location::create(2,7));
00104         loc->push_back(simple_location::create(2,10));
00105         loc->push_back(simple_location::create(2,13));
00106         loc->push_back(simple_location::create(2,16));
00107         loc->push_back(simple_location::create(2,19));
00108         loc->push_back(simple_location::create(2,22));
00109         loc->push_back(simple_location::create(2,25));
00110         loc->push_back(simple_location::create(2,28));
00111                 
00112         loc->push_back(simple_location::create(2,31));
00113         loc->push_back(simple_location::create(2,32));
00114         loc->push_back(simple_location::create(2,33));
00115         loc->push_back(simple_location::create(3,1));
00116         loc->push_back(simple_location::create(3,2));
00117                 
00118         ulint i;
00119 
00120         ptr<pre_lex> plx = pre_lex::create(string_source::create(inp),encoder_host::create());
00121         ptr<ucn_token> tok;
00122 
00123         i = 0;
00124         do {
00125                 
00126                 tok = plx->read();
00127                 if (tok->type_get() == ucn_token::TOK_EOF) break;
00128 #if 0
00129                 ::std::cerr << " test " << i << " : " <<
00130                         "type " <<
00131                         (int)tok->type_get() << " ?== " << out[i] << 
00132                         "value " <<
00133                         (int)tok->value_get() << " ?== " << (int)ouv[i] << 
00134                         " line " <<
00135                         (int)tok->location_get()->line_get() << " ?== " << loc->at(i)->line_get() << 
00136                         " column " <<
00137                         (int)tok->location_get()->column_get() << " ?== " << loc->at(i)->column_get() 
00138                         << ::std::endl;
00139 #endif
00140                 lassert(is_equal((char)tok->value_get(),ouv[i]));
00141                 lassert(is_equal((char)tok->value_get(),ouv[i]));
00142                 lassert(is_equal(tok->type_get(),out[i]));
00143                 lassert(is_equal(tok->location_get(),ptr<simple_location>(loc->at(i))));
00144                 
00145                 i++;
00146         } while (true);
00147 }
00148 
00149 end_package(lex);
00150 end_package(cplus);
00151 end_package(lang);
00152 end_package(lestes);
00153 
00154 int main(void)
00155 {
00156 	::lestes::lang::cplus::lex::pre_lex_test();
00157         return 0;
00158 }
00159 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:23:10 2007 for lestes by doxygen 1.5.1-20070107