Added new FileConfigurationOptions.copyHeader, defaulting to true. Copies the header from default config, if there is one.

This commit is contained in:
Nathan Adams
2011-10-12 13:24:57 +01:00
parent ab46572125
commit 98633dfddf
6 changed files with 153 additions and 54 deletions

View File

@@ -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();