forked from kiritsuku/IndentGuide
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gbr
committed
Mar 25, 2023
1 parent
4b666a2
commit f23525d
Showing
5 changed files
with
115 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src/test/java"> | ||
<attributes> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" path="src/test/resources"> | ||
<attributes> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/attic/ |
88 changes: 88 additions & 0 deletions
88
...guide.plugin.test/src/test/java/net/certiv/tools/indentguide/painter/IndentWidthTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package net.certiv.tools.indentguide.painter; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.custom.StyledText; | ||
import org.eclipse.swt.graphics.Font; | ||
import org.eclipse.swt.graphics.FontData; | ||
import org.eclipse.swt.graphics.GC; | ||
import org.eclipse.swt.graphics.Point; | ||
import org.eclipse.swt.layout.FillLayout; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class IndentWidthTest { | ||
|
||
public final static boolean isWin = SWT.getPlatform().startsWith("win32"); | ||
public final static boolean isCocoa = SWT.getPlatform().startsWith("cocoa"); | ||
public final static boolean isGTK = SWT.getPlatform().equals("gtk"); | ||
public final static boolean isWinOS = System.getProperty("os.name").startsWith("Windows"); | ||
public final static boolean isLinux = System.getProperty("os.name").equals("Linux"); | ||
|
||
String[] fontnames = new String[] { // | ||
"Consolas", "Courier New", "Menlo", // | ||
"Fira Code", "Source Code Pro", "Liberation Mono" // | ||
}; | ||
|
||
Display display; | ||
Shell shell; | ||
GC gc; | ||
|
||
StyledText widget; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
// display = new Display(); | ||
shell = new Shell(display); | ||
gc = new GC(shell); | ||
|
||
shell.setSize(200, 200); | ||
shell.setLayout(new FillLayout()); | ||
|
||
widget = new StyledText(shell, SWT.BORDER); | ||
widget.setText("This is some dummy text. Sufficient text to have the scroll bars appear."); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
if (gc != null) gc.dispose(); | ||
if (shell != null) shell.dispose(); | ||
} | ||
|
||
@Test | ||
void test_stringExtent() { | ||
for (int size = 7; size < 15; size++) { | ||
for (String name : fontnames) { | ||
FontData fd = new FontData(name, size, SWT.NORMAL); | ||
Font font = new Font(widget.getDisplay(), fd); | ||
widget.setFont(font); | ||
gc.setFont(font); | ||
|
||
Map<Integer, Integer> widths0 = new LinkedHashMap<>(); | ||
Map<Integer, Integer> widths1 = new LinkedHashMap<>(); | ||
for (int col = 1; col <= 10; col++) { | ||
Point p = gc.stringExtent(" "); | ||
widths0.put(col, p.x * col); | ||
|
||
p = gc.stringExtent(" ".repeat(col)); | ||
widths1.put(col, p.x); | ||
} | ||
System.out.printf("Font %-20s: size [%02d] multiply widths %s\n", name, size, widths0); | ||
System.out.printf("Font %-20s: size [%02d] *repeat* widths %s\n", name, size, widths1); | ||
|
||
gc.setFont(null); | ||
widget.setFont(null); | ||
font.dispose(); | ||
|
||
assertTrue(widths0.equals(widths1), String.format("Font %s did not match.", name)); | ||
} | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...rtiv/tools/indentguide/util/LineTest.java → ...v/tools/indentguide/painter/LineTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters