mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 08:55:05 -04:00
added some test cases
This commit is contained in:
parent
b87f2450c1
commit
275415a29d
@ -149,7 +149,7 @@ public final class GraphicsFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
private final static class TextFragment extends Fragment {
|
||||
final static class TextFragment extends Fragment {
|
||||
private final String text;
|
||||
private final Font font;
|
||||
|
||||
@ -287,7 +287,7 @@ public final class GraphicsFormatter {
|
||||
/**
|
||||
* Must set the size of the given fragment by calling the {@link Fragment#set(int, int, int)} method.
|
||||
*
|
||||
* @param fragment fragment which size
|
||||
* @param fragment fragment which size is requested
|
||||
* @param font the used font
|
||||
* @param str the string to measure
|
||||
*/
|
||||
|
@ -1,9 +1,21 @@
|
||||
package de.neemann.digital.draw.graphics.text;
|
||||
|
||||
import de.neemann.digital.draw.graphics.text.text.Simple;
|
||||
import de.neemann.digital.draw.graphics.text.text.Text;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class ParserTest extends TestCase {
|
||||
|
||||
|
||||
public void testPlainString() throws ParseException {
|
||||
Text t = new Parser("Q").parse();
|
||||
assertTrue(t instanceof Simple);
|
||||
assertEquals("Q", ((Simple) t).getText());
|
||||
t = new Parser("In").parse();
|
||||
assertTrue(t instanceof Simple);
|
||||
assertEquals("In", ((Simple) t).getText());
|
||||
}
|
||||
|
||||
public void testSimple() throws ParseException {
|
||||
assertEquals("Decorate{Q_{i}, OVERLINE}", new Parser("~{Q_{i}}").parse().toString());
|
||||
assertEquals("Decorate{Q, OVERLINE}_{i}", new Parser("~Q_{i}").parse().toString());
|
||||
|
@ -0,0 +1,26 @@
|
||||
package de.neemann.digital.draw.graphics.text.formatter;
|
||||
|
||||
import de.neemann.digital.draw.graphics.text.text.Simple;
|
||||
import de.neemann.digital.draw.graphics.text.text.Text;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class GraphicsFormatterTest extends TestCase {
|
||||
|
||||
/**
|
||||
* Ensures that a simple string leads to the simplest text fragment
|
||||
*/
|
||||
public void testSimple() throws GraphicsFormatter.FormatterException {
|
||||
Text t = new Simple("Q");
|
||||
GraphicsFormatter.Fragment f = GraphicsFormatter.createFragment(
|
||||
(fragment, font, str) -> {
|
||||
assertEquals("Q", str);
|
||||
fragment.set(10, 10, 5);
|
||||
},
|
||||
Font.getFont("Arial"), t);
|
||||
|
||||
assertTrue(f instanceof GraphicsFormatter.TextFragment);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user