Skip to content

Commit 5300996

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

File tree

4 files changed

+298
-70
lines changed

4 files changed

+298
-70
lines changed

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

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@
2828
*/
2929
package EOorg.EOeolang; // NOPMD
3030

31-
import org.eolang.Attr;
3231
import org.eolang.Data;
3332
import org.eolang.Dataized;
3433
import org.eolang.ExAbstract;
3534
import org.eolang.PhWith;
36-
import org.eolang.Phi;
3735
import org.hamcrest.MatcherAssert;
3836
import org.hamcrest.Matchers;
3937
import org.junit.jupiter.api.Assertions;
@@ -42,50 +40,12 @@
4240
/**
4341
* Test case for {@link EOmalloc$EOof$EOallocated$EOread}.
4442
*
45-
* @since 0.51.2
43+
* @since 0.52
4644
* @checkstyle TypeNameCheck (5 lines)
4745
*/
4846
@SuppressWarnings("PMD.AvoidDollarSigns")
4947
final class EOmalloc$EOof$EOallocated$EOreadTest {
5048

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-
8949
@Test
9050
void throwsCorrectErrorForLengthAttrNaN() {
9151
MatcherAssert.assertThat(
@@ -95,7 +55,7 @@ void throwsCorrectErrorForLengthAttrNaN() {
9555
() -> new Dataized(
9656
new PhWith(
9757
new PhWith(
98-
new Dummy().it(),
58+
new EOmallocTest.PhiWithDummyId(new EOmalloc$EOof$EOallocated$EOread()).it(),
9959
"offset",
10060
new Data.ToPhi(42)
10161
),
@@ -118,7 +78,7 @@ void throwsCorrectErrorForLengthAttrNotAnInt() {
11878
() -> new Dataized(
11979
new PhWith(
12080
new PhWith(
121-
new Dummy().it(),
81+
new EOmallocTest.PhiWithDummyId(new EOmalloc$EOof$EOallocated$EOread()).it(),
12282
"offset",
12383
new Data.ToPhi(42)
12484
),
@@ -132,27 +92,4 @@ void throwsCorrectErrorForLengthAttrNotAnInt() {
13292
);
13393
}
13494

135-
/**
136-
* Dummy with correct id attr.
137-
* @since 0.51.2
138-
*/
139-
@SuppressWarnings("PMD.MethodNameCheck")
140-
private static final class Dummy {
141-
/**
142-
* Produce EOmalloc$EOof$EOallocated$EOread with id attr.
143-
* @checkstyle TypeNameCheck (5 lines)
144-
*/
145-
private Phi it() {
146-
return new PhWith(
147-
new EOmalloc$EOof$EOallocated$EOread(),
148-
Attr.RHO,
149-
new PhWith(
150-
new EOmallocTest.IdDummy(),
151-
"id",
152-
new Data.ToPhi(42)
153-
)
154-
);
155-
}
156-
}
157-
15895
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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.Data;
32+
import org.eolang.Dataized;
33+
import org.eolang.ExAbstract;
34+
import org.eolang.PhWith;
35+
import org.hamcrest.MatcherAssert;
36+
import org.hamcrest.Matchers;
37+
import org.junit.jupiter.api.Assertions;
38+
import org.junit.jupiter.api.Test;
39+
40+
/**
41+
* Test case for {@link EOmalloc$EOof$EOallocated$EOresized}.
42+
*
43+
* @since 0.52
44+
* @checkstyle TypeNameCheck (5 lines)
45+
*/
46+
@SuppressWarnings("PMD.AvoidDollarSigns")
47+
final class EOmalloc$EOof$EOallocated$EOresizedTest {
48+
49+
@Test
50+
void throwsCorrectErrorForNewSizeAttrNaN() {
51+
MatcherAssert.assertThat(
52+
"the message in the error is correct",
53+
Assertions.assertThrows(
54+
ExAbstract.class,
55+
() -> new Dataized(
56+
new PhWith(
57+
new EOmallocTest.PhiWithDummyId(new EOmalloc$EOof$EOallocated$EOresized()).it(),
58+
"new-size",
59+
new Data.ToPhi(true)
60+
)
61+
).take(),
62+
"put TRUE in int attr fails with a proper message that explains what happened"
63+
).getMessage(),
64+
Matchers.equalTo("the 'new-size' attribute must be a number")
65+
);
66+
}
67+
68+
@Test
69+
void throwsCorrectErrorForNewSizeAttrNotAnInt() {
70+
MatcherAssert.assertThat(
71+
"the message in the error is correct",
72+
Assertions.assertThrows(
73+
ExAbstract.class,
74+
() -> new Dataized(
75+
new PhWith(
76+
new EOmallocTest.PhiWithDummyId(new EOmalloc$EOof$EOallocated$EOresized()).it(),
77+
"new-size",
78+
new Data.ToPhi(42.42)
79+
)
80+
).take(),
81+
"put double in int attr fails with a proper message that explains what happened"
82+
).getMessage(),
83+
Matchers.equalTo("the 'new-size' attribute (42.42) must be an integer")
84+
);
85+
}
86+
87+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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.52
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+
*/
101+
private static class SizeDummy extends PhDefault {
102+
/**
103+
* Ctor.
104+
*/
105+
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
106+
SizeDummy() {
107+
this.add("size", new AtVoid("size"));
108+
}
109+
}
110+
111+
}

0 commit comments

Comments
 (0)