tcstatements.pas 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  1. unit tcstatements;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, fpcunit, pastree, pscanner, pparser,
  6. tcbaseparser, testregistry;
  7. Type
  8. { TTestStatementParser }
  9. TTestStatementParser = Class(TTestParser)
  10. private
  11. FStatement: TPasImplBlock;
  12. FVariables : TStrings;
  13. Protected
  14. Procedure SetUp; override;
  15. Procedure TearDown; override;
  16. procedure AddStatements(ASource : Array of string);
  17. Procedure DeclareVar(Const AVarType : String; Const AVarName : String = 'A');
  18. function TestStatement(ASource : string) : TPasImplElement;
  19. function TestStatement(ASource : Array of string) : TPasImplElement;
  20. Procedure ExpectParserError(Const Msg : string);
  21. Procedure ExpectParserError(Const Msg : string; ASource : Array of string);
  22. Function AssertStatement(Msg : String; AClass : TClass;AIndex : Integer = 0) : TPasImplBlock;
  23. Property Statement: TPasImplBlock Read FStatement;
  24. Published
  25. Procedure TestEmpty;
  26. Procedure TestEmptyStatement;
  27. Procedure TestEmptyStatements;
  28. Procedure TestBlock;
  29. Procedure TestAssignment;
  30. Procedure TestAssignmentAdd;
  31. Procedure TestAssignmentMinus;
  32. Procedure TestAssignmentMul;
  33. Procedure TestAssignmentDivision;
  34. Procedure TestCall;
  35. Procedure TestCallQualified;
  36. Procedure TestCallQualified2;
  37. Procedure TestCallNoArgs;
  38. Procedure TestCallOneArg;
  39. Procedure TestIf;
  40. Procedure TestIfBlock;
  41. Procedure TestIfAssignment;
  42. Procedure TestIfElse;
  43. Procedure TestIfElseBlock;
  44. Procedure TestIfSemiColonElseError;
  45. Procedure TestNestedIf;
  46. Procedure TestNestedIfElse;
  47. Procedure TestWhile;
  48. Procedure TestWhileBlock;
  49. Procedure TestWhileNested;
  50. Procedure TestRepeat;
  51. Procedure TestRepeatBlock;
  52. procedure TestRepeatBlockNosemicolon;
  53. Procedure TestRepeatNested;
  54. Procedure TestFor;
  55. Procedure TestForIn;
  56. Procedure TestForExpr;
  57. Procedure TestForBlock;
  58. procedure TestDowntoBlock;
  59. Procedure TestForNested;
  60. Procedure TestWith;
  61. Procedure TestWithMultiple;
  62. Procedure TestCaseEmpty;
  63. Procedure TestCaseOneInteger;
  64. Procedure TestCaseTwoIntegers;
  65. Procedure TestCaseRange;
  66. Procedure TestCaseRangeSeparate;
  67. Procedure TestCase2Cases;
  68. Procedure TestCaseBlock;
  69. Procedure TestCaseElseBlockEmpty;
  70. Procedure TestCaseElseBlockAssignment;
  71. Procedure TestCaseElseBlock2Assignments;
  72. Procedure TestCaseIfCaseElse;
  73. Procedure TestCaseIfElse;
  74. Procedure TestRaise;
  75. Procedure TestRaiseEmpty;
  76. Procedure TestRaiseAt;
  77. Procedure TestTryFinally;
  78. Procedure TestTryFinallyEmpty;
  79. Procedure TestTryFinallyNested;
  80. procedure TestTryExcept;
  81. procedure TestTryExceptNested;
  82. procedure TestTryExceptEmpty;
  83. Procedure TestTryExceptOn;
  84. Procedure TestTryExceptOn2;
  85. Procedure TestTryExceptOnElse;
  86. Procedure TestTryExceptOnIfElse;
  87. end;
  88. implementation
  89. { TTestStatementParser }
  90. procedure TTestStatementParser.SetUp;
  91. begin
  92. inherited SetUp;
  93. FVariables:=TStringList.Create;
  94. end;
  95. procedure TTestStatementParser.TearDown;
  96. begin
  97. FreeAndNil(FVariables);
  98. inherited TearDown;
  99. end;
  100. procedure TTestStatementParser.AddStatements(ASource: array of string);
  101. Var
  102. I :Integer;
  103. begin
  104. StartProgram('afile');
  105. if FVariables.Count>0 then
  106. begin
  107. Add('Var');
  108. For I:=0 to FVariables.Count-1 do
  109. Add(' '+Fvariables[I]);
  110. end;
  111. Add('begin');
  112. For I:=Low(ASource) to High(ASource) do
  113. Add(' '+ASource[i]);
  114. end;
  115. procedure TTestStatementParser.DeclareVar(const AVarType: String;
  116. const AVarName: String);
  117. begin
  118. FVariables.Add(AVarName+' : '+AVarType+';');
  119. end;
  120. function TTestStatementParser.TestStatement(ASource: string): TPasImplElement;
  121. begin
  122. Result:=TestStatement([ASource]);
  123. end;
  124. function TTestStatementParser.TestStatement(ASource: array of string): TPasImplElement;
  125. begin
  126. Result:=Nil;
  127. FStatement:=Nil;
  128. AddStatements(ASource);
  129. ParseModule;
  130. AssertEquals('Have program',TPasProgram,Module.ClassType);
  131. AssertNotNull('Have program section',PasProgram.ProgramSection);
  132. AssertNotNull('Have initialization section',PasProgram.InitializationSection);
  133. if (PasProgram.InitializationSection.Elements.Count>0) then
  134. if TObject(PasProgram.InitializationSection.Elements[0]) is TPasImplBlock then
  135. FStatement:=TPasImplBlock(PasProgram.InitializationSection.Elements[0]);
  136. Result:=FStatement;
  137. end;
  138. procedure TTestStatementParser.ExpectParserError(Const Msg : string);
  139. begin
  140. AssertException(Msg,EParserError,@ParseModule);
  141. end;
  142. procedure TTestStatementParser.ExpectParserError(const Msg: string;
  143. ASource: array of string);
  144. begin
  145. AddStatements(ASource);
  146. ExpectParserError(Msg);
  147. end;
  148. function TTestStatementParser.AssertStatement(Msg: String; AClass: TClass;
  149. AIndex: Integer): TPasImplBlock;
  150. begin
  151. if not (AIndex<PasProgram.InitializationSection.Elements.Count) then
  152. Fail(Msg+': No such statement : '+intTostr(AIndex));
  153. AssertNotNull(Msg+' Have statement',PasProgram.InitializationSection.Elements[AIndex]);
  154. AssertEquals(Msg+' statement class',AClass,TObject(PasProgram.InitializationSection.Elements[AIndex]).ClassType);
  155. Result:=TObject(PasProgram.InitializationSection.Elements[AIndex]) as TPasImplBlock;
  156. end;
  157. procedure TTestStatementParser.TestEmpty;
  158. begin
  159. //TestStatement(';');
  160. TestStatement('');
  161. AssertEquals('No statements',0,PasProgram.InitializationSection.Elements.Count);
  162. end;
  163. procedure TTestStatementParser.TestEmptyStatement;
  164. begin
  165. TestStatement(';');
  166. AssertEquals('0 statement',0,PasProgram.InitializationSection.Elements.Count);
  167. end;
  168. procedure TTestStatementParser.TestEmptyStatements;
  169. begin
  170. TestStatement(';;');
  171. AssertEquals('0 statement',0,PasProgram.InitializationSection.Elements.Count);
  172. end;
  173. procedure TTestStatementParser.TestBlock;
  174. Var
  175. B : TPasImplBeginBlock;
  176. begin
  177. TestStatement(['begin','end']);
  178. AssertEquals('1 statement',1,PasProgram.InitializationSection.Elements.Count);
  179. AssertNotNull('Statement assigned',PasProgram.InitializationSection.Elements[0]);
  180. AssertEquals('Block statement',TPasImplBeginBlock,Statement.ClassType);
  181. B:= Statement as TPasImplBeginBlock;
  182. AssertEquals('Empty block',0,B.Elements.Count);
  183. end;
  184. procedure TTestStatementParser.TestAssignment;
  185. Var
  186. A : TPasImplAssign;
  187. begin
  188. DeclareVar('integer');
  189. TestStatement(['a:=1;']);
  190. AssertEquals('1 statement',1,PasProgram.InitializationSection.Elements.Count);
  191. AssertEquals('Assignment statement',TPasImplAssign,Statement.ClassType);
  192. A:=Statement as TPasImplAssign;
  193. AssertEquals('Normal assignment',akDefault,A.Kind);
  194. AssertExpression('Right side is constant',A.Right,pekNumber,'1');
  195. AssertExpression('Left side is variable',A.Left,pekIdent,'a');
  196. end;
  197. procedure TTestStatementParser.TestAssignmentAdd;
  198. Var
  199. A : TPasImplAssign;
  200. begin
  201. Parser.Scanner.Options:=[po_cassignments];
  202. DeclareVar('integer');
  203. TestStatement(['a+=1;']);
  204. AssertEquals('1 statement',1,PasProgram.InitializationSection.Elements.Count);
  205. AssertEquals('Assignment statement',TPasImplAssign,Statement.ClassType);
  206. A:=Statement as TPasImplAssign;
  207. AssertEquals('Add assignment',akAdd,A.Kind);
  208. AssertExpression('Right side is constant',A.Right,pekNumber,'1');
  209. AssertExpression('Left side is variable',A.Left,pekIdent,'a');
  210. end;
  211. procedure TTestStatementParser.TestAssignmentMinus;
  212. Var
  213. A : TPasImplAssign;
  214. begin
  215. Parser.Scanner.Options:=[po_cassignments];
  216. DeclareVar('integer');
  217. TestStatement(['a-=1;']);
  218. AssertEquals('1 statement',1,PasProgram.InitializationSection.Elements.Count);
  219. AssertEquals('Assignment statement',TPasImplAssign,Statement.ClassType);
  220. A:=Statement as TPasImplAssign;
  221. AssertEquals('Minus assignment',akMinus,A.Kind);
  222. AssertExpression('Right side is constant',A.Right,pekNumber,'1');
  223. AssertExpression('Left side is variable',A.Left,pekIdent,'a');
  224. end;
  225. procedure TTestStatementParser.TestAssignmentMul;
  226. Var
  227. A : TPasImplAssign;
  228. begin
  229. Parser.Scanner.Options:=[po_cassignments];
  230. DeclareVar('integer');
  231. TestStatement(['a*=1;']);
  232. AssertEquals('1 statement',1,PasProgram.InitializationSection.Elements.Count);
  233. AssertEquals('Assignment statement',TPasImplAssign,Statement.ClassType);
  234. A:=Statement as TPasImplAssign;
  235. AssertEquals('Mul assignment',akMul,A.Kind);
  236. AssertExpression('Right side is constant',A.Right,pekNumber,'1');
  237. AssertExpression('Left side is variable',A.Left,pekIdent,'a');
  238. end;
  239. procedure TTestStatementParser.TestAssignmentDivision;
  240. Var
  241. A : TPasImplAssign;
  242. begin
  243. Parser.Scanner.Options:=[po_cassignments];
  244. DeclareVar('integer');
  245. TestStatement(['a/=1;']);
  246. AssertEquals('1 statement',1,PasProgram.InitializationSection.Elements.Count);
  247. AssertEquals('Assignment statement',TPasImplAssign,Statement.ClassType);
  248. A:=Statement as TPasImplAssign;
  249. AssertEquals('Division assignment',akDivision,A.Kind);
  250. AssertExpression('Right side is constant',A.Right,pekNumber,'1');
  251. AssertExpression('Left side is variable',A.Left,pekIdent,'a');
  252. end;
  253. procedure TTestStatementParser.TestCall;
  254. Var
  255. S : TPasImplSimple;
  256. begin
  257. TestStatement('Doit;');
  258. AssertEquals('1 statement',1,PasProgram.InitializationSection.Elements.Count);
  259. AssertEquals('Simple statement',TPasImplSimple,Statement.ClassType);
  260. S:=Statement as TPasImplSimple;
  261. AssertExpression('Doit call',S.Expr,pekIdent,'Doit');
  262. end;
  263. procedure TTestStatementParser.TestCallQualified;
  264. Var
  265. S : TPasImplSimple;
  266. B : TBinaryExpr;
  267. begin
  268. TestStatement('Unita.Doit;');
  269. AssertEquals('1 statement',1,PasProgram.InitializationSection.Elements.Count);
  270. AssertEquals('Simple statement',TPasImplSimple,Statement.ClassType);
  271. S:=Statement as TPasImplSimple;
  272. AssertExpression('Doit call',S.Expr,pekBinary,TBinaryExpr);
  273. B:=S.Expr as TBinaryExpr;
  274. AssertExpression('Unit name',B.Left,pekIdent,'Unita');
  275. AssertExpression('Doit call',B.Right,pekIdent,'Doit');
  276. end;
  277. procedure TTestStatementParser.TestCallQualified2;
  278. Var
  279. S : TPasImplSimple;
  280. B : TBinaryExpr;
  281. begin
  282. TestStatement('Unita.ClassB.Doit;');
  283. AssertEquals('1 statement',1,PasProgram.InitializationSection.Elements.Count);
  284. AssertEquals('Simple statement',TPasImplSimple,Statement.ClassType);
  285. S:=Statement as TPasImplSimple;
  286. AssertExpression('Doit call',S.Expr,pekBinary,TBinaryExpr);
  287. B:=S.Expr as TBinaryExpr;
  288. AssertExpression('Unit name',B.Left,pekIdent,'Unita');
  289. AssertExpression('Doit call',B.Right,pekBinary,TBinaryExpr);
  290. B:=B.Right as TBinaryExpr;
  291. AssertExpression('Unit name',B.Left,pekIdent,'ClassB');
  292. AssertExpression('Doit call',B.Right,pekIdent,'Doit');
  293. end;
  294. procedure TTestStatementParser.TestCallNoArgs;
  295. Var
  296. S : TPasImplSimple;
  297. P : TParamsExpr;
  298. begin
  299. TestStatement('Doit();');
  300. AssertEquals('1 statement',1,PasProgram.InitializationSection.Elements.Count);
  301. AssertEquals('Simple statement',TPasImplSimple,Statement.ClassType);
  302. S:=Statement as TPasImplSimple;
  303. AssertExpression('Doit call',S.Expr,pekFuncParams,TParamsExpr);
  304. P:=S.Expr as TParamsExpr;
  305. AssertExpression('Correct function call name',P.Value,pekIdent,'Doit');
  306. AssertEquals('No params',0,Length(P.Params));
  307. end;
  308. procedure TTestStatementParser.TestCallOneArg;
  309. Var
  310. S : TPasImplSimple;
  311. P : TParamsExpr;
  312. begin
  313. TestStatement('Doit(1);');
  314. AssertEquals('1 statement',1,PasProgram.InitializationSection.Elements.Count);
  315. AssertEquals('Simple statement',TPasImplSimple,Statement.ClassType);
  316. S:=Statement as TPasImplSimple;
  317. AssertExpression('Doit call',S.Expr,pekFuncParams,TParamsExpr);
  318. P:=S.Expr as TParamsExpr;
  319. AssertExpression('Correct function call name',P.Value,pekIdent,'Doit');
  320. AssertEquals('One param',1,Length(P.Params));
  321. AssertExpression('Parameter is constant',P.Params[0],pekNumber,'1');
  322. end;
  323. procedure TTestStatementParser.TestIf;
  324. Var
  325. I : TPasImplIfElse;
  326. begin
  327. DeclareVar('boolean');
  328. TestStatement(['if a then',';']);
  329. I:=AssertStatement('If statement',TPasImplIfElse) as TPasImplIfElse;
  330. AssertExpression('IF condition',I.ConditionExpr,pekIdent,'a');
  331. AssertNull('No else',i.ElseBranch);
  332. AssertNull('No if branch',I.IfBranch);
  333. end;
  334. procedure TTestStatementParser.TestIfBlock;
  335. Var
  336. I : TPasImplIfElse;
  337. begin
  338. DeclareVar('boolean');
  339. TestStatement(['if a then',' begin',' end']);
  340. I:=AssertStatement('If statement',TPasImplIfElse) as TPasImplIfElse;
  341. AssertExpression('IF condition',I.ConditionExpr,pekIdent,'a');
  342. AssertNull('No else',i.ElseBranch);
  343. AssertNotNull('if branch',I.IfBranch);
  344. AssertEquals('begin end block',TPasImplBeginBlock,I.ifBranch.ClassType);
  345. end;
  346. procedure TTestStatementParser.TestIfAssignment;
  347. Var
  348. I : TPasImplIfElse;
  349. begin
  350. DeclareVar('boolean');
  351. TestStatement(['if a then',' a:=False;']);
  352. I:=AssertStatement('If statement',TPasImplIfElse) as TPasImplIfElse;
  353. AssertExpression('IF condition',I.ConditionExpr,pekIdent,'a');
  354. AssertNull('No else',i.ElseBranch);
  355. AssertNotNull('if branch',I.IfBranch);
  356. AssertEquals('assignment statement',TPasImplAssign,I.ifBranch.ClassType);
  357. end;
  358. procedure TTestStatementParser.TestIfElse;
  359. Var
  360. I : TPasImplIfElse;
  361. begin
  362. DeclareVar('boolean');
  363. TestStatement(['if a then',' begin',' end','else',';']);
  364. I:=AssertStatement('If statement',TPasImplIfElse) as TPasImplIfElse;
  365. AssertExpression('IF condition',I.ConditionExpr,pekIdent,'a');
  366. AssertNull('No else',i.ElseBranch);
  367. AssertNotNull('if branch',I.IfBranch);
  368. AssertEquals('begin end block',TPasImplBeginBlock,I.ifBranch.ClassType);
  369. end;
  370. procedure TTestStatementParser.TestIfElseBlock;
  371. Var
  372. I : TPasImplIfElse;
  373. begin
  374. DeclareVar('boolean');
  375. TestStatement(['if a then',' begin',' end','else',' begin',' end']);
  376. I:=AssertStatement('If statement',TPasImplIfElse) as TPasImplIfElse;
  377. AssertExpression('IF condition',I.ConditionExpr,pekIdent,'a');
  378. AssertNotNull('if branch',I.IfBranch);
  379. AssertEquals('begin end block',TPasImplBeginBlock,I.ifBranch.ClassType);
  380. AssertNotNull('Else branch',i.ElseBranch);
  381. AssertEquals('begin end block',TPasImplBeginBlock,I.ElseBranch.ClassType);
  382. end;
  383. procedure TTestStatementParser.TestIfSemiColonElseError;
  384. begin
  385. DeclareVar('boolean');
  386. ExpectParserError('No semicolon before else',['if a then',' begin',' end;','else',' begin',' end']);
  387. end;
  388. procedure TTestStatementParser.TestNestedIf;
  389. Var
  390. I : TPasImplIfElse;
  391. begin
  392. DeclareVar('boolean');
  393. DeclareVar('boolean','b');
  394. TestStatement(['if a then',' if b then',' begin',' end','else',' begin',' end']);
  395. I:=AssertStatement('If statement',TPasImplIfElse) as TPasImplIfElse;
  396. AssertExpression('IF condition',I.ConditionExpr,pekIdent,'a');
  397. AssertNotNull('if branch',I.IfBranch);
  398. AssertNull('Else branch',i.ElseBranch);
  399. AssertEquals('if in if branch',TPasImplIfElse,I.ifBranch.ClassType);
  400. I:=I.Ifbranch as TPasImplIfElse;
  401. AssertEquals('begin end block',TPasImplBeginBlock,I.ElseBranch.ClassType);
  402. end;
  403. procedure TTestStatementParser.TestNestedIfElse;
  404. Var
  405. I : TPasImplIfElse;
  406. begin
  407. DeclareVar('boolean');
  408. TestStatement(['if a then',' if b then',' begin',' end',' else',' begin',' end','else',' begin','end']);
  409. I:=AssertStatement('If statement',TPasImplIfElse) as TPasImplIfElse;
  410. AssertExpression('IF condition',I.ConditionExpr,pekIdent,'a');
  411. AssertNotNull('if branch',I.IfBranch);
  412. AssertNotNull('Else branch',i.ElseBranch);
  413. AssertEquals('begin end block',TPasImplBeginBlock,I.ElseBranch.ClassType);
  414. AssertEquals('if in if branch',TPasImplIfElse,I.ifBranch.ClassType);
  415. I:=I.Ifbranch as TPasImplIfElse;
  416. AssertEquals('begin end block',TPasImplBeginBlock,I.ElseBranch.ClassType);
  417. end;
  418. procedure TTestStatementParser.TestWhile;
  419. Var
  420. W : TPasImplWhileDo;
  421. begin
  422. DeclareVar('boolean');
  423. TestStatement(['While a do ;']);
  424. W:=AssertStatement('While statement',TPasImplWhileDo) as TPasImplWhileDo;
  425. AssertExpression('While condition',W.ConditionExpr,pekIdent,'a');
  426. AssertNull('Empty body',W.Body);
  427. end;
  428. procedure TTestStatementParser.TestWhileBlock;
  429. Var
  430. W : TPasImplWhileDo;
  431. begin
  432. DeclareVar('boolean');
  433. TestStatement(['While a do',' begin',' end']);
  434. W:=AssertStatement('While statement',TPasImplWhileDo) as TPasImplWhileDo;
  435. AssertExpression('While condition',W.ConditionExpr,pekIdent,'a');
  436. AssertNotNull('Have while body',W.Body);
  437. AssertEquals('begin end block',TPasImplBeginBlock,W.Body.ClassType);
  438. AssertEquals('Empty block',0,TPasImplBeginBlock(W.Body).ELements.Count);
  439. end;
  440. procedure TTestStatementParser.TestWhileNested;
  441. Var
  442. W : TPasImplWhileDo;
  443. begin
  444. DeclareVar('boolean');
  445. DeclareVar('boolean','b');
  446. TestStatement(['While a do',' while b do',' begin',' end']);
  447. W:=AssertStatement('While statement',TPasImplWhileDo) as TPasImplWhileDo;
  448. AssertExpression('While condition',W.ConditionExpr,pekIdent,'a');
  449. AssertNotNull('Have while body',W.Body);
  450. AssertEquals('Nested while',TPasImplWhileDo,W.Body.ClassType);
  451. W:=W.Body as TPasImplWhileDo;
  452. AssertExpression('While condition',W.ConditionExpr,pekIdent,'b');
  453. AssertNotNull('Have nested while body',W.Body);
  454. AssertEquals('Nested begin end block',TPasImplBeginBlock,W.Body.ClassType);
  455. AssertEquals('Empty nested block',0,TPasImplBeginBlock(W.Body).ELements.Count);
  456. end;
  457. procedure TTestStatementParser.TestRepeat;
  458. Var
  459. R : TPasImplRepeatUntil;
  460. begin
  461. DeclareVar('boolean');
  462. TestStatement(['Repeat','Until a;']);
  463. R:=AssertStatement('Repeat statement',TPasImplRepeatUntil) as TPasImplRepeatUntil;
  464. AssertExpression('repeat condition',R.ConditionExpr,pekIdent,'a');
  465. AssertEquals('Empty body',0,R.Elements.Count);
  466. end;
  467. procedure TTestStatementParser.TestRepeatBlock;
  468. Var
  469. R : TPasImplRepeatUntil;
  470. begin
  471. DeclareVar('boolean');
  472. TestStatement(['Repeat','begin','end;','Until a;']);
  473. R:=AssertStatement('repeat statement',TPasImplRepeatUntil) as TPasImplRepeatUntil;
  474. AssertExpression('repeat condition',R.ConditionExpr,pekIdent,'a');
  475. AssertEquals('Have statement',1,R.Elements.Count);
  476. AssertEquals('begin end block',TPasImplBeginBlock,TObject(R.Elements[0]).ClassType);
  477. AssertEquals('Empty block',0,TPasImplBeginBlock(R.Elements[0]).ELements.Count);
  478. end;
  479. procedure TTestStatementParser.TestRepeatBlockNosemicolon;
  480. Var
  481. R : TPasImplRepeatUntil;
  482. begin
  483. DeclareVar('boolean');
  484. TestStatement(['Repeat','begin','end','Until a;']);
  485. R:=AssertStatement('repeat statement',TPasImplRepeatUntil) as TPasImplRepeatUntil;
  486. AssertExpression('repeat condition',R.ConditionExpr,pekIdent,'a');
  487. AssertEquals('Have statement',1,R.Elements.Count);
  488. AssertEquals('begin end block',TPasImplBeginBlock,TObject(R.Elements[0]).ClassType);
  489. AssertEquals('Empty block',0,TPasImplBeginBlock(R.Elements[0]).ELements.Count);
  490. end;
  491. procedure TTestStatementParser.TestRepeatNested;
  492. Var
  493. R : TPasImplRepeatUntil;
  494. begin
  495. DeclareVar('boolean');
  496. DeclareVar('boolean','b');
  497. TestStatement(['Repeat','repeat','begin','end','until b','Until a;']);
  498. R:=AssertStatement('repeat statement',TPasImplRepeatUntil) as TPasImplRepeatUntil;
  499. AssertExpression('repeat condition',R.ConditionExpr,pekIdent,'a');
  500. AssertEquals('Have statement',1,R.Elements.Count);
  501. AssertEquals('Nested repeat',TPasImplRepeatUntil,TObject(R.Elements[0]).ClassType);
  502. R:=TPasImplRepeatUntil(R.Elements[0]);
  503. AssertExpression('repeat condition',R.ConditionExpr,pekIdent,'b');
  504. AssertEquals('Have statement',1,R.Elements.Count);
  505. AssertEquals('begin end block',TPasImplBeginBlock,TObject(R.Elements[0]).ClassType);
  506. AssertEquals('Empty block',0,TPasImplBeginBlock(R.Elements[0]).ELements.Count);
  507. end;
  508. procedure TTestStatementParser.TestFor;
  509. Var
  510. F : TPasImplForLoop;
  511. begin
  512. DeclareVar('integer');
  513. TestStatement(['For a:=1 to 10 do',';']);
  514. F:=AssertStatement('For statement',TPasImplForLoop) as TPasImplForLoop;
  515. AssertEquals('Loop variable name','a',F.VariableName);
  516. AssertEquals('Loop type',ltNormal,F.Looptype);
  517. AssertEquals('Up loop',False,F.Down);
  518. AssertExpression('Start value',F.StartExpr,pekNumber,'1');
  519. AssertExpression('End value',F.EndExpr,pekNumber,'10');
  520. AssertNull('Empty body',F.Body);
  521. end;
  522. procedure TTestStatementParser.TestForIn;
  523. Var
  524. F : TPasImplForLoop;
  525. begin
  526. DeclareVar('integer');
  527. TestStatement(['For a in SomeSet Do',';']);
  528. F:=AssertStatement('For statement',TPasImplForLoop) as TPasImplForLoop;
  529. AssertEquals('Loop variable name','a',F.VariableName);
  530. AssertEquals('Loop type',ltIn,F.Looptype);
  531. AssertEquals('In loop',False,F.Down);
  532. AssertExpression('Start value',F.StartExpr,pekIdent,'SomeSet');
  533. AssertNull('Loop type',F.EndExpr);
  534. AssertNull('Empty body',F.Body);
  535. end;
  536. procedure TTestStatementParser.TestForExpr;
  537. Var
  538. F : TPasImplForLoop;
  539. B : TBinaryExpr;
  540. begin
  541. DeclareVar('integer');
  542. TestStatement(['For a:=1+1 to 5+5 do',';']);
  543. F:=AssertStatement('For statement',TPasImplForLoop) as TPasImplForLoop;
  544. AssertEquals('Loop variable name','a',F.VariableName);
  545. AssertEquals('Up loop',False,F.Down);
  546. AssertExpression('Start expression',F.StartExpr,pekBinary,TBinaryExpr);
  547. B:=F.StartExpr as TBinaryExpr;
  548. AssertExpression('Start value left',B.left,pekNumber,'1');
  549. AssertExpression('Start value right',B.right,pekNumber,'1');
  550. AssertExpression('Start expression',F.StartExpr,pekBinary,TBinaryExpr);
  551. B:=F.EndExpr as TBinaryExpr;
  552. AssertExpression('End value left',B.left,pekNumber,'5');
  553. AssertExpression('End value right',B.right,pekNumber,'5');
  554. AssertNull('Empty body',F.Body);
  555. end;
  556. procedure TTestStatementParser.TestForBlock;
  557. Var
  558. F : TPasImplForLoop;
  559. begin
  560. DeclareVar('integer');
  561. TestStatement(['For a:=1 to 10 do','begin','end']);
  562. F:=AssertStatement('For statement',TPasImplForLoop) as TPasImplForLoop;
  563. AssertEquals('Loop variable name','a',F.VariableName);
  564. AssertEquals('Up loop',False,F.Down);
  565. AssertExpression('Start value',F.StartExpr,pekNumber,'1');
  566. AssertExpression('End value',F.EndExpr,pekNumber,'10');
  567. AssertNotNull('Have for body',F.Body);
  568. AssertEquals('begin end block',TPasImplBeginBlock,F.Body.ClassType);
  569. AssertEquals('Empty block',0,TPasImplBeginBlock(F.Body).ELements.Count);
  570. end;
  571. procedure TTestStatementParser.TestDowntoBlock;
  572. Var
  573. F : TPasImplForLoop;
  574. begin
  575. DeclareVar('integer');
  576. TestStatement(['For a:=10 downto 1 do','begin','end']);
  577. F:=AssertStatement('For statement',TPasImplForLoop) as TPasImplForLoop;
  578. AssertEquals('Loop variable name','a',F.VariableName);
  579. AssertEquals('Down loop',True,F.Down);
  580. AssertExpression('Start value',F.StartExpr,pekNumber,'10');
  581. AssertExpression('End value',F.EndExpr,pekNumber,'1');
  582. AssertNotNull('Have for body',F.Body);
  583. AssertEquals('begin end block',TPasImplBeginBlock,F.Body.ClassType);
  584. AssertEquals('Empty block',0,TPasImplBeginBlock(F.Body).ELements.Count);
  585. end;
  586. procedure TTestStatementParser.TestForNested;
  587. Var
  588. F : TPasImplForLoop;
  589. begin
  590. DeclareVar('integer');
  591. DeclareVar('integer','b');
  592. TestStatement(['For a:=1 to 10 do','For b:=11 to 20 do','begin','end']);
  593. F:=AssertStatement('For statement',TPasImplForLoop) as TPasImplForLoop;
  594. AssertEquals('Loop variable name','a',F.VariableName);
  595. AssertEquals('Up loop',False,F.Down);
  596. AssertExpression('Start value',F.StartExpr,pekNumber,'1');
  597. AssertExpression('End value',F.EndExpr,pekNumber,'10');
  598. AssertNotNull('Have while body',F.Body);
  599. AssertEquals('begin end block',TPasImplForLoop,F.Body.ClassType);
  600. F:=F.Body as TPasImplForLoop;
  601. AssertEquals('Loop variable name','b',F.VariableName);
  602. AssertEquals('Up loop',False,F.Down);
  603. AssertExpression('Start value',F.StartExpr,pekNumber,'11');
  604. AssertExpression('End value',F.EndExpr,pekNumber,'20');
  605. AssertNotNull('Have for body',F.Body);
  606. AssertEquals('begin end block',TPasImplBeginBlock,F.Body.ClassType);
  607. AssertEquals('Empty block',0,TPasImplBeginBlock(F.Body).ELements.Count);
  608. end;
  609. procedure TTestStatementParser.TestWith;
  610. Var
  611. W : TpasImplWithDo;
  612. begin
  613. DeclareVar('record X,Y : Integer; end');
  614. TestStatement(['With a do','begin','end']);
  615. W:=AssertStatement('For statement',TpasImplWithDo) as TpasImplWithDo;
  616. AssertEquals('1 expression',1,W.Expressions.Count);
  617. AssertExpression('With identifier',TPasExpr(W.Expressions[0]),pekIdent,'a');
  618. AssertNotNull('Have with body',W.Body);
  619. AssertEquals('begin end block',TPasImplBeginBlock,W.Body.ClassType);
  620. AssertEquals('Empty block',0,TPasImplBeginBlock(W.Body).ELements.Count);
  621. end;
  622. procedure TTestStatementParser.TestWithMultiple;
  623. Var
  624. W : TpasImplWithDo;
  625. begin
  626. DeclareVar('record X,Y : Integer; end');
  627. DeclareVar('record W,Z : Integer; end','b');
  628. TestStatement(['With a,b do','begin','end']);
  629. W:=AssertStatement('For statement',TpasImplWithDo) as TpasImplWithDo;
  630. AssertEquals('2 expressions',2,W.Expressions.Count);
  631. AssertExpression('With identifier 1',TPasExpr(W.Expressions[0]),pekIdent,'a');
  632. AssertExpression('With identifier 2',TPasExpr(W.Expressions[1]),pekIdent,'b');
  633. AssertNotNull('Have with body',W.Body);
  634. AssertEquals('begin end block',TPasImplBeginBlock,W.Body.ClassType);
  635. AssertEquals('Empty block',0,TPasImplBeginBlock(W.Body).ELements.Count);
  636. end;
  637. procedure TTestStatementParser.TestCaseEmpty;
  638. begin
  639. DeclareVar('integer');
  640. AddStatements(['case a of','end;']);
  641. ExpectParserError('Empty case not allowed');
  642. end;
  643. procedure TTestStatementParser.TestCaseOneInteger;
  644. Var
  645. C : TPasImplCaseOf;
  646. S : TPasImplCaseStatement;
  647. begin
  648. DeclareVar('integer');
  649. TestStatement(['case a of','1 : ;','end;']);
  650. C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf;
  651. AssertNotNull('Have case expression',C.CaseExpr);
  652. AssertExpression('Case expression',C.CaseExpr,pekIdent,'a');
  653. AssertNull('No else branch',C.ElseBranch);
  654. AssertEquals('One case label',1,C.Elements.Count);
  655. AssertEquals('Correct case for case label',TPasImplCaseStatement,TPasElement(C.Elements[0]).ClassType);
  656. S:=TPasImplCaseStatement(C.Elements[0]);
  657. AssertEquals('1 expression for case',1,S.Expressions.Count);
  658. AssertExpression('With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'1');
  659. AssertEquals('Empty case label statement',0,S.Elements.Count);
  660. AssertNull('Empty case label statement',S.Body);
  661. end;
  662. procedure TTestStatementParser.TestCaseTwoIntegers;
  663. Var
  664. C : TPasImplCaseOf;
  665. S : TPasImplCaseStatement;
  666. begin
  667. DeclareVar('integer');
  668. TestStatement(['case a of','1,2 : ;','end;']);
  669. C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf;
  670. AssertNotNull('Have case expression',C.CaseExpr);
  671. AssertExpression('Case expression',C.CaseExpr,pekIdent,'a');
  672. AssertNull('No else branch',C.ElseBranch);
  673. AssertEquals('One case label',1,C.Elements.Count);
  674. AssertEquals('Correct case for case label',TPasImplCaseStatement,TPasElement(C.Elements[0]).ClassType);
  675. S:=TPasImplCaseStatement(C.Elements[0]);
  676. AssertEquals('2 expressions for case',2,S.Expressions.Count);
  677. AssertExpression('With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'1');
  678. AssertExpression('With identifier 2',TPasExpr(S.Expressions[1]),pekNumber,'2');
  679. AssertEquals('Empty case label statement',0,S.Elements.Count);
  680. AssertNull('Empty case label statement',S.Body);
  681. end;
  682. procedure TTestStatementParser.TestCaseRange;
  683. Var
  684. C : TPasImplCaseOf;
  685. S : TPasImplCaseStatement;
  686. begin
  687. DeclareVar('integer');
  688. TestStatement(['case a of','1..3 : ;','end;']);
  689. C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf;
  690. AssertNotNull('Have case expression',C.CaseExpr);
  691. AssertExpression('Case expression',C.CaseExpr,pekIdent,'a');
  692. AssertNull('No else branch',C.ElseBranch);
  693. AssertEquals('One case label',1,C.Elements.Count);
  694. AssertEquals('Correct case for case label',TPasImplCaseStatement,TPasElement(C.Elements[0]).ClassType);
  695. S:=TPasImplCaseStatement(C.Elements[0]);
  696. AssertEquals('1 expression for case',1,S.Expressions.Count);
  697. AssertExpression('With identifier 1',TPasExpr(S.Expressions[0]),pekRange,TBinaryExpr);
  698. AssertEquals('Empty case label statement',0,S.Elements.Count);
  699. AssertNull('Empty case label statement',S.Body);
  700. end;
  701. procedure TTestStatementParser.TestCaseRangeSeparate;
  702. Var
  703. C : TPasImplCaseOf;
  704. S : TPasImplCaseStatement;
  705. begin
  706. DeclareVar('integer');
  707. TestStatement(['case a of','1..3,5 : ;','end;']);
  708. C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf;
  709. AssertNotNull('Have case expression',C.CaseExpr);
  710. AssertExpression('Case expression',C.CaseExpr,pekIdent,'a');
  711. AssertNull('No else branch',C.ElseBranch);
  712. AssertEquals('One case label',1,C.Elements.Count);
  713. AssertEquals('Correct case for case label',TPasImplCaseStatement,TPasElement(C.Elements[0]).ClassType);
  714. S:=TPasImplCaseStatement(C.Elements[0]);
  715. AssertEquals('2 expressions for case',2,S.Expressions.Count);
  716. AssertExpression('With identifier 1',TPasExpr(S.Expressions[0]),pekRange,TBinaryExpr);
  717. AssertExpression('With identifier 2',TPasExpr(S.Expressions[1]),pekNumber,'5');
  718. AssertEquals('Empty case label statement',0,S.Elements.Count);
  719. AssertNull('Empty case label statement',S.Body);
  720. end;
  721. procedure TTestStatementParser.TestCase2Cases;
  722. Var
  723. C : TPasImplCaseOf;
  724. S : TPasImplCaseStatement;
  725. begin
  726. DeclareVar('integer');
  727. TestStatement(['case a of','1 : ;','2 : ;','end;']);
  728. C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf;
  729. AssertNotNull('Have case expression',C.CaseExpr);
  730. AssertExpression('Case expression',C.CaseExpr,pekIdent,'a');
  731. AssertNull('No else branch',C.ElseBranch);
  732. AssertEquals('Two case labels',2,C.Elements.Count);
  733. AssertEquals('Correct case for case label 1',TPasImplCaseStatement,TPasElement(C.Elements[0]).ClassType);
  734. S:=TPasImplCaseStatement(C.Elements[0]);
  735. AssertEquals('2 expressions for case 1',1,S.Expressions.Count);
  736. AssertExpression('Case 1 With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'1');
  737. AssertEquals('Empty case label statement 1',0,S.Elements.Count);
  738. AssertNull('Empty case label statement 1',S.Body);
  739. // Two
  740. AssertEquals('Correct case for case label 2',TPasImplCaseStatement,TPasElement(C.Elements[1]).ClassType);
  741. S:=TPasImplCaseStatement(C.Elements[1]);
  742. AssertEquals('2 expressions for case 2',1,S.Expressions.Count);
  743. AssertExpression('Case 2 With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'2');
  744. AssertEquals('Empty case label statement 2',0,S.Elements.Count);
  745. AssertNull('Empty case label statement 2',S.Body);
  746. end;
  747. procedure TTestStatementParser.TestCaseBlock;
  748. Var
  749. C : TPasImplCaseOf;
  750. S : TPasImplCaseStatement;
  751. B : TPasImplbeginBlock;
  752. begin
  753. DeclareVar('integer');
  754. TestStatement(['case a of','1 : begin end;','end;']);
  755. C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf;
  756. AssertNotNull('Have case expression',C.CaseExpr);
  757. AssertExpression('Case expression',C.CaseExpr,pekIdent,'a');
  758. AssertNull('No else branch',C.ElseBranch);
  759. AssertEquals('Two case labels',1,C.Elements.Count);
  760. AssertEquals('Correct case for case label 1',TPasImplCaseStatement,TPasElement(C.Elements[0]).ClassType);
  761. S:=TPasImplCaseStatement(C.Elements[0]);
  762. AssertEquals('2 expressions for case 1',1,S.Expressions.Count);
  763. AssertExpression('Case With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'1');
  764. AssertEquals('1 case label statement',1,S.Elements.Count);
  765. AssertEquals('Correct case for case label 1',TPasImplbeginBlock,TPasElement(S.Elements[0]).ClassType);
  766. B:=TPasImplbeginBlock(S.Elements[0]);
  767. AssertEquals('0 statements in block',0,B.Elements.Count);
  768. end;
  769. procedure TTestStatementParser.TestCaseElseBlockEmpty;
  770. Var
  771. C : TPasImplCaseOf;
  772. S : TPasImplCaseStatement;
  773. B : TPasImplbeginBlock;
  774. begin
  775. DeclareVar('integer');
  776. TestStatement(['case a of','1 : begin end;','else',' end;']);
  777. C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf;
  778. AssertNotNull('Have case expression',C.CaseExpr);
  779. AssertExpression('Case expression',C.CaseExpr,pekIdent,'a');
  780. AssertEquals('Two case labels',2,C.Elements.Count);
  781. AssertEquals('Correct case for case label 1',TPasImplCaseStatement,TPasElement(C.Elements[0]).ClassType);
  782. S:=TPasImplCaseStatement(C.Elements[0]);
  783. AssertEquals('2 expressions for case 1',1,S.Expressions.Count);
  784. AssertExpression('Case With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'1');
  785. AssertEquals('1 case label statement',1,S.Elements.Count);
  786. AssertEquals('Correct case for case label 1',TPasImplbeginBlock,TPasElement(S.Elements[0]).ClassType);
  787. B:=TPasImplbeginBlock(S.Elements[0]);
  788. AssertEquals('0 statements in block',0,B.Elements.Count);
  789. AssertNotNull('Have else branch',C.ElseBranch);
  790. AssertEquals('Correct else branch class',TPasImplCaseElse,C.ElseBranch.ClassType);
  791. AssertEquals('Zero statements ',0,TPasImplCaseElse(C.ElseBranch).Elements.Count);
  792. end;
  793. procedure TTestStatementParser.TestCaseElseBlockAssignment;
  794. Var
  795. C : TPasImplCaseOf;
  796. S : TPasImplCaseStatement;
  797. B : TPasImplbeginBlock;
  798. begin
  799. DeclareVar('integer');
  800. TestStatement(['case a of','1 : begin end;','else','a:=1',' end;']);
  801. C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf;
  802. AssertNotNull('Have case expression',C.CaseExpr);
  803. AssertExpression('Case expression',C.CaseExpr,pekIdent,'a');
  804. AssertEquals('Two case labels',2,C.Elements.Count);
  805. AssertEquals('Correct case for case label 1',TPasImplCaseStatement,TPasElement(C.Elements[0]).ClassType);
  806. S:=TPasImplCaseStatement(C.Elements[0]);
  807. AssertEquals('2 expressions for case 1',1,S.Expressions.Count);
  808. AssertExpression('Case With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'1');
  809. AssertEquals('1 case label statement',1,S.Elements.Count);
  810. AssertEquals('Correct case for case label 1',TPasImplbeginBlock,TPasElement(S.Elements[0]).ClassType);
  811. B:=TPasImplbeginBlock(S.Elements[0]);
  812. AssertEquals('0 statements in block',0,B.Elements.Count);
  813. AssertNotNull('Have else branch',C.ElseBranch);
  814. AssertEquals('Correct else branch class',TPasImplCaseElse,C.ElseBranch.ClassType);
  815. AssertEquals('1 statement in else branch ',1,TPasImplCaseElse(C.ElseBranch).Elements.Count);
  816. end;
  817. procedure TTestStatementParser.TestCaseElseBlock2Assignments;
  818. Var
  819. C : TPasImplCaseOf;
  820. S : TPasImplCaseStatement;
  821. B : TPasImplbeginBlock;
  822. begin
  823. DeclareVar('integer');
  824. TestStatement(['case a of','1 : begin end;','else','a:=1;','a:=32;',' end;']);
  825. C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf;
  826. AssertNotNull('Have case expression',C.CaseExpr);
  827. AssertExpression('Case expression',C.CaseExpr,pekIdent,'a');
  828. AssertEquals('Two case labels',2,C.Elements.Count);
  829. AssertEquals('Correct case for case label 1',TPasImplCaseStatement,TPasElement(C.Elements[0]).ClassType);
  830. S:=TPasImplCaseStatement(C.Elements[0]);
  831. AssertEquals('2 expressions for case 1',1,S.Expressions.Count);
  832. AssertExpression('Case With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'1');
  833. AssertEquals('1 case label statement',1,S.Elements.Count);
  834. AssertEquals('Correct case for case label 1',TPasImplbeginBlock,TPasElement(S.Elements[0]).ClassType);
  835. B:=TPasImplbeginBlock(S.Elements[0]);
  836. AssertEquals('0 statements in block',0,B.Elements.Count);
  837. AssertNotNull('Have else branch',C.ElseBranch);
  838. AssertEquals('Correct else branch class',TPasImplCaseElse,C.ElseBranch.ClassType);
  839. AssertEquals('2 statements in else branch ',2,TPasImplCaseElse(C.ElseBranch).Elements.Count);
  840. end;
  841. procedure TTestStatementParser.TestCaseIfCaseElse;
  842. Var
  843. C : TPasImplCaseOf;
  844. begin
  845. DeclareVar('integer');
  846. DeclareVar('boolean','b');
  847. TestStatement(['case a of','1 : if b then',' begin end;','else',' end;']);
  848. C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf;
  849. AssertNotNull('Have case expression',C.CaseExpr);
  850. AssertExpression('Case expression',C.CaseExpr,pekIdent,'a');
  851. AssertEquals('Two case labels',2,C.Elements.Count);
  852. AssertNotNull('Have else branch',C.ElseBranch);
  853. AssertEquals('Correct else branch class',TPasImplCaseElse,C.ElseBranch.ClassType);
  854. AssertEquals('0 statement in else branch ',0,TPasImplCaseElse(C.ElseBranch).Elements.Count);
  855. end;
  856. procedure TTestStatementParser.TestCaseIfElse;
  857. Var
  858. C : TPasImplCaseOf;
  859. S : TPasImplCaseStatement;
  860. begin
  861. DeclareVar('integer');
  862. DeclareVar('boolean','b');
  863. TestStatement(['case a of','1 : if b then',' begin end','else','begin','end',' end;']);
  864. C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf;
  865. AssertNotNull('Have case expression',C.CaseExpr);
  866. AssertExpression('Case expression',C.CaseExpr,pekIdent,'a');
  867. AssertEquals('Two case labels',1,C.Elements.Count);
  868. AssertNull('Have no else branch',C.ElseBranch);
  869. S:=TPasImplCaseStatement(C.Elements[0]);
  870. AssertEquals('2 expressions for case 1',1,S.Expressions.Count);
  871. AssertExpression('Case With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'1');
  872. AssertEquals('1 case label statement',1,S.Elements.Count);
  873. AssertEquals('If statement in case label 1',TPasImplIfElse,TPasElement(S.Elements[0]).ClassType);
  874. AssertNotNull('If statement has else block',TPasImplIfElse(S.Elements[0]).ElseBranch);
  875. end;
  876. procedure TTestStatementParser.TestRaise;
  877. Var
  878. R : TPasImplRaise;
  879. begin
  880. DeclareVar('Exception');
  881. TestStatement('Raise A;');
  882. R:=AssertStatement('Raise statement',TPasImplRaise) as TPasImplRaise;
  883. AssertEquals(0,R.Elements.Count);
  884. AssertNotNull(R.ExceptObject);
  885. AssertNull(R.ExceptAddr);
  886. AssertExpression('Expression object',R.ExceptObject,pekIdent,'A');
  887. end;
  888. procedure TTestStatementParser.TestRaiseEmpty;
  889. Var
  890. R : TPasImplRaise;
  891. begin
  892. TestStatement('Raise;');
  893. R:=AssertStatement('Raise statement',TPasImplRaise) as TPasImplRaise;
  894. AssertEquals(0,R.Elements.Count);
  895. AssertNull(R.ExceptObject);
  896. AssertNull(R.ExceptAddr);
  897. end;
  898. procedure TTestStatementParser.TestRaiseAt;
  899. Var
  900. R : TPasImplRaise;
  901. begin
  902. DeclareVar('Exception');
  903. DeclareVar('Pointer','B');
  904. TestStatement('Raise A at B;');
  905. R:=AssertStatement('Raise statement',TPasImplRaise) as TPasImplRaise;
  906. AssertEquals(0,R.Elements.Count);
  907. AssertNotNull(R.ExceptObject);
  908. AssertNotNull(R.ExceptAddr);
  909. AssertExpression('Expression object',R.ExceptAddr,pekIdent,'B');
  910. end;
  911. procedure TTestStatementParser.TestTryFinally;
  912. Var
  913. T : TPasImplTry;
  914. S : TPasImplSimple;
  915. F : TPasImplTryFinally;
  916. begin
  917. TestStatement(['Try',' DoSomething;','finally',' DoSomethingElse','end']);
  918. T:=AssertStatement('Try statement',TPasImplTry) as TPasImplTry;
  919. AssertEquals(1,T.Elements.Count);
  920. AssertNotNull(T.FinallyExcept);
  921. AssertNull(T.ElseBranch);
  922. AssertNotNull(T.Elements[0]);
  923. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  924. S:=TPasImplSimple(T.Elements[0]);
  925. AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomething');
  926. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  927. AssertEquals('Finally statement',TPasImplTryFinally,T.FinallyExcept.ClassType);
  928. F:=TPasImplTryFinally(T.FinallyExcept);
  929. AssertEquals(1,F.Elements.Count);
  930. AssertEquals('Simple statement',TPasImplSimple,TPasElement(F.Elements[0]).ClassType);
  931. S:=TPasImplSimple(F.Elements[0]);
  932. AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse');
  933. end;
  934. procedure TTestStatementParser.TestTryFinallyEmpty;
  935. Var
  936. T : TPasImplTry;
  937. F : TPasImplTryFinally;
  938. begin
  939. TestStatement(['Try','finally','end;']);
  940. T:=AssertStatement('Try statement',TPasImplTry) as TPasImplTry;
  941. AssertEquals(0,T.Elements.Count);
  942. AssertNotNull(T.FinallyExcept);
  943. AssertNull(T.ElseBranch);
  944. AssertEquals('Finally statement',TPasImplTryFinally,T.FinallyExcept.ClassType);
  945. F:=TPasImplTryFinally(T.FinallyExcept);
  946. AssertEquals(0,F.Elements.Count);
  947. end;
  948. procedure TTestStatementParser.TestTryFinallyNested;
  949. Var
  950. T : TPasImplTry;
  951. S : TPasImplSimple;
  952. F : TPasImplTryFinally;
  953. begin
  954. TestStatement(['Try',' DoSomething1;',' Try',' DoSomething2;',' finally',' DoSomethingElse2',' end;','Finally',' DoSomethingElse1','end']);
  955. T:=AssertStatement('Try statement',TPasImplTry) as TPasImplTry;
  956. AssertEquals(2,T.Elements.Count);
  957. AssertNotNull(T.FinallyExcept);
  958. AssertNull(T.ElseBranch);
  959. AssertNotNull(T.Elements[0]);
  960. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  961. S:=TPasImplSimple(T.Elements[0]);
  962. AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomething1');
  963. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  964. AssertEquals('Finally statement',TPasImplTryFinally,T.FinallyExcept.ClassType);
  965. F:=TPasImplTryFinally(T.FinallyExcept);
  966. AssertEquals(1,F.Elements.Count);
  967. AssertEquals('Simple statement',TPasImplSimple,TPasElement(F.Elements[0]).ClassType);
  968. S:=TPasImplSimple(F.Elements[0]);
  969. AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse1');
  970. // inner statement
  971. AssertNotNull(T.Elements[1]);
  972. AssertEquals('Nested try statement',TPasImplTry,TPasElement(T.Elements[1]).ClassType);
  973. T:=TPasImplTry(T.Elements[1]);
  974. AssertEquals(1,T.Elements.Count);
  975. AssertNotNull(T.FinallyExcept);
  976. AssertNull(T.ElseBranch);
  977. AssertNotNull(T.Elements[0]);
  978. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  979. S:=TPasImplSimple(T.Elements[0]);
  980. AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomething2');
  981. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  982. AssertEquals('Finally statement',TPasImplTryFinally,T.FinallyExcept.ClassType);
  983. F:=TPasImplTryFinally(T.FinallyExcept);
  984. AssertEquals(1,F.Elements.Count);
  985. AssertEquals('Simple statement',TPasImplSimple,TPasElement(F.Elements[0]).ClassType);
  986. S:=TPasImplSimple(F.Elements[0]);
  987. AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse2');
  988. end;
  989. procedure TTestStatementParser.TestTryExcept;
  990. Var
  991. T : TPasImplTry;
  992. S : TPasImplSimple;
  993. E : TPasImplTryExcept;
  994. begin
  995. TestStatement(['Try',' DoSomething;','except',' DoSomethingElse','end']);
  996. T:=AssertStatement('Try statement',TPasImplTry) as TPasImplTry;
  997. AssertEquals(1,T.Elements.Count);
  998. AssertNotNull(T.FinallyExcept);
  999. AssertNull(T.ElseBranch);
  1000. AssertNotNull(T.Elements[0]);
  1001. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1002. S:=TPasImplSimple(T.Elements[0]);
  1003. AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomething');
  1004. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1005. AssertEquals('Except statement',TPasImplTryExcept,T.FinallyExcept.ClassType);
  1006. E:=TPasImplTryExcept(T.FinallyExcept);
  1007. AssertEquals(1,E.Elements.Count);
  1008. AssertEquals('Simple statement',TPasImplSimple,TPasElement(E.Elements[0]).ClassType);
  1009. S:=TPasImplSimple(E.Elements[0]);
  1010. AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse');
  1011. end;
  1012. procedure TTestStatementParser.TestTryExceptNested;
  1013. Var
  1014. T : TPasImplTry;
  1015. S : TPasImplSimple;
  1016. E : TPasImplTryExcept;
  1017. begin
  1018. TestStatement(['Try',' DoSomething1;',' try',' DoSomething2;',' except',' DoSomethingElse2',' end','except',' DoSomethingElse1','end']);
  1019. T:=AssertStatement('Try statement',TPasImplTry) as TPasImplTry;
  1020. AssertEquals(2,T.Elements.Count);
  1021. AssertNotNull(T.FinallyExcept);
  1022. AssertNull(T.ElseBranch);
  1023. AssertNotNull(T.Elements[0]);
  1024. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1025. S:=TPasImplSimple(T.Elements[0]);
  1026. AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomething1');
  1027. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1028. AssertEquals('Except statement',TPasImplTryExcept,T.FinallyExcept.ClassType);
  1029. E:=TPasImplTryExcept(T.FinallyExcept);
  1030. AssertEquals(1,E.Elements.Count);
  1031. AssertEquals('Simple statement',TPasImplSimple,TPasElement(E.Elements[0]).ClassType);
  1032. S:=TPasImplSimple(E.Elements[0]);
  1033. AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse1');
  1034. AssertNotNull(T.Elements[1]);
  1035. AssertEquals('Simple statement',TPasImplTry,TPasElement(T.Elements[1]).ClassType);
  1036. T:=TPasImplTry(T.Elements[1]);
  1037. AssertEquals(1,T.Elements.Count);
  1038. AssertNotNull(T.FinallyExcept);
  1039. AssertNull(T.ElseBranch);
  1040. AssertNotNull(T.Elements[0]);
  1041. AssertEquals('Simple statement 2',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1042. S:=TPasImplSimple(T.Elements[0]);
  1043. AssertExpression('DoSomething2 call ',S.Expr,pekIdent,'DoSomething2');
  1044. AssertEquals('Simple statement2',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1045. AssertEquals('Except statement2',TPasImplTryExcept,T.FinallyExcept.ClassType);
  1046. E:=TPasImplTryExcept(T.FinallyExcept);
  1047. AssertEquals(1,E.Elements.Count);
  1048. AssertEquals('Simple statement2',TPasImplSimple,TPasElement(E.Elements[0]).ClassType);
  1049. S:=TPasImplSimple(E.Elements[0]);
  1050. AssertExpression('DoSomethingElse2 call',S.Expr,pekIdent,'DoSomethingElse2');
  1051. end;
  1052. procedure TTestStatementParser.TestTryExceptEmpty;
  1053. Var
  1054. T : TPasImplTry;
  1055. E : TPasImplTryExcept;
  1056. begin
  1057. TestStatement(['Try','except','end;']);
  1058. T:=AssertStatement('Try statement',TPasImplTry) as TPasImplTry;
  1059. AssertEquals(0,T.Elements.Count);
  1060. AssertNotNull(T.FinallyExcept);
  1061. AssertNull(T.ElseBranch);
  1062. AssertEquals('Except statement',TPasImplTryExcept,T.FinallyExcept.ClassType);
  1063. E:=TPasImplTryExcept(T.FinallyExcept);
  1064. AssertEquals(0,E.Elements.Count);
  1065. end;
  1066. procedure TTestStatementParser.TestTryExceptOn;
  1067. Var
  1068. T : TPasImplTry;
  1069. S : TPasImplSimple;
  1070. E : TPasImplTryExcept;
  1071. O : TPasImplExceptOn;
  1072. begin
  1073. TestStatement(['Try',' DoSomething;','except','On E : Exception do','DoSomethingElse;','end']);
  1074. T:=AssertStatement('Try statement',TPasImplTry) as TPasImplTry;
  1075. AssertEquals(1,T.Elements.Count);
  1076. AssertNotNull(T.FinallyExcept);
  1077. AssertNull(T.ElseBranch);
  1078. AssertNotNull(T.Elements[0]);
  1079. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1080. S:=TPasImplSimple(T.Elements[0]);
  1081. AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomething');
  1082. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1083. AssertEquals('Except statement',TPasImplTryExcept,T.FinallyExcept.ClassType);
  1084. E:=TPasImplTryExcept(T.FinallyExcept);
  1085. AssertEquals(1,E.Elements.Count);
  1086. AssertEquals('Except on handler',TPasImplExceptOn,TPasElement(E.Elements[0]).ClassType);
  1087. O:=TPasImplExceptOn(E.Elements[0]);
  1088. AssertEquals(1,O.Elements.Count);
  1089. AssertEquals('Simple statement',TPasImplSimple,TPasElement(O.Elements[0]).ClassType);
  1090. AssertExpression('Exception Variable name',O.VarExpr,pekIdent,'E');
  1091. AssertExpression('Exception Type name',O.TypeExpr,pekIdent,'Exception');
  1092. S:=TPasImplSimple(O.Elements[0]);
  1093. AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse');
  1094. // AssertEquals('Variable name',
  1095. end;
  1096. procedure TTestStatementParser.TestTryExceptOn2;
  1097. Var
  1098. T : TPasImplTry;
  1099. S : TPasImplSimple;
  1100. E : TPasImplTryExcept;
  1101. O : TPasImplExceptOn;
  1102. begin
  1103. TestStatement(['Try',' DoSomething;','except',
  1104. 'On E : Exception do','DoSomethingElse;',
  1105. 'On Y : Exception2 do','DoSomethingElse2;',
  1106. 'end']);
  1107. T:=AssertStatement('Try statement',TPasImplTry) as TPasImplTry;
  1108. AssertEquals(1,T.Elements.Count);
  1109. AssertNotNull(T.FinallyExcept);
  1110. AssertNull(T.ElseBranch);
  1111. AssertNotNull(T.Elements[0]);
  1112. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1113. S:=TPasImplSimple(T.Elements[0]);
  1114. AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomething');
  1115. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1116. AssertEquals('Except statement',TPasImplTryExcept,T.FinallyExcept.ClassType);
  1117. E:=TPasImplTryExcept(T.FinallyExcept);
  1118. AssertEquals(2,E.Elements.Count);
  1119. // Exception handler 1
  1120. AssertEquals('Except on handler',TPasImplExceptOn,TPasElement(E.Elements[0]).ClassType);
  1121. O:=TPasImplExceptOn(E.Elements[0]);
  1122. AssertEquals(1,O.Elements.Count);
  1123. AssertEquals('Simple statement',TPasImplSimple,TPasElement(O.Elements[0]).ClassType);
  1124. AssertExpression('Exception Variable name',O.VarExpr,pekIdent,'E');
  1125. AssertExpression('Exception Type name',O.TypeExpr,pekIdent,'Exception');
  1126. S:=TPasImplSimple(O.Elements[0]);
  1127. AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse');
  1128. // Exception handler 2
  1129. AssertEquals('Except on handler',TPasImplExceptOn,TPasElement(E.Elements[1]).ClassType);
  1130. O:=TPasImplExceptOn(E.Elements[1]);
  1131. AssertEquals(1,O.Elements.Count);
  1132. AssertEquals('Simple statement',TPasImplSimple,TPasElement(O.Elements[0]).ClassType);
  1133. AssertExpression('Exception Variable name',O.VarExpr,pekIdent,'Y');
  1134. AssertExpression('Exception Type name',O.TypeExpr,pekIdent,'Exception2');
  1135. S:=TPasImplSimple(O.Elements[0]);
  1136. AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse2');
  1137. end;
  1138. procedure TTestStatementParser.TestTryExceptOnElse;
  1139. Var
  1140. T : TPasImplTry;
  1141. S : TPasImplSimple;
  1142. E : TPasImplTryExcept;
  1143. O : TPasImplExceptOn;
  1144. EE : TPasImplTryExceptElse;
  1145. I : TPasImplIfElse;
  1146. begin
  1147. DeclareVar('Boolean','b');
  1148. // Check that Else belongs to Except, not to IF
  1149. TestStatement(['Try',' DoSomething;','except','On E : Exception do','if b then','DoSomethingElse;','else','DoSomethingMore;','end']);
  1150. T:=AssertStatement('Try statement',TPasImplTry) as TPasImplTry;
  1151. AssertEquals(1,T.Elements.Count);
  1152. AssertNotNull(T.FinallyExcept);
  1153. AssertNotNull(T.ElseBranch);
  1154. AssertNotNull(T.Elements[0]);
  1155. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1156. S:=TPasImplSimple(T.Elements[0]);
  1157. AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomething');
  1158. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1159. AssertEquals('Except statement',TPasImplTryExcept,T.FinallyExcept.ClassType);
  1160. E:=TPasImplTryExcept(T.FinallyExcept);
  1161. AssertEquals(1,E.Elements.Count);
  1162. AssertEquals('Except on handler',TPasImplExceptOn,TPasElement(E.Elements[0]).ClassType);
  1163. O:=TPasImplExceptOn(E.Elements[0]);
  1164. AssertExpression('Exception Variable name',O.VarExpr,pekIdent,'E');
  1165. AssertExpression('Exception Type name',O.TypeExpr,pekIdent,'Exception');
  1166. AssertEquals(1,O.Elements.Count);
  1167. AssertEquals('Simple statement',TPasImplIfElse,TPasElement(O.Elements[0]).ClassType);
  1168. I:=TPasImplIfElse(O.Elements[0]);
  1169. AssertEquals(1,I.Elements.Count);
  1170. AssertNull('No else barcnh for if',I.ElseBranch);
  1171. AssertEquals('Simple statement',TPasImplSimple,TPasElement(I.Elements[0]).ClassType);
  1172. S:=TPasImplSimple(I.Elements[0]);
  1173. AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse');
  1174. AssertEquals('Except Else statement',TPasImplTryExceptElse,T.ElseBranch.ClassType);
  1175. EE:=TPasImplTryExceptElse(T.ElseBranch);
  1176. AssertEquals(1,EE.Elements.Count);
  1177. AssertNotNull(EE.Elements[0]);
  1178. AssertEquals('Simple statement',TPasImplSimple,TPasElement(EE.Elements[0]).ClassType);
  1179. S:=TPasImplSimple(EE.Elements[0]);
  1180. AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomethingMore');
  1181. end;
  1182. procedure TTestStatementParser.TestTryExceptOnIfElse;
  1183. Var
  1184. T : TPasImplTry;
  1185. S : TPasImplSimple;
  1186. E : TPasImplTryExcept;
  1187. O : TPasImplExceptOn;
  1188. EE : TPasImplTryExceptElse;
  1189. begin
  1190. TestStatement(['Try',' DoSomething;','except','On E : Exception do','DoSomethingElse;','else','DoSomethingMore;','end']);
  1191. T:=AssertStatement('Try statement',TPasImplTry) as TPasImplTry;
  1192. AssertEquals(1,T.Elements.Count);
  1193. AssertNotNull(T.FinallyExcept);
  1194. AssertNotNull(T.ElseBranch);
  1195. AssertNotNull(T.Elements[0]);
  1196. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1197. S:=TPasImplSimple(T.Elements[0]);
  1198. AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomething');
  1199. AssertEquals('Simple statement',TPasImplSimple,TPasElement(T.Elements[0]).ClassType);
  1200. AssertEquals('Except statement',TPasImplTryExcept,T.FinallyExcept.ClassType);
  1201. E:=TPasImplTryExcept(T.FinallyExcept);
  1202. AssertEquals(1,E.Elements.Count);
  1203. AssertEquals('Except on handler',TPasImplExceptOn,TPasElement(E.Elements[0]).ClassType);
  1204. O:=TPasImplExceptOn(E.Elements[0]);
  1205. AssertExpression('Exception Variable name',O.VarExpr,pekIdent,'E');
  1206. AssertExpression('Exception Type name',O.TypeExpr,pekIdent,'Exception');
  1207. AssertEquals(1,O.Elements.Count);
  1208. AssertEquals('Simple statement',TPasImplSimple,TPasElement(O.Elements[0]).ClassType);
  1209. S:=TPasImplSimple(O.Elements[0]);
  1210. AssertExpression('DoSomethingElse call',S.Expr,pekIdent,'DoSomethingElse');
  1211. AssertEquals('Except Else statement',TPasImplTryExceptElse,T.ElseBranch.ClassType);
  1212. EE:=TPasImplTryExceptElse(T.ElseBranch);
  1213. AssertEquals(1,EE.Elements.Count);
  1214. AssertNotNull(EE.Elements[0]);
  1215. AssertEquals('Simple statement',TPasImplSimple,TPasElement(EE.Elements[0]).ClassType);
  1216. S:=TPasImplSimple(EE.Elements[0]);
  1217. AssertExpression('DoSomething call',S.Expr,pekIdent,'DoSomethingMore');
  1218. end;
  1219. initialization
  1220. RegisterTests([TTestStatementParser]);
  1221. end.