File tree 2 files changed +44
-3
lines changed
2 files changed +44
-3
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,11 @@ def visit_ident_token(node)
47
47
q . text ( node . value )
48
48
end
49
49
50
+ # Visit a HashToken node.
51
+ def visit_hash_token ( node )
52
+ q . text ( node . value )
53
+ end
54
+
50
55
# Visit a StyleRule node.
51
56
def visit_style_rule ( node )
52
57
q . group do
@@ -77,12 +82,24 @@ def visit_type_selector(node)
77
82
end
78
83
end
79
84
85
+ # Visit a Selectors::IdSelector node.
86
+ def visit_id_selector ( node )
87
+ q . text ( "#" )
88
+ node . value . format ( q )
89
+ end
90
+
80
91
# Visit a Selectors::ClassSelector node.
81
92
def visit_class_selector ( node )
82
93
q . text ( "." )
83
94
node . value . format ( q )
84
95
end
85
96
97
+ # Visit a Selectors::PseudoClassSelector node.
98
+ def visit_pseudo_class_selector ( node )
99
+ q . text ( ":" )
100
+ node . value . format ( q )
101
+ end
102
+
86
103
# Visit a Selectors::Combinator node.
87
104
def visit_combinator ( node )
88
105
node . value . format ( q )
Original file line number Diff line number Diff line change @@ -194,8 +194,32 @@ class SelectorsTest < Minitest::Spec
194
194
end
195
195
196
196
describe "formatting" do
197
- it "formats complex selectors" do
198
- assert_selector_format ( ".outer section.foo>table.bar tr" , ".outer section.foo > table.bar tr" )
197
+ it "formats compound selector with an id selector" do
198
+ assert_selector_format (
199
+ "div#foo" ,
200
+ "div#foo" ,
201
+ )
202
+ end
203
+
204
+ it "formats compound selector with an pseudo-class selector" do
205
+ assert_selector_format (
206
+ "div:hover" ,
207
+ "div:hover" ,
208
+ )
209
+ end
210
+
211
+ it "formats compound selectors" do
212
+ assert_selector_format (
213
+ "div.flex.text-xl" ,
214
+ "div.flex.text-xl" ,
215
+ )
216
+ end
217
+
218
+ it "formats complex selectors with whitespace" do
219
+ assert_selector_format (
220
+ ".outer section.foo>table.bar tr" ,
221
+ ".outer section.foo > table.bar tr" ,
222
+ )
199
223
end
200
224
201
225
private
@@ -205,7 +229,7 @@ def assert_selector_format(selectors, expected)
205
229
206
230
io = StringIO . new
207
231
selectors . each do |selector |
208
- selector . format ( ::PrettyPrint . new ( io ) )
232
+ selector . format ( ::PP . new ( io ) )
209
233
assert_equal ( expected , io . string )
210
234
end
211
235
end
You can’t perform that action at this time.
0 commit comments