Skip to content

Commit 64e790c

Browse files
Add tests for EOmalloc objects
1 parent 6d4e245 commit 64e790c

File tree

4 files changed

+305
-45
lines changed

4 files changed

+305
-45
lines changed

eo-runtime/src/test/java/EOorg/EOeolang/EOmalloc$EOof$EOallocated$EOreadTest.java

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -42,50 +42,12 @@
4242
/**
4343
* Test case for {@link EOmalloc$EOof$EOallocated$EOread}.
4444
*
45-
* @since 0.51.2
45+
* @since 0.52
4646
* @checkstyle TypeNameCheck (5 lines)
4747
*/
4848
@SuppressWarnings("PMD.AvoidDollarSigns")
4949
final class EOmalloc$EOof$EOallocated$EOreadTest {
5050

51-
@Test
52-
void throwsCorrectErrorForOffsetAttrNaN() {
53-
MatcherAssert.assertThat(
54-
"the message in the error is correct",
55-
Assertions.assertThrows(
56-
ExAbstract.class,
57-
() -> new Dataized(
58-
new PhWith(
59-
new Dummy().it(),
60-
"offset",
61-
new Data.ToPhi(true)
62-
)
63-
).take(),
64-
"put TRUE in int attr fails with a proper message that explains what happened"
65-
).getMessage(),
66-
Matchers.equalTo("the 'offset' attribute must be a number")
67-
);
68-
}
69-
70-
@Test
71-
void throwsCorrectErrorForOffsetAttrNotAnInt() {
72-
MatcherAssert.assertThat(
73-
"the message in the error is correct",
74-
Assertions.assertThrows(
75-
ExAbstract.class,
76-
() -> new Dataized(
77-
new PhWith(
78-
new Dummy().it(),
79-
"offset",
80-
new Data.ToPhi(42.42)
81-
)
82-
).take(),
83-
"put double in int attr fails with a proper message that explains what happened"
84-
).getMessage(),
85-
Matchers.equalTo("the 'offset' attribute (42.42) must be an integer")
86-
);
87-
}
88-
8951
@Test
9052
void throwsCorrectErrorForLengthAttrNaN() {
9153
MatcherAssert.assertThat(
@@ -134,13 +96,15 @@ void throwsCorrectErrorForLengthAttrNotAnInt() {
13496

13597
/**
13698
* Dummy with correct id attr.
137-
* @since 0.51.2
99+
*
100+
* @since 0.52
138101
*/
139-
@SuppressWarnings("PMD.MethodNameCheck")
102+
@SuppressWarnings("PMD.ShortMethodName")
140103
private static final class Dummy {
141104
/**
142-
* Produce EOmalloc$EOof$EOallocated$EOread with id attr.
143-
* @checkstyle TypeNameCheck (5 lines)
105+
* Produce {@link EOmalloc$EOof$EOallocated$EOread} with id attr.
106+
*
107+
* @checkstyle MethodNameCheck (5 lines)
144108
*/
145109
private Phi it() {
146110
return new PhWith(
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2016-2025 Objectionary.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
/*
26+
* @checkstyle PackageNameCheck (4 lines)
27+
* @checkstyle TrailingCommentCheck (3 lines)
28+
*/
29+
package EOorg.EOeolang; // NOPMD
30+
31+
import org.eolang.Attr;
32+
import org.eolang.Data;
33+
import org.eolang.Dataized;
34+
import org.eolang.ExAbstract;
35+
import org.eolang.PhWith;
36+
import org.eolang.Phi;
37+
import org.hamcrest.MatcherAssert;
38+
import org.hamcrest.Matchers;
39+
import org.junit.jupiter.api.Assertions;
40+
import org.junit.jupiter.api.Test;
41+
42+
/**
43+
* Test case for {@link EOmalloc$EOof$EOallocated$EOresized}.
44+
*
45+
* @since 0.52
46+
* @checkstyle TypeNameCheck (5 lines)
47+
*/
48+
@SuppressWarnings("PMD.AvoidDollarSigns")
49+
final class EOmalloc$EOof$EOallocated$EOresizedTest {
50+
51+
@Test
52+
void throwsCorrectErrorForNewSizeAttrNaN() {
53+
MatcherAssert.assertThat(
54+
"the message in the error is correct",
55+
Assertions.assertThrows(
56+
ExAbstract.class,
57+
() -> new Dataized(
58+
new PhWith(
59+
new Dummy().it(),
60+
"new-size",
61+
new Data.ToPhi(true)
62+
)
63+
).take(),
64+
"put TRUE in int attr fails with a proper message that explains what happened"
65+
).getMessage(),
66+
Matchers.equalTo("the 'new-size' attribute must be a number")
67+
);
68+
}
69+
70+
@Test
71+
void throwsCorrectErrorForNewSizeAttrNotAnInt() {
72+
MatcherAssert.assertThat(
73+
"the message in the error is correct",
74+
Assertions.assertThrows(
75+
ExAbstract.class,
76+
() -> new Dataized(
77+
new PhWith(
78+
new Dummy().it(),
79+
"new-size",
80+
new Data.ToPhi(42.42)
81+
)
82+
).take(),
83+
"put double in int attr fails with a proper message that explains what happened"
84+
).getMessage(),
85+
Matchers.equalTo("the 'new-size' attribute (42.42) must be an integer")
86+
);
87+
}
88+
89+
/**
90+
* Dummy with correct id attr.
91+
* @since 0.52
92+
*/
93+
@SuppressWarnings("PMD.ShortMethodName")
94+
private static final class Dummy {
95+
/**
96+
* Produce EOmalloc$EOof$EOallocated$EOresized with id attr.
97+
* @checkstyle MethodNameCheck (5 lines)
98+
*/
99+
private Phi it() {
100+
return new PhWith(
101+
new EOmalloc$EOof$EOallocated$EOresized(),
102+
Attr.RHO,
103+
new PhWith(
104+
new EOmallocTest.IdDummy(),
105+
"id",
106+
new Data.ToPhi(42)
107+
)
108+
);
109+
}
110+
}
111+
112+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2016-2025 Objectionary.com
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included
14+
* in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
/*
26+
* @checkstyle PackageNameCheck (4 lines)
27+
* @checkstyle TrailingCommentCheck (3 lines)
28+
*/
29+
package EOorg.EOeolang; // NOPMD
30+
31+
import org.eolang.AtVoid;
32+
import org.eolang.Attr;
33+
import org.eolang.Data;
34+
import org.eolang.Dataized;
35+
import org.eolang.ExAbstract;
36+
import org.eolang.PhDefault;
37+
import org.eolang.PhWith;
38+
import org.hamcrest.MatcherAssert;
39+
import org.hamcrest.Matchers;
40+
import org.junit.jupiter.api.Assertions;
41+
import org.junit.jupiter.api.Test;
42+
43+
/**
44+
* Test case for {@link EOmalloc$EOof$EOφ}.
45+
*
46+
* @since 0.51.2
47+
* @checkstyle TypeNameCheck (5 lines)
48+
*/
49+
@SuppressWarnings("PMD.AvoidDollarSigns")
50+
final class EOmalloc$EOof$EOφTest {
51+
52+
@Test
53+
void throwsCorrectErrorForSizeAttrNaN() {
54+
MatcherAssert.assertThat(
55+
"the message in the error is correct",
56+
Assertions.assertThrows(
57+
ExAbstract.class,
58+
() -> new Dataized(
59+
new PhWith(
60+
new EOmalloc$EOof$EOφ(),
61+
Attr.RHO,
62+
new PhWith(
63+
new EOmalloc$EOof$EOφTest.SizeDummy(),
64+
"size",
65+
new Data.ToPhi(true)
66+
)
67+
)
68+
).take(),
69+
"put TRUE in int attr fails with a proper message that explains what happened"
70+
).getMessage(),
71+
Matchers.equalTo("the 'size' attribute must be a number")
72+
);
73+
}
74+
75+
@Test
76+
void throwsCorrectErrorForSizeAttrNotAnInt() {
77+
MatcherAssert.assertThat(
78+
"the message in the error is correct",
79+
Assertions.assertThrows(
80+
ExAbstract.class,
81+
() -> new Dataized(
82+
new PhWith(
83+
new EOmalloc$EOof$EOφ(),
84+
Attr.RHO,
85+
new PhWith(
86+
new EOmalloc$EOof$EOφTest.SizeDummy(),
87+
"size",
88+
new Data.ToPhi(42.42)
89+
)
90+
)
91+
).take(),
92+
"put double in int attr fails with a proper message that explains what happened"
93+
).getMessage(),
94+
Matchers.equalTo("the 'size' attribute (42.42) must be an integer")
95+
);
96+
}
97+
98+
/**
99+
* Dummy with size attr.
100+
* @since 0.51.2
101+
*/
102+
static class SizeDummy extends PhDefault {
103+
/**
104+
* Ctor.
105+
*/
106+
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
107+
SizeDummy() {
108+
this.add("size", new AtVoid("size"));
109+
}
110+
}
111+
112+
}

eo-runtime/src/test/java/EOorg/EOeolang/EOmallocTest.java

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ void freesMemoryIfErrorIsOccurred() {
9090
}
9191

9292
@ParameterizedTest
93-
@ValueSource(classes = EOmalloc$EOof$EOallocated$EOread.class)
93+
@ValueSource(classes = {
94+
EOmalloc$EOof$EOallocated$EOread.class,
95+
EOmalloc$EOof$EOallocated$EOresized.class,
96+
EOmalloc$EOof$EOallocated$EOsize.class,
97+
EOmalloc$EOof$EOallocated$EOwrite.class
98+
})
9499
void throwsCorrectErrorForIdAttrNaN(final Class<?> cls) {
95100
MatcherAssert.assertThat(
96101
"the message in the error is correct",
@@ -114,7 +119,12 @@ void throwsCorrectErrorForIdAttrNaN(final Class<?> cls) {
114119
}
115120

116121
@ParameterizedTest
117-
@ValueSource(classes = EOmalloc$EOof$EOallocated$EOread.class)
122+
@ValueSource(classes = {
123+
EOmalloc$EOof$EOallocated$EOread.class,
124+
EOmalloc$EOof$EOallocated$EOresized.class,
125+
EOmalloc$EOof$EOallocated$EOsize.class,
126+
EOmalloc$EOof$EOallocated$EOwrite.class
127+
})
118128
void throwsCorrectErrorForIdAttrNotAnInt(final Class<?> cls) {
119129
MatcherAssert.assertThat(
120130
"the message in the error is correct",
@@ -137,6 +147,68 @@ void throwsCorrectErrorForIdAttrNotAnInt(final Class<?> cls) {
137147
);
138148
}
139149

150+
@ParameterizedTest
151+
@ValueSource(classes = {
152+
EOmalloc$EOof$EOallocated$EOread.class,
153+
EOmalloc$EOof$EOallocated$EOwrite.class
154+
})
155+
void throwsCorrectErrorForOffsetAttrNaN(final Class<?> cls) {
156+
MatcherAssert.assertThat(
157+
"the message in the error is correct",
158+
Assertions.assertThrows(
159+
ExAbstract.class,
160+
() -> new Dataized(
161+
new PhWith(
162+
new PhWith(
163+
(Phi) cls.getDeclaredConstructor().newInstance(),
164+
Attr.RHO,
165+
new PhWith(
166+
new EOmallocTest.IdDummy(),
167+
"id",
168+
new Data.ToPhi(42)
169+
)
170+
),
171+
"offset",
172+
new Data.ToPhi(true)
173+
)
174+
).take(),
175+
"put TRUE in int attr fails with a proper message that explains what happened"
176+
).getMessage(),
177+
Matchers.equalTo("the 'offset' attribute must be a number")
178+
);
179+
}
180+
181+
@ParameterizedTest
182+
@ValueSource(classes = {
183+
EOmalloc$EOof$EOallocated$EOread.class,
184+
EOmalloc$EOof$EOallocated$EOwrite.class
185+
})
186+
void throwsCorrectErrorForOffsetAttrNotAnInt(final Class<?> cls) {
187+
MatcherAssert.assertThat(
188+
"the message in the error is correct",
189+
Assertions.assertThrows(
190+
ExAbstract.class,
191+
() -> new Dataized(
192+
new PhWith(
193+
new PhWith(
194+
(Phi) cls.getDeclaredConstructor().newInstance(),
195+
Attr.RHO,
196+
new PhWith(
197+
new EOmallocTest.IdDummy(),
198+
"id",
199+
new Data.ToPhi(42)
200+
)
201+
),
202+
"offset",
203+
new Data.ToPhi(42.42)
204+
)
205+
).take(),
206+
"put double in int attr fails with a proper message that explains what happened"
207+
).getMessage(),
208+
Matchers.equalTo("the 'offset' attribute (42.42) must be an integer")
209+
);
210+
}
211+
140212
/**
141213
* Allocated data.
142214
* @param obj Init object

0 commit comments

Comments
 (0)