hydromatic / morel

Standard ML interpreter, with relational extensions, implemented in Java
Apache License 2.0
291 stars 15 forks source link

Simplify testing for locations in error messages #214

Open julianhyde opened 5 months ago

julianhyde commented 5 months ago

Simplify testing for locations in error messages. Currently we write

ml("from {x, y} group")
    .assertParseThrowsParseException(
        startsWith("Encountered \" \"group\" \"group \"\" at line 1, column 13."));

but we should instead write something like

ml("from {x, y} $group")
    .withErrorAt('$')
    .assertParseThrowsParseException(loc ->
        startsWith("Encountered \" \"group\" \"group \"\" at " + loc + "."));

The new withErrorAt method scans the source string for $, removes the $, and sets the error location to where it was (line 1, column 13). The assertParseThrowsParseException method now accepts a Function<String, Matcher<String>>, and the first argument is the error location.