Skip to content

Commit a6e4e04

Browse files
committed
Add doctype case-sensitive tests and update case-insensitive peek helpers
1 parent 5b42cb1 commit a6e4e04

7 files changed

+48
-5
lines changed

β€Žsrc/lexer_peek_helpers.cβ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ bool lexer_peek_for_doctype(lexer_T* lexer, int offset) {
3232
}
3333

3434
bool lexer_peek_for_html_comment_start(lexer_T* lexer, int offset) {
35-
return lexer_peek_for(lexer, offset, "<!--", true);
35+
return lexer_peek_for(lexer, offset, "<!--", false);
3636
}
3737

3838
bool lexer_peek_for_html_comment_end(lexer_T* lexer, int offset) {
39-
return lexer_peek_for(lexer, offset, "-->", true);
39+
return lexer_peek_for(lexer, offset, "-->", false);
4040
}
4141

4242
bool lexer_peek_erb_close_tag(lexer_T* lexer, int offset) {
43-
return lexer_peek_for(lexer, offset, "%>", true);
43+
return lexer_peek_for(lexer, offset, "%>", false);
4444
}
4545

4646
bool lexer_peek_erb_dash_close_tag(lexer_T* lexer, int offset) {
47-
return lexer_peek_for(lexer, offset, "-%>", true);
47+
return lexer_peek_for(lexer, offset, "-%>", false);
4848
}
4949

5050
bool lexer_peek_erb_percent_close_tag(lexer_T* lexer, int offset) {
51-
return lexer_peek_for(lexer, offset, "%%>", true);
51+
return lexer_peek_for(lexer, offset, "%%>", false);
5252
}
5353

5454
bool lexer_peek_erb_end(lexer_T* lexer, int offset) {

β€Žtest/lexer/doctype_test.rbβ€Ž

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,19 @@ class DoctypeTest < Minitest::Spec
7272

7373
assert_equal expected, result.array.items.map(&:type)
7474
end
75+
76+
test "doctype case insensitivity" do
77+
doctypes = ["<!DOCTYPE>", "<!doctype>", "<!DoCtYpE>", "<!dOcTyPe>"]
78+
79+
expected = %w[
80+
TOKEN_HTML_DOCTYPE
81+
TOKEN_HTML_TAG_END
82+
TOKEN_EOF
83+
]
84+
85+
doctypes.each do |doctype|
86+
assert_equal expected, ERBX.lex(doctype).array.items.map(&:type), "#{doctype} didn't match"
87+
end
88+
end
7589
end
7690
end

β€Žtest/parser/doctype_test.rbβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,13 @@ class DoctypeTest < Minitest::Spec
2525
test "html4 doctype" do
2626
assert_parsed_snapshot(%(<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">))
2727
end
28+
29+
test "doctype case insensitivity" do
30+
doctypes = ["<!DOCTYPE>", "<!doctype>", "<!DoCtYpE>", "<!dOcTyPe>"]
31+
32+
doctypes.each do |doctype|
33+
assert_parsed_snapshot(doctype)
34+
end
35+
end
2836
end
2937
end

test/snapshots/parser/doctype_test/test_0001_doctype_d50c7b32f19e4848938905f3dc675f44.txt renamed to test/snapshots/parser/doctype_test/test_0006_doctype_case_insensitivity_2f56dc84fb5f8e284f42eae7d1f1c597.txt

File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@ DocumentNode (location: (0,0)-(0,0))
2+
β”œβ”€β”€ name: βˆ…
3+
└── children: (1)
4+
@ Doctype (location: (0,0)-(0,0))
5+
β”œβ”€β”€ name: ""
6+
└── children: []
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@ DocumentNode (location: (0,0)-(0,0))
2+
β”œβ”€β”€ name: βˆ…
3+
└── children: (1)
4+
@ Doctype (location: (0,0)-(0,0))
5+
β”œβ”€β”€ name: ""
6+
└── children: []
7+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@ DocumentNode (location: (0,0)-(0,0))
2+
β”œβ”€β”€ name: βˆ…
3+
└── children: (1)
4+
@ Doctype (location: (0,0)-(0,0))
5+
β”œβ”€β”€ name: ""
6+
└── children: []
7+

0 commit comments

Comments
Β (0)