From 75a3442f9ff38222606a1e24753d4a57da1e8c0a Mon Sep 17 00:00:00 2001 From: 2xsaiko Date: Tue, 4 Aug 2020 20:42:39 +0200 Subject: Configuration stuff (#301) * Begin writing new config system * Make config work * Save window size and position * Add editor font chooser * Use *.ini for windows and mac instead of *rc * Allow for changing language without having to restart the program * Save selected directory in file dialogs * Make dialog visible after moving it to the correct position * Don't change theme on the fly since it's broken * Remove unused gui parameter * Use xdg-open to open URLs on Linux since Desktop.browse doesn't work, at least not on my PC * Fix default proposed highlight color * Multi font selection dialog thingy * Remember network options * Make font selection dialog actually work * Collapse general actions ("OK", "Cancel", ..) into one translation * Localize font dialog * Use enum name when saving colors for consistency with currently selected theme * Save size of split panes * Import old config * Add test & fix some parts of the config serializer * TranslationChangeListener/TranslationUtil -> LanguageChangeListener/LanguageUtil--- enigma/src/test/java/cuchaz/enigma/ConfigTest.java | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 enigma/src/test/java/cuchaz/enigma/ConfigTest.java (limited to 'enigma/src/test/java/cuchaz') diff --git a/enigma/src/test/java/cuchaz/enigma/ConfigTest.java b/enigma/src/test/java/cuchaz/enigma/ConfigTest.java new file mode 100644 index 0000000..a44f037 --- /dev/null +++ b/enigma/src/test/java/cuchaz/enigma/ConfigTest.java @@ -0,0 +1,86 @@ +package cuchaz.enigma; + +import org.junit.Test; + +import cuchaz.enigma.config.ConfigContainer; + +import static org.junit.Assert.assertEquals; + +public class ConfigTest { + + @Test + public void serialize() { + ConfigContainer cc = new ConfigContainer(); + cc.data().setString("a", "a"); + cc.data().section("a").section("b").section("c").setString("a", "abcd"); + cc.data().section("a").section("b").section("c").setBool("b", true); + cc.data().section("a").section("b").section("c").setInt("c", 5); + cc.data().section("a").section("b").section("c").setDouble("d", 3.5); + cc.data().section("a").section("b").section("c").setRgbColor("e", 0x123456); + assertEquals("a=a\n" + + "\n" + + "[a][b][c]\n" + + "a=abcd\n" + + "b=true\n" + + "c=5\n" + + "d=3.5\n" + + "e=#123456\n", + cc.serialize()); + } + + @Test + public void deserialize() { + ConfigContainer cc = new ConfigContainer(); + cc.data().setString("a", "a"); + cc.data().section("a").section("b").section("c").setString("a", "abcd"); + cc.data().section("a").section("b").section("c").setBool("b", true); + cc.data().section("a").section("b").section("c").setInt("c", 5); + cc.data().section("a").section("b").section("c").setDouble("d", 3.5); + cc.data().section("a").section("b").section("c").setRgbColor("e", 0x123456); + assertEquals(ConfigContainer.parse("a=a\n" + + "\n" + + "[a][b][c]\n" + + "a=abcd\n" + + "b=true\n" + + "c=5\n" + + "d=3.5\n" + + "e=#123456\n").data(), cc.data()); + } + + @Test + public void weirdChars() { + ConfigContainer cc = new ConfigContainer(); + String thing = "\\[],\\,./'\"`~!@#$%^&*()_+-=|}{\n\\\\\r\b\u0000\uffff\u1234"; + cc.data().section(thing).setString(thing, thing); + cc.data().section(thing).setArray("arr", new String[] { thing, thing, thing, thing }); + + assertEquals( + "[\\\\[\\],\\\\,./'\"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234]\n" + + "\\\\\\[],\\\\,./'\"`~!@#$%^&*()_+-\\=|}{\\n\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234=\\\\[],\\\\,./'\"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234\n" + + "arr=\\\\\\\\[]\\\\,\\\\\\\\\\\\,./'\"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234,\\\\\\\\[]\\\\,\\\\\\\\\\\\,./'\"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234,\\\\\\\\[]\\\\,\\\\\\\\\\\\,./'\"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234,\\\\\\\\[]\\\\,\\\\\\\\\\\\,./'\"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234\n", + cc.serialize()); + + ConfigContainer cc1 = ConfigContainer.parse(cc.serialize()); + assertEquals(cc.data(), cc1.data()); + + cc1 = ConfigContainer.parse(cc1.serialize()); + assertEquals(cc.data(), cc1.data()); + } + + @Test + public void syntaxErrors() { + assertEquals("", ConfigContainer.parse("abcde").serialize()); + assertEquals("", ConfigContainer.parse("what\\=?").serialize()); + + assertEquals("[a]\nb=c\n", ConfigContainer.parse("[a] what is this\nb=c").serialize()); + assertEquals("b=c\n", ConfigContainer.parse("[a][ what is this\nb=c").serialize()); + assertEquals("", ConfigContainer.parse("[").serialize()); + assertEquals("[a]\na=b\nc=d\n", ConfigContainer.parse("[a]\na=b\n[\nc=d").serialize()); + + + // not technically syntax errors but never something that gets generated + assertEquals("", ConfigContainer.parse("[a]").serialize()); + assertEquals("", ConfigContainer.parse("[a]\n[b]").serialize()); + } + +} -- cgit v1.2.3