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 @@ -197,8 +197,32 @@ class SelectorsTest < Minitest::Spec
197
197
end
198
198
199
199
describe "formatting" do
200
- it "formats complex selectors" do
201
- assert_selector_format ( ".outer section.foo>table.bar tr" , ".outer section.foo > table.bar tr" )
200
+ it "formats compound selector with an id selector" do
201
+ assert_selector_format (
202
+ "div#foo" ,
203
+ "div#foo" ,
204
+ )
205
+ end
206
+
207
+ it "formats compound selector with an pseudo-class selector" do
208
+ assert_selector_format (
209
+ "div:hover" ,
210
+ "div:hover" ,
211
+ )
212
+ end
213
+
214
+ it "formats compound selectors" do
215
+ assert_selector_format (
216
+ "div.flex.text-xl" ,
217
+ "div.flex.text-xl" ,
218
+ )
219
+ end
220
+
221
+ it "formats complex selectors with whitespace" do
222
+ assert_selector_format (
223
+ ".outer section.foo>table.bar tr" ,
224
+ ".outer section.foo > table.bar tr" ,
225
+ )
202
226
end
203
227
204
228
private
@@ -208,7 +232,7 @@ def assert_selector_format(selectors, expected)
208
232
209
233
io = StringIO . new
210
234
selectors . each do |selector |
211
- selector . format ( ::PrettyPrint . new ( io ) )
235
+ selector . format ( ::PP . new ( io ) )
212
236
assert_equal ( expected , io . string )
213
237
end
214
238
end
You can’t perform that action at this time.
0 commit comments