* fixed test to reflect current ideas how generics should be used

git-svn-id: trunk@5163 -
This commit is contained in:
florian 2006-11-01 23:15:25 +00:00
parent be2b715d3c
commit 107721f760

View File

@ -1,30 +1,30 @@
{$mode objfpc}
type
generic PListItem<_T>=^specialize TListItem<_T>;
generic TListItem<_T>=record
data : _T;
next : specialize PListItem<_T>;
end;
generic TList<_T>=class(TObject)
first : specialize PListItem<_T>;
type
PListItem = ^TListItem;
TListItem = record
data : _T;
next : PListItem;
end;
var
first : PListItem;
procedure Add(item: _T);
end;
procedure TList.Add(data: _T);
procedure TList.Add(item: _T);
var
newitem : specialize PListItem<_T>;
newitem : PListItem;
begin
new(newitem);
newitem.data:=data;
newitem.next:=first;
newitem^.data:=item;
newitem^.next:=first;
end;
type
TMyIntList = specialize TList<integer>;
TMyStringList = specialize TList<string>;
var
ilist : TMyIntList;
slist : TMyStringList;
@ -35,16 +35,17 @@ begin
ilist.Add(someInt);
ilist.Add(someInt+1);
writeln(ilist.first^.data);
if ilist.data<>10 then
if ilist.first^.data<>10 then
halt(1);
writeln(ilist.first^.next^.data);
if ilist.data<>11 then
if ilist.first^.data<>11 then
halt(1);
slist := TMyStringList.Create;
slist.Add('Test1');
slist.Add('Test2');
writeln(slist.data);
if slist.data<>'Test1' then
writeln(slist.first^.data);
if slist.first^.data<>'Test1' then
halt(1);
writeln('ok');
end.