toml-rb 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +7 -5
- data/Rakefile +2 -3
- data/init.rb +1 -1
- data/lib/toml.rb +0 -2
- data/lib/toml/dumper.rb +49 -8
- data/lib/toml/grammars/array.citrus +7 -7
- data/lib/toml/grammars/document.citrus +6 -2
- data/lib/toml/grammars/primitive.citrus +72 -10
- data/lib/toml/keygroup.rb +4 -3
- data/lib/toml/keyvalue.rb +1 -1
- data/lib/toml/parser.rb +4 -0
- data/lib/toml/string.rb +39 -23
- data/lib/toml/table_array.rb +29 -0
- data/test/dumper_test.rb +20 -11
- data/test/errors_test.rb +10 -12
- data/test/example-v0.3.1.toml +180 -0
- data/test/grammar_test.rb +56 -6
- data/test/hard_example.toml +5 -2
- data/test/toml_examples.rb +171 -0
- data/test/toml_test.rb +22 -55
- data/toml-rb.gemspec +13 -13
- metadata +22 -23
@@ -0,0 +1,171 @@
|
|
1
|
+
class TomlExamples
|
2
|
+
def self.example_v_0_3_1
|
3
|
+
{
|
4
|
+
'Table' => {
|
5
|
+
'key' => 'value'
|
6
|
+
},
|
7
|
+
'dog' => {
|
8
|
+
'tater' => {
|
9
|
+
'type' => 'pug'
|
10
|
+
}
|
11
|
+
},
|
12
|
+
'x' => {
|
13
|
+
'y' => {
|
14
|
+
'z' => {
|
15
|
+
'w' => {}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
},
|
19
|
+
'String' => {
|
20
|
+
'basic' => "I'm a string. \"You can quote me\". Name\tJos\\u00E9\nLocation\tSF.",
|
21
|
+
'Multiline' => {
|
22
|
+
'key1' => "One\nTwo",
|
23
|
+
'key2' => "One\nTwo",
|
24
|
+
'key3' => "One\nTwo"
|
25
|
+
},
|
26
|
+
'Multilined' => {
|
27
|
+
'Singleline' => {
|
28
|
+
'key1' => 'The quick brown fox jumps over the lazy dog.',
|
29
|
+
'key2' => 'The quick brown fox jumps over the lazy dog.',
|
30
|
+
'key3' => 'The quick brown fox jumps over the lazy dog.'
|
31
|
+
}
|
32
|
+
},
|
33
|
+
'Literal' => {
|
34
|
+
'winpath' => 'C:\\Users\nodejs\templates',
|
35
|
+
'winpath2' => "\\\\ServerX\\admin$\\system32\\",
|
36
|
+
'quoted' => 'Tom "Dubs" Preston-Werner',
|
37
|
+
'regex' => '<\i\c*\s*>',
|
38
|
+
'Multiline' => {
|
39
|
+
"regex2" => "I [dw]on't need \\d{2} apples",
|
40
|
+
"lines" => "The first newline is\ntrimmed in raw strings.\n All other whitespace\n is preserved.\n"
|
41
|
+
}
|
42
|
+
}
|
43
|
+
},
|
44
|
+
"Integer" => {
|
45
|
+
"key1" => 99,
|
46
|
+
"key2" => 42,
|
47
|
+
"key3" => 0,
|
48
|
+
"key4" => -17
|
49
|
+
},
|
50
|
+
"Float" => {
|
51
|
+
"fractional" => {
|
52
|
+
"key1" => 1.0,
|
53
|
+
"key2" => 3.1415,
|
54
|
+
"key3" => -0.01
|
55
|
+
},
|
56
|
+
"both" => {
|
57
|
+
"key" => 6.626e-34
|
58
|
+
},
|
59
|
+
"exponent" => {
|
60
|
+
"key1" => 5.0e+22,
|
61
|
+
"key2" => 1000000.0,
|
62
|
+
"key3" => -0.02
|
63
|
+
}
|
64
|
+
},
|
65
|
+
"Booleans" => {
|
66
|
+
"True" => true,
|
67
|
+
"False" => false
|
68
|
+
},
|
69
|
+
"Datetime" => {
|
70
|
+
"key1" => Time.utc(1979, 05, 27, 07, 32, 0),
|
71
|
+
"key2" => Time.new(1979, 05, 27, 00, 32, 0, '-07:00'),
|
72
|
+
"key3" => Time.new(1979, 05, 27, 00, 32, 0.999999, '-07:00')
|
73
|
+
},
|
74
|
+
"Array" => {
|
75
|
+
"key1" => [1, 2, 3],
|
76
|
+
"key2" => %w(red yellow green),
|
77
|
+
"key3" => [[1, 2], [3, 4, 5]],
|
78
|
+
"key4" => [[1, 2], %w(a b c)],
|
79
|
+
"key5" => [1, 2, 3],
|
80
|
+
"key6" => [1, 2]
|
81
|
+
},
|
82
|
+
"products" => [
|
83
|
+
{ "name" => "Hammer", "sku" => 738594937 },
|
84
|
+
{},
|
85
|
+
{ "name" => "Nail", "sku" => 284758393, "color" => "gray" }
|
86
|
+
],
|
87
|
+
"fruit" => [
|
88
|
+
{
|
89
|
+
"name" => "apple",
|
90
|
+
"physical" => {
|
91
|
+
"color" => "red",
|
92
|
+
"shape" => "round"
|
93
|
+
},
|
94
|
+
"variety" => [
|
95
|
+
{ "name" => "red delicious" },
|
96
|
+
{ "name" => "granny smith" }
|
97
|
+
]
|
98
|
+
},
|
99
|
+
{
|
100
|
+
"name" => "banana",
|
101
|
+
"variety" => [
|
102
|
+
{ "name" => "plantain" }
|
103
|
+
]
|
104
|
+
}
|
105
|
+
]
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.example
|
110
|
+
{
|
111
|
+
'title' => 'TOML Example',
|
112
|
+
|
113
|
+
'owner' => {
|
114
|
+
'name' => 'Tom Preston-Werner',
|
115
|
+
'organization' => 'GitHub',
|
116
|
+
'bio' => "GitHub Cofounder & CEO\nLikes tater tots and beer.",
|
117
|
+
'dob' => Time.utc(1979, 05, 27, 07, 32, 00)
|
118
|
+
},
|
119
|
+
|
120
|
+
'database' => {
|
121
|
+
'server' => '192.168.1.1',
|
122
|
+
'ports' => [8001, 8001, 8002],
|
123
|
+
'connection_max' => 5000,
|
124
|
+
'enabled' => true
|
125
|
+
},
|
126
|
+
|
127
|
+
'servers' => {
|
128
|
+
'alpha' => {
|
129
|
+
'ip' => '10.0.0.1',
|
130
|
+
'dc' => 'eqdc10'
|
131
|
+
},
|
132
|
+
'beta' => {
|
133
|
+
'ip' => '10.0.0.2',
|
134
|
+
'dc' => 'eqdc10'
|
135
|
+
}
|
136
|
+
},
|
137
|
+
|
138
|
+
'clients' => {
|
139
|
+
'data' => [%w(gamma delta), [1, 2]],
|
140
|
+
'hosts' => %w(alpha omega)
|
141
|
+
}
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
def self.hard_example
|
146
|
+
{
|
147
|
+
'the' => {
|
148
|
+
'test_string' => "You'll hate me after this - #",
|
149
|
+
'hard' => {
|
150
|
+
'test_array' => ['] ', ' # '],
|
151
|
+
'test_array2' => ['Test #11 ]proved that', 'Experiment #9 was a success'],
|
152
|
+
'another_test_string' => ' Same thing, but with a string #',
|
153
|
+
'harder_test_string' => " And when \"'s are in the string, along with # \"",
|
154
|
+
'bit#' => {
|
155
|
+
'what?' => "You don't think some user won't do that?",
|
156
|
+
'multi_line_array' => [']']
|
157
|
+
}
|
158
|
+
}
|
159
|
+
},
|
160
|
+
"nested" => [
|
161
|
+
{
|
162
|
+
"table" => [
|
163
|
+
{
|
164
|
+
"array" => [{}]
|
165
|
+
}
|
166
|
+
]
|
167
|
+
}
|
168
|
+
]
|
169
|
+
}
|
170
|
+
end
|
171
|
+
end
|
data/test/toml_test.rb
CHANGED
@@ -1,68 +1,35 @@
|
|
1
1
|
require_relative 'helper'
|
2
|
+
require_relative 'toml_examples'
|
2
3
|
|
3
4
|
class TomlTest < Test::Unit::TestCase
|
5
|
+
def test_file_v_0_3_1
|
6
|
+
path = File.join(File.dirname(__FILE__), 'example-v0.3.1.toml')
|
7
|
+
parsed = TOML.load_file(path)
|
8
|
+
hash = TomlExamples.example_v_0_3_1
|
9
|
+
|
10
|
+
assert_equal hash['Array'], parsed['Array']
|
11
|
+
assert_equal hash['Booleans'], parsed['Booleans']
|
12
|
+
assert_equal hash['Datetime'], parsed['Datetime']
|
13
|
+
assert_equal hash['Float'], parsed['Float']
|
14
|
+
assert_equal hash['Integer'], parsed['Integer']
|
15
|
+
assert_equal hash['String'], parsed['String']
|
16
|
+
assert_equal hash['Table'], parsed['Table']
|
17
|
+
assert_equal hash['products'], parsed['products']
|
18
|
+
assert_equal hash['fruit'], parsed['fruit']
|
19
|
+
end
|
20
|
+
|
4
21
|
def test_file
|
5
22
|
path = File.join(File.dirname(__FILE__), 'example.toml')
|
6
23
|
parsed = TOML.load_file(path)
|
7
24
|
|
8
|
-
|
9
|
-
'title' => 'TOML Example',
|
10
|
-
|
11
|
-
'owner' => {
|
12
|
-
'name' => 'Tom Preston-Werner',
|
13
|
-
'organization' => 'GitHub',
|
14
|
-
'bio' => "GitHub Cofounder & CEO\nLikes tater tots and beer.",
|
15
|
-
'dob' => Time.utc(1979, 05, 27, 07, 32, 00)
|
16
|
-
},
|
17
|
-
|
18
|
-
'database' => {
|
19
|
-
'server' => '192.168.1.1',
|
20
|
-
'ports' => [8001, 8001, 8002],
|
21
|
-
'connection_max' => 5000,
|
22
|
-
'enabled' => true
|
23
|
-
},
|
24
|
-
|
25
|
-
'servers' => {
|
26
|
-
'alpha' => {
|
27
|
-
'ip' => '10.0.0.1',
|
28
|
-
'dc' => 'eqdc10'
|
29
|
-
},
|
30
|
-
'beta' => {
|
31
|
-
'ip' => '10.0.0.2',
|
32
|
-
'dc' => 'eqdc10'
|
33
|
-
}
|
34
|
-
},
|
35
|
-
|
36
|
-
'clients' => {
|
37
|
-
'data' => [['gamma', 'delta'], [1, 2]],
|
38
|
-
'hosts' => ['alpha', 'omega']
|
39
|
-
}
|
40
|
-
}
|
41
|
-
|
42
|
-
assert_equal(hash, parsed)
|
25
|
+
assert_equal TomlExamples.example, parsed
|
43
26
|
end
|
44
27
|
|
45
28
|
def test_hard_example
|
46
29
|
path = File.join(File.dirname(__FILE__), 'hard_example.toml')
|
47
30
|
parsed = TOML.load_file(path)
|
48
31
|
|
49
|
-
|
50
|
-
'the' => {
|
51
|
-
'test_string' => "You'll hate me after this - #",
|
52
|
-
'hard' => {
|
53
|
-
'test_array' => ['] ', ' # '],
|
54
|
-
'test_array2' => ['Test #11 ]proved that', 'Experiment #9 was a success'],
|
55
|
-
'another_test_string' => ' Same thing, but with a string #',
|
56
|
-
'harder_test_string' => " And when \"'s are in the string, along with # \"",
|
57
|
-
'bit#' => {
|
58
|
-
'what?' => "You don't think some user won't do that?",
|
59
|
-
'multi_line_array' => [']']
|
60
|
-
}
|
61
|
-
}
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
assert_equal(hash, parsed)
|
32
|
+
assert_equal TomlExamples.hard_example, parsed
|
66
33
|
end
|
67
34
|
|
68
35
|
def test_symbolize_keys
|
@@ -98,8 +65,8 @@ class TomlTest < Test::Unit::TestCase
|
|
98
65
|
},
|
99
66
|
|
100
67
|
clients: {
|
101
|
-
data: [
|
102
|
-
hosts:
|
68
|
+
data: [%w(gamma delta), [1, 2]],
|
69
|
+
hosts: %w(alpha omega)
|
103
70
|
}
|
104
71
|
}
|
105
72
|
|
@@ -108,6 +75,6 @@ class TomlTest < Test::Unit::TestCase
|
|
108
75
|
|
109
76
|
def test_line_break
|
110
77
|
parsed = TOML.parse("hello = 'world'\r\nline_break = true")
|
111
|
-
assert_equal({'hello' => 'world', 'line_break' => true}, parsed)
|
78
|
+
assert_equal({ 'hello' => 'world', 'line_break' => true }, parsed)
|
112
79
|
end
|
113
80
|
end
|
data/toml-rb.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'toml-rb'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.2.0'
|
4
4
|
s.date = Time.now.strftime('%Y-%m-%d')
|
5
|
-
s.summary =
|
6
|
-
s.description =
|
7
|
-
s.authors = [
|
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
8
|
s.email = ['emiliano.mancuso@gmail.com', 'lucas.tolchinsky@gmail.com']
|
9
9
|
s.homepage = 'http://github.com/eMancu/toml-rb'
|
10
|
-
s.license =
|
10
|
+
s.license = 'MIT'
|
11
11
|
|
12
12
|
s.files = Dir[
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
'README.md',
|
14
|
+
'Rakefile',
|
15
|
+
'lib/**/*.rb',
|
16
|
+
'lib/**/*.citrus',
|
17
|
+
'*.gemspec',
|
18
|
+
'test/*.*',
|
19
|
+
'init.rb'
|
20
20
|
]
|
21
21
|
|
22
|
-
s.add_dependency
|
22
|
+
s.add_dependency 'citrus', '~> 3.0', '> 3.0'
|
23
23
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toml-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Emiliano Mancuso
|
@@ -10,31 +9,29 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2015-01-31 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: citrus
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- - ~>
|
18
|
+
- - "~>"
|
21
19
|
- !ruby/object:Gem::Version
|
22
20
|
version: '3.0'
|
23
|
-
- -
|
21
|
+
- - ">"
|
24
22
|
- !ruby/object:Gem::Version
|
25
23
|
version: '3.0'
|
26
24
|
type: :runtime
|
27
25
|
prerelease: false
|
28
26
|
version_requirements: !ruby/object:Gem::Requirement
|
29
|
-
none: false
|
30
27
|
requirements:
|
31
|
-
- - ~>
|
28
|
+
- - "~>"
|
32
29
|
- !ruby/object:Gem::Version
|
33
30
|
version: '3.0'
|
34
|
-
- -
|
31
|
+
- - ">"
|
35
32
|
- !ruby/object:Gem::Version
|
36
33
|
version: '3.0'
|
37
|
-
description:
|
34
|
+
description: 'A TOML parser using Citrus parsing library. '
|
38
35
|
email:
|
39
36
|
- emiliano.mancuso@gmail.com
|
40
37
|
- lucas.tolchinsky@gmail.com
|
@@ -44,48 +41,50 @@ extra_rdoc_files: []
|
|
44
41
|
files:
|
45
42
|
- README.md
|
46
43
|
- Rakefile
|
47
|
-
-
|
48
|
-
- lib/toml/keygroup.rb
|
49
|
-
- lib/toml/keyvalue.rb
|
50
|
-
- lib/toml/parser.rb
|
51
|
-
- lib/toml/string.rb
|
44
|
+
- init.rb
|
52
45
|
- lib/toml.rb
|
46
|
+
- lib/toml/dumper.rb
|
53
47
|
- lib/toml/grammars/array.citrus
|
54
48
|
- lib/toml/grammars/document.citrus
|
55
49
|
- lib/toml/grammars/helper.citrus
|
56
50
|
- lib/toml/grammars/primitive.citrus
|
57
|
-
- toml
|
51
|
+
- lib/toml/keygroup.rb
|
52
|
+
- lib/toml/keyvalue.rb
|
53
|
+
- lib/toml/parser.rb
|
54
|
+
- lib/toml/string.rb
|
55
|
+
- lib/toml/table_array.rb
|
58
56
|
- test/dumper_test.rb
|
59
57
|
- test/errors_test.rb
|
58
|
+
- test/example-v0.3.1.toml
|
60
59
|
- test/example.toml
|
61
60
|
- test/grammar_test.rb
|
62
61
|
- test/hard_example.toml
|
63
62
|
- test/helper.rb
|
63
|
+
- test/toml_examples.rb
|
64
64
|
- test/toml_test.rb
|
65
|
-
-
|
65
|
+
- toml-rb.gemspec
|
66
66
|
homepage: http://github.com/eMancu/toml-rb
|
67
67
|
licenses:
|
68
68
|
- MIT
|
69
|
+
metadata: {}
|
69
70
|
post_install_message:
|
70
71
|
rdoc_options: []
|
71
72
|
require_paths:
|
72
73
|
- lib
|
73
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
75
|
requirements:
|
76
|
-
- -
|
76
|
+
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
80
|
requirements:
|
82
|
-
- -
|
81
|
+
- - ">="
|
83
82
|
- !ruby/object:Gem::Version
|
84
83
|
version: '0'
|
85
84
|
requirements: []
|
86
85
|
rubyforge_project:
|
87
|
-
rubygems_version:
|
86
|
+
rubygems_version: 2.4.5
|
88
87
|
signing_key:
|
89
|
-
specification_version:
|
88
|
+
specification_version: 4
|
90
89
|
summary: TOML parser in ruby, for ruby.
|
91
90
|
test_files: []
|