Parcourir la source

* fix case of string with ranges as labels
+ add test

git-svn-id: trunk@38860 -

svenbarth il y a 7 ans
Parent
commit
cfa373a8cf
3 fichiers modifiés avec 44 ajouts et 1 suppressions
  1. 1 0
      .gitattributes
  2. 1 1
      compiler/nset.pas
  3. 42 0
      tests/tbs/tb0642.pp

+ 1 - 0
.gitattributes

@@ -11521,6 +11521,7 @@ tests/tbs/tb0637.pp svneol=native#text/pascal
 tests/tbs/tb0638.pp svneol=native#text/pascal
 tests/tbs/tb0639.pp svneol=native#text/pascal
 tests/tbs/tb0641.pp svneol=native#text/pascal
+tests/tbs/tb0642.pp svneol=native#text/pascal
 tests/tbs/tb205.pp svneol=native#text/plain
 tests/tbs/tb610.pp svneol=native#text/pascal
 tests/tbs/tb613.pp svneol=native#text/plain

+ 1 - 1
compiler/nset.pas

@@ -723,7 +723,7 @@ implementation
                     newcheck:=@check;
                   labitem:=TLinkedListCaseLabelItem(lablist[j]).casenode;
                   newcheck^:=caddnode.create(equaln,left.getcopy,labitem^._low_str.getcopy);
-                  if (labtree^._low_str.fullcompare(labtree^._high_str)<>0) then
+                  if (labitem^._low_str.fullcompare(labitem^._high_str)<>0) then
                     begin
                       newcheck^.nodetype:=gten;
                       newcheck^:=caddnode.create(

+ 42 - 0
tests/tbs/tb0642.pp

@@ -0,0 +1,42 @@
+program tb0642;
+{$mode objfpc}
+{$h+}
+
+type
+  TResult = (
+    resFirst,
+    resSecond,
+    resElse
+  );
+
+function Test(const aStr: String): TResult;
+begin
+  case aStr of
+    'Hello', 'Hello2': Exit(resFirst);
+    'a'..'z': Exit(resSecond);
+    else
+      Exit(resElse);
+  end;
+end;
+
+begin
+  if Test('Hello') <> resFirst then
+    Halt(1);
+  if Test('Hello2') <> resFirst then
+    Halt(2);
+  if Test('a') <> resSecond then
+    Halt(3);
+  if Test('z') <> resSecond then
+    Halt(4);
+  if Test('g') <> resSecond then
+    Halt(5);
+  if Test('alpha') <> resSecond then
+    Halt(6);
+  if Test('zeta') <> resElse then
+    Halt(7);
+  if Test('A') <> resElse then
+    Halt(8);
+  if Test('1') <> resElse then
+    Halt(9);
+  Writeln('ok');
+end.