summaryrefslogtreecommitdiff
path: root/tests/test/tisconstvalue1.pp
blob: 63d124cb4c0ad68c07044609f3b52fb5e4df903a (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
program tisconstvalue1;

{$mode objfpc}
{$modeswitch advancedrecords}

type
  TTestLongInt = record
    a: LongInt;
  end;

  TTestAnsiString = record
    a: AnsiString;
  end;
{
  TTestManaged = record
    a: LongInt;
    class operator Initialize(var aTestManaged: TTestManaged);
  end;

  class operator TTestManaged.Initialize(var aTestManaged: TTestManaged);
  begin
    aTestManaged.a := 42;
  end;
}
type
  TDynArrayLongInt = array of LongInt;
  TStaticArrayAnsiString = array[0..4] of AnsiString;

  TEnum = (eOne, eTwo, eThree);
  TSet = set of (sOne, sTwo, sThree);

const
  // untyped
  Number = 100;
  Str = 'Hello World!';
  Dbl = 1.1;
  NilPtr = nil;
  IsConst = True;
  GUID = '{10101010-1010-0101-1001-110110110110}';
  // typed
  IntConst: Integer = 13;
  RealConst: Real = 12;
  Alphabet: array [1..26] of char =
       ('A','B','C','D','E','F','G','H','I',
        'J','K','L','M','N','O','P','Q','R',
        'S','T','U','V','W','X','Y','Z');
  MyGUID: TGUID = '{10101010-1010-0101-1001-110110110110}';
  Bool: Boolean = False;

var
  l: LongInt;
  o: TObject;
  _as: AnsiString;
  lir: TTestLongInt;
  asr: TTestAnsiString;
  //mr: TTestManaged;
  liarr: TDynArrayLongInt;
  sasarr: TStaticArrayAnsiString;

begin
  l := 1;
  if IsConstValue(l) then
    Halt(1);

  o := TObject.Create;
  try
    if IsConstValue(o) then
      Halt(2);
  finally
    o.Free;
  end;

  _as := 'Hello World!';
  if IsConstValue(_as) then
    Halt(3);

  if not IsConstValue(eOne) then
    Halt(4);
  if not IsConstValue(eTwo) then
    Halt(5);
  if not IsConstValue(eThree) then
    Halt(6);

  if not IsConstValue(Number) then
    Halt(7);
  if not IsConstValue(Str) then
    Halt(8);

  lir.a := 5;
  if IsConstValue(lir) then
    Halt(9);

  asr.a := 'Hello World!';
  if IsConstValue(asr) then
    Halt(10);
{
  if IsConstValue(mr) then
    Halt(11);
}
  SetLength(liarr, 2);
  liarr[0] := 1;
  liarr[1] := 2;
  if IsConstValue(liarr) then
    Halt(12);

  sasarr[0] := 'Hell';
  sasarr[1] := 'o ';
  sasarr[2] := 'Wor';
  sasarr[3] := 'ld!';
  if IsConstValue(sasarr) then
    Halt(13);

  if not IsConstValue(sOne) then
    Halt(14);
  if not IsConstValue(sTwo) then
    Halt(15);
  if not IsConstValue(sThree) then
    Halt(16);

  if not IsConstValue(Dbl) then
    Halt(17);

  if not IsConstValue(NilPtr) then
    Halt(18);

  if not IsConstValue(IsConst) then
    Halt(19);

  if not IsConstValue(GUID) then
    Halt(20);

  if IsConstValue(IntConst) then
    Halt(21);

  if IsConstValue(RealConst) then
    Halt(22);

  if IsConstValue(Alphabet) then
    Halt(23);

  if IsConstValue(MyGUID) then
    Halt(24);

  if IsConstValue(Bool) then
    Halt(25);

  Writeln('Ok');
end.