summaryrefslogtreecommitdiff
path: root/enigma/src/test/java/cuchaz
diff options
context:
space:
mode:
authorGravatar 2xsaiko2020-08-04 20:42:39 +0200
committerGravatar GitHub2020-08-04 14:42:39 -0400
commit75a3442f9ff38222606a1e24753d4a57da1e8c0a (patch)
tree5b0e12fb055d15fcb31b0fd07ae4cf9512e0758e /enigma/src/test/java/cuchaz
parentRevamp About dialog (diff)
downloadenigma-fork-75a3442f9ff38222606a1e24753d4a57da1e8c0a.tar.gz
enigma-fork-75a3442f9ff38222606a1e24753d4a57da1e8c0a.tar.xz
enigma-fork-75a3442f9ff38222606a1e24753d4a57da1e8c0a.zip
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
Diffstat (limited to 'enigma/src/test/java/cuchaz')
-rw-r--r--enigma/src/test/java/cuchaz/enigma/ConfigTest.java86
1 files changed, 86 insertions, 0 deletions
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 @@
1package cuchaz.enigma;
2
3import org.junit.Test;
4
5import cuchaz.enigma.config.ConfigContainer;
6
7import static org.junit.Assert.assertEquals;
8
9public class ConfigTest {
10
11 @Test
12 public void serialize() {
13 ConfigContainer cc = new ConfigContainer();
14 cc.data().setString("a", "a");
15 cc.data().section("a").section("b").section("c").setString("a", "abcd");
16 cc.data().section("a").section("b").section("c").setBool("b", true);
17 cc.data().section("a").section("b").section("c").setInt("c", 5);
18 cc.data().section("a").section("b").section("c").setDouble("d", 3.5);
19 cc.data().section("a").section("b").section("c").setRgbColor("e", 0x123456);
20 assertEquals("a=a\n" +
21 "\n" +
22 "[a][b][c]\n" +
23 "a=abcd\n" +
24 "b=true\n" +
25 "c=5\n" +
26 "d=3.5\n" +
27 "e=#123456\n",
28 cc.serialize());
29 }
30
31 @Test
32 public void deserialize() {
33 ConfigContainer cc = new ConfigContainer();
34 cc.data().setString("a", "a");
35 cc.data().section("a").section("b").section("c").setString("a", "abcd");
36 cc.data().section("a").section("b").section("c").setBool("b", true);
37 cc.data().section("a").section("b").section("c").setInt("c", 5);
38 cc.data().section("a").section("b").section("c").setDouble("d", 3.5);
39 cc.data().section("a").section("b").section("c").setRgbColor("e", 0x123456);
40 assertEquals(ConfigContainer.parse("a=a\n" +
41 "\n" +
42 "[a][b][c]\n" +
43 "a=abcd\n" +
44 "b=true\n" +
45 "c=5\n" +
46 "d=3.5\n" +
47 "e=#123456\n").data(), cc.data());
48 }
49
50 @Test
51 public void weirdChars() {
52 ConfigContainer cc = new ConfigContainer();
53 String thing = "\\[],\\,./'\"`~!@#$%^&*()_+-=|}{\n\\\\\r\b\u0000\uffff\u1234";
54 cc.data().section(thing).setString(thing, thing);
55 cc.data().section(thing).setArray("arr", new String[] { thing, thing, thing, thing });
56
57 assertEquals(
58 "[\\\\[\\],\\\\,./'\"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234]\n" +
59 "\\\\\\[],\\\\,./'\"`~!@#$%^&*()_+-\\=|}{\\n\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234=\\\\[],\\\\,./'\"`~!@#$%^&*()_+-=|}{\\n\\\\\\\\\\u000d\\u0008\\u0000\\uffff\\u1234\n" +
60 "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",
61 cc.serialize());
62
63 ConfigContainer cc1 = ConfigContainer.parse(cc.serialize());
64 assertEquals(cc.data(), cc1.data());
65
66 cc1 = ConfigContainer.parse(cc1.serialize());
67 assertEquals(cc.data(), cc1.data());
68 }
69
70 @Test
71 public void syntaxErrors() {
72 assertEquals("", ConfigContainer.parse("abcde").serialize());
73 assertEquals("", ConfigContainer.parse("what\\=?").serialize());
74
75 assertEquals("[a]\nb=c\n", ConfigContainer.parse("[a] what is this\nb=c").serialize());
76 assertEquals("b=c\n", ConfigContainer.parse("[a][ what is this\nb=c").serialize());
77 assertEquals("", ConfigContainer.parse("[").serialize());
78 assertEquals("[a]\na=b\nc=d\n", ConfigContainer.parse("[a]\na=b\n[\nc=d").serialize());
79
80
81 // not technically syntax errors but never something that gets generated
82 assertEquals("", ConfigContainer.parse("[a]").serialize());
83 assertEquals("", ConfigContainer.parse("[a]\n[b]").serialize());
84 }
85
86}