Browse Source

Added some tests for:
- multiple symbols with a similar name
- hint directives
- inline specializations

git-svn-id: branches/svenbarth/generics@17542 -

svenbarth 14 years ago
parent
commit
66b667cc18

+ 19 - 0
.gitattributes

@@ -9800,8 +9800,27 @@ tests/test/tgeneric32.pp svneol=native#text/pascal
 tests/test/tgeneric33.pp svneol=native#text/pascal
 tests/test/tgeneric34.pp svneol=native#text/pascal
 tests/test/tgeneric35.pp svneol=native#text/pascal
+tests/test/tgeneric36.pp svneol=native#text/pascal
+tests/test/tgeneric37.pp svneol=native#text/pascal
+tests/test/tgeneric38.pp svneol=native#text/pascal
+tests/test/tgeneric39.pp svneol=native#text/pascal
 tests/test/tgeneric4.pp svneol=native#text/plain
+tests/test/tgeneric40.pp svneol=native#text/pascal
+tests/test/tgeneric41.pp svneol=native#text/pascal
+tests/test/tgeneric42.pp svneol=native#text/pascal
+tests/test/tgeneric43.pp svneol=native#text/pascal
+tests/test/tgeneric44.pp svneol=native#text/pascal
+tests/test/tgeneric45.pp svneol=native#text/pascal
+tests/test/tgeneric46.pp svneol=native#text/pascal
+tests/test/tgeneric47.pp svneol=native#text/pascal
+tests/test/tgeneric48.pp svneol=native#text/pascal
+tests/test/tgeneric49.pp svneol=native#text/pascal
 tests/test/tgeneric5.pp svneol=native#text/plain
+tests/test/tgeneric50.pp svneol=native#text/pascal
+tests/test/tgeneric51.pp svneol=native#text/pascal
+tests/test/tgeneric52.pp svneol=native#text/pascal
+tests/test/tgeneric53.pp svneol=native#text/pascal
+tests/test/tgeneric54.pp svneol=native#text/pascal
 tests/test/tgeneric6.pp svneol=native#text/plain
 tests/test/tgeneric7.pp svneol=native#text/plain
 tests/test/tgeneric8.pp svneol=native#text/plain

+ 25 - 0
tests/test/tgeneric36.pp

@@ -0,0 +1,25 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: class only }
+program tgeneric36;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest = class
+
+  end;
+
+  TTest<T> = class
+
+  end;
+
+  TTest<T, S> = class
+
+  end;
+
+begin
+
+end.

+ 25 - 0
tests/test/tgeneric37.pp

@@ -0,0 +1,25 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: record only }
+program tgeneric37;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest = record
+
+  end;
+
+  TTest<T> = record
+
+  end;
+
+  TTest<T, S> = record
+
+  end;
+
+begin
+
+end.

+ 25 - 0
tests/test/tgeneric38.pp

@@ -0,0 +1,25 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: interface only }
+program tgeneric38;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest = interface
+
+  end;
+
+  TTest<T> = interface
+
+  end;
+
+  TTest<T, S> = interface
+
+  end;
+
+begin
+
+end.

+ 19 - 0
tests/test/tgeneric39.pp

@@ -0,0 +1,19 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: procvars only }
+program tgeneric39;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest = procedure;
+
+  TTest<T> = procedure;
+
+  TTest<T, S> = procedure;
+
+begin
+
+end.

+ 19 - 0
tests/test/tgeneric40.pp

@@ -0,0 +1,19 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: arrays only }
+program tgeneric40;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest = array of Integer;
+
+  TTest<T> = array of Integer;
+
+  TTest<T, S> = array of Integer;
+
+begin
+
+end.

+ 19 - 0
tests/test/tgeneric41.pp

@@ -0,0 +1,19 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: method vars only }
+program tgeneric41;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest = procedure of object;
+
+  TTest<T> = procedure of object;
+
+  TTest<T, S> = procedure of object;
+
+begin
+
+end.

+ 26 - 0
tests/test/tgeneric42.pp

@@ -0,0 +1,26 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: class only
+  Note: This tests a different code path than in the compiler than tgeneric36! }
+program tgeneric42;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest<T> = class
+
+  end;
+
+  TTest = class
+
+  end;
+
+  TTest<T, S> = class
+
+  end;
+
+begin
+
+end.

+ 26 - 0
tests/test/tgeneric43.pp

@@ -0,0 +1,26 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: record only
+  Note: This tests a different code path than in the compiler than tgeneric37! }
+program tgeneric43;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest<T> = record
+
+  end;
+
+  TTest = record
+
+  end;
+
+  TTest<T, S> = record
+
+  end;
+
+begin
+
+end.

+ 26 - 0
tests/test/tgeneric44.pp

@@ -0,0 +1,26 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: interface only
+  Note: This tests a different code path than in the compiler than tgeneric38! }
+program tgeneric44;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest<T> = interface
+
+  end;
+
+  TTest = interface
+
+  end;
+
+  TTest<T, S> = interface
+
+  end;
+
+begin
+
+end.

+ 20 - 0
tests/test/tgeneric45.pp

@@ -0,0 +1,20 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: procvars only
+  Note: This tests a different code path than in the compiler than tgeneric39! }
+program tgeneric45;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest<T> = procedure;
+
+  TTest = procedure;
+
+  TTest<T, S> = procedure;
+
+begin
+
+end.

+ 20 - 0
tests/test/tgeneric46.pp

@@ -0,0 +1,20 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: arrays only
+  Note: This tests a different code path than in the compiler than tgeneric40! }
+program tgeneric40;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest<T> = array of Integer;
+
+  TTest = array of Integer;
+
+  TTest<T, S> = array of Integer;
+
+begin
+
+end.

+ 20 - 0
tests/test/tgeneric47.pp

@@ -0,0 +1,20 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: method vars only
+  Note: This tests a different code path than in the compiler than tgeneric39! }
+program tgeneric47;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest<T> = procedure of object;
+
+  TTest = procedure of object;
+
+  TTest<T, S> = procedure of object;
+
+begin
+
+end.

+ 28 - 0
tests/test/tgeneric48.pp

@@ -0,0 +1,28 @@
+{ %NORUN }
+
+{ in mode Delphi generic types might be overloaded - here: a mix }
+program tgeneric48;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest = class
+  end;
+
+  TTest<T> = record
+  end;
+
+  TTest<T, S> = interface
+  end;
+
+  TTest<T, S, R> = procedure;
+
+  TTest<T, S, R, Q> = array of Integer;
+
+  TTest<T, S, R, Q, P> = procedure of object;
+
+begin
+
+end.

+ 38 - 0
tests/test/tgeneric49.pp

@@ -0,0 +1,38 @@
+{ %NORUN }
+
+{ This tests whether the correct deprecated messages are printed. As I don't
+  know of a way to check these inside a test this needs to be done by hand }
+program tgeneric49;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest<T> = class
+
+  end deprecated 'Message A';
+
+  TTest = class
+
+  end deprecated 'Message B';
+
+  // this should print 'Message A'
+  TTestInteger = TTest<Integer>;
+
+  FooInt = Integer deprecated;
+
+  // this should print that TTest<T> and FooInt are deprecated
+  TTestFooInt = TTest<FooInt>;
+
+var
+  // this should print 'Message B'
+  t: TTest;
+  // this should print nothing
+  t2: TTestInteger;
+  // this should print that TTest<T> and FooInt are deprecated
+  t3: TTest<FooInt>;
+begin
+  // this should print that TTest<T> and FooInt are deprecated
+  t3 := TTest<FooInt>.Create;
+end.

+ 29 - 0
tests/test/tgeneric50.pp

@@ -0,0 +1,29 @@
+{ %NORUN }
+
+{ this tests that hint directives defined for a generic only apply when
+  specializung a generic and that specializations may introduce their own
+  directives }
+program tgeneric50;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TTest<T> = class
+
+  end deprecated 'Message A' platform;
+
+  // this will print that TTest<T> is deprecated and platform dependant
+  TTestInteger = TTest<Integer> deprecated 'Message B' experimental;
+  TTestString = TTest<String>;
+
+var
+  // this will print that TTestInteger is deprecated and experimental
+  t: TTestInteger;
+  // this will print nothing
+  t2: TTestString;
+begin
+  // this will print that TTest<T> is deprecated and platform dependant
+  t2 := TTest<String>.Create;
+end.

+ 39 - 0
tests/test/tgeneric51.pp

@@ -0,0 +1,39 @@
+{ this tests that simple inline specializations work }
+program tgeneric51;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+{$apptype console}
+
+type
+  TTest<T> = class
+    function Test(a: T): T;
+    class function ClassTest(a: T): T;
+  end;
+
+function TTest<T>.Test(a: T): T;
+begin
+  Result := a;
+end;
+
+class function TTest<T>.ClassTest(a: T): T;
+begin
+  Result := a;
+end;
+
+var
+  t: TTest<Integer>;
+  res: Integer;
+begin
+  t := TTest<Integer>.Create;
+  res := t.Test(42);
+  Writeln('t.Test: ', res);
+  if res <> 42 then
+    Halt(1);
+  res := TTest<Integer>.ClassTest(42);
+  Writeln('t.ClassTest: ', res);
+  if res <> 42 then
+    Halt(2);
+  Writeln('ok');
+end.

+ 38 - 0
tests/test/tgeneric52.pp

@@ -0,0 +1,38 @@
+{ this tests that forced typecasts to inline specialized types work }
+program tgeneric52;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+{$apptype console}
+
+type
+  TTest = class
+    function Test: Integer;
+  end;
+
+  TTestGen<T> = class(TTest)
+    function Test: Integer;
+  end;
+
+function TTest.Test: Integer;
+begin
+  Result := 1;
+end;
+
+function TTestGen<T>.Test: Integer;
+begin
+  Result := 2;
+end;
+
+var
+  t: TTest;
+  res: Integer;
+begin
+  t := TTestGen<Integer>.Create;
+  res := TTestGen<Integer>(t).Test;
+  Writeln('t.Test: ', res);
+  if res <> 2 then
+    Halt(1);
+  Writeln('ok');
+end.

+ 39 - 0
tests/test/tgeneric53.pp

@@ -0,0 +1,39 @@
+{ this tests that checked typecasts to inline specialized types work }
+program tgeneric53;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+{$apptype console}
+
+type
+  TTest = class
+    function Test: Integer;
+  end;
+
+  TTestGen<T> = class(TTest)
+    function Test: Integer;
+  end;
+
+function TTest.Test: Integer;
+begin
+  Result := 1;
+end;
+
+function TTestGen<T>.Test: Integer;
+begin
+  Result := 2;
+end;
+
+var
+  t: TTest;
+  res: Integer;
+begin
+  t := TTestGen<Integer>.Create;
+  res := (t as TTestGen<Integer>).Test;
+  Writeln('t.Test: ', res);
+  if res <> 2 then
+    Halt(1);
+  Writeln('ok');
+end.
+

+ 40 - 0
tests/test/tgeneric54.pp

@@ -0,0 +1,40 @@
+{ this tests that type checks for inline specialized types work }
+program tgeneric53;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+{$apptype console}
+
+type
+  TTest = class
+    function Test: Integer;
+  end;
+
+  TTestGen<T> = class(TTest)
+    function Test: Integer;
+  end;
+
+function TTest.Test: Integer;
+begin
+  Result := 1;
+end;
+
+function TTestGen<T>.Test: Integer;
+begin
+  Result := 2;
+end;
+
+var
+  t: TTest;
+begin
+  t := TTestGen<Integer>.Create;
+  if t is TTestGen<Integer> then
+    Writeln('t is a TTestGen<Integer>')
+  else begin
+    Writeln('t is not a TTestGen<Integer>');
+    Halt(1);
+  end;
+  Writeln('ok');
+end.
+