only:dropComments
This commit is contained in:
parent
9126940adb
commit
029b9b56b8
|
@ -4,6 +4,7 @@ import com.rusefi.*;
|
||||||
import com.rusefi.util.LazyFileImpl;
|
import com.rusefi.util.LazyFileImpl;
|
||||||
import com.rusefi.util.Output;
|
import com.rusefi.util.Output;
|
||||||
import com.rusefi.util.SystemOut;
|
import com.rusefi.util.SystemOut;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
||||||
|
|
||||||
private final String tsPath;
|
private final String tsPath;
|
||||||
private final ReaderStateImpl state;
|
private final ReaderStateImpl state;
|
||||||
|
public boolean dropComments;
|
||||||
private int totalTsSize;
|
private int totalTsSize;
|
||||||
private final TsOutput tsOutput;
|
private final TsOutput tsOutput;
|
||||||
|
|
||||||
|
@ -70,7 +72,13 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
||||||
*/
|
*/
|
||||||
private TsFileContent readTsTemplateInputFile(String tsPath) throws IOException {
|
private TsFileContent readTsTemplateInputFile(String tsPath) throws IOException {
|
||||||
String fileName = getTsFileInputName(tsPath);
|
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 prefix = new StringBuilder();
|
||||||
StringBuilder postfix = new StringBuilder();
|
StringBuilder postfix = new StringBuilder();
|
||||||
|
@ -87,6 +95,8 @@ public class TSProjectConsumer implements ConfigurationConsumer {
|
||||||
isAfterEndTag = true;
|
isAfterEndTag = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (line.trim().startsWith("!") && dropComments)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (line.contains(TS_CONDITION)) {
|
if (line.contains(TS_CONDITION)) {
|
||||||
String token = getToken(line);
|
String token = getToken(line);
|
||||||
|
|
|
@ -1,14 +1,23 @@
|
||||||
package com.rusefi.test;
|
package com.rusefi.test;
|
||||||
|
|
||||||
import com.rusefi.ReaderStateImpl;
|
import com.rusefi.ReaderStateImpl;
|
||||||
|
import com.rusefi.TsFileContent;
|
||||||
import com.rusefi.output.BaseCHeaderConsumer;
|
import com.rusefi.output.BaseCHeaderConsumer;
|
||||||
import com.rusefi.output.JavaFieldsConsumer;
|
import com.rusefi.output.JavaFieldsConsumer;
|
||||||
import com.rusefi.output.TSProjectConsumer;
|
import com.rusefi.output.TSProjectConsumer;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.StringBufferInputStream;
|
||||||
|
|
||||||
import static com.rusefi.AssertCompatibility.assertEquals;
|
import static com.rusefi.AssertCompatibility.assertEquals;
|
||||||
|
|
||||||
public class TSProjectConsumerTest {
|
public class TSProjectConsumerTest {
|
||||||
|
private static final String smallContent = "hello = \"!\"\n" +
|
||||||
|
"world!comment\n" +
|
||||||
|
"!comment2\n" +
|
||||||
|
"end\n";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getTsCondition() {
|
public void getTsCondition() {
|
||||||
assertEquals("ts", TSProjectConsumer.getToken("\"HIP9011 Settings (knock sensor) (alpha version)\" @@if_ts\r\n"));
|
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" +
|
"static_assert(sizeof(pid_s) == 1);\n" +
|
||||||
"\n", consumer.getContent());
|
"\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());
|
||||||
|
}}
|
||||||
|
|
Loading…
Reference in New Issue