mirror of
https://github.com/lightbend/config.git
synced 2025-03-19 13:50:40 +08:00
fix a stray "return" in Scala that was making many tests not run
Then fix a few of the tests that now run. Fortunately the bugs were all in the tests, not in the actual code.
This commit is contained in:
parent
145cb40ec2
commit
c27fa2cd68
@ -30,7 +30,7 @@ class ConfParserTest extends TestUtils {
|
||||
@Test
|
||||
def invalidConfThrows(): Unit = {
|
||||
// be sure we throw
|
||||
for (invalid <- whitespaceVariations(invalidConf)) {
|
||||
for (invalid <- whitespaceVariations(invalidConf, false)) {
|
||||
addOffendingJsonToException("config", invalid.test) {
|
||||
intercept[ConfigException] {
|
||||
parse(invalid.test)
|
||||
@ -43,7 +43,7 @@ class ConfParserTest extends TestUtils {
|
||||
def validConfWorks(): Unit = {
|
||||
// all we're checking here unfortunately is that it doesn't throw.
|
||||
// for a more thorough check, use the EquivalentsTest stuff.
|
||||
for (valid <- whitespaceVariations(validConf)) {
|
||||
for (valid <- whitespaceVariations(validConf, true)) {
|
||||
val ourAST = addOffendingJsonToException("config-conf", valid.test) {
|
||||
parse(valid.test)
|
||||
}
|
||||
|
@ -94,12 +94,15 @@ class JsonTest extends TestUtils {
|
||||
|
||||
@Test
|
||||
def invalidJsonThrows(): Unit = {
|
||||
var tested = 0
|
||||
// be sure Lift throws on the string
|
||||
for (invalid <- whitespaceVariations(invalidJson)) {
|
||||
for (invalid <- whitespaceVariations(invalidJson, false)) {
|
||||
if (invalid.liftBehaviorUnexpected) {
|
||||
// lift unexpectedly doesn't throw, confirm that
|
||||
fromJsonWithLiftParser(invalid.test)
|
||||
fromJsonWithLiftParser(new java.io.StringReader(invalid.test))
|
||||
addOffendingJsonToException("lift-nonthrowing", invalid.test) {
|
||||
fromJsonWithLiftParser(invalid.test)
|
||||
fromJsonWithLiftParser(new java.io.StringReader(invalid.test))
|
||||
}
|
||||
} else {
|
||||
addOffendingJsonToException("lift", invalid.test) {
|
||||
intercept[ConfigException] {
|
||||
@ -108,23 +111,34 @@ class JsonTest extends TestUtils {
|
||||
intercept[ConfigException] {
|
||||
fromJsonWithLiftParser(new java.io.StringReader(invalid.test))
|
||||
}
|
||||
tested += 1
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
assertTrue(tested > 100) // just checking we ran a bunch of tests
|
||||
tested = 0
|
||||
|
||||
// be sure we also throw
|
||||
for (invalid <- whitespaceVariations(invalidJson)) {
|
||||
for (invalid <- whitespaceVariations(invalidJson, false)) {
|
||||
addOffendingJsonToException("config", invalid.test) {
|
||||
intercept[ConfigException] {
|
||||
parse(invalid.test)
|
||||
}
|
||||
tested += 1
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(tested > 100)
|
||||
}
|
||||
|
||||
@Test
|
||||
def validJsonWorks(): Unit = {
|
||||
var tested = 0
|
||||
|
||||
// be sure we do the same thing as Lift when we build our JSON "DOM"
|
||||
for (valid <- whitespaceVariations(validJson)) {
|
||||
for (valid <- whitespaceVariations(validJson, true)) {
|
||||
val liftAST = if (valid.liftBehaviorUnexpected) {
|
||||
SimpleConfigObject.empty()
|
||||
} else {
|
||||
@ -151,7 +165,11 @@ class JsonTest extends TestUtils {
|
||||
addOffendingJsonToException("config", valid.test) {
|
||||
assertEquals(ourAST, ourConfAST)
|
||||
}
|
||||
|
||||
tested += 1
|
||||
}
|
||||
|
||||
assertTrue(tested > 100) // just verify we ran a lot of tests
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -104,7 +104,7 @@ abstract trait TestUtils {
|
||||
"{ : 10 }", // no key in object
|
||||
"{ \"foo\" }", // no value or colon
|
||||
"{ \"a\" : [ }", // [ is not a valid value
|
||||
"{ \"foo\" : 10, }", // extra trailing comma
|
||||
ParseTest(true, "{ \"foo\" : 10, }"), // extra trailing comma (lift fails to throw)
|
||||
"{ \"foo\" : 10, true }", // non-key after comma
|
||||
"{ foo \n bar : 10 }", // newline in the middle of the unquoted key
|
||||
"[ 1, \\", // ends with backslash
|
||||
@ -114,7 +114,7 @@ abstract trait TestUtils {
|
||||
"[ 10e3e3 ]", // two exponents. ideally this might parse to a number plus string "e3" but it's hard to implement.
|
||||
"[ 1-e3 ]", // malformed number but all chars can appear in a number
|
||||
"[ \"hello ]", // unterminated string
|
||||
"[ 1, 2, 3, ]", // array with empty element
|
||||
ParseTest(true, "[ 1, 2, 3, ]"), // array with empty element (lift fails to throw)
|
||||
ParseTest(true, "{ \"foo\" , true }"), // comma instead of colon, lift is fine with this
|
||||
ParseTest(true, "{ \"foo\" : true \"bar\" : false }"), // missing comma between fields, lift fine with this
|
||||
"[ 10, }]", // array with } as an element
|
||||
@ -196,8 +196,8 @@ abstract trait TestUtils {
|
||||
ParseTest(false, true, "[${foo.bar }]"), // substitution with trailing spaces
|
||||
ParseTest(false, true, "[${ \"foo.bar\"}]"), // substitution with leading spaces and quoted
|
||||
ParseTest(false, true, "[${\"foo.bar\" }]"), // substitution with trailing spaces and quoted
|
||||
"""${"foo""bar"}""", // multiple strings in substitution
|
||||
"""${foo "bar" baz}""", // multiple strings and whitespace in substitution
|
||||
"""[ ${"foo""bar"} ]""", // multiple strings in substitution
|
||||
"""[ ${foo "bar" baz} ]""", // multiple strings and whitespace in substitution
|
||||
"[${true}]") // substitution with unquoted true token
|
||||
|
||||
protected val invalidJson = validConfInvalidJson ++ invalidJsonInvalidConf;
|
||||
@ -222,7 +222,7 @@ abstract trait TestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
protected def whitespaceVariations(tests: Seq[ParseTest]): Seq[ParseTest] = {
|
||||
protected def whitespaceVariations(tests: Seq[ParseTest], validInLift: Boolean): Seq[ParseTest] = {
|
||||
val variations = List({ s: String => s }, // identity
|
||||
{ s: String => " " + s },
|
||||
{ s: String => s + " " },
|
||||
@ -233,11 +233,14 @@ abstract trait TestUtils {
|
||||
)
|
||||
tests flatMap { t =>
|
||||
if (t.whitespaceMatters) {
|
||||
return Seq(t)
|
||||
Seq(t)
|
||||
} else {
|
||||
val withNonAscii = ParseTest(true,
|
||||
t.test.replace(" ", "\u2003")) // 2003 = em space, to test non-ascii whitespace
|
||||
Seq(withNonAscii) ++ (for (v <- variations)
|
||||
val withNonAscii = if (t.test.contains(" "))
|
||||
Seq(ParseTest(validInLift,
|
||||
t.test.replace(" ", "\u2003"))) // 2003 = em space, to test non-ascii whitespace
|
||||
else
|
||||
Seq()
|
||||
withNonAscii ++ (for (v <- variations)
|
||||
yield ParseTest(t.liftBehaviorUnexpected, v(t.test)))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user