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.Assert.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.Test;
31
32
33
34
35
36
37 public class StyleAttributesTest {
38
39
40
41
42 @Test
43 public void lexicographicOrder() {
44 String lastName = null;
45 for (final Definition definition : StyleAttributes.Definition.values()) {
46 final String name = definition.name();
47 if (lastName != null && name.compareToIgnoreCase(lastName) < 1) {
48 fail("StyleAttributes.Definition: '"
49 + name + "' should be before '" + lastName + "'");
50 }
51 lastName = name;
52 }
53 }
54
55
56
57
58 @Test
59 public void unique() {
60 final List<String> nameList = new ArrayList<>();
61 for (final Definition definition : StyleAttributes.Definition.values()) {
62 final String propertyName = definition.getPropertyName();
63 if (nameList.contains(propertyName)) {
64 fail("StyleAttributes.Definition: the property name '"
65 + propertyName + "' is defined more than once");
66 }
67 nameList.add(propertyName);
68 }
69 }
70
71
72
73
74 @Test
75 public void name() {
76 for (final Definition definition : StyleAttributes.Definition.values()) {
77 final String propertyName = definition.getPropertyName();
78 if (propertyName.indexOf('-') == -1) {
79 if (definition.name().endsWith("_") && Character.isLowerCase(definition.name().charAt(0))) {
80 fail("StyleAttributes.Definition: '" + definition.name() + "' must not end with underscore");
81 }
82 }
83 else {
84 if (!definition.name().endsWith("_")) {
85 fail("StyleAttributes.Definition: '" + definition.name() + "' must end with underscore");
86 }
87 }
88 }
89 }
90
91
92
93
94
95 @Test
96 public void javaDoc() throws IOException {
97 try (Stream<String> stream = Files.lines(Paths.get("src/main/java/"
98 + getClass().getPackage().getName().replace('.', '/') + "/StyleAttributes.java"))) {
99 final List<String> lines = stream.collect(Collectors.toList());
100 final Pattern pattern = Pattern.compile("\\s+[A-Z_]+\\(\"(.*?)\",");
101 for (int i = 1; i < lines.size(); i++) {
102 final Matcher matcher = pattern.matcher(lines.get(i));
103 if (matcher.find() && !lines.get(i - 1).contains("{@code " + matcher.group(1) + "}")) {
104 fail("StyleAttributes: not matching JavaDoc in line " + i);
105 }
106 }
107 }
108 }
109
110 }