summaryrefslogtreecommitdiff
path: root/tests/test/terecs15.pp
blob: 88bcf39de39c79af2d07fa18a317d63239d58459 (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
program terecs15;

{$mode delphi}

type

  { TRec }

  TRec = record
  private
    X: Integer;
    Y: Integer;
  public
    // delphi does not allow constructors without arguments
    constructor CreateAndTest(dummy: byte);
    constructor Create(dummy: boolean); overload;
    constructor Create(AX, AY: Integer); overload;
    constructor Create(AY: Integer); overload;
  end;

{ TRec }

constructor TRec.CreateAndTest(dummy: byte);
begin
  X := 1;
  if X <> 1 then
    halt(1);
  Y := 2;
  if Y <> 2 then
    halt(2);
end;

constructor TRec.Create(dummy: boolean);
begin
  X := 10;
  Y := 20;
end;

constructor TRec.Create(AX, AY: Integer);
begin
  X := AX;
  Y := AY;
end;

constructor TRec.Create(AY: Integer);
begin
  Create(false);
  Y := AY;
end;

procedure TestRec(R: TRec; ExpectedX, ExpectedY: Integer; ErrorX, ErrorY: Integer);
begin
  if R.X <> ExpectedX then
    halt(ErrorX);
  if R.Y <> ExpectedY then
    halt(ErrorY);
end;

var
  R: TRec;
begin
  R.CreateAndTest(0);
  R := TRec.Create(false);
  if R.X <> 10 then
    halt(3);
  if R.Y <> 20 then
    halt(4);
  TestRec(TRec.Create(1, 2), 1, 2, 5, 6);
  TestRec(TRec.Create(2), 10, 2, 7, 8);
  // delphi has an internal error here
  TestRec(R.Create(false), 10, 20, 9, 10);
end.