Browse Source

* Added tests for #41210

J. Gareth "Curious Kit" Moreton 4 months ago
parent
commit
7719a5a5a7
2 changed files with 73 additions and 0 deletions
  1. 19 0
      tests/webtbs/tw41210.pp
  2. 54 0
      tests/webtbs/tw41210a.pp

+ 19 - 0
tests/webtbs/tw41210.pp

@@ -0,0 +1,19 @@
+{ %OPT=-O3 }
+{$mode objfpc} {$coperators on}
+program tw41210;
+var
+  x, oops: uint32;
+begin
+  x := random(0) + $123456;
+  oops := 0;
+  x := x shr 8;
+  if byte(x) <> $34 then oops += 1;
+  x := x shr 8;
+  if byte(x) <> $12 then oops += 2;
+  if oops <> 0 then
+    begin
+      writeln('FAILED: oops = ', oops);
+      Halt(1);
+    end;
+  Writeln('ok');
+end.

+ 54 - 0
tests/webtbs/tw41210a.pp

@@ -0,0 +1,54 @@
+{ %OPT=-O2 }
+program tw41210b;
+{$MODE OBJFPC}
+function strspn(s, accept: pointer): integer;
+var
+  p: PCardinal;
+  c: AnsiChar;
+  d: cardinal;
+begin
+  // returns size of initial segment of s which are in accept
+  result := 0;
+  repeat
+    c := PAnsiChar(s)[result];
+    if c = #0 then
+      break;
+    p := accept;
+    repeat // stop as soon as we find any character not from accept
+      d := p^;
+      inc(p);
+      if AnsiChar(d) = c then
+        break
+      else if AnsiChar(d) = #0 then
+        exit;
+      d := d shr 8;
+      if AnsiChar(d) = c then
+        break
+      else if AnsiChar(d) = #0 then
+        exit;
+      d := d shr 8;
+      if AnsiChar(d) = c then
+        break
+      else if AnsiChar(d) = #0 then
+        exit;
+      d := d shr 8;
+      if AnsiChar(d) = c then
+        break
+      else if AnsiChar(d) = #0 then
+        exit;
+    until false;
+    inc(result);
+  until false;
+end;
+
+var
+  Output: integer;
+begin
+  Output := strspn(PAnsiChar('abcdef'), PAnsiChar('debca'));
+  if Output <> 5 then
+    begin
+      WriteLn('FAILED: Returned ', Output, ' instead of 5');
+      Halt(1);
+    end;
+  WriteLn('ok');
+end.