test_xpLex.pas
上传用户:yjb1804
上传日期:2021-01-30
资源大小:3105k
文件大小:2k
源码类别:

Email服务器

开发平台:

Delphi

  1. unit test_xpLex;
  2. (*
  3.  * The contents of this file are subject to the Mozilla Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/MPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * This code was inspired to expidite the creation of unit tests 
  14.  * for use the Dunit test frame work.
  15.  * 
  16.  * The Initial Developer of XPGen is Michael A. Johnson.
  17.  * Portions created The Initial Developer is Copyright (C) 2000.
  18.  * Portions created by The DUnit Group are Copyright (C) 2000.
  19.  * All rights reserved.
  20.  *
  21.  * Contributor(s):
  22.  * Michael A. Johnson <majohnson@golden.net>
  23.  * Juanco A馿z <juanco@users.sourceforge.net>
  24.  * Chris Morris <chrismo@users.sourceforge.net>
  25.  * Jeff Moore <JeffMoore@users.sourceforge.net>
  26.  * The DUnit group at SourceForge <http://dunit.sourceforge.net>
  27.  *
  28.  *)
  29. interface
  30. uses
  31.   classes,
  32.   TestFramework,
  33.   parseDef,
  34.   xpParse,
  35.   xpLex,
  36.   SysUtils;
  37. type
  38.   MockTLexer = class(TLexer);
  39.   TEST_TLexer = class(TTestCase)
  40.     InputFile: TFileStream;
  41.     testInstance: MockTLexer;
  42.   public
  43.     procedure setUp; override;
  44.     procedure tearDown; override;
  45.   published
  46.     procedure testNextToken;
  47.   end;
  48. implementation
  49. { TEST_TLexer }
  50. procedure TEST_TLexer.setUp;
  51. begin
  52.   InputFile := TFileStream.Create('testNextToken.txt', fmOpenRead);
  53.   testInstance := MockTLexer.create(InputFile);
  54. end;
  55. procedure TEST_TLexer.tearDown;
  56. begin
  57.   testInstance.free;
  58.   InputFile.free;
  59. end;
  60. procedure TEST_TLexer.testNextToken;
  61. const
  62.   compStr: array[1..12] of string = (
  63.     'begin',
  64.     'end',
  65.     'if',
  66.     '(',
  67.     'a',
  68.     '=',
  69.     'b',
  70.     ')',
  71.     'then',
  72.     'do',
  73.     '''this is a full string''',
  74.     ';');
  75. var
  76.   tokenIter: integer;
  77.   tokStr : string;
  78. begin
  79.   for tokenIter := low(compStr) to high(compStr) do
  80.     begin
  81.       tokStr := testInstance.TokenString;
  82.       check(tokStr = compStr[tokenIter], format('unexpected token <%s>',[tokStr]));
  83.       testInstance.NextToken;
  84.     end;
  85. end;
  86. initialization
  87.   TestFrameWork.RegisterTests('XPGEN lex tests',[TEST_TLexer.Suite]);  
  88. end.