-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathstring_spec.lua
165 lines (151 loc) · 4.69 KB
/
string_spec.lua
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
describe("string parsing", function()
setup(function()
TOML = require "toml"
end)
it("multiline", function()
local obj = TOML.parse[=[
multiline_empty_one = """"""
multiline_empty_two = """
"""
multiline_empty_three = """\
"""
multiline_empty_four = """\
\
\
"""
equivalent_one = "The quick brown fox jumps over the lazy dog."
equivalent_two = """
The quick brown \
fox jumps over \
the lazy dog."""
equivalent_three = """\
The quick brown \
fox jumps over \
the lazy dog.\
"""]=]
local sol = {
multiline_empty_one = "",
multiline_empty_two = "",
multiline_empty_three = "",
multiline_empty_four = "",
equivalent_one = "The quick brown fox jumps over the lazy dog.",
equivalent_two = "The quick brown fox jumps over the lazy dog.",
equivalent_three = "The quick brown fox jumps over the lazy dog.",
}
assert.same(sol, obj)
end)
it("raw multiline", function()
local obj = TOML.parse[=[
oneline = '''This string has a ' quote character.'''
firstnl = '''
This string has a ' quote character.'''
multiline = '''
This string
has a ' quote character
and more than
one newline
in it.''']=]
local sol = {
oneline = "This string has a ' quote character.",
firstnl = "This string has a ' quote character.",
multiline = [[
This string
has a ' quote character
and more than
one newline
in it.]],
}
assert.same(sol, obj)
end)
it("raw", function()
local obj = TOML.parse[=[
backspace = 'This string has a \b backspace character.'
tab = 'This string has a \t tab character.'
newline = 'This string has a \n new line character.'
formfeed = 'This string has a \f form feed character.'
carriage = 'This string has a \r carriage return character.'
slash = 'This string has a / slash character.'
backslash = 'This string has a \\ backslash character.']=]
local sol = {
backspace = "This string has a \\b backspace character.",
tab = "This string has a \\t tab character.",
newline = "This string has a \\n new line character.",
formfeed = "This string has a \\f form feed character.",
carriage = "This string has a \\r carriage return character.",
slash = "This string has a / slash character.",
backslash = "This string has a \\\\ backslash character."
}
assert.same(sol, obj)
end)
it("empty", function()
local obj = TOML.parse[=[
answer = ""
]=]
local sol = {
answer = ""
}
assert.same(sol, obj)
end)
it("escapes", function()
local obj = TOML.parse[=[
backspace = "This string has a \b backspace character."
tab = "This string has a \t tab character."
newline = "This string has a \n new line character."
formfeed = "This string has a \f form feed character."
carriage = "This string has a \r carriage return character."
quote = "This string has a \" quote character."
backslash = "This string has a \\ backslash character."
notunicode1 = "This string does not have a unicode \\u escape."
notunicode2 = "This string does not have a unicode \u005Cu escape."
notunicode3 = "This string does not have a unicode \\u0075 escape."
notunicode4 = "This string does not have a unicode \\\u0075 escape."]=]
local sol = {
backspace = "This string has a \b backspace character.",
tab = "This string has a \t tab character.",
newline = "This string has a \n new line character.",
formfeed = "This string has a \f form feed character.",
carriage = "This string has a \r carriage return character.",
quote = "This string has a \" quote character.",
backslash = "This string has a \\ backslash character.",
notunicode1 = "This string does not have a unicode \\u escape.",
notunicode2 = "This string does not have a unicode \\u escape.",
notunicode3 = "This string does not have a unicode \\u0075 escape.",
notunicode4 = "This string does not have a unicode \\u escape."
}
assert.same(sol, obj)
end)
it("simple", function()
local obj = TOML.parse[=[
answer = "You are not drinking enough whisky."]=]
local sol = {
answer = "You are not drinking enough whisky."
}
assert.same(sol, obj)
end)
it("with pound", function()
local obj = TOML.parse[=[
pound = "We see no # comments here."
poundcomment = "But there are # some comments here." # Did I # mess you up?]=]
local sol = {
pound = "We see no # comments here.",
poundcomment = "But there are # some comments here."
}
assert.same(sol, obj)
end)
it("unicode", function()
local obj = TOML.parse[=[
a = "第五福龍丸"
b = "東方地霊殿"]=]
local sol = {
a = "第五福龍丸",
b = "東方地霊殿"
}
assert.same(sol, obj)
end)
it("supports crlf", function()
assert.has_error(function()
TOML.parse("a = " .. '"' .. "\13\10" .. '"')
end)
assert.has_no.errors(function() TOML.parse("a = " .. '"' .. "\13" .. '"') end)
end)
end)