1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-26 12:49:21 +00:00

Merged branch ignoring trailing whitespace in reference files. Closes !4

This commit is contained in:
jespergravgaard 2020-12-11 01:26:42 +01:00
commit 8a89a4e0a1

View File

@ -47,7 +47,7 @@ abstract class ReferenceHelper {
String outLine = outLines.get(i);
if(refLines.size()>i) {
String refLine = refLines.get(i);
if(!outLine.equals(refLine)) {
if(!trimTrailing(outLine).equals(trimTrailing(refLine))) {
writeOutputFile(fileName, extension, outputString);
System.out.println(
"Output does not match reference on line "+i+"\n"+
@ -69,6 +69,21 @@ abstract class ReferenceHelper {
return true;
}
/**
* Trim trailing whitespace from a string
* @param str The string
* @return a copy of the string with any trailing whitespace removed.
*/
public String trimTrailing(String str) {
int len = str.length();
int st = 0;
char[] val = str.toCharArray();
while ((st < len) && (val[len - 1] <= ' ')) {
len--;
}
return str.substring(st, len);
}
private List<String> getOutLines(String outputString) throws IOException {
BufferedReader rdr = new BufferedReader(new StringReader(outputString));
List<String> outLines = new ArrayList<>();