2
0
Эх сурвалжийг харах

test:
+ add a simple test for the 'for-in' loop

git-svn-id: branches/paul/features@13924 -

paul 16 жил өмнө
parent
commit
82e5f936cc

+ 1 - 0
.gitattributes

@@ -8206,6 +8206,7 @@ tests/test/texception9.pp svneol=native#text/plain
 tests/test/tfillchr.pp svneol=native#text/plain
 tests/test/tfillchr.pp svneol=native#text/plain
 tests/test/tfinal1.pp svneol=native#text/pascal
 tests/test/tfinal1.pp svneol=native#text/pascal
 tests/test/tfinal2.pp svneol=native#text/pascal
 tests/test/tfinal2.pp svneol=native#text/pascal
+tests/test/tforin1.pp svneol=native#text/pascal
 tests/test/tfpu1.pp svneol=native#text/plain
 tests/test/tfpu1.pp svneol=native#text/plain
 tests/test/tfpu2.pp svneol=native#text/plain
 tests/test/tfpu2.pp svneol=native#text/plain
 tests/test/tfpu3.pp svneol=native#text/plain
 tests/test/tfpu3.pp svneol=native#text/plain

+ 69 - 0
tests/test/tforin1.pp

@@ -0,0 +1,69 @@
+program project1;
+
+{$mode objfpc}{$H+}
+{$apptype console}
+uses
+  Classes, typinfo;
+
+type
+  TColor = (clRed, clGreen, clBlue);
+
+procedure LoopTypes;
+type
+  IntRange = 0..9;
+var
+  c: TColor;
+  i: integer;
+begin
+  // check loop in range
+  for i in IntRange do
+    writeln(i);
+
+  // check loop in enum
+  for c in TColor do
+    writeln(GetEnumName(TypeInfo(c), ord(c)));
+end;
+
+procedure LoopString(s: string);
+var
+  c: char;
+begin
+  // check loop in string
+  for c in s do
+    write(c);
+  WriteLn;
+end;
+
+procedure LoopArray(a: array of integer);
+var
+  i: integer;
+begin
+  // check loop in array
+  for i in a do
+    write(i);
+  WriteLn;
+end;
+
+procedure LoopSet;
+const
+  s = [clRed, clBlue];
+var
+  c: TColor;
+begin
+  // check loop in set
+  for c in s do
+    writeln(GetEnumName(TypeInfo(c), ord(c)));
+end;
+
+var
+  a: array[0..2] of integer;
+begin
+  LoopTypes;
+  LoopString('test');
+  a[0]:=0;
+  a[1]:=1;
+  a[2]:=2;
+  LoopArray(a);
+  LoopSet;
+end.
+