Repository navigation
Expand file tree
/
Copy pathtest_parser.rb
More file actions
170 lines (127 loc) · 4.98 KB
/
Copy pathtest_parser.rb
File metadata and controls
170 lines (127 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# frozen_string_literal: true
require_relative 'test_helper'
class TestParser < Minitest::Test
def test_handles_extraneous_characters_at_start_of_file
parser = DotStrings::Parser.new
error = assert_raises DotStrings::ParsingError do
parser << '$'
end
assert_equal "Unexpected character '$' at line 1, column 1 (offset: 0)", error.message
end
def test_handles_malformed_comments
parser = DotStrings::Parser.new
error = assert_raises DotStrings::ParsingError do
parser << '/@ test'
end
assert_equal "Unexpected character '@' at line 1, column 2 (offset: 1)", error.message
end
def test_raises_error_when_escaping_invalid_character
parser = DotStrings::Parser.new
error = assert_raises DotStrings::ParsingError do
parser << '"\\z" = "value";'
end
assert_equal "Unexpected character 'z' at line 1, column 3 (offset: 2)", error.message
end
def test_raises_error_when_items_are_not_separated_by_semicolon
parser = DotStrings::Parser.new
error = assert_raises DotStrings::ParsingError do
parser << '"key_1" = "value_1" "key_2" = "value_2"'
end
assert_equal "Unexpected character '\"', expecting ';' at line 1, column 21 (offset: 20)", error.message
end
def test_raises_error_if_low_surrogate_is_not_formatted_correctly
parser = DotStrings::Parser.new
error = assert_raises DotStrings::ParsingError do
parser << '"key" = "\UD83D\$DC7B";'
end
assert_equal "Unexpected character '$', expecting 'U' at line 1, column 17 (offset: 16)", error.message
end
def test_raises_error_if_unicode_sequence_contains_invalid_characters
parser = DotStrings::Parser.new
error = assert_raises DotStrings::ParsingError do
parser << '"key" = "\UD83Z";'
end
assert_equal "Unexpected character 'Z', expecting a hex digit at line 1, column 15 (offset: 14)", error.message
end
def test_finish_raises_on_escape_at_eof
parser = DotStrings::Parser.new
parser << '"key" = "value\\'
error = assert_raises DotStrings::ParsingError do
parser.finish!
end
assert_equal 'Unexpected end of input after escape character at line 1, column 16 (offset: 15)', error.message
end
def test_finish_raises_on_incomplete_multiline_comment
parser = DotStrings::Parser.new
parser << '/* comment'
error = assert_raises DotStrings::ParsingError do
parser.finish!
end
assert_equal 'Unexpected end of input inside multiline comment at line 1, column 11 (offset: 10)', error.message
end
def test_finish_raises_on_incomplete_key
parser = DotStrings::Parser.new
parser << '"incomplete_key'
error = assert_raises DotStrings::ParsingError do
parser.finish!
end
assert_equal 'Unexpected end of input inside key at line 1, column 16 (offset: 15)', error.message
end
def test_finish_raises_on_missing_equals
parser = DotStrings::Parser.new
parser << '"key"'
error = assert_raises DotStrings::ParsingError do
parser.finish!
end
assert_equal "Unexpected end of input, expecting '=' at line 1, column 6 (offset: 5)", error.message
end
def test_finish_raises_on_missing_value
parser = DotStrings::Parser.new
parser << '"key" = '
error = assert_raises DotStrings::ParsingError do
parser.finish!
end
assert_equal 'Unexpected end of input before value at line 1, column 9 (offset: 8)', error.message
end
def test_finish_raises_on_incomplete_value
parser = DotStrings::Parser.new
parser << '"key" = "value'
error = assert_raises DotStrings::ParsingError do
parser.finish!
end
assert_equal 'Unexpected end of input inside value at line 1, column 15 (offset: 14)', error.message
end
def test_finish_raises_on_missing_semicolon
parser = DotStrings::Parser.new
parser << '"key" = "value"'
error = assert_raises DotStrings::ParsingError do
parser.finish!
end
assert_equal "Unexpected end of input, expecting ';' at line 1, column 16 (offset: 15)", error.message
end
def test_finish_raises_on_incomplete_unicode_escape
parser = DotStrings::Parser.new
parser << '"key" = "\\U12'
error = assert_raises DotStrings::ParsingError do
parser.finish!
end
assert_equal 'Unexpected end of input inside unicode escape at line 1, column 14 (offset: 13)', error.message
end
def test_finish_raises_on_incomplete_surrogate_pair
parser = DotStrings::Parser.new
parser << '"key" = "\\UD83D'
error = assert_raises DotStrings::ParsingError do
parser.finish!
end
assert_equal 'Unexpected end of input after high surrogate code point at line 1, column 16 (offset: 15)',
error.message
end
def test_finish_raises_when_surrogate_u_prefix_is_incomplete
parser = DotStrings::Parser.new
parser << '"key" = "\\UD83D\\'
error = assert_raises DotStrings::ParsingError do
parser.finish!
end
assert_equal "Unexpected end of input, expecting 'U' at line 1, column 17 (offset: 16)", error.message
end
end