macro_head.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   \brief Unit test.
00030 
00031   Unit test for class macro_head.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/std/source_location.hh>
00036 #include <lestes/lang/cplus/lex/macro_head.hh>
00037 #include <lestes/lang/cplus/lex/token_sequence.hh>
00038 #include <lestes/lang/cplus/lex/token_value.hh>
00039 #include <lestes/lang/cplus/lex/pp_token.hh>
00040 
00041 package(lestes);
00042 package(lang);
00043 package(cplus);
00044 package(lex);
00045 
00046 using namespace ::std;
00047 
00048 /*!
00049   \brief Tests macro_head class.
00050 
00051   Performs testing of macro_head class.
00052 */
00053 void macro_head_test(void)
00054 {
00055         ptr<file_info> fi = file_info::create("abc",NULL);
00056         ptr<source_location> loc = source_location::create(fi,0,0);
00057 
00058         ptr<token_value> tv1 = token_value::create("abc");
00059         ptr<token_value> tv2 = token_value::create("def");
00060         
00061         ptr<token_sequence> ts = token_sequence::create();
00062         
00063         ts->add_back(pp_token::create(loc,pp_token::TOK_BLANK));
00064         ts->add_back(pp_token::create(loc,pp_token::TOK_BLANK));
00065         ts->add_back(pp_token::create(loc,pp_token::TOK_LINE_END));
00066                 
00067         ts->add_back(pp_token::create(loc,pp_token::TOK_BLANK));
00068         ts->add_back(pp_token::create(loc,pp_token::TOK_DOT));
00069                 
00070         ts->add_back(pp_token::create(loc,pp_token::TOK_IDENT,tv1));
00071         ts->add_back(pp_token::create(loc,pp_token::TOK_BLANK));
00072         ts->add_back(pp_token::create(loc,pp_token::TOK_DOT));
00073 
00074         ts->add_back(pp_token::create(loc,pp_token::TOK_IDENT,tv1));
00075         ts->add_back(pp_token::create(loc,pp_token::TOK_COMMA));
00076         ts->add_back(pp_token::create(loc,pp_token::TOK_IDENT,tv1));
00077 
00078         ts->add_back(pp_token::create(loc,pp_token::TOK_IDENT,tv1));
00079         ts->add_back(pp_token::create(loc,pp_token::TOK_COMMA));
00080         ts->add_back(pp_token::create(loc,pp_token::TOK_IDENT,tv2));
00081         ts->add_back(pp_token::create(loc,pp_token::TOK_RIGHT_PAR));
00082 
00083         ts->add_back(pp_token::create(loc,pp_token::TOK_IDENT,tv2));
00084         ts->add_back(pp_token::create(loc,pp_token::TOK_COMMA));
00085         ts->add_back(pp_token::create(loc,pp_token::TOK_IDENT,tv1));
00086         ts->add_back(pp_token::create(loc,pp_token::TOK_RIGHT_PAR));
00087 
00088         ptr<macro_head> mh0 = macro_head::create();
00089 
00090         // created object
00091         lassert(is_equal(mh0,mh0));
00092         lassert(is_equal(mh0->state_get(),macro_head::BEGIN));
00093         
00094         // eol 
00095         lassert(is_equal(mh0->parse(ts),false));
00096         lassert(is_equal(mh0->state_get(),macro_head::DEAD));
00097         lassert(is_equal(mh0,mh0));
00098 
00099         ptr<macro_head> mh1 = macro_head::create();
00100 
00101         // nonidentifier 
00102         lassert(is_equal(mh1->parse(ts),false));
00103         lassert(is_equal(mh1->state_get(),macro_head::DEAD));
00104 
00105         ptr<macro_head> mh2 = macro_head::create();
00106 
00107         // ident and noncomma 
00108         lassert(is_equal(mh2->parse(ts),false));
00109         lassert(is_equal(mh2->state_get(),macro_head::DEAD));
00110 
00111         ptr<macro_head> mh3 = macro_head::create();
00112 
00113         // duplicate ident 
00114         lassert(is_equal(mh3->parse(ts),false));
00115         lassert(is_equal(mh3->state_get(),macro_head::DEAD));
00116 
00117         ptr<macro_head> mh4 = macro_head::create();
00118 
00119         // two distinct idents 
00120         lassert(is_equal(mh4->parse(ts),true));
00121         lassert(is_equal(mh4->state_get(),macro_head::PARSED));
00122         lassert(is_equal(mh4,mh4));
00123         lassert(is_equal(mh4->length(),2U));
00124         lassert(is_equal(mh4->index_of(tv1),0U));
00125         lassert(is_equal(mh4->index_of(tv2),1U));
00126         lassert(is_equal(mh4->index_of(token_value::create("ghi")),mh4->length()));
00127 
00128         ptr<macro_head> mh5 = macro_head::create();
00129 
00130         // swapped idents
00131         lassert(is_equal(mh5->parse(ts),true));
00132         lassert(is_equal(mh5->state_get(),macro_head::PARSED));
00133         lassert(!is_equal(mh5,mh4));
00134         lassert(is_equal(mh5->length(),2U));
00135         lassert(is_equal(mh5->index_of(tv2),0U));
00136         lassert(is_equal(mh5->index_of(tv1),1U));
00137         lassert(is_equal(mh5->index_of(token_value::create("ghi")),mh5->length()));
00138 
00139 }
00140 
00141 end_package(lex);
00142 end_package(cplus);
00143 end_package(lang);
00144 end_package(lestes);
00145 
00146 /*!
00147   \brief Main function.
00148 
00149   Runs the unit test in different namespace.
00150 */
00151 int main(void)
00152 {
00153 	::lestes::lang::cplus::lex::macro_head_test();
00154         return 0;
00155 }
00156 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:22:40 2007 for lestes by doxygen 1.5.1-20070107