Răsfoiți Sursa

* make tgeneric10 more complex

git-svn-id: trunk@5359 -
micha 19 ani în urmă
părinte
comite
90b19e0be2
4 a modificat fișierele cu 38 adăugiri și 23 ștergeri
  1. 1 0
      .gitattributes
  2. 5 19
      tests/test/tgeneric10.pp
  3. 2 4
      tests/test/tgeneric11.pp
  4. 30 0
      tests/test/ugeneric10.pp

+ 1 - 0
.gitattributes

@@ -6600,6 +6600,7 @@ tests/test/tvarset1.pp svneol=native#text/plain
 tests/test/twide1.pp svneol=native#text/plain
 tests/test/twide2.pp svneol=native#text/plain
 tests/test/uabstrcl.pp svneol=native#text/plain
+tests/test/ugeneric10.pp svneol=native#text/plain
 tests/test/ugeneric3.pp svneol=native#text/plain
 tests/test/ugeneric4.pp svneol=native#text/plain
 tests/test/uimpluni1.pp svneol=native#text/plain

+ 5 - 19
tests/test/tgeneric10.pp

@@ -1,37 +1,23 @@
 {$mode objfpc}
 
-type
-   generic TList<_T>=class(TObject)
-   type public
-     TCompareFunc = function(const Item1, Item2: _T): Integer;
-   var public
-     data : _T;
-     compare : TCompareFunc;
-     procedure Add(item: _T);
-   end;
+uses
+  ugeneric10;
 
-procedure TList.Add(item: _T);
-begin
-  data:=item;
-  if compare(data, 20) <= 0 then
-    halt(1);
-end;
+type
+  TMyIntList = specialize TList<integer>;
 
 function CompareInt(Item1, Item2: Integer): Integer;
 begin
   Result := Item2 - Item1;
 end;
 
-type
-  TMyIntList = specialize TList<integer>;
-
 var
   ilist : TMyIntList;
   someInt : integer;
 begin
   someInt:=10;
   ilist := TMyIntList.Create;
-  ilist.compare := ilist.TCompareFunc(@CompareInt);
   ilist.add(someInt);
+  ilist.sort(ilist.TCompareFunc(@CompareInt));
   writeln('ok');
 end.

+ 2 - 4
tests/test/tgeneric11.pp

@@ -2,12 +2,10 @@
 
 type
    generic TList<_T>=class(TObject)
-   type protected
-     TSelf = specialize TList<_T>;
    var public 
      data : _T;
      procedure Add(item: _T);
-     procedure Assign(Source: TSelf);
+     procedure Assign(Source: TList);
    end;
 
 procedure TList.Add(item: _T);
@@ -15,7 +13,7 @@ begin
   data:=item;
 end;
 
-procedure TList.Assign(Source: TSelf);
+procedure TList.Assign(Source: TList);
 begin
   data:=Source.data;
 end;

+ 30 - 0
tests/test/ugeneric10.pp

@@ -0,0 +1,30 @@
+unit ugeneric10;
+
+{$mode objfpc}
+
+interface
+
+type
+   generic TList<_T>=class(TObject)
+   type public
+     TCompareFunc = function(const Item1, Item2: _T): Integer;
+   var public
+     data : _T;
+     procedure Add(item: _T);
+     procedure Sort(compare: TCompareFunc);
+   end;
+
+implementation
+
+procedure TList.Add(item: _T);
+begin
+  data:=item;
+end;
+
+procedure TList.Sort(compare: TCompareFunc);
+begin
+  if compare(data, 20) <= 0 then
+    halt(1);
+end;
+
+end.