LCOV - code coverage report
Current view: top level - tests - test_as2js_node_display.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 254 267 95.1 %
Date: 2014-11-22 Functions: 7 7 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* test_as2js_node_display.cpp -- written by Alexis WILKE for Made to Order Software Corp. (c) 2005-2014 */
       2             : 
       3             : /*
       4             : 
       5             : Copyright (c) 2005-2014 Made to Order Software Corp.
       6             : 
       7             : http://snapwebsites.org/project/as2js
       8             : 
       9             : Permission is hereby granted, free of charge, to any
      10             : person obtaining a copy of this software and
      11             : associated documentation files (the "Software"), to
      12             : deal in the Software without restriction, including
      13             : without limitation the rights to use, copy, modify,
      14             : merge, publish, distribute, sublicense, and/or sell
      15             : copies of the Software, and to permit persons to whom
      16             : the Software is furnished to do so, subject to the
      17             : following conditions:
      18             : 
      19             : The above copyright notice and this permission notice
      20             : shall be included in all copies or substantial
      21             : portions of the Software.
      22             : 
      23             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
      24             : ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
      25             : LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
      26             : FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
      27             : EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
      28             : LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
      29             : WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
      30             : ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      31             : SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      32             : SOFTWARE.
      33             : 
      34             : */
      35             : 
      36             : #include    "test_as2js_node.h"
      37             : #include    "test_as2js_main.h"
      38             : 
      39             : #include    "as2js/message.h"
      40             : #include    "as2js/exceptions.h"
      41             : 
      42             : #include    <algorithm>
      43             : #include    <cstring>
      44             : #include    <iomanip>
      45             : 
      46             : #include    <cppunit/config/SourcePrefix.h>
      47             : //CPPUNIT_TEST_SUITE_REGISTRATION( As2JsNodeUnitTests ); -- already registered in test_as2js_node.cpp
      48             : 
      49             : 
      50             : #include "test_as2js_node_data.ci"
      51             : 
      52             : 
      53             : 
      54           1 : void As2JsNodeUnitTests::test_display_all_types()
      55             : {
      56             :     // display all the different types available
      57             :     // this is "easy" so we do not have to test all
      58             :     // the potential flag, attributes, etc.
      59         171 :     for(size_t i(0); i < g_node_types_size; ++i)
      60             :     {
      61             :         // get the type
      62         170 :         as2js::Node::node_t const node_type(g_node_types[i].f_type);
      63         170 :         int node_type_int(static_cast<int>(static_cast<as2js::Node::node_t>(node_type)));
      64             : 
      65             :         // get the next type of node
      66         170 :         as2js::Node::pointer_t node(new as2js::Node(node_type));
      67             : 
      68             :         // check the type
      69         170 :         CPPUNIT_ASSERT(node->get_type() == node_type);
      70             : 
      71         340 :         std::stringstream out;
      72         170 :         out << *node;
      73             : 
      74             :         // build the expected message
      75         340 :         std::stringstream expected;
      76             :         // indent is expected to be exactly 2 on startup and here we only have one line
      77         170 :         expected << node << ": " << std::setfill('0') << std::setw(2) << 2 << std::setfill(' ') << '.' << std::setw(2) << ""
      78         340 :                  << std::setw(4) << std::setfill('0') << node_type_int
      79         340 :                  << std::setfill('\0') << ": " << g_node_types[i].f_name;
      80             : 
      81             :         // add the type as a character if it represents just one character
      82         170 :         if(node_type_int > ' ' && node_type_int < 0x7F)
      83             :         {
      84          24 :             expected << " = '" << static_cast<char>(node_type_int) << "'";
      85             :         }
      86             : 
      87         170 :         switch(node_type)
      88             :         {
      89             :         case as2js::Node::node_t::NODE_BREAK:
      90             :         case as2js::Node::node_t::NODE_CLASS:
      91             :         case as2js::Node::node_t::NODE_CONTINUE:
      92             :         case as2js::Node::node_t::NODE_ENUM:
      93             :         case as2js::Node::node_t::NODE_FUNCTION:
      94             :         case as2js::Node::node_t::NODE_GOTO:
      95             :         case as2js::Node::node_t::NODE_IDENTIFIER:
      96             :         case as2js::Node::node_t::NODE_IMPORT:
      97             :         case as2js::Node::node_t::NODE_INTERFACE:
      98             :         case as2js::Node::node_t::NODE_LABEL:
      99             :         case as2js::Node::node_t::NODE_NAMESPACE:
     100             :         case as2js::Node::node_t::NODE_PACKAGE:
     101             :         case as2js::Node::node_t::NODE_REGULAR_EXPRESSION:
     102             :         case as2js::Node::node_t::NODE_STRING:
     103             :         case as2js::Node::node_t::NODE_VARIABLE:
     104             :         case as2js::Node::node_t::NODE_VAR_ATTRIBUTES:
     105             :         case as2js::Node::node_t::NODE_VIDENTIFIER:
     106          17 :             output_str(expected, node->get_string());
     107          17 :             break;
     108             : 
     109             :         case as2js::Node::node_t::NODE_INT64:
     110           1 :             expected << ": " << node->get_int64().get() << ", 0x" << std::hex << std::setw(16) << std::setfill('0') << node->get_int64().get() << std::dec << std::setw(0) << std::setfill('\0');
     111           1 :             break;
     112             : 
     113             :         case as2js::Node::node_t::NODE_FLOAT64:
     114           1 :             expected << ": " << node->get_float64().get();
     115           1 :             break;
     116             : 
     117             :         case as2js::Node::node_t::NODE_CATCH:
     118             :         case as2js::Node::node_t::NODE_DIRECTIVE_LIST:
     119             :         case as2js::Node::node_t::NODE_FOR:
     120             :         case as2js::Node::node_t::NODE_PARAM:
     121             :         case as2js::Node::node_t::NODE_PARAM_MATCH:
     122             :         case as2js::Node::node_t::NODE_SWITCH:
     123             :         case as2js::Node::node_t::NODE_TYPE:
     124           7 :             expected << ":";
     125           7 :             break;
     126             : 
     127             :         default:
     128         144 :             break;
     129             : 
     130             :         }
     131         170 :         expected << " (" << node->get_position() << ")" << std::endl;
     132             : 
     133             : //std::cerr << "output [" << out.str() << "]\n";
     134             : //std::cerr << "expected [" << expected.str() << "]\n";
     135             : 
     136         170 :         CPPUNIT_ASSERT(out.str() == expected.str());
     137         170 :     }
     138           1 : }
     139             : 
     140             : 
     141           1 : void As2JsNodeUnitTests::test_display_unicode_string()
     142             : {
     143           1 :     int got_all(0);
     144         592 :     for(size_t idx(0); idx < 100 || got_all != 7; ++idx)
     145             :     {
     146             :         // get a string node
     147         591 :         as2js::Node::pointer_t node(new as2js::Node(as2js::Node::node_t::NODE_STRING));
     148             : 
     149             :         // generate a random string
     150        1182 :         as2js::String s;
     151      151887 :         for(int j(0); j < 256; ++j)
     152             :         {
     153             :             as2js::as_char_t c;
     154      285906 :             do
     155             :             {
     156      285906 :                 c = ((rand() << 16) ^ rand()) & 0x1FFFFF;
     157             :             }
     158             :             while(c == '\0'                         // skip null char
     159      285906 :                || c > 0x10FFFF                      // too large (not unicode)
     160      151596 :                || (c >= 0xD800 && c <= 0xDFFF));    // surrogate
     161      151296 :             if(c < 0x7F)
     162             :             {
     163          21 :                 got_all |= 1;
     164          21 :                 if(c == '\'')
     165             :                 {
     166           1 :                     got_all |= 4;
     167             :                 }
     168             :             }
     169             :             else
     170             :             {
     171      151275 :                 got_all |= 2;
     172             :             }
     173      151296 :             s += c;
     174             :         }
     175             : 
     176             :         // save random string in node
     177         591 :         node->set_string(s);
     178             : 
     179             :         // display that now
     180        1182 :         std::stringstream out;
     181         591 :         out << *node;
     182             : 
     183             :         // build the expected message
     184        1182 :         std::stringstream expected;
     185             :         // indent is expected to be exactly 2 on startup and here we only have one line
     186         591 :         expected << node << ": " << std::setfill('0') << std::setw(2) << 2 << std::setfill(' ') << '.' << std::setw(2) << ""
     187        1182 :                  << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_STRING))
     188        1182 :                  << std::setfill('\0') << ": " << "STRING";
     189         591 :         output_str(expected, s);
     190         591 :         expected << " (" << node->get_position() << ")" << std::endl;
     191             : 
     192             : //std::cerr << "output [" << out.str() << "]\n";
     193             : //std::cerr << "expected [" << expected.str() << "]\n";
     194             : 
     195         591 :         CPPUNIT_ASSERT(out.str() == expected.str());
     196         591 :     }
     197           1 : }
     198             : 
     199             : 
     200           1 : void As2JsNodeUnitTests::test_display_flags()
     201             : {
     202             :     // go through all the node types
     203         171 :     for(size_t i(0); i < g_node_types_size; ++i)
     204             :     {
     205         170 :         size_t max_flags(0);
     206         454 :         for(flags_per_node_t const *flags(g_node_types[i].f_node_flags);
     207         227 :                                     flags->f_flag != as2js::Node::flag_t::NODE_FLAG_max;
     208             :                                     ++flags)
     209             :         {
     210          57 :             ++max_flags;
     211             :         }
     212         170 :         if(max_flags == 0)
     213             :         {
     214             :             // ignore types without flags, they are not interesting here
     215         154 :             continue;
     216             :         }
     217             : 
     218          16 :         as2js::Node::pointer_t node(new as2js::Node(g_node_types[i].f_type));
     219             : 
     220          16 :         CPPUNIT_ASSERT(max_flags < sizeof(size_t) * 8);
     221          16 :         size_t const possibilities_max(1 << max_flags);
     222        5302 :         for(size_t j(0); j < possibilities_max; ++j)
     223             :         {
     224        5286 :             int pos(0);
     225      123096 :             for(flags_per_node_t const *flags(g_node_types[i].f_node_flags);
     226       61548 :                                         flags->f_flag != as2js::Node::flag_t::NODE_FLAG_max;
     227             :                                         ++flags, ++pos)
     228             :             {
     229       56262 :                 node->set_flag(flags->f_flag, ((1 << pos) & j) != 0);
     230             :             }
     231             : 
     232             :             // display that now
     233        5286 :             std::stringstream out;
     234        5286 :             out << *node;
     235             : 
     236             :             // build the expected message
     237       10572 :             std::stringstream expected;
     238             :             // indent is expected to be exactly 2 on startup and here we only have one line
     239        5286 :             expected << node << ": " << std::setfill('0') << std::setw(2) << 2 << std::setfill(' ') << '.' << std::setw(2) << ""
     240       10572 :                      << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(g_node_types[i].f_type))
     241       10572 :                      << std::setfill('\0') << ": " << g_node_types[i].f_name;
     242             : 
     243        5286 :             switch(g_node_types[i].f_type)
     244             :             {
     245             :             case as2js::Node::node_t::NODE_BREAK:
     246             :             case as2js::Node::node_t::NODE_CLASS:
     247             :             case as2js::Node::node_t::NODE_CONTINUE:
     248             :             case as2js::Node::node_t::NODE_ENUM:
     249             :             case as2js::Node::node_t::NODE_FUNCTION:
     250             :             case as2js::Node::node_t::NODE_GOTO:
     251             :             case as2js::Node::node_t::NODE_IDENTIFIER:
     252             :             case as2js::Node::node_t::NODE_IMPORT:
     253             :             case as2js::Node::node_t::NODE_INTERFACE:
     254             :             case as2js::Node::node_t::NODE_LABEL:
     255             :             case as2js::Node::node_t::NODE_NAMESPACE:
     256             :             case as2js::Node::node_t::NODE_PACKAGE:
     257             :             case as2js::Node::node_t::NODE_STRING:
     258             :             case as2js::Node::node_t::NODE_VARIABLE:
     259             :             case as2js::Node::node_t::NODE_VAR_ATTRIBUTES:
     260             :             case as2js::Node::node_t::NODE_VIDENTIFIER:
     261        4244 :                 output_str(expected, node->get_string());
     262        4244 :                 break;
     263             : 
     264             :             case as2js::Node::node_t::NODE_INT64:
     265           0 :                 expected << ": " << node->get_int64().get() << ", 0x" << std::hex << std::setw(16) << std::setfill('0') << node->get_int64().get() << std::dec << std::setw(0) << std::setfill('\0');
     266           0 :                 break;
     267             : 
     268             :             case as2js::Node::node_t::NODE_FLOAT64:
     269           0 :                 expected << ": " << node->get_float64().get();
     270           0 :                 break;
     271             : 
     272             :             //case as2js::Node::node_t::NODE_PARAM_MATCH:
     273             :             default:
     274        1042 :                 expected << ":";
     275        1042 :                 break;
     276             : 
     277             :             }
     278             : 
     279        5286 :             pos = 0;
     280      123096 :             for(flags_per_node_t const *flags(g_node_types[i].f_node_flags);
     281       61548 :                                         flags->f_flag != as2js::Node::flag_t::NODE_FLAG_max;
     282             :                                         ++flags, ++pos)
     283             :             {
     284       56262 :                 if(((1 << pos) & j) != 0)
     285             :                 {
     286       28131 :                     expected << " " << flags->f_name;
     287             :                 }
     288             :             }
     289             : 
     290        5286 :             expected << " (" << node->get_position() << ")" << std::endl;
     291             : 
     292             : //std::cerr << "output [" << out.str() << "]\n";
     293             : //std::cerr << "expected [" << expected.str() << "]\n";
     294             : 
     295        5286 :             CPPUNIT_ASSERT(out.str() == expected.str());
     296        5286 :         }
     297          16 :     }
     298           1 : }
     299             : 
     300             : 
     301           1 : void As2JsNodeUnitTests::test_display_attributes()
     302             : {
     303             :     // Test all the attributes in the output
     304             :     //
     305             :     // Note that we test all the attributes, although we always test
     306             :     // exactly 2 attributes in common... we may enhance this algorithm
     307             :     // later to test all the attributes in all possible combinasons,
     308             :     // but that is a bit tricky because of the conflicts.
     309             :     //
     310          11 :     for(int i(0); i < 10; ++i)
     311             :     {
     312             :         // create a node that is not a NODE_PROGRAM
     313             :         // (i.e. a node that accepts all attributes)
     314             :         size_t idx_node;
     315          10 :         do
     316             :         {
     317          10 :             idx_node = rand() % g_node_types_size;
     318             :         }
     319          10 :         while(g_node_types[idx_node].f_type == as2js::Node::node_t::NODE_PROGRAM);
     320          10 :         as2js::Node::pointer_t node(new as2js::Node(g_node_types[idx_node].f_type));
     321             : 
     322             :         // need to test all combinatorial cases...
     323          60 :         for(size_t j(0); j < g_groups_of_attributes_size; ++j)
     324             :         {
     325             :             // go through the list of attributes that generate conflicts
     326         380 :             for(as2js::Node::attribute_t const *attr_list(g_groups_of_attributes[j].f_attributes);
     327         190 :                                          *attr_list != as2js::Node::attribute_t::NODE_ATTR_max;
     328             :                                          ++attr_list)
     329             :             {
     330             :                 // set that one attribute first
     331         140 :                 node->set_attribute(*attr_list, true);
     332             : 
     333             :                 // test against all the other attributes
     334        3920 :                 for(int a(0); a < static_cast<int>(as2js::Node::attribute_t::NODE_ATTR_max); ++a)
     335             :                 {
     336             :                     // no need to test with itself, we do that earlier
     337        3780 :                     if(static_cast<as2js::Node::attribute_t>(a) == *attr_list)
     338             :                     {
     339         140 :                         continue;
     340             :                     }
     341             : 
     342             :                     // is attribute 'a' in conflict with attribute '*attr_list'?
     343        3640 :                     if(!in_conflict(j, *attr_list, static_cast<as2js::Node::attribute_t>(a)))
     344             :                     {
     345             :                         // if in conflict we do not care much here because the
     346             :                         // display is going to be exactly the same
     347        3320 :                         node->set_attribute(static_cast<as2js::Node::attribute_t>(a), true);
     348             : 
     349             :                         // display that now
     350        3320 :                         std::stringstream out;
     351        3320 :                         out << *node;
     352             : 
     353             :                         // build the expected message
     354        6640 :                         std::stringstream expected;
     355             :                         // indent is expected to be exactly 2 on startup and here we only have one line
     356        3320 :                         expected << node << ": " << std::setfill('0') << std::setw(2) << 2 << std::setfill(' ') << '.' << std::setw(2) << ""
     357        6640 :                                  << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(g_node_types[idx_node].f_type))
     358        6640 :                                  << std::setfill('\0') << ": " << g_node_types[idx_node].f_name;
     359             : 
     360             :                         // add the type as a character if it represents just one character
     361        3320 :                         if(static_cast<int>(static_cast<as2js::Node::node_t>(g_node_types[idx_node].f_type)) > ' '
     362        3320 :                         && static_cast<int>(static_cast<as2js::Node::node_t>(g_node_types[idx_node].f_type)) < 0x7F)
     363             :                         {
     364           0 :                             expected << " = '" << static_cast<char>(static_cast<int>(static_cast<as2js::Node::node_t>(g_node_types[idx_node].f_type))) << "'";
     365             :                         }
     366             : 
     367        3320 :                         switch(g_node_types[idx_node].f_type)
     368             :                         {
     369             :                         case as2js::Node::node_t::NODE_BREAK:
     370             :                         case as2js::Node::node_t::NODE_CLASS:
     371             :                         case as2js::Node::node_t::NODE_CONTINUE:
     372             :                         case as2js::Node::node_t::NODE_ENUM:
     373             :                         case as2js::Node::node_t::NODE_FUNCTION:
     374             :                         case as2js::Node::node_t::NODE_GOTO:
     375             :                         case as2js::Node::node_t::NODE_IDENTIFIER:
     376             :                         case as2js::Node::node_t::NODE_IMPORT:
     377             :                         case as2js::Node::node_t::NODE_INTERFACE:
     378             :                         case as2js::Node::node_t::NODE_LABEL:
     379             :                         case as2js::Node::node_t::NODE_NAMESPACE:
     380             :                         case as2js::Node::node_t::NODE_PACKAGE:
     381             :                         case as2js::Node::node_t::NODE_STRING:
     382             :                         case as2js::Node::node_t::NODE_VARIABLE:
     383             :                         case as2js::Node::node_t::NODE_VAR_ATTRIBUTES:
     384             :                         case as2js::Node::node_t::NODE_VIDENTIFIER:
     385           0 :                             output_str(expected, node->get_string());
     386           0 :                             break;
     387             : 
     388             :                         case as2js::Node::node_t::NODE_INT64:
     389           0 :                             expected << ": " << node->get_int64().get() << ", 0x" << std::hex << std::setw(16) << std::setfill('0') << node->get_int64().get() << std::dec << std::setw(0) << std::setfill('\0');
     390           0 :                             break;
     391             : 
     392             :                         case as2js::Node::node_t::NODE_FLOAT64:
     393           0 :                             expected << ": " << node->get_float64().get();
     394           0 :                             break;
     395             : 
     396             :                         case as2js::Node::node_t::NODE_CATCH:
     397             :                         case as2js::Node::node_t::NODE_DIRECTIVE_LIST:
     398             :                         case as2js::Node::node_t::NODE_FOR:
     399             :                         case as2js::Node::node_t::NODE_PARAM:
     400             :                         case as2js::Node::node_t::NODE_PARAM_MATCH:
     401             :                         case as2js::Node::node_t::NODE_SWITCH:
     402             :                         case as2js::Node::node_t::NODE_TYPE:
     403           0 :                             expected << ":";
     404           0 :                             break;
     405             : 
     406             :                         default:
     407        3320 :                             break;
     408             : 
     409             :                         }
     410             : 
     411        3320 :                         int pa(a);
     412        3320 :                         int pb(static_cast<int>(*attr_list));
     413        3320 :                         if(pa > pb)
     414             :                         {
     415        1730 :                             std::swap(pa, pb);
     416             :                         }
     417        3320 :                         expected << " attrs: " << g_attribute_names[pa] << " " << g_attribute_names[pb];
     418             : 
     419        3320 :                         expected << " (" << node->get_position() << ")" << std::endl;
     420             : 
     421             : //std::cerr << "output [" << out.str() << "]\n";
     422             : //std::cerr << "expected [" << expected.str() << "]\n";
     423             : 
     424        3320 :                         CPPUNIT_ASSERT(out.str() == expected.str());
     425             : 
     426        6640 :                         node->set_attribute(static_cast<as2js::Node::attribute_t>(a), false);
     427             :                     }
     428             :                 }
     429             : 
     430             :                 // we are done with that loop, restore the attribute to the default
     431         140 :                 node->set_attribute(*attr_list, false);
     432             :             }
     433             :         }
     434          10 :     }
     435           1 : }
     436             : 
     437             : 
     438           1 : void As2JsNodeUnitTests::test_display_tree()
     439             : {
     440             :     // create all the nodes as the lexer would do
     441           1 :     as2js::Node::pointer_t root(new as2js::Node(as2js::Node::node_t::NODE_ROOT));
     442           2 :     as2js::Position pos;
     443           1 :     pos.reset_counters(22);
     444           1 :     pos.set_filename("display.js");
     445           1 :     root->set_position(pos);
     446           2 :     as2js::Node::pointer_t directive_list_a(new as2js::Node(as2js::Node::node_t::NODE_DIRECTIVE_LIST));
     447           2 :     as2js::Node::pointer_t directive_list_b(new as2js::Node(as2js::Node::node_t::NODE_DIRECTIVE_LIST));
     448           1 :     directive_list_b->set_flag(as2js::Node::flag_t::NODE_DIRECTIVE_LIST_FLAG_NEW_VARIABLES, true);
     449           2 :     as2js::Node::pointer_t assignment(new as2js::Node(as2js::Node::node_t::NODE_ASSIGNMENT));
     450           2 :     as2js::Node::pointer_t identifier_a(new as2js::Node(as2js::Node::node_t::NODE_IDENTIFIER));
     451           1 :     identifier_a->set_string("a");
     452           1 :     identifier_a->set_attribute(as2js::Node::attribute_t::NODE_ATTR_TRUE, true);
     453           2 :     as2js::Node::pointer_t power(new as2js::Node(as2js::Node::node_t::NODE_POWER));
     454           2 :     as2js::Node::pointer_t member(new as2js::Node(as2js::Node::node_t::NODE_MEMBER));
     455           2 :     as2js::Node::pointer_t identifier_math(new as2js::Node(as2js::Node::node_t::NODE_IDENTIFIER));
     456           1 :     identifier_math->set_string("Math");
     457           1 :     identifier_math->set_attribute(as2js::Node::attribute_t::NODE_ATTR_NATIVE, true);
     458           2 :     as2js::Node::pointer_t math_type(new as2js::Node(as2js::Node::node_t::NODE_IDENTIFIER));
     459           1 :     math_type->set_string("Math");
     460           1 :     identifier_math->set_link(as2js::Node::link_t::LINK_TYPE, math_type);
     461           2 :     as2js::Node::pointer_t math_instance(new as2js::Node(as2js::Node::node_t::NODE_IDENTIFIER));
     462           1 :     math_instance->set_string("m");
     463           1 :     identifier_math->set_link(as2js::Node::link_t::LINK_INSTANCE, math_instance);
     464           2 :     as2js::Node::pointer_t identifier_e(new as2js::Node(as2js::Node::node_t::NODE_IDENTIFIER));
     465           1 :     identifier_e->set_string("e");
     466           1 :     identifier_e->set_flag(as2js::Node::flag_t::NODE_IDENTIFIER_FLAG_TYPED, true);
     467           2 :     as2js::Node::pointer_t e_type(new as2js::Node(as2js::Node::node_t::NODE_IDENTIFIER));
     468           1 :     e_type->set_string("Float");
     469           1 :     identifier_e->set_link(as2js::Node::link_t::LINK_TYPE, e_type);
     470           2 :     as2js::Node::pointer_t literal(new as2js::Node(as2js::Node::node_t::NODE_FLOAT64));
     471           1 :     as2js::Float64 f;
     472           1 :     f.set(1.424);
     473           1 :     literal->set_float64(f);
     474           2 :     as2js::Node::pointer_t function(new as2js::Node(as2js::Node::node_t::NODE_FUNCTION));
     475           1 :     function->set_string("my_func");
     476           2 :     as2js::Node::pointer_t func_var(new as2js::Node(as2js::Node::node_t::NODE_VAR));
     477           2 :     as2js::Node::pointer_t func_variable(new as2js::Node(as2js::Node::node_t::NODE_VARIABLE));
     478           1 :     func_variable->set_string("q");
     479           2 :     as2js::Node::pointer_t label(new as2js::Node(as2js::Node::node_t::NODE_LABEL));
     480           1 :     label->set_string("ignore");
     481           1 :     function->add_label(label);
     482           1 :     function->add_variable(func_variable);
     483             : 
     484             :     // build the tree as the parser would do
     485           1 :     root->append_child(directive_list_a);
     486           1 :     root->append_child(directive_list_b);
     487           1 :     directive_list_a->append_child(assignment);
     488           1 :     assignment->append_child(identifier_a);
     489           1 :     assignment->insert_child(-1, power);
     490           1 :     power->append_child(member);
     491           1 :     power->insert_child(1, literal);
     492           1 :     member->append_child(identifier_e);
     493           1 :     member->insert_child(0, identifier_math);
     494           1 :     directive_list_b->append_child(function);
     495           1 :     function->append_child(func_var);
     496           1 :     func_var->append_child(func_variable);
     497           1 :     function->append_child(label);
     498             : 
     499             :     // now test the output
     500           2 :     std::stringstream out;
     501           1 :     out << *root;
     502             : 
     503             :     // build the expected message
     504           2 :     std::stringstream expected;
     505             : 
     506             :     // ROOT
     507           1 :     expected << root << ": " << std::setfill('0') << std::setw(2) << 2 << std::setfill(' ') << '.' << std::setw(2) << ""
     508           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_ROOT))
     509           2 :              << std::setfill('\0') << ": ROOT"
     510           2 :              << " (" << root->get_position() << ")" << std::endl;
     511             : 
     512             :     // DIRECTIVE_LIST A
     513           1 :     expected << directive_list_a << ": " << std::setfill('0') << std::setw(2) << 3 << std::setfill(' ') << '-' << std::setw(3) << ""
     514           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_DIRECTIVE_LIST))
     515           2 :              << std::setfill('\0') << ": DIRECTIVE_LIST:"
     516           2 :              << " (" << directive_list_a->get_position() << ")" << std::endl;
     517             : 
     518             :     // ASSIGNMENT
     519           1 :     expected << assignment << ": " << std::setfill('0') << std::setw(2) << 4 << std::setfill(' ') << '-' << std::setw(4) << ""
     520           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_ASSIGNMENT))
     521           2 :              << std::setfill('\0') << ": ASSIGNMENT = '='"
     522           2 :              << " (" << assignment->get_position() << ")" << std::endl;
     523             : 
     524             :     // IDENTIFIER A
     525           1 :     expected << identifier_a << ": " << std::setfill('0') << std::setw(2) << 5 << std::setfill(' ') << '-' << std::setw(5) << ""
     526           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_IDENTIFIER))
     527           2 :              << std::setfill('\0') << ": IDENTIFIER: 'a' attrs: TRUE"
     528           2 :              << " (" << identifier_a->get_position() << ")" << std::endl;
     529             : 
     530             :     // POWER
     531           1 :     expected << power << ": " << std::setfill('0') << std::setw(2) << 5 << std::setfill(' ') << '-' << std::setw(5) << ""
     532           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_POWER))
     533           2 :              << std::setfill('\0') << ": POWER"
     534           2 :              << " (" << power->get_position() << ")" << std::endl;
     535             : 
     536             :     // MEMBER
     537           1 :     expected << member << ": " << std::setfill('0') << std::setw(2) << 6 << std::setfill(' ') << '-' << std::setw(6) << ""
     538           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_MEMBER))
     539           2 :              << std::setfill('\0') << ": MEMBER = '.'"
     540           2 :              << " (" << member->get_position() << ")" << std::endl;
     541             : 
     542             :     // IDENTIFIER MATH
     543           1 :     expected << identifier_math << ": " << std::setfill('0') << std::setw(2) << 7 << std::setfill(' ') << '-' << std::setw(7) << ""
     544           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_IDENTIFIER))
     545           2 :              << std::setfill('\0') << ": IDENTIFIER: 'Math' Lnk: [0]=" << math_instance << " [1]=" << math_type << " attrs: NATIVE"
     546           2 :              << " (" << identifier_math->get_position() << ")" << std::endl;
     547             : 
     548             :     // IDENTIFIER E
     549           1 :     expected << identifier_e << ": " << std::setfill('0') << std::setw(2) << 7 << std::setfill(' ') << '-' << std::setw(7) << ""
     550           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_IDENTIFIER))
     551           2 :              << std::setfill('\0') << ": IDENTIFIER: 'e' TYPED Lnk: [1]=" << e_type
     552           2 :              << " (" << identifier_e->get_position() << ")" << std::endl;
     553             : 
     554             :     // FLOAT64
     555           1 :     expected << literal << ": " << std::setfill('0') << std::setw(2) << 6 << std::setfill(' ') << '-' << std::setw(6) << ""
     556           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_FLOAT64))
     557           2 :              << std::setfill('\0') << ": FLOAT64: 1.424"
     558           2 :              << " (" << literal->get_position() << ")" << std::endl;
     559             : 
     560             :     // DIRECTIVE_LIST B
     561           1 :     expected << directive_list_b << ": " << std::setfill('0') << std::setw(2) << 3 << std::setfill(' ') << '-' << std::setw(3) << ""
     562           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_DIRECTIVE_LIST))
     563           2 :              << std::setfill('\0') << ": DIRECTIVE_LIST: NEW-VARIABLES"
     564           2 :              << " (" << directive_list_b->get_position() << ")" << std::endl;
     565             : 
     566             :     // FUNCTION
     567           1 :     expected << function << ": " << std::setfill('0') << std::setw(2) << 4 << std::setfill(' ') << '-' << std::setw(4) << ""
     568           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_FUNCTION))
     569           2 :              << std::setfill('\0') << ": FUNCTION: 'my_func'"
     570           2 :              << " (" << function->get_position() << ")" << std::endl;
     571             : 
     572             :     // VAR
     573           1 :     expected << func_var << ": " << std::setfill('0') << std::setw(2) << 5 << std::setfill(' ') << '-' << std::setw(5) << ""
     574           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_VAR))
     575           2 :              << std::setfill('\0') << ": VAR"
     576           2 :              << " (" << func_var->get_position() << ")" << std::endl;
     577             : 
     578             :     // VARIABLE
     579           1 :     expected << func_variable << ": " << std::setfill('0') << std::setw(2) << 6 << std::setfill(' ') << '-' << std::setw(6) << ""
     580           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_VARIABLE))
     581           2 :              << std::setfill('\0') << ": VARIABLE: 'q'"
     582           2 :              << " (" << func_variable->get_position() << ")" << std::endl;
     583             : 
     584             :     // LABEL
     585           1 :     expected << label << ": " << std::setfill('0') << std::setw(2) << 5 << std::setfill(' ') << '-' << std::setw(5) << ""
     586           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_LABEL))
     587           2 :              << std::setfill('\0') << ": LABEL: 'ignore'"
     588           2 :              << " (" << label->get_position() << ")" << std::endl;
     589             : 
     590             :     // VARIABLE
     591           1 :     expected << func_variable << ": " << std::setfill('0') << std::setw(2) << 5 << std::setfill(' ') << '=' << std::setw(5) << ""
     592           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_VARIABLE))
     593           2 :              << std::setfill('\0') << ": VARIABLE: 'q'"
     594           2 :              << " (" << func_variable->get_position() << ")" << std::endl;
     595             : 
     596             :     // LABEL
     597           1 :     expected << label << ": " << std::setfill('0') << std::setw(2) << 5 << std::setfill(' ') << ':' << std::setw(5) << ""
     598           2 :              << std::setw(4) << std::setfill('0') << static_cast<int>(static_cast<as2js::Node::node_t>(as2js::Node::node_t::NODE_LABEL))
     599           2 :              << std::setfill('\0') << ": LABEL: 'ignore'"
     600           2 :              << " (" << label->get_position() << ")" << std::endl;
     601             : 
     602             : //std::cerr << "output [" << out.str() << "]\n";
     603             : //std::cerr << "expected [" << expected.str() << "]\n";
     604             : 
     605           2 :     CPPUNIT_ASSERT(out.str() == expected.str());
     606          13 : }
     607             : 
     608             : 
     609             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.10