1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.css;
16
17 import static org.junit.jupiter.api.Assertions.fail;
18
19 import java.io.IOException;
20 import java.nio.file.Files;
21 import java.nio.file.Paths;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26 import java.util.stream.Collectors;
27 import java.util.stream.Stream;
28
29 import org.htmlunit.css.StyleAttributes.Definition;
30 import org.junit.jupiter.api.Test;
31
32
33
34
35
36
37
38 public class StyleAttributesTest {
39
40
41
42
43 @Test
44 public void lexicographicOrder() {
45 String lastName = null;
46 for (final Definition definition : StyleAttributes.Definition.values()) {
47 final String name = definition.name();
48 if (lastName != null && name.compareToIgnoreCase(lastName) < 1) {
49 fail("StyleAttributes.Definition: '"
50 + name + "' should be before '" + lastName + "'");
51 }
52 lastName = name;
53 }
54 }
55
56
57
58
59 @Test
60 public void unique() {
61 final List<String> nameList = new ArrayList<>();
62 for (final Definition definition : StyleAttributes.Definition.values()) {
63 final String propertyName = definition.getPropertyName();
64 if (nameList.contains(propertyName)) {
65 fail("StyleAttributes.Definition: the property name '"
66 + propertyName + "' is defined more than once");
67 }
68 nameList.add(propertyName);
69 }
70 }
71
72
73
74
75 @Test
76 public void name() {
77 for (final Definition definition : StyleAttributes.Definition.values()) {
78 final String propertyName = definition.getPropertyName();
79 if (propertyName.indexOf('-') == -1) {
80 if (definition.name().endsWith("_") && Character.isLowerCase(definition.name().charAt(0))) {
81 fail("StyleAttributes.Definition: '" + definition.name() + "' must not end with underscore");
82 }
83 }
84 else {
85 if (!definition.name().endsWith("_")) {
86 fail("StyleAttributes.Definition: '" + definition.name() + "' must end with underscore");
87 }
88 }
89 }
90 }
91
92
93
94
95
96 @Test
97 public void javaDoc() throws IOException {
98 try (Stream<String> stream = Files.lines(Paths.get("src/main/java/"
99 + getClass().getPackage().getName().replace('.', '/') + "/StyleAttributes.java"))) {
100 final List<String> lines = stream.collect(Collectors.toList());
101 final Pattern pattern = Pattern.compile("\\s+[A-Z_]+\\(\"(.*?)\",");
102 for (int i = 1; i < lines.size(); i++) {
103 final Matcher matcher = pattern.matcher(lines.get(i));
104 if (matcher.find() && !lines.get(i - 1).contains("{@code " + matcher.group(1) + "}")) {
105 fail("StyleAttributes: not matching JavaDoc in line " + i);
106 }
107 }
108 }
109 }
110
111 }