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