Support ConfigMemorySize in fromAnyRef

We don't preserve its "memory-size-ness" but we can parse
it into a Long.
This commit is contained in:
Havoc Pennington 2015-02-25 21:01:09 -05:00
parent 2e43d9b21c
commit 97718593c6
2 changed files with 9 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import java.util.concurrent.Callable;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigException;
import com.typesafe.config.ConfigIncluder;
import com.typesafe.config.ConfigMemorySize;
import com.typesafe.config.ConfigObject;
import com.typesafe.config.ConfigOrigin;
import com.typesafe.config.ConfigParseOptions;
@ -273,6 +274,8 @@ public class ConfigImpl {
}
return new SimpleConfigList(origin, values);
} else if (object instanceof ConfigMemorySize) {
return new ConfigLong(origin, ((ConfigMemorySize) object).toBytes(), null);
} else {
throw new ConfigException.BugOrBroken(
"bug in method caller: not valid to create ConfigValue from: "

View File

@ -169,6 +169,12 @@ class PublicApiTest extends TestUtils {
assertEquals("foo", ConfigValueFactory.fromIterable(treeSet, "foo").origin().description())
}
@Test
def fromConfigMemorySize() {
testFromValue(longValue(1024), ConfigMemorySize.ofBytes(1024));
testFromValue(longValue(512), ConfigMemorySize.ofBytes(512));
}
@Test
def roundTripUnwrap() {
val conf = ConfigFactory.load("test01")