//============================================================================== // // Copyright (C) 2004 Dick van Oudheusden // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public // License along with this program; if not, write to the Free // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // //============================================================================== // // $Date: 2004/05/15 20:09:03 $ $Revision: 1.2 $ // //============================================================================== #include #include "ofc/config.h" #include "ofc/DTokenizer.h" #include "ofc/DFile.h" #include "DInc.h" #include "DTest.h" //-Misc------------------------------------------------------------------------ void DTokenizer_test() { DFile *file = [DFile new]; DTokenizer *tok = [DTokenizer new]; [file open :"test.tok" :"r"]; STARTTEST(); TEST([tok source :file :"test.tok"]); TEST([tok skipWhiteSpace] == YES); TEST([tok nextToken] == DTK_COMMENT); TEST(strcmp([tok text], "# comment") == 0); TEST([tok nextToken] == DTK_KEYWORD); TEST(strcmp([tok text], "keyword") == 0); TEST([tok nextToken] == DTK_OPERATOR); TEST(strcmp([tok text], "+") == 0); TEST([tok nextToken] == DTK_STRING); TEST(strcmp([tok text], "\"string\"") == 0); TEST([tok nextToken] == DTK_OPERATOR); TEST(strcmp([tok text], "%") == 0); TEST([tok nextToken] == DTK_STRING); TEST(strcmp([tok text], "'chars'") == 0); TEST([tok nextToken] == DTK_KEYWORD); TEST(strcmp([tok text], "keyword") == 0); TEST([tok nextToken] == DTK_OPERATOR); TEST(strcmp([tok text], "+") == 0); TEST([tok nextToken] == DTK_STRING); TEST(strcmp([tok text], "\"string\"") == 0); TEST([tok nextToken] == DTK_OPERATOR); TEST(strcmp([tok text], "%") == 0); TEST([tok nextToken] == DTK_NUMBER); TEST(strcmp([tok text], "155") == 0); TEST([[tok skipWhiteSpace :NO] skipWhiteSpace] == NO); TEST([tok nextToken] == DTK_KEYWORD); TEST(strcmp([tok text], "keyword") == 0); TEST([tok nextToken] == DTK_WHITESPACE); TEST([tok nextToken] == DTK_OPERATOR); TEST(strcmp([tok text], "^") == 0); TEST([tok nextToken] == DTK_WHITESPACE); TEST([tok nextToken] == DTK_STRING); TEST(strcmp([tok text], "\"string\"") == 0); TEST([tok nextToken] == DTK_WHITESPACE); TEST([tok nextToken] == DTK_OPERATOR); TEST(strcmp([tok text], "%") == 0); // [tok error :"no problem.."]; TEST([tok nextToken] == DTK_WHITESPACE); TEST([tok nextToken] == DTK_NUMBER); TEST(strcmp([tok text], "123") == 0); TEST([tok nextToken] == DTK_EOFF); [tok free]; [file free]; STOPTEST(); }