only:dropComments

This commit is contained in:
rusefillc 2024-03-18 09:51:18 -04:00
parent 9126940adb
commit 029b9b56b8
2 changed files with 39 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import com.rusefi.*;
import com.rusefi.util.LazyFileImpl;
import com.rusefi.util.Output;
import com.rusefi.util.SystemOut;
import org.jetbrains.annotations.NotNull;
import java.io.*;
@ -22,6 +23,7 @@ public class TSProjectConsumer implements ConfigurationConsumer {
private final String tsPath;
private final ReaderStateImpl state;
public boolean dropComments;
private int totalTsSize;
private final TsOutput tsOutput;
@ -70,7 +72,13 @@ public class TSProjectConsumer implements ConfigurationConsumer {
*/
private TsFileContent readTsTemplateInputFile(String tsPath) throws IOException {
String fileName = getTsFileInputName(tsPath);
BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), CHARSET.name()));
FileInputStream in = new FileInputStream(fileName);
return getTsFileContent(in);
}
@NotNull
public TsFileContent getTsFileContent(InputStream in) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(in, CHARSET));
StringBuilder prefix = new StringBuilder();
StringBuilder postfix = new StringBuilder();
@ -87,6 +95,8 @@ public class TSProjectConsumer implements ConfigurationConsumer {
isAfterEndTag = true;
continue;
}
if (line.trim().startsWith("!") && dropComments)
continue;
if (line.contains(TS_CONDITION)) {
String token = getToken(line);

View File

@ -1,14 +1,23 @@
package com.rusefi.test;
import com.rusefi.ReaderStateImpl;
import com.rusefi.TsFileContent;
import com.rusefi.output.BaseCHeaderConsumer;
import com.rusefi.output.JavaFieldsConsumer;
import com.rusefi.output.TSProjectConsumer;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.StringBufferInputStream;
import static com.rusefi.AssertCompatibility.assertEquals;
public class TSProjectConsumerTest {
private static final String smallContent = "hello = \"!\"\n" +
"world!comment\n" +
"!comment2\n" +
"end\n";
@Test
public void getTsCondition() {
assertEquals("ts", TSProjectConsumer.getToken("\"HIP9011 Settings (knock sensor) (alpha version)\" @@if_ts\r\n"));
@ -121,4 +130,22 @@ public class TSProjectConsumerTest {
"static_assert(sizeof(pid_s) == 1);\n" +
"\n", consumer.getContent());
}
}
@Test
public void testReaderKeepComments() throws IOException {
TSProjectConsumer consumer = new TestTSProjectConsumer(null, new ReaderStateImpl());
TsFileContent content = consumer.getTsFileContent(new StringBufferInputStream(smallContent));
assertEquals(smallContent, content.getPrefix());
assertEquals("", content.getPostfix());
}
@Test
public void testReaderDropComments() throws IOException {
TSProjectConsumer consumer = new TestTSProjectConsumer(null, new ReaderStateImpl());
consumer.dropComments = true;
TsFileContent content = consumer.getTsFileContent(new StringBufferInputStream(smallContent));
assertEquals("hello = \"!\"\n" +
"world!comment\n" +
"end\n", content.getPrefix());
assertEquals("", content.getPostfix());
}}