summaryrefslogtreecommitdiff
path: root/tests/test/tarray22.pp
blob: 6466e9e6ef3f455893966c0caa5ac18267655ecc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{ %OPT = -gh }

program tarray22;

{$mode objfpc}{$h+}

type
  TIntegerArray = array of Integer;
  TStringArray = array of String;

generic procedure CheckArray<T>(const Actual, Expected: array of T; Code: LongInt);
var
  i: SizeInt;
begin
  if Length(Actual) <> Length(Expected) then
    Halt(Code);
  for i := 0 to High(Actual) do
    if Actual[i] <> Expected[i] then
      Halt(Code);
end;

procedure TestOpen(const A: array of Integer; Exp: array of Integer; Code: LongInt);
var
  B: array of Integer;
begin
  B := Copy(A);
  specialize CheckArray<Integer>(B, Exp, Code);
end;

procedure TestOpen2(const A: array of Integer; Exp: array of Integer; Code: LongInt);
var
  B: array of Integer;
begin
  B := Copy(A, 1, 2);
  specialize CheckArray<Integer>(B, Exp, Code);
end;

procedure TestDyn(const A: TIntegerArray; Exp: array of Integer; Code: LongInt);
var
  B: array of Integer;
begin
  B := Copy(A);
  specialize CheckArray<Integer>(B, Exp, Code);
end;

procedure TestDyn2(const A: TIntegerArray; Exp: array of Integer; Code: LongInt);
var
  B: array of Integer;
begin
  B := Copy(A, 1, 2);
  specialize CheckArray<Integer>(B, Exp, Code);
end;

procedure TestOpen(const A: array of String; Exp: array of String; Code: LongInt);
var
  B: array of String;
begin
  B := Copy(A);
  specialize CheckArray<String>(B, Exp, Code);
end;

procedure TestOpen2(const A: array of String; Exp: array of String; Code: LongInt);
var
  B: array of String;
begin
  B := Copy(A, 1, 2);
  specialize CheckArray<String>(B, Exp, Code);
end;

procedure TestDyn(const A: TStringArray; Exp: array of String; Code: LongInt);
var
  B: array of String;
begin
  B := Copy(A);
  specialize CheckArray<String>(B, Exp, Code);
end;

procedure TestDyn2(const A: TStringArray; Exp: array of String; Code: LongInt);
var
  B: array of String;
begin
  B := Copy(A, 1, 2);
  specialize CheckArray<String>(B, Exp, Code);
end;

begin
  HaltOnNotReleased := True;

  TestOpen([0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], 1);
  TestOpen2([0, 1, 2, 3, 4, 5], [1, 2], 2);
  TestDyn([0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], 3);
  TestDyn2([0, 1, 2, 3, 4, 5], [1, 2], 4);

  TestOpen(['Alpha', 'Beta', 'Gamma', 'Delta'], ['Alpha', 'Beta', 'Gamma', 'Delta'], 5);
  TestOpen2(['Alpha', 'Beta', 'Gamma', 'Delta'], ['Beta', 'Gamma'], 6);
  TestDyn(['Alpha', 'Beta', 'Gamma', 'Delta'], ['Alpha', 'Beta', 'Gamma', 'Delta'], 7);
  TestDyn2(['Alpha', 'Beta', 'Gamma', 'Delta'], ['Beta', 'Gamma'], 8);
end.