This commit is contained in:
rusefillc 2021-10-17 11:48:41 -04:00
parent 8318978077
commit d1afb8eee2
2 changed files with 11 additions and 23 deletions

View File

@ -1,30 +1,26 @@
package com.rusefi.ui.livedata;
import com.rusefi.livedata.LiveDataParserPanel;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import java.awt.*;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
public class LiveDataParserTest {
@Test
public void testParsing() throws IOException {
public void testParsing() {
Map<String, Object> values = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
values.put("engineTooSlow", Boolean.TRUE);
values.put("engineTooFast", Boolean.FALSE);
VariableValueSource valueSource = new VariableValueSource() {
@Override
public Object getValue(String name) {
return values.get(name);
}
};
VariableValueSource valueSource = values::get;
String sourceCode = "bool AcState::getAcState(DECLARE_ENGINE_PARAMETER_SIGNATURE) {\n" +
"\tauto rpm = Sensor::getOrZero(SensorType::Rpm);\n" +
@ -43,24 +39,15 @@ public class LiveDataParserTest {
"return ff;\n" +
"}";
SourceCodePainter painter = new SourceCodePainter() {
@Override
public void paintBackground(Color color, Range range) {
System.out.println("paint " + color + " " + range);
}
@Override
public void paintForeground(Color color, Range range) {
System.out.println("paintForeground");
}
};
SourceCodePainter painter = mock(SourceCodePainter.class);
ParseTree tree = LiveDataParserPanel.getParseTree(sourceCode);
new ParseTreeWalker().walk(new PrintCPP14ParserListener(), tree);
LiveDataParserPanel.applyVariables(valueSource, sourceCode, painter, tree);
verify(painter, times(2)).paintForeground(eq(Color.blue), any());
verify(painter).paintBackground(eq(Color.red), any());
verify(painter).paintBackground(eq(Color.green), any());
}
}

View File

@ -32,5 +32,6 @@
<orderEntry type="library" name="dfu_java" level="project" />
<orderEntry type="module" module-name="proxy_server" scope="TEST" />
<orderEntry type="library" name="antlr" level="project" />
<orderEntry type="library" scope="TEST" name="mockito-all-1.10.19" level="project" />
</component>
</module>