Skip to content

Commit

Permalink
Temporary fix for #1: don't parse lines ending with backslash
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuckame committed Nov 7, 2020
1 parent bd0d9db commit fb1892f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.nio.file.FileAlreadyExistsException;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;

Expand All @@ -29,6 +30,9 @@ public void run(final String[] args) throws Exception {
if (e.getCause() instanceof NoSuchFileException) {
consoleHelper.writeErrorLine("File not found: " + Path.of(e.getCause().getMessage()).toAbsolutePath());
System.exit(4);
} else if (e.getCause() instanceof FileAlreadyExistsException) {
consoleHelper.writeErrorLine("File already present: " + Path.of(e.getCause().getMessage()).toAbsolutePath());
System.exit(6);
} else {
consoleHelper.writeErrorLine(e.getMessage());
System.exit(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ public static class ParsedConstant {

public Mono<ParsedConstant> parseLine(final String line) {
return Mono.just(line)
.filter(this::isNotMultilineValue)
.map(CONSTANT_REGEX::matcher)
.filter(Matcher::matches)
.map(this::toConstant);
}

private boolean isNotMultilineValue(final String line) {
return !line.endsWith("\\");
}

public Mono<String> disableLine(final ConstantLineDetails constantLineDetails) {
return Mono.just(constantLineDetails)
.map(ConstantLineDetails::getLine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ protected DumperOptions buildDumperOptions(final int jsonFeatures, final int yam
opts.setIndicatorIndent(indentation);
return opts;
}

@Override
public void writeNull() throws IOException {
_verifyValueWrite("write null value");
// no real type for this, is there?
_writeScalar("", "object", DumperOptions.ScalarStyle.PLAIN);
}
};
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.chuckame.marlinfw.configurator.constant;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
Expand All @@ -9,6 +10,16 @@
class ConstantLineInterpreterTest {
private final ConstantLineInterpreter constantLineInterpreter = new ConstantLineInterpreter();

// fixme cannot parse following lines when first line ending with backslash '\': https://github.com/Chuckame/marlin-console-configurator/issues/1
@Test
void TEMPORARY_FIX_parseLineShouldReturnNothingWhenValueEndsWithBackslash() {
final var line = "#define CONSTANT value \\";

final var constant = constantLineInterpreter.parseLine(line);

assertThat(constant.blockOptional()).isEmpty();
}

@ParameterizedTest
@CsvSource({
"'#define coNsTANT ',coNsTANT,",
Expand Down

0 comments on commit fb1892f

Please sign in to comment.