2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.plot;
|
2016-04-19 22:59:10 +02:00
|
|
|
|
2022-01-22 11:02:08 +01:00
|
|
|
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.database.AbstractDBTest;
|
|
|
|
import com.plotsquared.core.database.DBFunc;
|
2022-01-22 11:02:08 +01:00
|
|
|
import com.plotsquared.core.plot.flag.FlagParseException;
|
2020-08-07 02:53:05 +02:00
|
|
|
import com.plotsquared.core.plot.flag.PlotFlag;
|
2022-01-22 11:02:08 +01:00
|
|
|
import com.plotsquared.core.plot.flag.implementations.PlotTitleFlag;
|
2020-08-07 02:53:05 +02:00
|
|
|
import com.plotsquared.core.plot.flag.implementations.UseFlag;
|
2019-11-12 21:38:18 +01:00
|
|
|
import com.sk89q.worldedit.world.item.ItemType;
|
2021-06-03 12:40:27 +02:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2021-12-13 10:41:36 +01:00
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
|
import org.junit.jupiter.api.Test;
|
2016-04-19 22:59:10 +02:00
|
|
|
|
|
|
|
public class FlagTest {
|
|
|
|
|
2021-06-03 12:40:27 +02:00
|
|
|
private static final Logger LOGGER = LogManager.getLogger("PlotSquared/" + FlagTest.class.getSimpleName());
|
2020-10-08 20:52:02 +02:00
|
|
|
|
2019-11-12 21:38:18 +01:00
|
|
|
private ItemType testBlock;
|
2016-04-19 22:59:10 +02:00
|
|
|
|
2021-12-13 10:41:36 +01:00
|
|
|
@BeforeEach
|
2021-01-09 22:28:41 +01:00
|
|
|
public void setUp() throws Exception {
|
2020-03-15 12:22:49 +01:00
|
|
|
//EventUtil.manager = new EventUtilTest();
|
2016-04-28 22:38:51 +02:00
|
|
|
DBFunc.dbManager = new AbstractDBTest();
|
2016-04-19 22:59:10 +02:00
|
|
|
}
|
|
|
|
|
2019-12-07 03:16:09 +01:00
|
|
|
// @Test public void flagTest() throws Exception {
|
2020-07-18 11:05:16 +02:00
|
|
|
// Plot plot = new Plot(null, PlotId.of(0, 0));
|
2019-12-07 03:16:09 +01:00
|
|
|
// plot.owner = UUID.fromString("84499644-ad72-454b-a19d-f28c28df382b");
|
|
|
|
// //plot.setFlag(use, use.parseValue("33,33:1,6:4")); //TODO fix this so FlagTest will run during compile
|
|
|
|
// Optional<? extends Collection> flag = plot.getFlag(use);
|
|
|
|
// if (flag.isPresent()) {
|
2021-06-03 12:40:27 +02:00
|
|
|
// LOGGER.info(Flags.USE.valueToString(flag.get()));
|
2019-12-07 03:16:09 +01:00
|
|
|
// testBlock = ItemTypes.BONE_BLOCK;
|
|
|
|
// flag.get().add(testBlock);
|
|
|
|
// }
|
2021-06-03 12:40:27 +02:00
|
|
|
// flag.ifPresent(collection -> LOGGER.info(Flags.USE.valueToString(collection)));
|
2019-12-07 03:16:09 +01:00
|
|
|
// Optional<Set<BlockType>> flag2 = plot.getFlag(Flags.USE);
|
|
|
|
// if (flag2.isPresent()) {
|
|
|
|
// // assertThat(flag2.get(), (Matcher<? super Set<BlockType>>) IsCollectionContaining.hasItem(testBlock));
|
|
|
|
// }
|
|
|
|
// if (flag.isPresent() && flag2.isPresent()) {
|
|
|
|
// assertEquals(flag.get(), flag2.get());
|
|
|
|
// }
|
|
|
|
// }
|
2020-08-07 02:53:05 +02:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Test
|
|
|
|
public void testFlagName() {
|
2020-08-07 02:53:05 +02:00
|
|
|
String flagName = PlotFlag.getFlagName(UseFlag.class);
|
2021-12-13 10:41:36 +01:00
|
|
|
Assertions.assertEquals("use", flagName);
|
2020-08-07 02:53:05 +02:00
|
|
|
}
|
2021-01-09 22:28:41 +01:00
|
|
|
|
2022-01-22 11:02:08 +01:00
|
|
|
@Test
|
|
|
|
public void shouldSuccessfullyParseTitleFlagWithTitleSingularAndSubTitleEmpty() {
|
|
|
|
Assertions.assertDoesNotThrow(() -> {
|
|
|
|
var title = PlotTitleFlag.TITLE_FLAG_DEFAULT.parse("\"test\" \"\"").getValue();
|
|
|
|
Assertions.assertEquals("test", title.title());
|
|
|
|
Assertions.assertEquals("", title.subtitle());
|
|
|
|
}, "Should not throw a FlagParseException");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldSuccessfullyParseTitleFlagWithTitleMultipleWordsAndSubTitleEmpty() {
|
|
|
|
Assertions.assertDoesNotThrow(() -> {
|
|
|
|
var title = PlotTitleFlag.TITLE_FLAG_DEFAULT.parse("\"test hello test\" \"\"").getValue();
|
|
|
|
Assertions.assertEquals("test hello test", title.title());
|
|
|
|
Assertions.assertEquals("", title.subtitle());
|
|
|
|
}, "Should not throw a FlagParseException");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldSuccessfullyParseTitleFlagWithTitleMultipleWordsAndSubTitleMultipleWords() {
|
|
|
|
Assertions.assertDoesNotThrow(() -> {
|
|
|
|
var title = PlotTitleFlag.TITLE_FLAG_DEFAULT.parse("\"test hello test\" \"a very long subtitle\"").getValue();
|
|
|
|
Assertions.assertEquals("test hello test", title.title());
|
|
|
|
Assertions.assertEquals("a very long subtitle", title.subtitle());
|
|
|
|
}, "Should not throw a FlagParseException");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldSuccessfullyParseTitleFlagWithTitleEmptyAndSubTitleSingleWord() {
|
|
|
|
Assertions.assertDoesNotThrow(() -> {
|
|
|
|
var title = PlotTitleFlag.TITLE_FLAG_DEFAULT.parse("\"\" \"single\"").getValue();
|
2022-10-10 18:41:35 +02:00
|
|
|
Assertions.assertEquals("", title.title());
|
2022-01-22 11:02:08 +01:00
|
|
|
Assertions.assertEquals("single", title.subtitle());
|
|
|
|
}, "Should not throw a FlagParseException");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldExtractTitleWhenASingleDoubleQuoteAtEndOfTitle() {
|
|
|
|
Assertions.assertDoesNotThrow(() -> {
|
|
|
|
var plotTitle = PlotTitleFlag.TITLE_FLAG_DEFAULT.parse("title\"").getValue();
|
|
|
|
Assertions.assertEquals("title", plotTitle.title());
|
|
|
|
Assertions.assertEquals("", plotTitle.subtitle());
|
|
|
|
}, "Should not throw a FlagParseException");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldThrowFlagParseExceptionWithQuotesGreater4() {
|
|
|
|
var exception = Assertions.assertThrows(
|
|
|
|
FlagParseException.class,
|
|
|
|
() -> PlotTitleFlag.TITLE_FLAG_DEFAULT.parse("\"title\" \"subtitle\" \"more\""),
|
|
|
|
"Needs to throw a FlagParseException"
|
|
|
|
);
|
|
|
|
Assertions.assertTrue(exception.getErrorMessage() instanceof TranslatableCaption);
|
|
|
|
Assertions.assertEquals(
|
|
|
|
"flags.flag_error_title",
|
|
|
|
((TranslatableCaption) exception.getErrorMessage()).getKey()
|
|
|
|
);
|
|
|
|
}
|
2023-03-06 11:38:30 +01:00
|
|
|
|
2016-04-19 22:59:10 +02:00
|
|
|
}
|