Skip to content

Commit f23525d

Browse files
author
gbr
committed
Added IndentWidthTest.
1 parent 4b666a2 commit f23525d

File tree

5 files changed

+115
-9
lines changed

5 files changed

+115
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3+
<classpathentry kind="src" path="src/test/java">
4+
<attributes>
5+
<attribute name="test" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src/test/resources">
9+
<attributes>
10+
<attribute name="test" value="true"/>
11+
</attributes>
12+
</classpathentry>
313
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
414
<attributes>
515
<attribute name="module" value="true"/>
616
</attributes>
717
</classpathentry>
818
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
19+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
920
<classpathentry kind="output" path="target/classes"/>
1021
</classpath>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/attic/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package net.certiv.tools.indentguide.painter;
2+
3+
import static org.junit.jupiter.api.Assertions.assertTrue;
4+
5+
import java.util.LinkedHashMap;
6+
import java.util.Map;
7+
8+
import org.eclipse.swt.SWT;
9+
import org.eclipse.swt.custom.StyledText;
10+
import org.eclipse.swt.graphics.Font;
11+
import org.eclipse.swt.graphics.FontData;
12+
import org.eclipse.swt.graphics.GC;
13+
import org.eclipse.swt.graphics.Point;
14+
import org.eclipse.swt.layout.FillLayout;
15+
import org.eclipse.swt.widgets.Display;
16+
import org.eclipse.swt.widgets.Shell;
17+
import org.junit.jupiter.api.AfterEach;
18+
import org.junit.jupiter.api.BeforeEach;
19+
import org.junit.jupiter.api.Test;
20+
21+
class IndentWidthTest {
22+
23+
public final static boolean isWin = SWT.getPlatform().startsWith("win32");
24+
public final static boolean isCocoa = SWT.getPlatform().startsWith("cocoa");
25+
public final static boolean isGTK = SWT.getPlatform().equals("gtk");
26+
public final static boolean isWinOS = System.getProperty("os.name").startsWith("Windows");
27+
public final static boolean isLinux = System.getProperty("os.name").equals("Linux");
28+
29+
String[] fontnames = new String[] { //
30+
"Consolas", "Courier New", "Menlo", //
31+
"Fira Code", "Source Code Pro", "Liberation Mono" //
32+
};
33+
34+
Display display;
35+
Shell shell;
36+
GC gc;
37+
38+
StyledText widget;
39+
40+
@BeforeEach
41+
public void setUp() {
42+
// display = new Display();
43+
shell = new Shell(display);
44+
gc = new GC(shell);
45+
46+
shell.setSize(200, 200);
47+
shell.setLayout(new FillLayout());
48+
49+
widget = new StyledText(shell, SWT.BORDER);
50+
widget.setText("This is some dummy text. Sufficient text to have the scroll bars appear.");
51+
}
52+
53+
@AfterEach
54+
public void tearDown() {
55+
if (gc != null) gc.dispose();
56+
if (shell != null) shell.dispose();
57+
}
58+
59+
@Test
60+
void test_stringExtent() {
61+
for (int size = 7; size < 15; size++) {
62+
for (String name : fontnames) {
63+
FontData fd = new FontData(name, size, SWT.NORMAL);
64+
Font font = new Font(widget.getDisplay(), fd);
65+
widget.setFont(font);
66+
gc.setFont(font);
67+
68+
Map<Integer, Integer> widths0 = new LinkedHashMap<>();
69+
Map<Integer, Integer> widths1 = new LinkedHashMap<>();
70+
for (int col = 1; col <= 10; col++) {
71+
Point p = gc.stringExtent(" ");
72+
widths0.put(col, p.x * col);
73+
74+
p = gc.stringExtent(" ".repeat(col));
75+
widths1.put(col, p.x);
76+
}
77+
System.out.printf("Font %-20s: size [%02d] multiply widths %s\n", name, size, widths0);
78+
System.out.printf("Font %-20s: size [%02d] *repeat* widths %s\n", name, size, widths1);
79+
80+
gc.setFont(null);
81+
widget.setFont(null);
82+
font.dispose();
83+
84+
assertTrue(widths0.equals(widths1), String.format("Font %s did not match.", name));
85+
}
86+
}
87+
}
88+
}

net.certiv.tools.indentguide.plugin.test/src/test/java/net/certiv/tools/indentguide/util/LineTest.java renamed to net.certiv.tools.indentguide.plugin.test/src/test/java/net/certiv/tools/indentguide/painter/LineTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package net.certiv.tools.indentguide.util;
1+
package net.certiv.tools.indentguide.painter;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertTrue;
55

66
import org.junit.jupiter.params.ParameterizedTest;
77
import org.junit.jupiter.params.provider.CsvFileSource;
88

9-
import net.certiv.tools.indentguide.painter.Line;
9+
import net.certiv.tools.indentguide.util.Utils;
1010

1111
class LineTest {
1212

net.certiv.tools.indentguide.plugin/src/main/java/net/certiv/tools/indentguide/preferences/GuidePage.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public GuidePage() {
6565
Set<String> exclude = Utils.undelimit(getPreferenceStore().getString(Pref.CONTENT_TYPES));
6666
excludeTypes = exclude.stream() //
6767
.map(e -> Utils.getPlatformTextType(e)) //
68-
.filter(t -> !t.equals(txtType)) //
68+
.filter(t -> t != null && !txtType.equals(t)) //
6969
.collect(Collectors.toCollection(LinkedHashSet::new));
7070
}
7171

@@ -131,7 +131,8 @@ private void createContentTypesGroup(Composite parent) {
131131
Composite comp = createGroup(parent, Messages.contenttype_group_label, true, 1);
132132
blocks.add(comp);
133133

134-
CheckboxTreeViewer viewer = new CheckboxTreeViewer(comp, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
134+
CheckboxTreeViewer viewer = new CheckboxTreeViewer(comp,
135+
SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
135136
viewer.getControl().setFont(comp.getFont());
136137
GridDataFactory.fillDefaults().hint(SWT.DEFAULT, 150).grab(true, true).applyTo(viewer.getControl());
137138
parts.add(viewer);
@@ -186,7 +187,8 @@ private void createVerticalSpacer(Composite comp, int lines) {
186187
private void createVerticalSpacer(Composite comp, int lines, int span) {
187188
Label spacer = new Label(comp, SWT.NONE);
188189
int height = Utils.lineHeight(comp, lines);
189-
GridDataFactory.fillDefaults().hint(SWT.DEFAULT, height).grab(true, false).span(span, 1).applyTo(spacer);
190+
GridDataFactory.fillDefaults().hint(SWT.DEFAULT, height).grab(true, false).span(span, 1)
191+
.applyTo(spacer);
190192
}
191193

192194
private Label createLabel(Composite comp, String text) {
@@ -207,7 +209,8 @@ private Button createLabeledCheckbox(Composite comp, String label, String key) {
207209
return btn;
208210
}
209211

210-
private Combo createLabeledCombo(Composite comp, String label, String trail, String[] styles, String key) {
212+
private Combo createLabeledCombo(Composite comp, String label, String trail, String[] styles,
213+
String key) {
211214
createLabel(comp, label);
212215
Combo combo = new Combo(comp, SWT.READ_ONLY);
213216
combo.setData(key);
@@ -224,7 +227,8 @@ private Combo createLabeledCombo(Composite comp, String label, String trail, Str
224227
return combo;
225228
}
226229

227-
private Spinner createLabeledSpinner(Composite comp, String label, String trail, int min, int max, String key) {
230+
private Spinner createLabeledSpinner(Composite comp, String label, String trail, int min, int max,
231+
String key) {
228232
createLabel(comp, label);
229233

230234
Spinner spin = new Spinner(comp, SWT.BORDER);
@@ -332,7 +336,8 @@ public boolean performOk() {
332336
}
333337

334338
/**
335-
* Returns the types of the checked, and optionally not grayed, elements in the tree viewer.
339+
* Returns the types of the checked, and optionally not grayed, elements in the tree
340+
* viewer.
336341
*
337342
* @param viewer the tree viewer
338343
* @param grayed include grayed if {@code true}; exclude grayed if {@code false}
@@ -343,7 +348,8 @@ private Set<IContentType> getChecked(CheckboxTreeViewer viewer, boolean grayed)
343348
.collect(Collectors.toCollection(LinkedHashSet::new));
344349

345350
if (grayed) return checked;
346-
return checked.stream().filter(t -> !viewer.getGrayed(t)).collect(Collectors.toCollection(LinkedHashSet::new));
351+
return checked.stream().filter(t -> !viewer.getGrayed(t))
352+
.collect(Collectors.toCollection(LinkedHashSet::new));
347353
}
348354

349355
/** Returns the types of the unchecked tree viewer items */

0 commit comments

Comments
 (0)