Skip to content

Commit

Permalink
code cleanup (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
inponomarev authored Apr 11, 2024
1 parent 63a0f6e commit 1ef2366
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 33 deletions.
14 changes: 7 additions & 7 deletions doc/src/main/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Unzip `jsyntrax-XXX.zip` file to any convenient folder. `/bin` directory will co

=== Using JSyntrax

JSyntrax is a command line tool. You pass it an input specification file and it will generate a diagram in any of the supported output formats.
JSyntrax is a command line tool. You pass it an input specification file, and it will generate a diagram in any of the supported output formats.

----
usage: syntrax [--get-style] [-h] [-i <arg>] [-o <arg>] [-s <arg>] [--scale
Expand Down Expand Up @@ -113,7 +113,7 @@ Done!

==== Transparency

By default the images have a white background. If you want a transparent background pass the `+-t+` option.
By default, the images have a white background. If you want a transparent background pass the `+-t+` option.

==== Scaling

Expand Down Expand Up @@ -181,7 +181,7 @@ Nodes in the diagram are represented by quoted strings.
Nodes default to rounded bubbles but will change to a box when prefixed with "/".
Note that this is the reverse of how the original SQLite generator works.
The rounded bubbles are typically used for literal tokens.
Boxes are typically place holders for syntactic elements too complex to include in the current diagram.
Boxes are typically placeholders for syntactic elements too complex to include in the current diagram.
Nodes starting with a non-alphanumeric character are rendered with their own font style so that punctuation tokens can be made more distinct.

The following functions are available for creating diagrams:
Expand Down Expand Up @@ -406,7 +406,7 @@ You can control the styling of the generated diagrams by passing in a
style INI file with the `+-s+` option.

You can use the `+--get-style+` option to generate a copy of the default
styles in the current directory so you can quickly make modifications.
styles in the current directory, so you can quickly make modifications.

Here is the default styling:

Expand Down Expand Up @@ -597,7 +597,7 @@ A regex pattern to match the node text to a style. Notes about pattern format:
- If given input sequence does not match specified expression, default style will be used.

shape::
Node outline shape. Must be "bubble", "box", or "hex".
Node outline shape. Must be one of the following: "bubble", "box", or "hex".

font::
Font style for the node.
Expand Down Expand Up @@ -650,7 +650,7 @@ jsyntrax(stack(
),
[
'entity_class': 'https://www.google.com/#q=vhdl+entity+class',
'(attribute) identifier': 'http://en.wikipedia.com/wiki/VHDL'
'(attribute) identifier': 'https://en.wikipedia.com/wiki/VHDL'
])
----

Expand All @@ -669,7 +669,7 @@ jsyntrax(stack(
),
[
'entity_class': 'https://www.google.com/#q=vhdl+entity+class',
'(attribute) identifier': 'http://en.wikipedia.com/wiki/VHDL'
'(attribute) identifier': 'https://en.wikipedia.com/wiki/VHDL'
])
....

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public void visitLine(Line line) {
this.canvas.addElement(l);
pos.f = xn + endPoint.endpoint.f;
} else {
// first element on line
// first element on the line
pos.f = endPoint.endpoint.f;
}
pos.s = endPoint.endpoint.s;
Expand Down Expand Up @@ -925,8 +925,8 @@ public static class UnitEndPoint {
this.endpoint = endpoint;
}

public String tag;
public Pair<Integer, Integer> endpoint;
public final String tag;
public final Pair<Integer, Integer> endpoint;
}

public UnitEndPoint getUnitEndPoint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Parser {
private final String title

Parser(String scriptText) throws CompilationFailedException {
this.scriptText = scriptText;
this.scriptText = scriptText
def config = new CompilerConfiguration()
config.setScriptBaseClass(SyntraxScript.class.name)
def sharedData = new Binding()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void urlMapTest() {
line("/entity_class", "is", "/expression", ';')
),
Map.of("entity_class", "https://www.google.com/#q=vhdl+entity+class",
"(attribute) identifier", "http://en.wikipedia.com/wiki/VHDL"));
"(attribute) identifier", "https://en.wikipedia.com/wiki/VHDL"));
SVGCanvas c = canvasBuilder.generateSVG(urlMapped);
String result = c.generateSVG();
Approvals.verify(result, OPTIONS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
import java.util.Arrays;
import java.util.stream.Stream;

import static org.atpfivt.jsyntrax.groovy_parser.SyntraxScript.*;

public class JSyntraxTitleTest extends SyntraxScript {
private final SVGCanvasBuilder canvasBuilder;

private final StyleConfig style;

public JSyntraxTitleTest()
throws IllegalAccessException, NoSuchFieldException, IOException {
throws IOException {
style = new StyleConfig(1, false);
JSyntraxTestUtils.updateStyle(style);
canvasBuilder = new SVGCanvasBuilder().withStyle(style);
Expand Down
19 changes: 7 additions & 12 deletions jsyntrax/src/test/java/org/atpfivt/jsyntrax/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@

import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

class MainTest {
@Test
void testEnd2EndHappyPath() throws URISyntaxException, IOException,
NoSuchFieldException, IllegalAccessException {
void testEnd2EndHappyPath() throws URISyntaxException, IOException {
Path inputPath = Paths.get(MainTest.class.getResource("jsyntrax.spec").toURI());
Path outPath = Files.createTempFile("jsyntrax-test-output", ".svg");
try {
Expand All @@ -32,8 +29,7 @@ void testEnd2EndHappyPath() throws URISyntaxException, IOException,
}

@Test
void testWriteHelp() throws IOException,
NoSuchFieldException, IllegalAccessException {
void testWriteHelp() throws IOException {
final PrintStream standardOut = System.out;
final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
System.setOut(new PrintStream(outputStreamCaptor));
Expand All @@ -48,8 +44,7 @@ void testWriteHelp() throws IOException,
}

@Test
void printVersionTest() throws IOException,
NoSuchFieldException, IllegalAccessException {
void printVersionTest() throws IOException {
final PrintStream standardOut = System.out;
final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
System.setOut(new PrintStream(outputStreamCaptor));
Expand Down Expand Up @@ -79,7 +74,7 @@ void getStyleTest() throws IOException, URISyntaxException {

@ValueSource(strings = {".png", ".PNG", ".PnG"})
@ParameterizedTest
void testPngByOutFileExtention(String ext) throws IOException, URISyntaxException, NoSuchFieldException, IllegalAccessException {
void testPngByOutFileExtention(String ext) throws IOException, URISyntaxException {
Path inputPath = Paths.get(MainTest.class.getResource("jsyntrax.spec").toURI());
Path outPath = Files.createTempFile("jsyntrax-test-output", ext);
try {
Expand All @@ -92,7 +87,7 @@ void testPngByOutFileExtention(String ext) throws IOException, URISyntaxExceptio
}

@Test
void testPngByOutFileType() throws IOException, URISyntaxException, NoSuchFieldException, IllegalAccessException {
void testPngByOutFileType() throws IOException, URISyntaxException {
Path inputPath = Paths.get(MainTest.class.getResource("jsyntrax.spec").toURI());
Path outPath = Paths.get(inputPath.toString().substring(0, inputPath.toString().lastIndexOf('.')) + ".png");
try {
Expand All @@ -105,7 +100,7 @@ void testPngByOutFileType() throws IOException, URISyntaxException, NoSuchFieldE
}

@Test
void testSvgByOutFileType() throws IOException, URISyntaxException, NoSuchFieldException, IllegalAccessException {
void testSvgByOutFileType() throws IOException, URISyntaxException {
Path inputPath = Paths.get(MainTest.class.getResource("jsyntrax.spec").toURI());
Path outPath = Paths.get(inputPath.toString().substring(0, inputPath.toString().lastIndexOf('.')) + ".svg");
try {
Expand All @@ -118,7 +113,7 @@ void testSvgByOutFileType() throws IOException, URISyntaxException, NoSuchFieldE
}

@Test
void testPngByDefault() throws IOException, URISyntaxException, NoSuchFieldException, IllegalAccessException {
void testPngByDefault() throws IOException, URISyntaxException {
Path inputPath = Paths.get(MainTest.class.getResource("jsyntrax.spec").toURI());
Path outPath = Paths.get(inputPath.toString().substring(0, inputPath.toString().lastIndexOf('.')) + ".png");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class PngOutputTest {
@Test
public void transcodeTest() throws IllegalAccessException, NoSuchFieldException,
public void transcodeTest() throws
IOException, URISyntaxException {
// Given
Path inputPath = Paths.get(MainTest.class.getResource("test_spec.txt").toURI());
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class JSyntraxStyleFileTest {
Files.createTempFile("jsyntrax-test-style", ".ini");

public JSyntraxStyleFileTest()
throws IOException, NoSuchFieldException, IllegalAccessException {
throws IOException {
StyleConfig s = new StyleConfig(1, false);
JSyntraxTestUtils.updateStyle(s);
canvasBuilder = new SVGCanvasBuilder().withStyle(s);
Expand Down Expand Up @@ -55,7 +55,7 @@ void fontFromString(){
}

@Test
void configParserTest() throws IOException, NoSuchFieldException, IllegalAccessException {
void configParserTest() throws IOException {
StringBuilder config = new StringBuilder();
config.append("[style]\n")
.append("line_width = 50\n")
Expand Down Expand Up @@ -86,8 +86,7 @@ void configParserTest() throws IOException, NoSuchFieldException, IllegalAccessE

@Test
public void svgFromConfigTest()
throws IOException, URISyntaxException,
NoSuchFieldException, IllegalAccessException {
throws IOException, URISyntaxException {
// Given
String config = Files.readString(
Path.of(this
Expand Down

0 comments on commit 1ef2366

Please sign in to comment.