toml-rb-hs 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,46 @@
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 ADDED
@@ -0,0 +1,8 @@
1
+ unless defined? require_relative
2
+ def require_relative(path)
3
+ require path
4
+ end
5
+ end
6
+
7
+ require 'minitest/autorun'
8
+ require_relative '../lib/toml-rb'
@@ -0,0 +1,203 @@
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 ADDED
@@ -0,0 +1,131 @@
1
+ unless defined? require_relative
2
+ def require_relative(path)
3
+ require path
4
+ end
5
+ end
6
+
7
+ require_relative 'helper'
8
+ require_relative 'toml_examples'
9
+ require 'json'
10
+
11
+ class TomlTest < Minitest::Test
12
+ def test_file_v_0_4_0
13
+ path = File.join(File.dirname(__FILE__), 'example-v0.4.0.toml')
14
+ parsed = TomlRB.load_file(path)
15
+ hash = TomlRB::Examples.example_v_0_4_0
16
+
17
+ assert_equal hash['Array'], parsed['Array']
18
+ assert_equal hash['Booleans'], parsed['Booleans']
19
+ assert_equal hash['Datetime'], parsed['Datetime']
20
+ assert_equal hash['Float'], parsed['Float']
21
+ assert_equal hash['Integer'], parsed['Integer']
22
+ assert_equal hash['String'], parsed['String']
23
+ assert_equal hash['Table'], parsed['Table']
24
+ assert_equal hash['products'], parsed['products']
25
+ assert_equal hash['fruit'], parsed['fruit']
26
+ end
27
+
28
+ def test_file
29
+ path = File.join(File.dirname(__FILE__), 'example.toml')
30
+ parsed = TomlRB.load_file(path)
31
+
32
+ assert_equal TomlRB::Examples.example, parsed
33
+ end
34
+
35
+ def test_hard_example
36
+ path = File.join(File.dirname(__FILE__), 'hard_example.toml')
37
+ parsed = TomlRB.load_file(path)
38
+
39
+ assert_equal TomlRB::Examples.hard_example, parsed
40
+ end
41
+
42
+ def test_symbolize_keys
43
+ path = File.join(File.dirname(__FILE__), 'example.toml')
44
+ parsed = TomlRB.load_file(path, symbolize_keys: true)
45
+
46
+ hash = {
47
+ title: 'TomlRB Example',
48
+
49
+ owner: {
50
+ name: 'Tom Preston-Werner',
51
+ organization: 'GitHub',
52
+ bio: "GitHub Cofounder & CEO\nLikes tater tots and beer.",
53
+ dob: Time.utc(1979, 05, 27, 07, 32, 00)
54
+ },
55
+
56
+ database: {
57
+ server: '192.168.1.1',
58
+ ports: [8001, 8001, 8002],
59
+ connection_max: 5000,
60
+ enabled: true
61
+ },
62
+
63
+ servers: {
64
+ alpha: {
65
+ ip: '10.0.0.1',
66
+ dc: 'eqdc10'
67
+ },
68
+ beta: {
69
+ ip: '10.0.0.2',
70
+ dc: 'eqdc10'
71
+ }
72
+ },
73
+
74
+ clients: {
75
+ data: [%w(gamma delta), [1, 2]],
76
+ hosts: %w(alpha omega)
77
+ },
78
+
79
+ amqp: {
80
+ exchange: {
81
+ durable: true,
82
+ auto_delete: false
83
+ }
84
+ },
85
+
86
+ products: [
87
+ { name: "Hammer", sku: 738_594_937 },
88
+ {},
89
+ { name: "Nail", sku: 284_758_393, color: "gray" }
90
+ ]
91
+
92
+ }
93
+
94
+ assert_equal(hash, parsed)
95
+ end
96
+
97
+ def test_line_break
98
+ parsed = TomlRB.parse("hello = 'world'\r\nline_break = true")
99
+ assert_equal({ 'hello' => 'world', 'line_break' => true }, parsed)
100
+ end
101
+
102
+ def compare_toml_files(folder, file = nil, &block)
103
+ file ||= '*'
104
+ Dir["test/examples/#{folder}/#{file}.json"].each do |json_file|
105
+ toml_file = File.join(File.dirname(json_file),
106
+ File.basename(json_file, '.json')) + '.toml'
107
+ begin
108
+ toml = TomlRB.load_file(toml_file)
109
+ rescue TomlRB::Error => e
110
+ assert false, "Error: #{e} in #{toml_file}"
111
+ end
112
+ json = JSON.parse(File.read(json_file))
113
+ block.call(json, toml, toml_file)
114
+ end
115
+ end
116
+
117
+ def test_valid_cases
118
+ compare_toml_files 'valid' do |json, toml, file|
119
+ assert_equal json, toml, "In file '#{file}'"
120
+ end
121
+ end
122
+
123
+ def test_invalid_cases
124
+ file = '*'
125
+ Dir["test/examples/invalid/#{file}.toml"].each do |toml_file|
126
+ assert_raises(TomlRB::Error, "For file #{toml_file}") do
127
+ TomlRB.load_file(toml_file)
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'toml-rb-hs'
3
+ s.version = ENV.key?('RUBYGEM_VERSION') ? ENV['RUBYGEM_VERSION'] : '1.1.1'
4
+ s.date = Time.now.strftime('%Y-%m-%d')
5
+ s.summary = 'Toml parser in ruby, for ruby, modified so it will work with Ruby 1.8.'
6
+ s.description = 'A Toml parser using Citrus parsing library. '
7
+ s.authors = ['Emiliano Mancuso', 'Lucas Tolchinsky', 'Alex Yamauchi']
8
+ s.email = ['emiliano.mancuso@gmail.com', 'lucas.tolchinsky@gmail.com', 'alex.yamauchi@hotschedules.com']
9
+ s.homepage = 'http://github.com/hotschedules/toml-rb-hs'
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.add_runtime_dependency 'citrus', '~> 3.0', '> 3.0'
22
+ s.signing_key = File.expand_path( ENV.key?('RUBYGEM_SIGNING_KEY') ? ENV['RUBYGEM_SIGNING_KEY'] : '~/certs/oss@hotschedules.com.key' ) if $0 =~ /\bgem[\.0-9]*\z/
23
+ s.cert_chain = %w[certs/oss@hotschedules.com.cert]
24
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toml-rb-hs
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 1
10
+ version: 1.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Emiliano Mancuso
14
+ - Lucas Tolchinsky
15
+ - Alex Yamauchi
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain:
19
+ - |
20
+ -----BEGIN CERTIFICATE-----
21
+ MIIELzCCAxGgAwIBAgIJAMOoRmNuvAZcMA0GCSqGSIb3DQEBCwUAMIGnMQswCQYD
22
+ VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5j
23
+ aXNjbzEVMBMGA1UECgwMSG90c2NoZWR1bGVzMQ4wDAYDVQQLDAVJbmZyYTEfMB0G
24
+ A1UEAwwWaW5mcmEuaG90c2NoZWR1bGVzLmNvbTEjMCEGCSqGSIb3DQEJARYUb3Nz
25
+ QGhvdHNjaGVkdWxlcy5jb20wHhcNMTcwMjE4MDA1NDU4WhcNMjEwMjE4MDA1NDU4
26
+ WjCBpzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcM
27
+ DVNhbiBGcmFuY2lzY28xFTATBgNVBAoMDEhvdHNjaGVkdWxlczEOMAwGA1UECwwF
28
+ SW5mcmExHzAdBgNVBAMMFmluZnJhLmhvdHNjaGVkdWxlcy5jb20xIzAhBgkqhkiG
29
+ 9w0BCQEWFG9zc0Bob3RzY2hlZHVsZXMuY29tMIIBKDANBgkqhkiG9w0BAQEFAAOC
30
+ ARUAMIIBEAKCAQcAutTytHjHFb5yK/29POqMS3DyxRSRRbKvBus/rEL3reeKDVlf
31
+ eO9a/9U3oUcxHFHeISF9uOBSvL88svxhLqxkKLVA0vMbVgDFoGsOlh93nA5Lmw+H
32
+ SEzG3+Z6JqH8YfAIqVyp1nZcdtC7u8xYpDD65ayjRALLuvOUXORGeqgedlgiwwLp
33
+ 2tZ7A9tCzBZnDjcNenD8zXLCOdRjJiBPq/XQS9h4POWvpom0z+jyUkRj3ojqOoXW
34
+ bKKdXzdZ3s5BSwgxlWJo+lK/50+xLpjJe4mEJwySkrluy8GOG/UR/j+Y4I1j1FbY
35
+ RwT9SUSairjh0zgiDC0LTjAJBIenuxxuM9jhRyoiu+YYVwIDAQABo1AwTjAdBgNV
36
+ HQ4EFgQUtlFsvLIJ59o2GyoRTXKEIPEgnn8wHwYDVR0jBBgwFoAUtlFsvLIJ59o2
37
+ GyoRTXKEIPEgnn8wDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQcAdELJ
38
+ QdrR55Xak3q5IhLnIdOLJC6ZEdHI2173SSmytInyDX6fe9uZION4I9WCCm/hCp+t
39
+ QILh4feu14iDWmBxzy6F6tiyuEjhaU5Ud9wZ/YDBQhP2AHquoPAufxXZAUFlA5er
40
+ wIYVupToBrWavfbjgRqRHAZ6vwrLwoIiomh2/wv06HLrFmSzj5q6BVp7FFMKDail
41
+ QWzJ4aQl786RMwPa776eVaKQTmQuTUUppvhVq9QdKyxwGPibAYGbYKZwmmtx+BV2
42
+ GJevNV8BSuhh6m2AHCxEzMaD7WKNbewTTgGLUlvppaR9SE2V/yUZ7x1Vp8/mGeO6
43
+ 2Zk648Ep9HVPKmwoVuB75+xEQw==
44
+ -----END CERTIFICATE-----
45
+
46
+ date: 2018-01-19 00:00:00 Z
47
+ dependencies:
48
+ - !ruby/object:Gem::Dependency
49
+ name: citrus
50
+ prerelease: false
51
+ requirement: &id001 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ hash: 7
57
+ segments:
58
+ - 3
59
+ - 0
60
+ version: "3.0"
61
+ - - ">"
62
+ - !ruby/object:Gem::Version
63
+ hash: 7
64
+ segments:
65
+ - 3
66
+ - 0
67
+ version: "3.0"
68
+ type: :runtime
69
+ version_requirements: *id001
70
+ description: "A Toml parser using Citrus parsing library. "
71
+ email:
72
+ - emiliano.mancuso@gmail.com
73
+ - lucas.tolchinsky@gmail.com
74
+ - alex.yamauchi@hotschedules.com
75
+ executables: []
76
+
77
+ extensions: []
78
+
79
+ extra_rdoc_files: []
80
+
81
+ files:
82
+ - README.md
83
+ - Rakefile
84
+ - lib/toml-rb.rb
85
+ - lib/toml-rb/array.rb
86
+ - lib/toml-rb/dumper.rb
87
+ - lib/toml-rb/errors.rb
88
+ - lib/toml-rb/inline_table.rb
89
+ - lib/toml-rb/keygroup.rb
90
+ - lib/toml-rb/keyvalue.rb
91
+ - lib/toml-rb/parser.rb
92
+ - lib/toml-rb/string.rb
93
+ - lib/toml-rb/table_array.rb
94
+ - lib/toml-rb/grammars/array.citrus
95
+ - lib/toml-rb/grammars/document.citrus
96
+ - lib/toml-rb/grammars/helper.citrus
97
+ - lib/toml-rb/grammars/primitive.citrus
98
+ - toml-rb-hs.gemspec
99
+ - test/dumper_test.rb
100
+ - test/errors_test.rb
101
+ - test/example-v0.4.0.toml
102
+ - test/example.toml
103
+ - test/grammar_test.rb
104
+ - test/hard_example.toml
105
+ - test/helper.rb
106
+ - test/toml_examples.rb
107
+ - test/toml_test.rb
108
+ homepage: http://github.com/hotschedules/toml-rb-hs
109
+ licenses:
110
+ - MIT
111
+ post_install_message:
112
+ rdoc_options: []
113
+
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ requirements: []
135
+
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.25
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Toml parser in ruby, for ruby, modified so it will work with Ruby 1.8.
141
+ test_files: []
142
+