-
-
Notifications
You must be signed in to change notification settings - Fork 101
/
BlockNBTComponentTest.java
134 lines (119 loc) · 5.94 KB
/
BlockNBTComponentTest.java
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
/*
* This file is part of adventure, licensed under the MIT License.
*
* Copyright (c) 2017-2022 KyoriPowered
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.kyori.adventure.text;
import com.google.common.collect.ImmutableSet;
import com.google.common.testing.EqualsTester;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class BlockNBTComponentTest extends AbstractNBTComponentTest<BlockNBTComponent, BlockNBTComponent.Builder> {
@Override
BlockNBTComponent.Builder builder() {
return Component.blockNBT().nbtPath("abc").absoluteWorldPos(1, 2, 3);
}
@Test
void testOf() {
final BlockNBTComponent component = Component.blockNBT("abc", BlockNBTComponent.LocalPos.localPos(1d, 2d, 3d));
assertEquals("abc", component.nbtPath());
assertEquals(BlockNBTComponent.LocalPos.localPos(1d, 2d, 3d), component.pos());
assertNull(component.color());
TextAssertions.assertDecorations(component, ImmutableSet.of(), ImmutableSet.of());
}
@Test
void testPos() {
final BlockNBTComponent c0 = Component.blockNBT("abc", BlockNBTComponent.LocalPos.localPos(1d, 2d, 3d));
final BlockNBTComponent c1 = c0.pos(BlockNBTComponent.WorldPos.worldPos(BlockNBTComponent.WorldPos.Coordinate.absolute(1), BlockNBTComponent.WorldPos.Coordinate.relative(2), BlockNBTComponent.WorldPos.Coordinate.absolute(3)));
assertEquals(BlockNBTComponent.LocalPos.localPos(1d, 2d, 3d), c0.pos());
assertEquals(BlockNBTComponent.WorldPos.worldPos(BlockNBTComponent.WorldPos.Coordinate.absolute(1), BlockNBTComponent.WorldPos.Coordinate.relative(2), BlockNBTComponent.WorldPos.Coordinate.absolute(3)), c1.pos());
assertEquals("abc", c1.nbtPath());
assertTrue(c0.pos() instanceof BlockNBTComponent.LocalPos);
assertEquals(1, ((BlockNBTComponent.LocalPos) c0.pos()).left());
assertEquals(2, ((BlockNBTComponent.LocalPos) c0.pos()).up());
assertEquals(3, ((BlockNBTComponent.LocalPos) c0.pos()).forwards());
assertTrue(c1.pos() instanceof BlockNBTComponent.WorldPos);
assertEquals(BlockNBTComponent.WorldPos.Coordinate.Type.ABSOLUTE, ((BlockNBTComponent.WorldPos) c1.pos()).x().type());
assertEquals(BlockNBTComponent.WorldPos.Coordinate.Type.RELATIVE, ((BlockNBTComponent.WorldPos) c1.pos()).y().type());
assertEquals(BlockNBTComponent.WorldPos.Coordinate.Type.ABSOLUTE, ((BlockNBTComponent.WorldPos) c1.pos()).z().type());
assertEquals(1, ((BlockNBTComponent.WorldPos) c1.pos()).x().value());
assertEquals(2, ((BlockNBTComponent.WorldPos) c1.pos()).y().value());
assertEquals(3, ((BlockNBTComponent.WorldPos) c1.pos()).z().value());
}
@Test
void testPosEquality() {
new EqualsTester()
.addEqualityGroup(BlockNBTComponent.LocalPos.localPos(1d, 2d, 3d))
.addEqualityGroup(BlockNBTComponent.WorldPos.worldPos(BlockNBTComponent.WorldPos.Coordinate.absolute(1), BlockNBTComponent.WorldPos.Coordinate.absolute(2), BlockNBTComponent.WorldPos.Coordinate.absolute(3)))
.testEquals();
}
@Test
void testLocalPosNoDecimalParsing() {
assertEquals(
BlockNBTComponent.LocalPos.localPos(1.0d, 2.0d, 3.89d),
BlockNBTComponent.Pos.fromString("^1 ^2 ^3.89")
);
}
@Test
void testLocalPosParsing() {
assertEquals(
BlockNBTComponent.LocalPos.localPos(1.23d, 2.0d, 3.89d),
BlockNBTComponent.Pos.fromString("^1.23 ^2.0 ^3.89")
);
}
@Test
void testAbsoluteWorldPosParsing() {
assertEquals(
BlockNBTComponent.WorldPos.worldPos(BlockNBTComponent.WorldPos.Coordinate.absolute(4), BlockNBTComponent.WorldPos.Coordinate.absolute(5), BlockNBTComponent.WorldPos.Coordinate.absolute(6)),
BlockNBTComponent.Pos.fromString("4 5 6")
);
}
@Test
void testRelativeWorldPosParsing() {
assertEquals(
BlockNBTComponent.WorldPos.worldPos(BlockNBTComponent.WorldPos.Coordinate.relative(7), BlockNBTComponent.WorldPos.Coordinate.relative(83), BlockNBTComponent.WorldPos.Coordinate.relative(900)),
BlockNBTComponent.Pos.fromString("~7 ~83 ~900")
);
}
@Test
void testWorldPosParsing() {
assertEquals(
BlockNBTComponent.WorldPos.worldPos(BlockNBTComponent.WorldPos.Coordinate.absolute(12), BlockNBTComponent.WorldPos.Coordinate.relative(3), BlockNBTComponent.WorldPos.Coordinate.absolute(1200)),
BlockNBTComponent.Pos.fromString("12 ~3 1200")
);
}
@Test
void testLocalPosParsingWithNegatives() {
assertEquals(
BlockNBTComponent.LocalPos.localPos(-4.5, 3, -35.67),
BlockNBTComponent.Pos.fromString("^-4.5 ^3 ^-35.67")
);
}
@Test
void testWorldPosParsingWithNegatives() {
assertEquals(
BlockNBTComponent.WorldPos.worldPos(BlockNBTComponent.WorldPos.Coordinate.relative(-6), BlockNBTComponent.WorldPos.Coordinate.absolute(-34), BlockNBTComponent.WorldPos.Coordinate.relative(13)),
BlockNBTComponent.Pos.fromString("~-6 -34 ~13")
);
}
}