explicit unit tests for config tokens in real source code

This commit is contained in:
rusefillc 2021-11-24 13:30:50 -05:00
parent f6c88cf4e9
commit fb8252883f
3 changed files with 27 additions and 0 deletions

View File

@ -3,6 +3,16 @@ package com.rusefi.ui.livedata;
import java.awt.*;
public interface SourceCodePainter {
SourceCodePainter VOID = new SourceCodePainter() {
@Override
public void paintBackground(Color color, Range range) {
}
@Override
public void paintForeground(Color color, Range range) {
}
};
void paintBackground(Color color, Range range);
void paintForeground(Color color, Range range);

View File

@ -1,5 +1,7 @@
package com.rusefi.ui.livedata;
public interface VariableValueSource {
VariableValueSource VOID = name -> null;
Object getValue(String name);
}

View File

@ -1,14 +1,19 @@
package com.rusefi.ui.livedata;
import com.rusefi.livedata.LiveDataParserPanel;
import com.rusefi.livedata.LiveDataView;
import com.rusefi.livedata.ParseResult;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.junit.Test;
import java.awt.*;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.TreeMap;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
@ -50,4 +55,14 @@ public class LiveDataParserTest {
verify(painter).paintBackground(eq(Color.red), any());
verify(painter).paintBackground(eq(Color.green), any());
}
@Test
public void testConfigurationInRealSourceCode() throws IOException, URISyntaxException {
String sourceCode = LiveDataParserPanel.getContent(LiveDataParserPanel.class, LiveDataView.BOOST_CONTROL.getFileName());
assertTrue(sourceCode.length() > 100);
ParseTree tree = LiveDataParserPanel.getParseTree(sourceCode);
ParseResult parseResult = LiveDataParserPanel.applyVariables(VariableValueSource.VOID, sourceCode, SourceCodePainter.VOID, tree);
assertTrue(!parseResult.getConfigTokens().isEmpty());
}
}