Skip to content
Snippets Groups Projects
Commit 6595ab10 authored by Shawn Pearce's avatar Shawn Pearce Committed by Code Review
Browse files

Merge "Don't confuse empty configuration variables with booleans"

parents e905d93f 869c8434
No related branches found
No related tags found
No related merge requests found
/*
* Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
* Copyright (C) 2009, Google Inc.
* Copyright (C) 2009-2010, Google Inc.
* Copyright (C) 2008, Marek Zawirski <marek.zawirski@gmail.com>
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
......@@ -242,6 +242,35 @@ public void testReadLong() throws ConfigInvalidException {
}
}
public void testBooleanWithNoValue() throws ConfigInvalidException {
Config c = parse("[my]\n\tempty\n");
assertEquals("", c.getString("my", null, "empty"));
assertEquals(1, c.getStringList("my", null, "empty").length);
assertEquals("", c.getStringList("my", null, "empty")[0]);
assertTrue(c.getBoolean("my", "empty", false));
assertEquals("[my]\n\tempty\n", c.toText());
}
public void testEmptyString() throws ConfigInvalidException {
Config c = parse("[my]\n\tempty =\n");
assertNull(c.getString("my", null, "empty"));
String[] values = c.getStringList("my", null, "empty");
assertNotNull(values);
assertEquals(1, values.length);
assertNull(values[0]);
// always matches the default, because its non-boolean
assertTrue(c.getBoolean("my", "empty", true));
assertFalse(c.getBoolean("my", "empty", false));
assertEquals("[my]\n\tempty =\n", c.toText());
c = new Config();
c.setStringList("my", null, "empty", Arrays.asList(values));
assertEquals("[my]\n\tempty =\n", c.toText());
}
private void assertReadLong(long exp) throws ConfigInvalidException {
assertReadLong(exp, String.valueOf(exp));
}
......
......@@ -715,9 +715,10 @@ public String toText() {
if (e.prefix == null || "".equals(e.prefix))
out.append('\t');
out.append(e.name);
if (e.value != null) {
if (MAGIC_EMPTY_VALUE != e.value) {
out.append(" = ");
if (MAGIC_EMPTY_VALUE != e.value) {
out.append(" =");
if (e.value != null) {
out.append(' ');
out.append(escapeValue(e.value));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment