mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-22 07:43:49 -07:00
Added new FileConfigurationOptions.copyHeader, defaulting to true. Copies the header from default config, if there is one.
By: Nathan Adams <dinnerbone@dinnerbone.com>
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package org.bukkit.configuration.file;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.Map;
|
||||
import org.bukkit.configuration.MemoryConfigurationTest;
|
||||
@@ -21,6 +19,10 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest {
|
||||
|
||||
public abstract String getTestValuesString();
|
||||
|
||||
public abstract String getTestHeaderInput();
|
||||
|
||||
public abstract String getTestHeaderResult();
|
||||
|
||||
@Test
|
||||
public void testSave_File() throws Exception {
|
||||
FileConfiguration config = getConfig();
|
||||
@@ -122,5 +124,65 @@ public abstract class FileConfigurationTest extends MemoryConfigurationTest {
|
||||
}
|
||||
|
||||
assertEquals(values.keySet(), config.getKeys(true));
|
||||
assertEquals(saved, config.saveToString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveToStringWithHeader() {
|
||||
FileConfiguration config = getConfig();
|
||||
config.options().header(getTestHeaderInput());
|
||||
|
||||
for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
|
||||
config.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
String result = config.saveToString();
|
||||
String expected = getTestHeaderResult() + "\n" + getTestValuesString();
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseHeader() throws Exception {
|
||||
FileConfiguration config = getConfig();
|
||||
Map<String, Object> values = getTestValues();
|
||||
String saved = getTestValuesString();
|
||||
String header = getTestHeaderResult();
|
||||
String expected = getTestHeaderInput();
|
||||
|
||||
config.loadFromString(header + "\n" + saved);
|
||||
|
||||
assertEquals(expected, config.options().header());
|
||||
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
assertEquals(entry.getValue(), config.get(entry.getKey()));
|
||||
}
|
||||
|
||||
assertEquals(values.keySet(), config.getKeys(true));
|
||||
assertEquals(header + "\n" + saved, config.saveToString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyHeader() throws Exception {
|
||||
FileConfiguration config = getConfig();
|
||||
FileConfiguration defaults = getConfig();
|
||||
Map<String, Object> values = getTestValues();
|
||||
String saved = getTestValuesString();
|
||||
String header = getTestHeaderResult();
|
||||
String expected = getTestHeaderInput();
|
||||
|
||||
defaults.loadFromString(header);
|
||||
config.loadFromString(saved);
|
||||
config.setDefaults(defaults);
|
||||
|
||||
assertNull(config.options().header());
|
||||
assertEquals(expected, defaults.options().header());
|
||||
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
assertEquals(entry.getValue(), config.get(entry.getKey()));
|
||||
}
|
||||
|
||||
assertEquals(values.keySet(), config.getKeys(true));
|
||||
assertEquals(header + "\n" + saved, config.saveToString());
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package org.bukkit.configuration.file;
|
||||
|
||||
import java.util.Map;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -9,6 +8,16 @@ public class YamlConfigurationTest extends FileConfigurationTest {
|
||||
public YamlConfiguration getConfig() {
|
||||
return new YamlConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTestHeaderInput() {
|
||||
return "This is a sample\nheader.\n\nNewline above should be commented.\n\n";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTestHeaderResult() {
|
||||
return "# This is a sample\n# header.\n# \n# Newline above should be commented.\n\n";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTestValuesString() {
|
||||
@@ -30,55 +39,6 @@ public class YamlConfigurationTest extends FileConfigurationTest {
|
||||
"- 5\n";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveToStringWithHeader() {
|
||||
YamlConfiguration config = getConfig();
|
||||
config.options().header("This is a sample\nheader.");
|
||||
|
||||
for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
|
||||
config.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
String result = config.saveToString();
|
||||
String expected = "# This is a sample\n# header.\n" + getTestValuesString();
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveToStringWithLongHeader() {
|
||||
YamlConfiguration config = getConfig();
|
||||
config.options().header("This is a sample\nheader.\n\nNewline above should be commented.\n\n");
|
||||
|
||||
for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
|
||||
config.set(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
String result = config.saveToString();
|
||||
String expected = "# This is a sample\n# header.\n# \n# Newline above should be commented.\n\n\n" + getTestValuesString();
|
||||
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseHeader() throws Exception {
|
||||
YamlConfiguration config = getConfig();
|
||||
Map<String, Object> values = getTestValues();
|
||||
String saved = getTestValuesString();
|
||||
String header = "# This is a sample\n# header.\n# \n# Newline above should be commented.\n\n\n";
|
||||
String expected = "This is a sample\nheader.\n\nNewline above should be commented.\n\n";
|
||||
|
||||
config.loadFromString(header + saved);
|
||||
|
||||
assertEquals(expected, config.options().header());
|
||||
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
assertEquals(entry.getValue(), config.get(entry.getKey()));
|
||||
}
|
||||
|
||||
assertEquals(values.keySet(), config.getKeys(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveToStringWithIndent() {
|
||||
YamlConfiguration config = getConfig();
|
||||
|
Reference in New Issue
Block a user