mirror of
https://github.com/lightbend/config.git
synced 2025-03-23 07:40:25 +08:00
include the message in Tokens#Problem#toString
Required adding accessor for "what" for use in tests
This commit is contained in:
parent
b3ac8d0539
commit
ac878d653c
@ -121,6 +121,10 @@ final class Tokens {
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
String what() {
|
||||
return what;
|
||||
}
|
||||
|
||||
String message() {
|
||||
return message;
|
||||
}
|
||||
@ -139,6 +143,9 @@ final class Tokens {
|
||||
sb.append('\'');
|
||||
sb.append(what);
|
||||
sb.append('\'');
|
||||
sb.append(" (");
|
||||
sb.append(message);
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@ -276,6 +283,14 @@ final class Tokens {
|
||||
return token instanceof Problem;
|
||||
}
|
||||
|
||||
static String getProblemWhat(Token token) {
|
||||
if (token instanceof Problem) {
|
||||
return ((Problem) token).what();
|
||||
} else {
|
||||
throw new ConfigException.BugOrBroken("tried to get problem what from " + token);
|
||||
}
|
||||
}
|
||||
|
||||
static String getProblemMessage(Token token) {
|
||||
if (token instanceof Problem) {
|
||||
return ((Problem) token).message();
|
||||
|
@ -229,9 +229,9 @@ class TokenizerTest extends TestUtils {
|
||||
val problem = tokenized(1)
|
||||
assertTrue("reserved char is a problem", Tokens.isProblem(problem))
|
||||
if (invalid == '+')
|
||||
assertEquals("'end of file'", problem.toString())
|
||||
assertEquals("end of file", Tokens.getProblemWhat(problem))
|
||||
else
|
||||
assertEquals("'" + invalid + "'", problem.toString())
|
||||
assertEquals("" + invalid, Tokens.getProblemWhat(problem))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user