Browse Source

pastojs: test range check string[] by reference

git-svn-id: trunk@38838 -
Mattias Gaertner 7 years ago
parent
commit
3bc75e6627
2 changed files with 6 additions and 4 deletions
  1. 2 2
      packages/pastojs/src/fppas2js.pp
  2. 4 2
      packages/pastojs/tests/tcmodules.pas

+ 2 - 2
packages/pastojs/src/fppas2js.pp

@@ -285,6 +285,7 @@ Works:
       enumrange:=, enumrange+=, char:=, char+=, charrange:=, charrange+=
   - procedure argument int, enum, intrange, enumrange, char, charrange
   - array[index1,index2,...]  read and assign
+  - string[index]  read and assign
 - Interfaces:
   - autogenerate GUID
   - method resolution
@@ -343,9 +344,8 @@ ToDos:
   v:=a[0]  gives Local variable "a" is assigned but never used
 - setlength(dynarray)  modeswitch to create a copy
 - range checks:
-  - string[index]
   - case duplicates
-- typecast longint(highprecint) -> value & $ffffffff
+- typecast byte(longword) -> value & $ff
 - static arrays
   - a[] of record
   - clone multi dim static array

+ 4 - 2
packages/pastojs/tests/tcmodules.pas

@@ -20108,7 +20108,7 @@ begin
   StartProgram(false);
   Add([
   '{$R+}',
-  'procedure DoIt;',
+  'procedure DoIt(var h: string);',
   'var',
   '  s: string;',
   '  i: longint;',
@@ -20116,18 +20116,20 @@ begin
   'begin',
   '  c:=s[1];',
   '  s[i]:=s[i];',
+  '  h[i]:=h[i];',
   'end;',
   'begin',
   '']);
   ConvertProgram;
   CheckSource('TestRangeChecks_StringIndex',
     LinesToStr([ // statements
-    'this.DoIt = function () {',
+    'this.DoIt = function (h) {',
     '  var s = "";',
     '  var i = 0;',
     '  var c = "";',
     '  c = rtl.rcc(rtl.rcCharAt(s, 0), 0, 65535);',
     '  s = rtl.rcSetCharAt(s, i - 1, rtl.rcCharAt(s, i - 1));',
+    '  h.set(rtl.rcSetCharAt(h.get(), i - 1, rtl.rcCharAt(h.get(), i - 1)));',
     '};',
     '']),
     LinesToStr([ // $mod.$main