toml-rb 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/LICENSE +19 -0
- data/README.md +3 -3
- data/lib/toml-rb.rb +2 -1
- data/lib/toml-rb/array.rb +2 -8
- data/lib/toml-rb/datetime.rb +38 -0
- data/lib/toml-rb/dumper.rb +9 -1
- data/lib/toml-rb/grammars/array.citrus +16 -18
- data/lib/toml-rb/grammars/document.citrus +20 -8
- data/lib/toml-rb/grammars/primitive.citrus +80 -23
- data/lib/toml-rb/inline_table.rb +6 -52
- data/lib/toml-rb/keyvalue.rb +25 -17
- data/lib/toml-rb/parser.rb +6 -3
- data/lib/toml-rb/{keygroup.rb → table.rb} +15 -14
- data/lib/toml-rb/table_array.rb +17 -17
- metadata +12 -22
- data/Rakefile +0 -6
- data/test/dumper_test.rb +0 -94
- data/test/errors_test.rb +0 -88
- data/test/example-v0.4.0.toml +0 -244
- data/test/example.toml +0 -49
- data/test/grammar_test.rb +0 -239
- data/test/hard_example.toml +0 -46
- data/test/helper.rb +0 -2
- data/test/toml_examples.rb +0 -203
- data/test/toml_test.rb +0 -125
- data/toml-rb.gemspec +0 -23
data/test/hard_example.toml
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# Test file for TomlRB
|
2
|
-
# Only this one tries to emulate a TomlRB file written by a user of the kind of parser writers probably hate
|
3
|
-
# This part you'll really hate
|
4
|
-
|
5
|
-
[the]
|
6
|
-
test_string = "You'll hate me after this - #" # " Annoying, isn't it?
|
7
|
-
|
8
|
-
[the.hard]
|
9
|
-
test_array = [ "] ", " # "] # ] There you go, parse this!
|
10
|
-
test_array2 = [ "Test #11 ]proved that", "Experiment #9 was a success" ]
|
11
|
-
# You didn't think it'd as easy as chucking out the last #, did you?
|
12
|
-
another_test_string = " Same thing, but with a string #"
|
13
|
-
harder_test_string = " And when \"'s are in the string, along with # \"" # "and comments are there too"
|
14
|
-
# Things will get harder
|
15
|
-
|
16
|
-
[the.hard."bit#"]
|
17
|
-
"what?" = "You don't think some user won't do that?"
|
18
|
-
multi_line_array = [
|
19
|
-
"]",
|
20
|
-
# ] Oh yes I did
|
21
|
-
]
|
22
|
-
|
23
|
-
[parent.child1]
|
24
|
-
key = 'value'
|
25
|
-
|
26
|
-
[[parent.child2]]
|
27
|
-
key2 = 'value'
|
28
|
-
|
29
|
-
[[parent.child2]]
|
30
|
-
key3 = 'value'
|
31
|
-
|
32
|
-
[[a.b]]
|
33
|
-
c = 3
|
34
|
-
|
35
|
-
# Each of the following keygroups/key value pairs should produce an error. Uncomment to them to test
|
36
|
-
|
37
|
-
#[error] if you didn't catch this, your parser is broken
|
38
|
-
#string = "Anything other than tabs, spaces and newline after a keygroup or key value pair has ended should produce an error unless it is a comment" like this
|
39
|
-
#array = [
|
40
|
-
# "This might most likely happen in multiline arrays",
|
41
|
-
# Like here,
|
42
|
-
# "or here,
|
43
|
-
# and here"
|
44
|
-
# ] End of array comment, forgot the #
|
45
|
-
#number = 3.14 pi <--again forgot the #
|
46
|
-
|
data/test/helper.rb
DELETED
data/test/toml_examples.rb
DELETED
@@ -1,203 +0,0 @@
|
|
1
|
-
class TomlRB::Examples
|
2
|
-
def self.example_v_0_4_0
|
3
|
-
{
|
4
|
-
"table" => {
|
5
|
-
"key" => "value",
|
6
|
-
"subtable" => {
|
7
|
-
"key" => "another value"
|
8
|
-
},
|
9
|
-
"inline" => {
|
10
|
-
"name" => {
|
11
|
-
"first" => "Tom",
|
12
|
-
"last" => "Preston-Werner"
|
13
|
-
},
|
14
|
-
"point" => {
|
15
|
-
"x" => 1,
|
16
|
-
"y" => 2
|
17
|
-
}
|
18
|
-
}
|
19
|
-
},
|
20
|
-
"x" => {
|
21
|
-
"y" => {
|
22
|
-
"z" => {
|
23
|
-
"w" => {}
|
24
|
-
}
|
25
|
-
}
|
26
|
-
},
|
27
|
-
"string" => {
|
28
|
-
"basic" => {
|
29
|
-
"basic" => "I'm a string. \"You can quote me\". Name\tJos\\u00E9\nLocation\tSF."
|
30
|
-
},
|
31
|
-
"multiline" => {
|
32
|
-
"key1" => "One\nTwo",
|
33
|
-
"key2" => "One\nTwo",
|
34
|
-
"key3" => "One\nTwo",
|
35
|
-
"continued" => {
|
36
|
-
"key1" => "The quick brown fox jumps over the lazy dog.",
|
37
|
-
"key2" => "The quick brown fox jumps over the lazy dog.",
|
38
|
-
"key3" => "The quick brown fox jumps over the lazy dog."
|
39
|
-
}
|
40
|
-
},
|
41
|
-
"literal" => {
|
42
|
-
"winpath" => "C:\\Users\\nodejs\\templates",
|
43
|
-
"winpath2" => "\\\\ServerX\\admin$\\system32\\",
|
44
|
-
"quoted" => "Tom\"Dubs\"Preston-Werner",
|
45
|
-
"regex" => "<\\i\\c*\\s*>",
|
46
|
-
"multiline" => {
|
47
|
-
"regex2" => "I[
|
48
|
-
dw
|
49
|
-
]on'tneed\\d{
|
50
|
-
2
|
51
|
-
}apples",
|
52
|
-
"lines" => "Thefirstnewlineis\ntrimmedinrawstrings.\nAllotherwhitespace\nispreserved.\n"
|
53
|
-
}
|
54
|
-
}
|
55
|
-
},
|
56
|
-
"integer" => {
|
57
|
-
"key1" => 99,
|
58
|
-
"key2" => 42,
|
59
|
-
"key3" => 0,
|
60
|
-
"key4" => -17,
|
61
|
-
"underscores" => {
|
62
|
-
"key1" => 1000,
|
63
|
-
"key2" => 5349221,
|
64
|
-
"key3" => 12345
|
65
|
-
}
|
66
|
-
},
|
67
|
-
"float" => {
|
68
|
-
"fractional" => {
|
69
|
-
"key1" => 1.0,
|
70
|
-
"key2" => 3.1415,
|
71
|
-
"key3" => -0.01
|
72
|
-
},
|
73
|
-
"exponent" => {
|
74
|
-
"key1" => 5.0e+22,
|
75
|
-
"key2" => 1000000.0,
|
76
|
-
"key3" => -0.02
|
77
|
-
},
|
78
|
-
"both" => {
|
79
|
-
"key" => 6.626e-34
|
80
|
-
},
|
81
|
-
"underscores" => {
|
82
|
-
"key1" => 9224617.445991227,
|
83
|
-
"key2" => 1e1_000
|
84
|
-
}
|
85
|
-
},
|
86
|
-
"boolean" => {
|
87
|
-
"True" => true,
|
88
|
-
"False" => false
|
89
|
-
},
|
90
|
-
"datetime" => {
|
91
|
-
"key1" => Time.utc(1979, 05, 27, 07, 32, 0),
|
92
|
-
"key2" => Time.new(1979, 05, 27, 00, 32, 0, '-07:00'),
|
93
|
-
"key3" => Time.new(1979, 05, 27, 00, 32, 0.999999, '-07:00')
|
94
|
-
},
|
95
|
-
"array" => {
|
96
|
-
"key1" => [1, 2, 3],
|
97
|
-
"key2" => %w(red yellow green),
|
98
|
-
"key3" => [[1, 2], [3, 4, 5]],
|
99
|
-
"key4" => [[1, 2], %w(a b c)],
|
100
|
-
"key5" => [1, 2, 3],
|
101
|
-
"key6" => [1, 2]
|
102
|
-
},
|
103
|
-
"products" => [
|
104
|
-
{ "name" => "Hammer", "sku" => 738594937 },
|
105
|
-
{},
|
106
|
-
{ "name" => "Nail", "sku" => 284758393, "color" => "gray" }
|
107
|
-
],
|
108
|
-
"fruit" => [
|
109
|
-
{
|
110
|
-
"name" => "apple",
|
111
|
-
"physical" => {
|
112
|
-
"color" => "red",
|
113
|
-
"shape" => "round"
|
114
|
-
},
|
115
|
-
"variety" => [
|
116
|
-
{ "name" => "red delicious" },
|
117
|
-
{ "name" => "granny smith" }
|
118
|
-
]
|
119
|
-
},
|
120
|
-
{
|
121
|
-
"name" => "banana",
|
122
|
-
"variety" => [
|
123
|
-
{ "name" => "plantain" }
|
124
|
-
]
|
125
|
-
}
|
126
|
-
]
|
127
|
-
}
|
128
|
-
end
|
129
|
-
|
130
|
-
def self.example
|
131
|
-
{
|
132
|
-
'title' => 'TomlRB Example',
|
133
|
-
'owner' => {
|
134
|
-
'name' => 'Tom Preston-Werner',
|
135
|
-
'organization' => 'GitHub',
|
136
|
-
'bio' => "GitHub Cofounder & CEO\nLikes tater tots and beer.",
|
137
|
-
'dob' => Time.utc(1979, 05, 27, 07, 32, 00)
|
138
|
-
},
|
139
|
-
|
140
|
-
'database' => {
|
141
|
-
'server' => '192.168.1.1',
|
142
|
-
'ports' => [8001, 8001, 8002],
|
143
|
-
'connection_max' => 5000,
|
144
|
-
'enabled' => true
|
145
|
-
},
|
146
|
-
'servers' => {
|
147
|
-
'alpha' => {
|
148
|
-
'ip' => '10.0.0.1',
|
149
|
-
'dc' => 'eqdc10'
|
150
|
-
},
|
151
|
-
'beta' => {
|
152
|
-
'ip' => '10.0.0.2',
|
153
|
-
'dc' => 'eqdc10'
|
154
|
-
}
|
155
|
-
},
|
156
|
-
'clients' => {
|
157
|
-
'data' => [%w(gamma delta), [1, 2]],
|
158
|
-
'hosts' => %w(alpha omega)
|
159
|
-
},
|
160
|
-
'amqp' => {
|
161
|
-
'exchange' => {
|
162
|
-
'durable' => true,
|
163
|
-
'auto_delete' => false
|
164
|
-
}
|
165
|
-
},
|
166
|
-
"products" => [
|
167
|
-
{ "name" => "Hammer", "sku" => 738_594_937 },
|
168
|
-
{},
|
169
|
-
{ "name" => "Nail", "sku" => 284_758_393, "color" => "gray" }
|
170
|
-
]
|
171
|
-
}
|
172
|
-
end
|
173
|
-
|
174
|
-
def self.hard_example
|
175
|
-
{
|
176
|
-
'the' => {
|
177
|
-
'test_string' => "You'll hate me after this - #",
|
178
|
-
'hard' => {
|
179
|
-
'test_array' => ['] ', ' # '],
|
180
|
-
'test_array2' => ['Test #11 ]proved that', 'Experiment #9 was a success'],
|
181
|
-
'another_test_string' => ' Same thing, but with a string #',
|
182
|
-
'harder_test_string' => " And when \"'s are in the string, along with # \"",
|
183
|
-
'bit#' => {
|
184
|
-
'what?' => "You don't think some user won't do that?",
|
185
|
-
'multi_line_array' => [']']
|
186
|
-
}
|
187
|
-
}
|
188
|
-
},
|
189
|
-
'parent' => {
|
190
|
-
'child1' => { 'key' => 'value' },
|
191
|
-
'child2' => [
|
192
|
-
{ 'key2' => 'value' },
|
193
|
-
{ 'key3' => 'value' }
|
194
|
-
]
|
195
|
-
},
|
196
|
-
'a' => {
|
197
|
-
'b' => [
|
198
|
-
{ 'c' => 3 }
|
199
|
-
]
|
200
|
-
}
|
201
|
-
}
|
202
|
-
end
|
203
|
-
end
|
data/test/toml_test.rb
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
require_relative 'toml_examples'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
class TomlTest < Minitest::Test
|
6
|
-
def test_file_v_0_4_0
|
7
|
-
path = File.join(File.dirname(__FILE__), 'example-v0.4.0.toml')
|
8
|
-
parsed = TomlRB.load_file(path)
|
9
|
-
hash = TomlRB::Examples.example_v_0_4_0
|
10
|
-
|
11
|
-
assert_equal hash['Array'], parsed['Array']
|
12
|
-
assert_equal hash['Booleans'], parsed['Booleans']
|
13
|
-
assert_equal hash['Datetime'], parsed['Datetime']
|
14
|
-
assert_equal hash['Float'], parsed['Float']
|
15
|
-
assert_equal hash['Integer'], parsed['Integer']
|
16
|
-
assert_equal hash['String'], parsed['String']
|
17
|
-
assert_equal hash['Table'], parsed['Table']
|
18
|
-
assert_equal hash['products'], parsed['products']
|
19
|
-
assert_equal hash['fruit'], parsed['fruit']
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_file
|
23
|
-
path = File.join(File.dirname(__FILE__), 'example.toml')
|
24
|
-
parsed = TomlRB.load_file(path)
|
25
|
-
|
26
|
-
assert_equal TomlRB::Examples.example, parsed
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_hard_example
|
30
|
-
path = File.join(File.dirname(__FILE__), 'hard_example.toml')
|
31
|
-
parsed = TomlRB.load_file(path)
|
32
|
-
|
33
|
-
assert_equal TomlRB::Examples.hard_example, parsed
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_symbolize_keys
|
37
|
-
path = File.join(File.dirname(__FILE__), 'example.toml')
|
38
|
-
parsed = TomlRB.load_file(path, symbolize_keys: true)
|
39
|
-
|
40
|
-
hash = {
|
41
|
-
title: 'TomlRB Example',
|
42
|
-
|
43
|
-
owner: {
|
44
|
-
name: 'Tom Preston-Werner',
|
45
|
-
organization: 'GitHub',
|
46
|
-
bio: "GitHub Cofounder & CEO\nLikes tater tots and beer.",
|
47
|
-
dob: Time.utc(1979, 05, 27, 07, 32, 00)
|
48
|
-
},
|
49
|
-
|
50
|
-
database: {
|
51
|
-
server: '192.168.1.1',
|
52
|
-
ports: [8001, 8001, 8002],
|
53
|
-
connection_max: 5000,
|
54
|
-
enabled: true
|
55
|
-
},
|
56
|
-
|
57
|
-
servers: {
|
58
|
-
alpha: {
|
59
|
-
ip: '10.0.0.1',
|
60
|
-
dc: 'eqdc10'
|
61
|
-
},
|
62
|
-
beta: {
|
63
|
-
ip: '10.0.0.2',
|
64
|
-
dc: 'eqdc10'
|
65
|
-
}
|
66
|
-
},
|
67
|
-
|
68
|
-
clients: {
|
69
|
-
data: [%w(gamma delta), [1, 2]],
|
70
|
-
hosts: %w(alpha omega)
|
71
|
-
},
|
72
|
-
|
73
|
-
amqp: {
|
74
|
-
exchange: {
|
75
|
-
durable: true,
|
76
|
-
auto_delete: false
|
77
|
-
}
|
78
|
-
},
|
79
|
-
|
80
|
-
products: [
|
81
|
-
{ name: "Hammer", sku: 738_594_937 },
|
82
|
-
{},
|
83
|
-
{ name: "Nail", sku: 284_758_393, color: "gray" }
|
84
|
-
]
|
85
|
-
|
86
|
-
}
|
87
|
-
|
88
|
-
assert_equal(hash, parsed)
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_line_break
|
92
|
-
parsed = TomlRB.parse("hello = 'world'\r\nline_break = true")
|
93
|
-
assert_equal({ 'hello' => 'world', 'line_break' => true }, parsed)
|
94
|
-
end
|
95
|
-
|
96
|
-
def compare_toml_files(folder, file = nil, &block)
|
97
|
-
file ||= '*'
|
98
|
-
Dir["test/examples/#{folder}/#{file}.json"].each do |json_file|
|
99
|
-
toml_file = File.join(File.dirname(json_file),
|
100
|
-
File.basename(json_file, '.json')) + '.toml'
|
101
|
-
begin
|
102
|
-
toml = TomlRB.load_file(toml_file)
|
103
|
-
rescue TomlRB::Error => e
|
104
|
-
assert false, "Error: #{e} in #{toml_file}"
|
105
|
-
end
|
106
|
-
json = JSON.parse(File.read(json_file))
|
107
|
-
block.call(json, toml, toml_file)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_valid_cases
|
112
|
-
compare_toml_files 'valid' do |json, toml, file|
|
113
|
-
assert_equal json, toml, "In file '#{file}'"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_invalid_cases
|
118
|
-
file = '*'
|
119
|
-
Dir["test/examples/invalid/#{file}.toml"].each do |toml_file|
|
120
|
-
assert_raises(TomlRB::Error, "For file #{toml_file}") do
|
121
|
-
TomlRB.load_file(toml_file)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
data/toml-rb.gemspec
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = 'toml-rb'
|
3
|
-
s.version = '1.1.2'
|
4
|
-
s.date = Time.now.strftime('%Y-%m-%d')
|
5
|
-
s.summary = 'Toml parser in ruby, for ruby.'
|
6
|
-
s.description = 'A Toml parser using Citrus parsing library. '
|
7
|
-
s.authors = ['Emiliano Mancuso', 'Lucas Tolchinsky']
|
8
|
-
s.email = ['emiliano.mancuso@gmail.com', 'lucas.tolchinsky@gmail.com']
|
9
|
-
s.homepage = 'http://github.com/emancu/toml-rb'
|
10
|
-
s.license = 'MIT'
|
11
|
-
|
12
|
-
s.files = Dir[
|
13
|
-
'README.md',
|
14
|
-
'Rakefile',
|
15
|
-
'lib/**/*.rb',
|
16
|
-
'lib/**/*.citrus',
|
17
|
-
'*.gemspec',
|
18
|
-
'test/*.*',
|
19
|
-
]
|
20
|
-
|
21
|
-
s.required_ruby_version = '>= 1.9'
|
22
|
-
s.add_dependency 'citrus', '~> 3.0', '> 3.0'
|
23
|
-
end
|