Skip to content

Commit

Permalink
Merge pull request #102 from bric3/windows-failure
Browse files Browse the repository at this point in the history
Understand windows failure
  • Loading branch information
bric3 authored Sep 18, 2023
2 parents 33343ac + 0a1e93e commit 257ee17
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 249 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
ignore-errors: [false]
ignore-errors: [true]
include:
- os: windows-latest
ignore-errors: true
Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
[versions]
asciidoctorj = "2.5.10"
asciidoctorjDiagram = "2.2.11"
junit-jupiter = "5.10.0"
assertj = "3.24.2"
junit-jupiter = "5.10.0"
mockito = "5.5.0"
picocli = "4.7.5"

[libraries]
Expand All @@ -25,6 +26,7 @@ assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" }
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit-jupiter" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit-jupiter" }
junit-jupiter-params = { module = "org.junit.jupiter:junit-jupiter-params", version.ref = "junit-jupiter" }
mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" }

jetbrains-annotations = { module = "org.jetbrains:annotations", version = "24.0.1" }

Expand Down
1 change: 1 addition & 0 deletions jufmt-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
implementation(projects.jufmtLib)

testImplementation(libs.assertj)
testImplementation(libs.mockito.core)
testImplementation(libs.bundles.junit.jupiter)
}

Expand Down
56 changes: 27 additions & 29 deletions jufmt-cli/src/main/java/io/github/bric3/jufmt/app/JufmtCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import picocli.CommandLine.Model.UsageMessageSpec;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.Character.UnicodeBlock;
import java.lang.Character.UnicodeScript;
import java.nio.file.Files;
Expand Down Expand Up @@ -115,18 +116,19 @@ public static void main(String[] args) {
cmd.execute(args);
}

private static void charDetails(int c) {
System.out.println("--------");
System.out.printf("char : %04x %s%n", c, Character.toString(c));
System.out.printf("char count : %d%n", Character.charCount(c));
System.out.printf("lower case : %04x %s%n", Character.toLowerCase(c), Character.toString(Character.toLowerCase(c)));
System.out.printf("title case : %04x %s%n", Character.toTitleCase(c), Character.toString(Character.toTitleCase(c)));
System.out.printf("upper case : %04x %s%n", Character.toUpperCase(c), Character.toString(Character.toUpperCase(c)));
System.out.printf("char name : %s%n", Character.getName(c));
System.out.printf("char type : %d%n", Character.getType(c));
System.out.printf("char direction: %d%n", Character.getDirectionality(c));
System.out.printf("unicode block : %s%n", UnicodeBlock.of(c));
System.out.printf("unicode script: %s%n", UnicodeScript.of(c));
private void charDetails(int c) {
var out = spec.commandLine().getOut();
out.println("--------");
out.printf("char : %04x %s%n", c, Character.toString(c));
out.printf("char count : %d%n", Character.charCount(c));
out.printf("lower case : %04x %s%n", Character.toLowerCase(c), Character.toString(Character.toLowerCase(c)));
out.printf("title case : %04x %s%n", Character.toTitleCase(c), Character.toString(Character.toTitleCase(c)));
out.printf("upper case : %04x %s%n", Character.toUpperCase(c), Character.toString(Character.toUpperCase(c)));
out.printf("char name : %s%n", Character.getName(c));
out.printf("char type : %d%n", Character.getType(c));
out.printf("char direction: %d%n", Character.getDirectionality(c));
out.printf("unicode block : %s%n", UnicodeBlock.of(c));
out.printf("unicode script: %s%n", UnicodeScript.of(c));
}

public void run() {
Expand Down Expand Up @@ -170,14 +172,14 @@ public void run() {
if (describe) {
if (stringToProcess != null && !stringToProcess.isBlank()) {
stringToProcess.codePoints()
.onClose(() -> System.out.println("--------"))
.forEach(JufmtCommand::charDetails);
.onClose(() -> spec.commandLine().getOut().println("--------"))
.forEach(this::charDetails);
return;
}
if (converter != FancyConverters.none) {
converter.chars.codePoints()
.onClose(() -> System.out.println("--------"))
.forEach(JufmtCommand::charDetails);
.onClose(() -> spec.commandLine().getOut().println("--------"))
.forEach(this::charDetails);
return;
}
}
Expand Down Expand Up @@ -255,27 +257,24 @@ void figlet(
*
* TODO expose layout options
*/

var out = spec.commandLine().getOut();
if (random) {
if (random || figletFont == null && !renderAll) {
out.println(Figlet.render(stringToProcess));
return;
}
if (renderAll) {
Arrays.stream(EmbeddedFigletFonts.values())
.forEach(f -> {
out.printf("%s:%n", f);
out.println();
out.println(Figlet.render(stringToProcess, f));
out.println();
});
.forEach(f -> {
out.printf("%s:%n", f);
out.println();
out.println(Figlet.render(stringToProcess, f));
out.println();
});
return;
}

Figlet.FontSpec font;
if (figletFont == null) {
font = EmbeddedFigletFonts.random();
} else if (figletFont.fontFile != null) {
if (figletFont.fontFile != null) {
try {
var fontFile = Path.of(".").toRealPath().resolve(figletFont.fontFile);
var fileName = fontFile.getFileName().toString();
Expand All @@ -300,8 +299,7 @@ void figlet(
font = figletFont.font;
}

var rendered = Figlet.render(stringToProcess, font);
out.println(rendered);
out.println(Figlet.render(stringToProcess, font));
}

@Command(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.text.Normalizer;
import java.util.stream.Stream;

import static io.github.bric3.jufmt.app.JufmtTestUtil.jufmt;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.params.provider.Arguments.arguments;

Expand All @@ -38,57 +39,45 @@ public class JufmtCommandTest {
@ParameterizedTest
@EnumSource
public void check_style(FancyStyle style) {
var stringWriter = new StringWriter();
new CommandLine(new JufmtCommand())
.setOut(new PrintWriter(stringWriter))
.execute("-s", style.name(), "bric3");
var result = jufmt("-s", style.name(), "bric3");

assertThat(stringWriter.toString())
assertThat(result.out())
.describedAs(style.name())
.isEqualToIgnoringNewLines(style.example);

System.out.printf("%s: %s", style.name(), stringWriter.toString());
System.out.printf("%s: %s", style.name(), result.out());

}

@ParameterizedTest
@EnumSource(mode = Mode.EXCLUDE, names = {"none"})
public void check_charset(FancyConverters converter) {
var stringWriter = new StringWriter();
new CommandLine(new JufmtCommand())
.setOut(new PrintWriter(stringWriter))
.execute("-c", converter.name(), "bric3");
var result = jufmt("-c", converter.name(), "bric3");

assertThat(stringWriter.toString())
assertThat(result.out())
.describedAs(converter.name())
.isEqualToIgnoringNewLines(converter.example);

System.out.printf("%s: %s", converter.name(), stringWriter.toString());
System.out.printf("%s: %s", converter.name(), result.out());
}

@ParameterizedTest
@EnumSource(FancyOrnaments.class)
public void check_ornament(FancyOrnaments ornaments) {
var stringWriter = new StringWriter();
new CommandLine(new JufmtCommand())
.setOut(new PrintWriter(stringWriter))
.execute("-o", ornaments.name(), "bric3");
var result = jufmt("-o", ornaments.name(), "bric3");

assertThat(stringWriter.toString())
assertThat(result.out())
.describedAs(ornaments.name())
.isEqualToIgnoringNewLines(ornaments.example);

System.out.printf("%s: %s", ornaments.name(), stringWriter.toString());
System.out.printf("%s: %s", ornaments.name(), result.out());
}

@Test
public void check_reversed() {
var stringWriter = new StringWriter();
new CommandLine(new JufmtCommand())
.setOut(new PrintWriter(stringWriter))
.execute("-r", "bric3");
var result = jufmt("-r", "bric3");

assertThat(stringWriter.toString())
assertThat(result.out())
.describedAs("reversed")
.isEqualToIgnoringNewLines("3cirb");

Expand All @@ -100,15 +89,11 @@ class Normalization {
@ParameterizedTest
@MethodSource("normalizationArguments")
void check_normalizer(Normalizer.Form form, String input, String expected) {
var cmd = new CommandLine(new JufmtCommand());

var stringWriter = new StringWriter();
cmd.setOut(new PrintWriter(stringWriter));
cmd.execute("-n", form.name(), input);
var result = jufmt("-n", form.name(), input);

// System.out.printf("Normalizer.Form.%s:%n%s%n%s", form.name(), input, stringWriter.toString());

assertThat(stringWriter.toString())
assertThat(result.out())
.describedAs(form.name())
.isEqualToIgnoringNewLines(expected);
}
Expand Down Expand Up @@ -258,15 +243,11 @@ private static Stream<Arguments> normalizationArguments() {
@ParameterizedTest
@MethodSource("diacriticalMarkStrippingArguments")
void check_normalizer_with_diacritical_mark_stripping(Normalizer.Form form, String input, String expected) {
var result = jufmt("-n", form.name(), "--strip-diacritic-marks", input);

var stringWriter = new StringWriter();
new CommandLine(new JufmtCommand())
.setOut(new PrintWriter(stringWriter))
.execute("-n", form.name(), "--strip-diacritic-marks", input);

System.out.printf("%s: %s", form.name(), stringWriter);
System.out.printf("%s: %s", form.name(), result.out());

assertThat(stringWriter.toString())
assertThat(result.out())
.describedAs(form.name())
.isEqualToIgnoringNewLines(expected);
}
Expand All @@ -281,16 +262,10 @@ private static Stream<Arguments> diacriticalMarkStrippingArguments() {
@ParameterizedTest
@EnumSource(mode = Mode.INCLUDE, names = {"NFC", "NFKC"})
void check_incompatible_normalizer_with_diacritical_mark_stripping(Normalizer.Form form) {
var result = jufmt("-n", form.name(), "--strip-diacritic-marks", "ignored");

var stdout = new StringWriter();
var stderr = new StringWriter();
var status = new CommandLine(new JufmtCommand())
.setOut(new PrintWriter(stdout))
.setErr(new PrintWriter(stderr))
.execute("-n", form.name(), "--strip-diacritic-marks", "ignored");

assertThat(status).isEqualTo(CommandLine.ExitCode.USAGE);
assertThat(stderr.toString())
assertThat(result.status()).isEqualTo(CommandLine.ExitCode.USAGE);
assertThat(result.err())
.describedAs(form.name())
.containsIgnoringCase("diacritical mark stripping")
.containsIgnoringCase("NFD")
Expand Down
Loading

0 comments on commit 257ee17

Please sign in to comment.