Skip to content

Commit e900661

Browse files
committed
Start testing with css-parsing-tests
1 parent 51e994b commit e900661

24 files changed

+2311
-411
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
coverage
12
test.css

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "css-parsing-tests"]
2-
path = css-parsing-tests
2+
path = test/css-parsing-tests
33
url = https://github.com/SimonSapin/css-parsing-tests.git

Gemfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
source "https://rubygems.org"
44

5-
gem "prettier_print"
6-
gem "syntax_tree"
5+
gemspec

Gemfile.lock

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
1+
PATH
2+
remote: .
3+
specs:
4+
syntax_tree-css (0.1.0)
5+
prettier_print
6+
syntax_tree (>= 2.0.1)
7+
18
GEM
29
remote: https://rubygems.org/
310
specs:
11+
docile (1.4.0)
12+
minitest (5.15.0)
413
prettier_print (0.1.0)
14+
rake (13.0.6)
15+
simplecov (0.21.2)
16+
docile (~> 1.1)
17+
simplecov-html (~> 0.11)
18+
simplecov_json_formatter (~> 0.1)
19+
simplecov-html (0.12.3)
20+
simplecov_json_formatter (0.1.4)
521
syntax_tree (2.7.1)
622
prettier_print
723

824
PLATFORMS
925
x86_64-darwin-21
1026

1127
DEPENDENCIES
12-
prettier_print
13-
syntax_tree
28+
bundler
29+
minitest
30+
rake
31+
simplecov
32+
syntax_tree-css!
1433

1534
BUNDLED WITH
1635
2.4.0.dev

Rakefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
require "bundler/gem_tasks"
4+
require "rake/testtask"
5+
require "syntax_tree/rake_tasks"
6+
7+
Rake::TestTask.new(:test) do |t|
8+
t.libs << "test"
9+
t.libs << "lib"
10+
t.test_files = FileList["test/**/*_test.rb"]
11+
end
12+
13+
SyntaxTree::Rake::CheckTask.new
14+
SyntaxTree::Rake::WriteTask.new
15+
16+
task default: :test

lib/syntax_tree/css.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
require_relative "css/nodes"
77
require_relative "css/parser"
88
require_relative "css/selectors"
9-
require_relative "css/visitor"
109

10+
require_relative "css/basic_visitor"
11+
require_relative "css/format"
12+
require_relative "css/visitor"
1113
require_relative "css/pretty_print"
1214

1315
module SyntaxTree

lib/syntax_tree/css/basic_visitor.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
module SyntaxTree
4+
module CSS
5+
# The parent class of all visitors that provides the double dispatch
6+
# pattern. It doesn't provide any of the aliases so it can't actually be
7+
# used to visit the tree. It's used to implement visitors that should raise
8+
# an error if a node that's not implemented is visited.
9+
class BasicVisitor
10+
def visit(node)
11+
node&.accept(self)
12+
end
13+
14+
def visit_all(nodes)
15+
nodes.map { |node| visit(node) }
16+
end
17+
18+
def visit_child_nodes(node)
19+
visit_all(node.child_nodes)
20+
end
21+
end
22+
end
23+
end

lib/syntax_tree/css/format.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
module SyntaxTree
4+
module CSS
5+
# A formatting visitor.
6+
class Format < BasicVisitor
7+
attr_reader :q
8+
9+
def initialize(q)
10+
@q = q
11+
end
12+
end
13+
end
14+
end

0 commit comments

Comments
 (0)