Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
xzel23 committed Dec 11, 2023
1 parent af00271 commit f9be5e5
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions utility/src/test/java/com/dua3/utility/text/AnsiConverterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.dua3.utility.text;

import org.junit.jupiter.api.Test;

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

class AnsiConverterTest {

@Test
void create() {
Style[] styles = {
Style.BOLD,
Style.ITALIC,
Style.UNDERLINE,
Style.LINE_THROUGH,
Style.RED
};
RichTextBuilder b = new RichTextBuilder();
b.push(Style.BOLD).append("AnsiConverterTest").pop(Style.BOLD);
b.append("\n");
for (int i = 0; i < (1 << styles.length); i++) {
StringBuilder sb = new StringBuilder("Styles:");
for (int j = 0; j < styles.length; j++) {
if ((i & (1 << j)) != 0) {
b.push(styles[j]);
sb.append(" ").append(styles[j].name());
}
}
b.append(sb);
for (int j = styles.length - 1; j >= 0; j--) {
if ((i & (1 << j)) != 0) {
b.pop(styles[j]);
}
}
b.append("\n");
}
b.append("normal\n");
RichText rt = b.toRichText();

AnsiConverter converter = AnsiConverter.create();
String s = converter.convert(rt);
System.out.println(s);
String expected = """
AnsiConverterTest
Styles:
Styles: bold
Styles: italic
Styles: bold italic
Styles: underline
Styles: bold underline
Styles: italic underline
Styles: bold italic underline
Styles: line-through
Styles: bold line-through
Styles: italic line-through
Styles: bold italic line-through
Styles: underline line-through
Styles: bold underline line-through
Styles: italic underline line-through
Styles: bold italic underline line-through
Styles: red
Styles: bold red
Styles: italic red
Styles: bold italic red
Styles: underline red
Styles: bold underline red
Styles: italic underline red
Styles: bold italic underline red
Styles: line-through red
Styles: bold line-through red
Styles: italic line-through red
Styles: bold italic line-through red
Styles: underline line-through red
Styles: bold underline line-through red
Styles: italic underline line-through red
Styles: bold italic underline line-through red
normal
""";
assertEquals(expected, s);
}
}

0 comments on commit f9be5e5

Please sign in to comment.