Skip to content

Commit be0c70d

Browse files
committed
Added example for #105
1 parent f9c6525 commit be0c70d

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (C) 2014-2025 Philip Helger (www.helger.com)
3+
* philip[at]helger[dot]com
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.helger.css.supplementary.issues;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotNull;
21+
22+
import org.junit.Test;
23+
24+
import com.helger.css.decl.CSSDeclaration;
25+
import com.helger.css.decl.CSSStyleRule;
26+
import com.helger.css.decl.CascadingStyleSheet;
27+
import com.helger.css.reader.CSSReader;
28+
import com.helger.css.reader.CSSReaderSettings;
29+
30+
/**
31+
* Test for issue: https://github.com/phax/ph-css/issues/105
32+
*
33+
* @author Philip Helger
34+
*/
35+
public final class Issue105Test
36+
{
37+
@Test
38+
public void testIssue ()
39+
{
40+
final String sCSS = "div {\n" + " color:red;\n" + "width: 100%;\n" + "}";
41+
final CascadingStyleSheet aCSS = CSSReader.readFromStringReader (sCSS,
42+
new CSSReaderSettings ().setUseSourceLocation (true));
43+
assertNotNull (aCSS);
44+
45+
final CSSStyleRule aRule = aCSS.getAllStyleRules ().get (0);
46+
assertNotNull (aRule);
47+
48+
// This is the "div"
49+
assertEquals (1, aRule.getSourceLocation ().getFirstTokenBeginLineNumber ());
50+
assertEquals (1, aRule.getSourceLocation ().getFirstTokenBeginColumnNumber ());
51+
assertEquals (1, aRule.getSourceLocation ().getFirstTokenEndLineNumber ());
52+
assertEquals (3, aRule.getSourceLocation ().getFirstTokenEndColumnNumber ());
53+
54+
// This is the "}"
55+
assertEquals (4, aRule.getSourceLocation ().getLastTokenBeginLineNumber ());
56+
assertEquals (1, aRule.getSourceLocation ().getLastTokenBeginColumnNumber ());
57+
assertEquals (4, aRule.getSourceLocation ().getLastTokenEndLineNumber ());
58+
assertEquals (1, aRule.getSourceLocation ().getLastTokenEndColumnNumber ());
59+
60+
{
61+
final CSSDeclaration aDecl = aRule.getAllDeclarations ().get (0);
62+
// This is the "color"
63+
assertEquals (2, aDecl.getSourceLocation ().getFirstTokenBeginLineNumber ());
64+
// It's 3, because of the 2 spaces for indent
65+
assertEquals (3, aDecl.getSourceLocation ().getFirstTokenBeginColumnNumber ());
66+
assertEquals (2, aDecl.getSourceLocation ().getFirstTokenEndLineNumber ());
67+
assertEquals (7, aDecl.getSourceLocation ().getFirstTokenEndColumnNumber ());
68+
69+
// This is the "red"
70+
assertEquals (2, aDecl.getSourceLocation ().getLastTokenBeginLineNumber ());
71+
assertEquals (9, aDecl.getSourceLocation ().getLastTokenBeginColumnNumber ());
72+
assertEquals (2, aDecl.getSourceLocation ().getLastTokenEndLineNumber ());
73+
assertEquals (11, aDecl.getSourceLocation ().getLastTokenEndColumnNumber ());
74+
}
75+
76+
{
77+
final CSSDeclaration aDecl = aRule.getAllDeclarations ().get (1);
78+
// This is the "width"
79+
assertEquals (3, aDecl.getSourceLocation ().getFirstTokenBeginLineNumber ());
80+
assertEquals (1, aDecl.getSourceLocation ().getFirstTokenBeginColumnNumber ());
81+
assertEquals (3, aDecl.getSourceLocation ().getFirstTokenEndLineNumber ());
82+
assertEquals (5, aDecl.getSourceLocation ().getFirstTokenEndColumnNumber ());
83+
84+
// This is the "100%"
85+
assertEquals (3, aDecl.getSourceLocation ().getLastTokenBeginLineNumber ());
86+
assertEquals (8, aDecl.getSourceLocation ().getLastTokenBeginColumnNumber ());
87+
assertEquals (3, aDecl.getSourceLocation ().getLastTokenEndLineNumber ());
88+
assertEquals (11, aDecl.getSourceLocation ().getLastTokenEndColumnNumber ());
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)