use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testTypesAreCoerced.
@Test
void testTypesAreCoerced() {
final DataContainer source = DataContainer.createNew();
source.set(DataQuery.of("i'm a short"), (short) 5);
final ConfigurationNode destination = BasicConfigurationNode.root(ConfigurationOptions.defaults().nativeTypes(Collections.singleton(Integer.class)));
ConfigurateTranslator.instance().translateDataToNode(destination, source);
assertEquals(5, destination.node("i'm a short").raw());
}
use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testMapInsideList.
@Test
void testMapInsideList() throws IOException {
final JsonDataFormat json = new JsonDataFormat();
final ConfigurationNode node = CommentedConfigurationNode.root();
final Map<String, String> map = Collections.singletonMap("mkey", "mvalue");
final List<Object> list = Arrays.asList("lelement", map);
node.node("foo").raw("bar");
node.node("l").raw(list);
final DataContainer jc = json.read("{\"foo\":\"bar\",\"l\":[\"lelement\",{\"mkey\":\"mvalue\"}]}");
final DataContainer hc = ConfigurateTranslator.instance().translate(node);
assertEquals(jc.getMap(DataQuery.of()), hc.getMap(DataQuery.of()));
}
use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testEmptyDataToNode.
@Test
void testEmptyDataToNode() {
final DataContainer source = DataContainer.createNew();
final ConfigurationNode destination = ConfigurateTranslator.instance().translate(source);
assertTrue(destination.empty());
}
use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testColor.
@Test
void testColor() throws IOException {
final Color color = Color.ofRgb(0x66, 0xCC, 0xFF);
final DataContainer original = color.toContainer();
final String serialized = ConfigurateDataViewTest.HOCON.write(original);
final DataContainer ret = ConfigurateDataViewTest.HOCON.read(serialized);
assertEquals(original, ret);
}
use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.
the class ConfigurateDataViewTest method testFireworkEffectData.
@Test
void testFireworkEffectData() throws IOException {
final Color color = Color.ofRgb(0x66, 0xCC, 0xFF);
final FireworkEffect fe = new SpongeFireworkEffectBuilder().colors(color, color, color).build();
final DataContainer container = fe.toContainer();
final String s = ConfigurateDataViewTest.HOCON.write(container);
final DataContainer dc = ConfigurateDataViewTest.HOCON.read(s);
assertEquals(container, dc);
}
Aggregations