Skip to content

Commit e8061b1

Browse files
[tests] Tests for primary constuctors,passing cases (#2009)
1 parent 4670a80 commit e8061b1

6 files changed

Lines changed: 987 additions & 26 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//test primary constructor-core dialect/net framework
2+
FUNCTION Start( ) AS VOID
3+
LOCAL TypedCntr:=TestC1{1} AS TestC1
4+
xAssert(TypedCntr:Value()==1)
5+
6+
LOCAL PrimaryCntr:=TestC2{2} AS TestC2
7+
xAssert(PrimaryCntr:Value==2)
8+
9+
LOCAL BothCntr1:=TestC3{} AS TestC3
10+
xAssert(BothCntr1:Value()==0)
11+
LOCAL BothCntr2:=TestC3{3} AS TestC3
12+
xAssert(BothCntr2:Value()==3)
13+
LOCAL BothCntr3:=TestC3{3,1} AS TestC3
14+
xAssert(BothCntr3:Value()==3)
15+
16+
LOCAL TypedStr:=TestS1{1} AS TestS1
17+
xAssert(TypedStr:Value()==1)
18+
19+
LOCAL PrimaryStr:=TestS2{2} AS TestS2
20+
xAssert(PrimaryStr:Value==2)
21+
22+
LOCAL BothStr1:=TestS3{} AS TestS3
23+
xAssert(BothStr1:Value()==0)
24+
LOCAL BothStr2:=TestS3{3} AS TestS3
25+
xAssert(BothStr2:Value()==3)
26+
LOCAL BothStr3:=TestS3{3,1} AS TestS3
27+
xAssert(BothStr3:Value()==3)
28+
29+
RETURN
30+
31+
#region Class
32+
CLASS TestC1 //Class with only a typed constructor
33+
PUBLIC CONSTRUCTOR (y AS INT)
34+
PUBLIC METHOD Value() AS INT
35+
RETURN 1
36+
END CLASS
37+
38+
CLASS TestC2(x AS INT) //Class with just a primary constructor
39+
PUBLIC Value:= x AS INT
40+
END CLASS
41+
42+
CLASS TestC3 (x AS INT) //Class with a primary construstor and two typed constructor
43+
PUBLIC CONSTRUCTOR ()
44+
SELF(0)
45+
PUBLIC CONSTRUCTOR(a AS INT, b AS INT)
46+
SELF(a)
47+
PUBLIC METHOD Value() AS INT
48+
RETURN x
49+
END CLASS
50+
#endregion
51+
52+
#region Struct
53+
STRUCT TestS1 //Struct with only a typed constructor
54+
PUBLIC CONSTRUCTOR (y AS INT)
55+
PUBLIC METHOD Value() AS INT
56+
RETURN 1
57+
END STRUCT
58+
59+
STRUCT TestS2(x AS INT) //Struct with just a primary constructor
60+
PUBLIC Value:= x AS INT
61+
END STRUCT
62+
63+
STRUCT TestS3 (x AS INT) //Struct with a primary construstor and two typed constructor
64+
PUBLIC CONSTRUCTOR ()
65+
SELF(0)
66+
PUBLIC CONSTRUCTOR(a AS INT, b AS INT)
67+
SELF(a)
68+
PUBLIC METHOD Value() AS INT
69+
RETURN x
70+
END STRUCT
71+
#endregion
72+
73+
PROC xAssert(l AS LOGIC)
74+
IF .NOT. l
75+
THROW Exception{"Incorrect result in line " + System.Diagnostics.StackTrace{TRUE}:GetFrame(1):GetFileLineNumber():ToString()}
76+
END IF
77+
? "Assertion passed"
78+
RETURN
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
//test primary constructor-core dialect/net sdk
2+
FUNCTION Start( ) AS VOID
3+
LOCAL TypedCntr:=TestC1{1} AS TestC1
4+
xAssert(TypedCntr:Value()==1)
5+
6+
LOCAL PrimaryCntr:=TestC2{2} AS TestC2
7+
xAssert(PrimaryCntr:Value==2)
8+
9+
LOCAL BothCntr1:=TestC3{} AS TestC3
10+
xAssert(BothCntr1:Value()==0)
11+
LOCAL BothCntr2:=TestC3{3} AS TestC3
12+
xAssert(BothCntr2:Value()==3)
13+
LOCAL BothCntr3:=TestC3{3,1} AS TestC3
14+
xAssert(BothCntr3:Value()==3)
15+
16+
LOCAL TypedStr:=TestS1{1} AS TestS1
17+
xAssert(TypedStr:Value()==1)
18+
19+
LOCAL PrimaryStr:=TestS2{2} AS TestS2
20+
xAssert(PrimaryStr:Value==2)
21+
22+
LOCAL BothStr1:=TestS3{} AS TestS3
23+
xAssert(BothStr1:Value()==0)
24+
LOCAL BothStr2:=TestS3{3} AS TestS3
25+
xAssert(BothStr2:Value()==3)
26+
LOCAL BothStr3:=TestS3{3,1} AS TestS3
27+
xAssert(BothStr3:Value()==3)
28+
29+
LOCAL TypedRcd:=TestR1{1} AS TestR1
30+
xAssert(TypedRcd:Value()==1)
31+
32+
LOCAL PrimaryRcd:=TestR2{2} AS TestR2
33+
xAssert(PrimaryRcd:Value==2)
34+
35+
LOCAL BothRcd1:=TestR3{} AS TestR3
36+
xAssert(BothRcd1:Value()==0)
37+
LOCAL BothRcd2:=TestR3{3} AS TestR3
38+
xAssert(BothRcd2:Value()==3)
39+
LOCAL BothRcd3:=TestR3{3,1} AS TestR3
40+
xAssert(BothRcd3:Value()==3)
41+
42+
LOCAL TypedRStr:=TestRS1{1} AS TestRS1
43+
xAssert(TypedRStr:Value()==1)
44+
45+
LOCAL PrimaryRStr:=TestRS2{2} AS TestRS2
46+
xAssert(PrimaryRStr:Value==2)
47+
48+
LOCAL BothRStr1:=TestRS3{} AS TestRS3
49+
xAssert(BothRStr1:Value()==0)
50+
LOCAL BothRStr2:=TestRS3{3} AS TestRS3
51+
xAssert(BothRStr2:Value()==3)
52+
LOCAL BothRStr3:=TestRS3{3,1} AS TestRS3
53+
xAssert(BothRStr3:Value()==3)
54+
55+
RETURN
56+
57+
#region Class
58+
CLASS TestC1 //Class with only a typed constructor
59+
PUBLIC CONSTRUCTOR (y AS INT)
60+
PUBLIC METHOD Value() AS INT
61+
RETURN 1
62+
END CLASS
63+
64+
CLASS TestC2(x AS INT) //Class with just a primary constructor
65+
PUBLIC Value:= x AS INT
66+
END CLASS
67+
68+
CLASS TestC3 (x AS INT) //Class with a primary construstor and two typed constructor
69+
PUBLIC CONSTRUCTOR ()
70+
SELF(0)
71+
PUBLIC CONSTRUCTOR(a AS INT, b AS INT)
72+
SELF(a)
73+
PUBLIC METHOD Value() AS INT
74+
RETURN x
75+
END CLASS
76+
#endregion
77+
78+
#region Struct
79+
STRUCT TestS1 //Struct with only a typed constructor
80+
PUBLIC CONSTRUCTOR (y AS INT)
81+
PUBLIC METHOD Value() AS INT
82+
RETURN 1
83+
END STRUCT
84+
85+
STRUCT TestS2(x AS INT) //Struct with just a primary constructor
86+
PUBLIC Value:= x AS INT
87+
END STRUCT
88+
89+
STRUCT TestS3 (x AS INT) //Struct with a primary construstor and two typed constructor
90+
PUBLIC CONSTRUCTOR ()
91+
SELF(0)
92+
PUBLIC CONSTRUCTOR(a AS INT, b AS INT)
93+
SELF(a)
94+
PUBLIC METHOD Value() AS INT
95+
RETURN x
96+
END STRUCT
97+
#endregion
98+
99+
#region Record
100+
RECORD TestR1 //Record with only a typed constructor
101+
PUBLIC CONSTRUCTOR (y AS INT)
102+
PUBLIC METHOD Value() AS INT
103+
RETURN 1
104+
END RECORD
105+
106+
RECORD TestR2(x AS INT) //Record with just a primary constructor
107+
PUBLIC Value:= x AS INT
108+
END RECORD
109+
110+
RECORD TestR3 (x AS INT) //Record with a primary construstor and two typed constructor
111+
PUBLIC CONSTRUCTOR ()
112+
SELF(0)
113+
PUBLIC CONSTRUCTOR(a AS INT, b AS INT)
114+
SELF(a)
115+
PUBLIC METHOD Value() AS INT
116+
RETURN x
117+
END RECORD
118+
#endregion
119+
120+
#region Record Struct
121+
RECORD STRUCT TestRS1 //Record Struct with only a typed constructor
122+
PUBLIC CONSTRUCTOR (y AS INT)
123+
PUBLIC METHOD Value() AS INT
124+
RETURN 1
125+
END STRUCT
126+
127+
RECORD STRUCT TestRS2(x AS INT) //Record Struct with just a primary constructor
128+
PUBLIC Value:= x AS INT
129+
END STRUCT
130+
131+
RECORD STRUCT TestRS3 (x AS INT) //Record Struct with a primary construstor and two typed constructor
132+
PUBLIC CONSTRUCTOR ()
133+
SELF(0)
134+
PUBLIC CONSTRUCTOR(a AS INT, b AS INT)
135+
SELF(a)
136+
PUBLIC METHOD Value() AS INT
137+
RETURN x
138+
END STRUCT
139+
#endregion
140+
141+
PROC xAssert(l AS LOGIC)
142+
IF .NOT. l
143+
THROW Exception{"Incorrect result in line " + System.Diagnostics.StackTrace{TRUE}:GetFrame(1):GetFileLineNumber():ToString()}
144+
END IF
145+
? "Assertion passed"
146+
RETURN
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//test primary constructor-vo dialect/net framework
2+
FUNCTION Start( ) AS VOID
3+
LOCAL TypedCntr:=TestC1{1} AS TestC1
4+
xAssert(TypedCntr:Value()==1)
5+
6+
LOCAL PrimaryCntr:=TestC2{2} AS TestC2
7+
xAssert(PrimaryCntr:Value==2)
8+
9+
LOCAL BothCntr1:=TestC3{} AS TestC3
10+
xAssert(BothCntr1:Value()==0)
11+
LOCAL BothCntr2:=TestC3{3} AS TestC3
12+
xAssert(BothCntr2:Value()==3)
13+
LOCAL BothCntr3:=TestC3{3,1} AS TestC3
14+
xAssert(BothCntr3:Value()==3)
15+
16+
LOCAL ClipperCntr:=TestC4{"apple", 42} AS TestC4
17+
xAssert(ClipperCntr:Value()==4)
18+
19+
LOCAL TypedStr:=TestS1{1} AS TestS1
20+
xAssert(TypedStr:Value()==1)
21+
22+
LOCAL PrimaryStr:=TestS2{2} AS TestS2
23+
xAssert(PrimaryStr:Value==2)
24+
25+
LOCAL BothStr1:=TestS3{} AS TestS3
26+
xAssert(BothStr1:Value()==0)
27+
LOCAL BothStr2:=TestS3{3} AS TestS3
28+
xAssert(BothStr2:Value()==3)
29+
LOCAL BothStr3:=TestS3{3,1} AS TestS3
30+
xAssert(BothStr3:Value()==3)
31+
32+
LOCAL ClipperStr:=TestS4{"notapple"} AS TestS4
33+
xAssert(ClipperStr:Value()==4)
34+
35+
RETURN
36+
37+
#region Class
38+
CLASS TestC1 //Class with only a typed constructor
39+
PUBLIC CONSTRUCTOR (y AS INT)
40+
PUBLIC METHOD Value() AS INT
41+
RETURN 1
42+
END CLASS
43+
44+
CLASS TestC2(x AS INT) //Class with just a primary constructor
45+
PUBLIC Value:= x AS INT
46+
END CLASS
47+
48+
CLASS TestC3 (x AS INT) //Class with a primary construstor and two typed constructor
49+
PUBLIC CONSTRUCTOR ()
50+
SELF(0)
51+
PUBLIC CONSTRUCTOR(a AS INT, b AS INT)
52+
SELF(a)
53+
PUBLIC METHOD Value() AS INT
54+
RETURN x
55+
END CLASS
56+
57+
CLASS TestC4 //Class with clipper constructor
58+
PUBLIC CONSTRUCTOR(a) CLIPPER
59+
PUBLIC METHOD Value() AS INT
60+
RETURN 4
61+
END CLASS
62+
#endregion
63+
64+
#region Struct
65+
STRUCT TestS1 //Struct with only a typed constructor
66+
PUBLIC CONSTRUCTOR (y AS INT)
67+
PUBLIC METHOD Value() AS INT
68+
RETURN 1
69+
END STRUCT
70+
71+
STRUCT TestS2(x AS INT) //Struct with just a primary constructor
72+
PUBLIC Value:= x AS INT
73+
END STRUCT
74+
75+
STRUCT TestS3 (x AS INT) //Struct with a primary construstor and two typed constructor
76+
PUBLIC CONSTRUCTOR ()
77+
SELF(0)
78+
PUBLIC CONSTRUCTOR(a AS INT, b AS INT)
79+
SELF(a)
80+
PUBLIC METHOD Value() AS INT
81+
RETURN x
82+
END STRUCT
83+
84+
STRUCT TestS4 //Struct with clipper constructor
85+
PUBLIC CONSTRUCTOR(b) CLIPPER
86+
PUBLIC METHOD Value() AS INT
87+
RETURN 4
88+
END STRUCT
89+
#endregion
90+
91+
PROC xAssert(l AS LOGIC)
92+
IF .NOT. l
93+
THROW Exception{"Incorrect result in line " + System.Diagnostics.StackTrace{TRUE}:GetFrame(1):GetFileLineNumber():ToString()}
94+
END IF
95+
? "Assertion passed"
96+
RETURN

0 commit comments

Comments
 (0)