Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
  • Loading branch information
arthurscchan committed Aug 22, 2023
1 parent 1e54c06 commit 4753292
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/test/java/org/fusesource/jansi/AnsiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.jupiter.params.provider.CsvSource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Tests for the {@link Ansi} class.
Expand Down Expand Up @@ -64,6 +65,32 @@ public void apply(Ansi ansi) {
}).toString());
}

@ParameterizedTest
@CsvSource({
"-2147483648,ESC[2147483647T", "2147483647,ESC[2147483647S",
"-100000,ESC[100000T", "100000,ESC[100000S"
})
public void testScrollUp(int x, String expected) {
try {
assertAnsi(expected, Ansi.ansi().scrollUp(x));
} catch (StackOverflowError e) {
fail("Infinite loop detected.");
}
}

@ParameterizedTest
@CsvSource({
"-2147483648,ESC[2147483647S", "2147483647,ESC[2147483647T",
"-100000,ESC[100000S", "100000,ESC[100000T"
})
public void testScrollDown(int x, String expected) {
try {
assertAnsi(expected, Ansi.ansi().scrollDown(x));
} catch (StackOverflowError e) {
fail("Infinite loop detected.");
}
}

@ParameterizedTest
@CsvSource({
"-1,-1,ESC[1;1H", "-1,0,ESC[1;1H", "-1,1,ESC[1;1H", "-1,2,ESC[1;2H",
Expand Down Expand Up @@ -152,4 +179,4 @@ public void testColorDisabled() {
private static void assertAnsi(String expected, Ansi actual) {
assertEquals(expected.replace("ESC", "\033"), actual.toString());
}
}
}

0 comments on commit 4753292

Please sign in to comment.