Skip to content

Commit b67479c

Browse files
authored
Implement Tags Test in Ruby (#19)
1 parent 93e5ac8 commit b67479c

File tree

6 files changed

+190
-23
lines changed

6 files changed

+190
-23
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33
source "https://rubygems.org"
44

55
gemspec
6+
7+
gem "maxitest"
8+
gem "minitest-difftastic"

Gemfile.lock

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,36 @@ PATH
77
GEM
88
remote: https://rubygems.org/
99
specs:
10+
difftastic (0.5.1)
11+
pretty_please
12+
difftastic (0.5.1-arm64-darwin)
13+
pretty_please
14+
difftastic (0.5.1-x86_64-darwin)
15+
pretty_please
16+
dispersion (0.2.0)
17+
prism
1018
ffi (1.17.0)
11-
ffi (1.17.0-x86_64-darwin)
1219
maxitest (5.5.0)
1320
minitest (>= 5.14.0, < 5.24.0)
1421
minitest (5.23.1)
22+
minitest-difftastic (0.1.2)
23+
difftastic (~> 0.2)
24+
pretty_please (0.1.1)
25+
dispersion (~> 0.2)
26+
prism (1.3.0)
1527
rake (13.2.1)
1628
rake-compiler (1.2.7)
1729
rake
1830

1931
PLATFORMS
32+
arm64-darwin
2033
ruby
2134
x86_64-darwin-23
2235

2336
DEPENDENCIES
2437
erbx!
2538
maxitest
39+
minitest-difftastic
2640
rake (~> 13.2)
2741
rake-compiler (~> 1.2)
2842

erbx.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@ Gem::Specification.new do |spec|
3131

3232
spec.add_development_dependency "rake", "~> 13.2"
3333
spec.add_development_dependency "rake-compiler", "~> 1.2"
34-
spec.add_development_dependency "maxitest"
3534
end

ext/erbx/test/lexer/tags_test.rb

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../test_helper"
4+
5+
module Lexer
6+
class TagsTest < Minitest::Spec
7+
test "empty file" do
8+
result = ERBX.lex("")
9+
10+
expected = %w[
11+
TOKEN_EOF
12+
]
13+
14+
assert_equal expected, result.array.items.map(&:type)
15+
end
16+
17+
test "basic tag" do
18+
result = ERBX.lex("<html></html>")
19+
20+
expected = %w[
21+
TOKEN_START_TAG_START
22+
TOKEN_TAG_NAME
23+
TOKEN_START_TAG_END
24+
TOKEN_END_TAG_START
25+
TOKEN_TAG_NAME
26+
TOKEN_END_TAG_END
27+
TOKEN_EOF
28+
]
29+
30+
assert_equal expected, result.array.items.map(&:type)
31+
end
32+
33+
test "basic void tag" do
34+
result = ERBX.lex("<img />")
35+
36+
expected = %w[
37+
TOKEN_START_TAG_START
38+
TOKEN_TAG_NAME
39+
TOKEN_START_TAG_END_VOID
40+
TOKEN_EOF
41+
]
42+
43+
assert_equal expected, result.array.items.map(&:type)
44+
end
45+
46+
test "namespaced tag" do
47+
result = ERBX.lex("<ns:table></ns:table>")
48+
49+
expected = %w[
50+
TOKEN_START_TAG_START
51+
TOKEN_TAG_NAME
52+
TOKEN_START_TAG_END
53+
TOKEN_END_TAG_START
54+
TOKEN_TAG_NAME
55+
TOKEN_END_TAG_END
56+
TOKEN_EOF
57+
]
58+
59+
assert_equal expected, result.array.items.map(&:type)
60+
end
61+
62+
test "text content" do
63+
result = ERBX.lex("<h1>Hello World</h1>")
64+
65+
expected = %w[
66+
TOKEN_START_TAG_START
67+
TOKEN_TAG_NAME
68+
TOKEN_START_TAG_END
69+
TOKEN_TEXT_CONTENT
70+
TOKEN_END_TAG_START
71+
TOKEN_TAG_NAME
72+
TOKEN_END_TAG_END
73+
TOKEN_EOF
74+
]
75+
76+
assert_equal expected, result.array.items.map(&:type)
77+
end
78+
79+
test "attribute value double quotes" do
80+
result = ERBX.lex("<img value=\"hello world\" />")
81+
82+
expected = %w[
83+
TOKEN_START_TAG_START
84+
TOKEN_TAG_NAME
85+
TOKEN_ATTRIBUTE_NAME
86+
TOKEN_EQUALS
87+
TOKEN_DOUBLE_QUOTE
88+
TOKEN_ATTRIBUTE_VALUE
89+
TOKEN_DOUBLE_QUOTE
90+
TOKEN_START_TAG_END_VOID
91+
TOKEN_EOF
92+
]
93+
94+
assert_equal expected, result.array.items.map(&:type)
95+
end
96+
97+
test "attribute value single quotes" do
98+
result = ERBX.lex("<img value='hello world' />")
99+
100+
expected = %w[
101+
TOKEN_START_TAG_START
102+
TOKEN_TAG_NAME
103+
TOKEN_ATTRIBUTE_NAME
104+
TOKEN_EQUALS
105+
TOKEN_SINGLE_QUOTE
106+
TOKEN_ATTRIBUTE_VALUE
107+
TOKEN_SINGLE_QUOTE
108+
TOKEN_START_TAG_END_VOID
109+
TOKEN_EOF
110+
]
111+
112+
assert_equal expected, result.array.items.map(&:type)
113+
end
114+
115+
test "attribute value empty double quotes" do
116+
result = ERBX.lex("<img value=\"\" />")
117+
118+
expected = %w[
119+
TOKEN_START_TAG_START
120+
TOKEN_TAG_NAME
121+
TOKEN_ATTRIBUTE_NAME
122+
TOKEN_EQUALS
123+
TOKEN_DOUBLE_QUOTE
124+
TOKEN_ATTRIBUTE_VALUE
125+
TOKEN_DOUBLE_QUOTE
126+
TOKEN_START_TAG_END_VOID
127+
TOKEN_EOF
128+
]
129+
130+
assert_equal expected, result.array.items.map(&:type)
131+
end
132+
133+
test "attribute value empty single quotes" do
134+
result = ERBX.lex("<img value='' />")
135+
136+
expected = %w[
137+
TOKEN_START_TAG_START
138+
TOKEN_TAG_NAME
139+
TOKEN_ATTRIBUTE_NAME
140+
TOKEN_EQUALS
141+
TOKEN_SINGLE_QUOTE
142+
TOKEN_ATTRIBUTE_VALUE
143+
TOKEN_SINGLE_QUOTE
144+
TOKEN_START_TAG_END_VOID
145+
TOKEN_EOF
146+
]
147+
148+
assert_equal expected, result.array.items.map(&:type)
149+
end
150+
151+
test "boolean attribute" do
152+
result = ERBX.lex("<img required />")
153+
154+
expected = %w[
155+
TOKEN_START_TAG_START
156+
TOKEN_TAG_NAME
157+
TOKEN_ATTRIBUTE_NAME
158+
TOKEN_START_TAG_END_VOID
159+
TOKEN_EOF
160+
]
161+
162+
assert_equal expected, result.array.items.map(&:type)
163+
end
164+
end
165+
end

ext/erbx/test/lexer_test.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

ext/erbx/test/test_helper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@
22

33
require "erbx"
44
require "maxitest/autorun"
5+
6+
class Minitest::Spec
7+
class << self
8+
alias_method :test, :it
9+
alias_method :xtest, :xit
10+
end
11+
end

0 commit comments

Comments
 (0)