toml-rb 0.3.15 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -8
- data/init.rb +13 -13
- data/lib/{toml.rb → toml-rb.rb} +22 -22
- data/lib/{toml → toml-rb}/array.rb +1 -1
- data/lib/{toml → toml-rb}/dumper.rb +1 -1
- data/lib/{toml → toml-rb}/errors.rb +2 -2
- data/lib/{toml → toml-rb}/grammars/array.citrus +3 -3
- data/lib/{toml → toml-rb}/grammars/document.citrus +8 -8
- data/lib/{toml → toml-rb}/grammars/helper.citrus +1 -1
- data/lib/{toml → toml-rb}/grammars/primitive.citrus +6 -6
- data/lib/{toml → toml-rb}/inline_table.rb +3 -3
- data/lib/{toml → toml-rb}/keygroup.rb +2 -2
- data/lib/{toml → toml-rb}/keyvalue.rb +2 -2
- data/lib/{toml → toml-rb}/parser.rb +3 -3
- data/lib/{toml → toml-rb}/string.rb +3 -3
- data/lib/{toml → toml-rb}/table_array.rb +3 -3
- data/test/dumper_test.rb +17 -17
- data/test/errors_test.rb +12 -12
- data/test/example-v0.4.0.toml +1 -1
- data/test/example.toml +3 -3
- data/test/grammar_test.rb +57 -57
- data/test/hard_example.toml +2 -2
- data/test/helper.rb +1 -1
- data/test/toml_examples.rb +2 -2
- data/test/toml_test.rb +13 -13
- data/toml-rb.gemspec +3 -3
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac69523887231de77fcd7f39324df5eb7e372056
|
4
|
+
data.tar.gz: aa219d97002259cc6c73ddee1acef86776dfa365
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87a4601c420d0455d4a3aff4b1f825c7fe34d41125b636de125862a47c6adcf8f8387fe9d8eb76232aa3f03d5a8a008ae460a9be4a459f7292916d36f9df6360
|
7
|
+
data.tar.gz: 172e265a83e3aaa2a4750959eaf66f00e41fb01c316f17a6e16bdb60f163d66aef055f123b58933a9c657e92cb1234eef709d07a2b290ce32acc6903a83bb7f4
|
data/README.md
CHANGED
@@ -6,9 +6,9 @@ toml-rb
|
|
6
6
|
[![Code Climate](https://codeclimate.com/github/emancu/toml-rb/badges/gpa.svg)](https://codeclimate.com/github/emancu/toml-rb)
|
7
7
|
[![Dependency Status](https://gemnasium.com/emancu/toml-rb.svg)](https://gemnasium.com/emancu/toml-rb)
|
8
8
|
|
9
|
-
A [
|
9
|
+
A [TomlRB](https://github.com/toml-lang/toml) parser using [Citrus](http://mjackson.github.io/citrus) library.
|
10
10
|
|
11
|
-
|
11
|
+
TomlRB specs supported: `0.4.0`
|
12
12
|
|
13
13
|
Installation
|
14
14
|
------------
|
@@ -23,7 +23,7 @@ require 'toml'
|
|
23
23
|
|
24
24
|
# From a file!
|
25
25
|
path = File.join(File.dirname(__FILE__), 'path', 'to', 'file')
|
26
|
-
|
26
|
+
TomlRB.load_file(path)
|
27
27
|
|
28
28
|
# From a stream!
|
29
29
|
stream = <<-EOS
|
@@ -33,12 +33,12 @@ stream = <<-EOS
|
|
33
33
|
you = true
|
34
34
|
others = false
|
35
35
|
EOS
|
36
|
-
|
36
|
+
TomlRB.parse(stream)
|
37
37
|
# => {"title"=>"wow!", "awesome"=>{"you"=>true, "others"=>false}}
|
38
38
|
|
39
39
|
# You want symbols as your keys? No problem!
|
40
|
-
|
41
|
-
# Works the same for
|
40
|
+
TomlRB.load_file(path, symbolize_keys: true)
|
41
|
+
# Works the same for TomlRB.parse
|
42
42
|
```
|
43
43
|
|
44
44
|
Dumper Usage
|
@@ -48,7 +48,7 @@ Dumper Usage
|
|
48
48
|
require 'toml'
|
49
49
|
|
50
50
|
# Simple example
|
51
|
-
|
51
|
+
TomlRB.dump( simple: true)
|
52
52
|
# => "simple = true\n"
|
53
53
|
|
54
54
|
|
@@ -61,7 +61,7 @@ hash = {
|
|
61
61
|
}
|
62
62
|
}
|
63
63
|
|
64
|
-
|
64
|
+
TomlRB.dump(hash)
|
65
65
|
# => "title = \"wow!\"\n[awesome]\nothers = false\nyou = true\n"
|
66
66
|
```
|
67
67
|
|
data/init.rb
CHANGED
@@ -2,17 +2,17 @@ require 'citrus'
|
|
2
2
|
|
3
3
|
ROOT = File.dirname(File.expand_path(__FILE__))
|
4
4
|
|
5
|
-
require "#{ROOT}/lib/toml/errors"
|
6
|
-
require "#{ROOT}/lib/toml/array"
|
7
|
-
require "#{ROOT}/lib/toml/string"
|
8
|
-
require "#{ROOT}/lib/toml/table_array"
|
9
|
-
require "#{ROOT}/lib/toml/inline_table"
|
10
|
-
require "#{ROOT}/lib/toml/keyvalue"
|
11
|
-
require "#{ROOT}/lib/toml/keygroup"
|
12
|
-
require "#{ROOT}/lib/toml/parser"
|
13
|
-
require "#{ROOT}/lib/toml/dumper"
|
5
|
+
require "#{ROOT}/lib/toml-rb/errors"
|
6
|
+
require "#{ROOT}/lib/toml-rb/array"
|
7
|
+
require "#{ROOT}/lib/toml-rb/string"
|
8
|
+
require "#{ROOT}/lib/toml-rb/table_array"
|
9
|
+
require "#{ROOT}/lib/toml-rb/inline_table"
|
10
|
+
require "#{ROOT}/lib/toml-rb/keyvalue"
|
11
|
+
require "#{ROOT}/lib/toml-rb/keygroup"
|
12
|
+
require "#{ROOT}/lib/toml-rb/parser"
|
13
|
+
require "#{ROOT}/lib/toml-rb/dumper"
|
14
14
|
|
15
|
-
Citrus.load "#{ROOT}/lib/toml/grammars/helper.citrus"
|
16
|
-
Citrus.load "#{ROOT}/lib/toml/grammars/primitive.citrus"
|
17
|
-
Citrus.load "#{ROOT}/lib/toml/grammars/array.citrus"
|
18
|
-
Citrus.load "#{ROOT}/lib/toml/grammars/document.citrus"
|
15
|
+
Citrus.load "#{ROOT}/lib/toml-rb/grammars/helper.citrus"
|
16
|
+
Citrus.load "#{ROOT}/lib/toml-rb/grammars/primitive.citrus"
|
17
|
+
Citrus.load "#{ROOT}/lib/toml-rb/grammars/array.citrus"
|
18
|
+
Citrus.load "#{ROOT}/lib/toml-rb/grammars/document.citrus"
|
data/lib/{toml.rb → toml-rb.rb}
RENAMED
@@ -1,68 +1,68 @@
|
|
1
1
|
require_relative '../init'
|
2
2
|
|
3
|
-
module
|
4
|
-
# Public: Returns a hash from *
|
3
|
+
module TomlRB
|
4
|
+
# Public: Returns a hash from *TomlRB* content.
|
5
5
|
#
|
6
|
-
# content -
|
6
|
+
# content - TomlRB string to be parsed.
|
7
7
|
# options - The Hash options used to refine the parser (default: {}):
|
8
8
|
# :symbolize_keys - true|false (optional).
|
9
9
|
#
|
10
10
|
#
|
11
11
|
# Examples
|
12
12
|
#
|
13
|
-
#
|
13
|
+
# TomlRB.parse('[group]')
|
14
14
|
# # => {"group"=>{}}
|
15
15
|
#
|
16
|
-
#
|
17
|
-
# # => {"title"=>"
|
16
|
+
# TomlRB.parse('title = "TomlRB parser"')
|
17
|
+
# # => {"title"=>"TomlRB parser"}
|
18
18
|
#
|
19
|
-
#
|
19
|
+
# TomlRB.parse('[group]', symbolize_keys: true)
|
20
20
|
# # => {group: {}}
|
21
21
|
#
|
22
|
-
#
|
23
|
-
# # => {title: "
|
22
|
+
# TomlRB.parse('title = "TomlRB parser"', symbolize_keys: true)
|
23
|
+
# # => {title: "TomlRB parser"}
|
24
24
|
#
|
25
25
|
#
|
26
|
-
# Returns a Ruby hash representation of the content according to
|
26
|
+
# Returns a Ruby hash representation of the content according to TomlRB spec.
|
27
27
|
# Raises ValueOverwriteError if a key is overwritten.
|
28
|
-
# Raises ParseError if the content has invalid
|
28
|
+
# Raises ParseError if the content has invalid TomlRB.
|
29
29
|
def self.parse(content, options = {})
|
30
30
|
Parser.new(content, options).hash
|
31
31
|
end
|
32
32
|
|
33
|
-
# Public: Returns a hash from a *
|
33
|
+
# Public: Returns a hash from a *TomlRB* file.
|
34
34
|
#
|
35
|
-
# path -
|
35
|
+
# path - TomlRB File path
|
36
36
|
# options - The Hash options used to refine the parser (default: {}):
|
37
37
|
# :symbolize_keys - true|false (optional).
|
38
38
|
#
|
39
39
|
#
|
40
40
|
# Examples
|
41
41
|
#
|
42
|
-
#
|
42
|
+
# TomlRB.load_file('/tmp/simple.toml')
|
43
43
|
# # => {"group"=>{}}
|
44
44
|
#
|
45
|
-
#
|
45
|
+
# TomlRB.load_file('/tmp/simple.toml', symbolize_keys: true)
|
46
46
|
# # => {group: {}}
|
47
47
|
#
|
48
48
|
#
|
49
49
|
# Returns a Ruby hash representation of the content.
|
50
50
|
# Raises ValueOverwriteError if a key is overwritten.
|
51
|
-
# Raises ParseError if the content has invalid
|
51
|
+
# Raises ParseError if the content has invalid TomlRB.
|
52
52
|
# Raises Errno::ENOENT if the file cannot be found.
|
53
53
|
# Raises Errno::EACCES if the file cannot be accessed.
|
54
54
|
def self.load_file(path, options = {})
|
55
|
-
|
55
|
+
TomlRB.parse(File.read(path), options)
|
56
56
|
end
|
57
57
|
|
58
|
-
# Public: Returns a *
|
58
|
+
# Public: Returns a *TomlRB* string from a Ruby Hash.
|
59
59
|
#
|
60
|
-
# hash - Ruby Hash to be dumped into *
|
60
|
+
# hash - Ruby Hash to be dumped into *TomlRB*
|
61
61
|
#
|
62
62
|
#
|
63
63
|
# Examples
|
64
64
|
#
|
65
|
-
#
|
65
|
+
# TomlRB.dump(title: 'TomlRB dump')
|
66
66
|
# # => "simple = true\n"
|
67
67
|
#
|
68
68
|
# hash = {
|
@@ -73,11 +73,11 @@ module TOML
|
|
73
73
|
# }
|
74
74
|
# }
|
75
75
|
#
|
76
|
-
#
|
76
|
+
# TomlRB.dump(hash)
|
77
77
|
# # => "title = \"wow!\"\n[awesome]\nothers = false\nyou = true\n"
|
78
78
|
#
|
79
79
|
#
|
80
|
-
# Returns a
|
80
|
+
# Returns a TomlRB string representing the hash.
|
81
81
|
def self.dump(hash)
|
82
82
|
Dumper.new(hash).toml_str
|
83
83
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
grammar
|
2
|
-
include
|
1
|
+
grammar TomlRB::Arrays
|
2
|
+
include TomlRB::Primitive
|
3
3
|
|
4
4
|
rule array
|
5
|
-
("[" array_comments (elements)? space ","? array_comments "]" indent?) <
|
5
|
+
("[" array_comments (elements)? space ","? array_comments "]" indent?) <TomlRB::ArrayParser>
|
6
6
|
end
|
7
7
|
|
8
8
|
rule array_comments
|
@@ -1,29 +1,29 @@
|
|
1
|
-
grammar
|
2
|
-
include
|
3
|
-
include
|
1
|
+
grammar TomlRB::Document
|
2
|
+
include TomlRB::Primitive
|
3
|
+
include TomlRB::Arrays
|
4
4
|
|
5
5
|
rule document
|
6
6
|
(comment | table_array | keygroup | keyvalue | line_break)*
|
7
7
|
end
|
8
8
|
|
9
9
|
rule table_array
|
10
|
-
(space? '[[' stripped_key ("." stripped_key)* ']]' comment?) <
|
10
|
+
(space? '[[' stripped_key ("." stripped_key)* ']]' comment?) <TomlRB::TableArrayParser>
|
11
11
|
end
|
12
12
|
|
13
13
|
rule keygroup
|
14
|
-
(space? '[' stripped_key ("." stripped_key)* ']' comment?) <
|
14
|
+
(space? '[' stripped_key ("." stripped_key)* ']' comment?) <TomlRB::KeygroupParser>
|
15
15
|
end
|
16
16
|
|
17
17
|
rule keyvalue
|
18
|
-
(stripped_key '=' space? v:(toml_values) comment?) <
|
18
|
+
(stripped_key '=' space? v:(toml_values) comment?) <TomlRB::KeyvalueParser>
|
19
19
|
end
|
20
20
|
|
21
21
|
rule inline_table
|
22
|
-
(space? '{' (keyvalue (',' keyvalue)*)? space? '}' ) <
|
22
|
+
(space? '{' (keyvalue (',' keyvalue)*)? space? '}' ) <TomlRB::InlineTableParser>
|
23
23
|
end
|
24
24
|
|
25
25
|
rule inline_table_array
|
26
|
-
("[" array_comments inline_table_array_elements space ","? array_comments "]" indent?) <
|
26
|
+
("[" array_comments inline_table_array_elements space ","? array_comments "]" indent?) <TomlRB::InlineTableArrayParser>
|
27
27
|
end
|
28
28
|
|
29
29
|
rule inline_table_array_elements
|
@@ -1,5 +1,5 @@
|
|
1
|
-
grammar
|
2
|
-
include
|
1
|
+
grammar TomlRB::Primitive
|
2
|
+
include TomlRB::Helper
|
3
3
|
|
4
4
|
rule primitive
|
5
5
|
string | bool | datetime | number
|
@@ -14,19 +14,19 @@ grammar TOML::Primitive
|
|
14
14
|
end
|
15
15
|
|
16
16
|
rule basic_string
|
17
|
-
(/(["])(?:\\?.)*?\1/ space) <
|
17
|
+
(/(["])(?:\\?.)*?\1/ space) <TomlRB::BasicString>
|
18
18
|
end
|
19
19
|
|
20
20
|
rule literal_string
|
21
|
-
(/(['])(?:\\?.)*?\1/ space) <
|
21
|
+
(/(['])(?:\\?.)*?\1/ space) <TomlRB::LiteralString>
|
22
22
|
end
|
23
23
|
|
24
24
|
rule multiline_string
|
25
|
-
('"""' line_break* (text:~('"""' !'"')|'') '"""' space) <
|
25
|
+
('"""' line_break* (text:~('"""' !'"')|'') '"""' space) <TomlRB::MultilineString>
|
26
26
|
end
|
27
27
|
|
28
28
|
rule multiline_literal
|
29
|
-
("'''" line_break* (text:~("'''" !"'")|'') "'''" space) <
|
29
|
+
("'''" line_break* (text:~("'''" !"'")|'') "'''" space) <TomlRB::MultilineLiteral>
|
30
30
|
end
|
31
31
|
|
32
32
|
##
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module TomlRB
|
2
2
|
class InlineTable
|
3
3
|
attr_reader :symbolize_keys
|
4
4
|
|
@@ -56,7 +56,7 @@ module TOML
|
|
56
56
|
|
57
57
|
module InlineTableParser
|
58
58
|
def value
|
59
|
-
|
59
|
+
TomlRB::InlineTable.new captures[:keyvalue].map(&:value)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -66,7 +66,7 @@ module TOML
|
|
66
66
|
x.captures[:inline_table]
|
67
67
|
end
|
68
68
|
|
69
|
-
|
69
|
+
TomlRB::InlineTableArray.new(tables.flatten.map(&:value)).value
|
70
70
|
end
|
71
71
|
end
|
72
72
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module TomlRB
|
2
2
|
class Keygroup
|
3
3
|
def initialize(nested_keys)
|
4
4
|
@nested_keys = nested_keys
|
@@ -35,7 +35,7 @@ module TOML
|
|
35
35
|
# Used in document.citrus
|
36
36
|
module KeygroupParser
|
37
37
|
def value
|
38
|
-
|
38
|
+
TomlRB::Keygroup.new(captures[:stripped_key].map(&:value))
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module TomlRB
|
2
2
|
class Keyvalue
|
3
3
|
attr_reader :value, :symbolize_keys
|
4
4
|
|
@@ -43,7 +43,7 @@ module TOML
|
|
43
43
|
# Used in document.citrus
|
44
44
|
module KeyvalueParser
|
45
45
|
def value
|
46
|
-
|
46
|
+
TomlRB::Keyvalue.new(capture(:stripped_key).value, capture(:v).value)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module TomlRB
|
2
2
|
class Parser
|
3
3
|
attr_reader :hash
|
4
4
|
|
@@ -9,10 +9,10 @@ module TOML
|
|
9
9
|
@symbolize_keys = options[:symbolize_keys]
|
10
10
|
|
11
11
|
begin
|
12
|
-
parsed =
|
12
|
+
parsed = TomlRB::Document.parse(content)
|
13
13
|
parsed.matches.map(&:value).compact.each { |m| m.accept_visitor(self) }
|
14
14
|
rescue Citrus::ParseError => e
|
15
|
-
raise
|
15
|
+
raise TomlRB::ParseError.new(e.message)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module TomlRB
|
2
2
|
# Used in primitive.citrus
|
3
3
|
module BasicString
|
4
4
|
SPECIAL_CHARS = {
|
@@ -13,7 +13,7 @@ module TOML
|
|
13
13
|
}.freeze
|
14
14
|
|
15
15
|
def value
|
16
|
-
aux =
|
16
|
+
aux = TomlRB::BasicString.transform_escaped_chars first.value
|
17
17
|
|
18
18
|
aux[1...-1]
|
19
19
|
end
|
@@ -53,7 +53,7 @@ module TOML
|
|
53
53
|
# Remove spaces on multilined Singleline strings
|
54
54
|
aux.gsub!(/\\\r?\n[\n\t\r ]*/, '')
|
55
55
|
|
56
|
-
|
56
|
+
TomlRB::BasicString.transform_escaped_chars aux
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module TomlRB
|
2
2
|
class TableArray
|
3
3
|
def initialize(nested_keys)
|
4
4
|
@nested_keys = nested_keys
|
@@ -22,7 +22,7 @@ module TOML
|
|
22
22
|
|
23
23
|
# Define Table Array
|
24
24
|
if hash[last_key].is_a? Hash
|
25
|
-
fail
|
25
|
+
fail TomlRB::ParseError,
|
26
26
|
"#{last_key} was defined as hash but is now redefined as a table!"
|
27
27
|
end
|
28
28
|
hash[last_key] = [] unless hash[last_key]
|
@@ -43,7 +43,7 @@ module TOML
|
|
43
43
|
# Used in document.citrus
|
44
44
|
module TableArrayParser
|
45
45
|
def value
|
46
|
-
|
46
|
+
TomlRB::TableArray.new(captures[:stripped_key].map(&:value))
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
data/test/dumper_test.rb
CHANGED
@@ -2,47 +2,47 @@ require_relative 'helper'
|
|
2
2
|
|
3
3
|
class DumperTest < Minitest::Test
|
4
4
|
def test_dump_empty
|
5
|
-
dumped =
|
5
|
+
dumped = TomlRB.dump({})
|
6
6
|
assert_equal('', dumped)
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_dump_types
|
10
|
-
dumped =
|
11
|
-
assert_equal("string = \"
|
10
|
+
dumped = TomlRB.dump(string: 'TomlRB "dump"')
|
11
|
+
assert_equal("string = \"TomlRB \\\"dump\\\"\"\n", dumped)
|
12
12
|
|
13
|
-
dumped =
|
13
|
+
dumped = TomlRB.dump(float: -13.24)
|
14
14
|
assert_equal("float = -13.24\n", dumped)
|
15
15
|
|
16
|
-
dumped =
|
16
|
+
dumped = TomlRB.dump(int: 1234)
|
17
17
|
assert_equal("int = 1234\n", dumped)
|
18
18
|
|
19
|
-
dumped =
|
19
|
+
dumped = TomlRB.dump(true: true)
|
20
20
|
assert_equal("true = true\n", dumped)
|
21
21
|
|
22
|
-
dumped =
|
22
|
+
dumped = TomlRB.dump(false: false)
|
23
23
|
assert_equal("false = false\n", dumped)
|
24
24
|
|
25
|
-
dumped =
|
25
|
+
dumped = TomlRB.dump(array: [1, 2, 3])
|
26
26
|
assert_equal("array = [1, 2, 3]\n", dumped)
|
27
27
|
|
28
|
-
dumped =
|
28
|
+
dumped = TomlRB.dump(array: [[1, 2], %w(weird one)])
|
29
29
|
assert_equal("array = [[1, 2], [\"weird\", \"one\"]]\n", dumped)
|
30
30
|
|
31
|
-
dumped =
|
31
|
+
dumped = TomlRB.dump(datetime: Time.utc(1986, 8, 28, 15, 15))
|
32
32
|
assert_equal("datetime = 1986-08-28T15:15:00Z\n", dumped)
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_dump_nested_attributes
|
36
36
|
hash = { nested: { hash: { deep: true } } }
|
37
|
-
dumped =
|
37
|
+
dumped = TomlRB.dump(hash)
|
38
38
|
assert_equal("[nested.hash]\ndeep = true\n", dumped)
|
39
39
|
|
40
40
|
hash[:nested].merge!(other: 12)
|
41
|
-
dumped =
|
41
|
+
dumped = TomlRB.dump(hash)
|
42
42
|
assert_equal("[nested]\nother = 12\n[nested.hash]\ndeep = true\n", dumped)
|
43
43
|
|
44
44
|
hash[:nested].merge!(nest: { again: 'it never ends' })
|
45
|
-
dumped =
|
45
|
+
dumped = TomlRB.dump(hash)
|
46
46
|
toml = <<-EOS.gsub(/^ {6}/, '')
|
47
47
|
[nested]
|
48
48
|
other = 12
|
@@ -55,17 +55,17 @@ class DumperTest < Minitest::Test
|
|
55
55
|
assert_equal(toml, dumped)
|
56
56
|
|
57
57
|
hash = { non: { 'bare."keys"' => { "works" => true } } }
|
58
|
-
dumped =
|
58
|
+
dumped = TomlRB.dump(hash)
|
59
59
|
assert_equal("[non.\"bare.\\\"keys\\\"\"]\nworks = true\n", dumped)
|
60
60
|
|
61
61
|
hash = { hola: [{ chau: 4 }, { chau: 3 }] }
|
62
|
-
dumped =
|
62
|
+
dumped = TomlRB.dump(hash)
|
63
63
|
assert_equal("[[hola]]\nchau = 4\n[[hola]]\nchau = 3\n", dumped)
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_print_empty_tables
|
67
67
|
hash = { plugins: { cpu: { foo: "bar", baz: 1234 }, disk: {}, io: {} } }
|
68
|
-
dumped =
|
68
|
+
dumped = TomlRB.dump(hash)
|
69
69
|
toml = <<-EOS.gsub(/^ {6}/, '')
|
70
70
|
[plugins.cpu]
|
71
71
|
baz = 1234
|
@@ -79,7 +79,7 @@ class DumperTest < Minitest::Test
|
|
79
79
|
|
80
80
|
def test_dump_array_tables
|
81
81
|
hash = { fruit: [{ physical: { color: "red" } }, { physical: { color: "blue" } }] }
|
82
|
-
dumped =
|
82
|
+
dumped = TomlRB.dump(hash)
|
83
83
|
toml = <<-EOS.gsub(/^ {6}/, '')
|
84
84
|
[[fruit]]
|
85
85
|
[fruit.physical]
|
data/test/errors_test.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative 'helper'
|
|
3
3
|
class ErrorsTest < Minitest::Test
|
4
4
|
def test_text_after_keygroup
|
5
5
|
str = "[error] if you didn't catch this, your parser is broken"
|
6
|
-
assert_raises(
|
6
|
+
assert_raises(TomlRB::ParseError) { TomlRB.parse(str) }
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_text_after_string
|
@@ -11,7 +11,7 @@ class ErrorsTest < Minitest::Test
|
|
11
11
|
str += 'keygroup or key value pair has ended should produce an error '
|
12
12
|
str += 'unless it is a comment" like this'
|
13
13
|
|
14
|
-
assert_raises(
|
14
|
+
assert_raises(TomlRB::ParseError) { TomlRB.parse(str) }
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_multiline_array_bad_string
|
@@ -24,7 +24,7 @@ class ErrorsTest < Minitest::Test
|
|
24
24
|
] End of array comment, forgot the #
|
25
25
|
EOS
|
26
26
|
|
27
|
-
assert_raises(
|
27
|
+
assert_raises(TomlRB::ParseError) { TomlRB.parse(str) }
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_multiline_array_string_not_ended
|
@@ -36,7 +36,7 @@ class ErrorsTest < Minitest::Test
|
|
36
36
|
] End of array comment, forgot the #
|
37
37
|
EOS
|
38
38
|
|
39
|
-
assert_raises(
|
39
|
+
assert_raises(TomlRB::ParseError) { TomlRB.parse(str) }
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_text_after_multiline_array
|
@@ -48,41 +48,41 @@ class ErrorsTest < Minitest::Test
|
|
48
48
|
] End of array comment, forgot the #
|
49
49
|
EOS
|
50
50
|
|
51
|
-
assert_raises(
|
51
|
+
assert_raises(TomlRB::ParseError) { TomlRB.parse(str) }
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_text_after_number
|
55
55
|
str = 'number = 3.14 pi <--again forgot the #'
|
56
|
-
assert_raises(
|
56
|
+
assert_raises(TomlRB::ParseError) { TomlRB.parse(str) }
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_value_overwrite
|
60
60
|
str = "a = 1\na = 2"
|
61
|
-
e = assert_raises(
|
61
|
+
e = assert_raises(TomlRB::ValueOverwriteError) { TomlRB.parse(str) }
|
62
62
|
assert_equal "Key \"a\" is defined more than once", e.message
|
63
63
|
assert_equal "a", e.key
|
64
64
|
|
65
65
|
str = "a = false\na = true"
|
66
|
-
assert_raises(
|
66
|
+
assert_raises(TomlRB::ValueOverwriteError) { TomlRB.parse(str) }
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_table_overwrite
|
70
70
|
str = "[a]\nb=1\n[a]\nc=2"
|
71
|
-
e = assert_raises(
|
71
|
+
e = assert_raises(TomlRB::ValueOverwriteError) { TomlRB.parse(str) }
|
72
72
|
assert_equal "Key \"a\" is defined more than once", e.message
|
73
73
|
|
74
74
|
str = "[a]\nb=1\n[a]\nb=1"
|
75
|
-
e = assert_raises(
|
75
|
+
e = assert_raises(TomlRB::ValueOverwriteError) { TomlRB.parse(str) }
|
76
76
|
assert_equal "Key \"a\" is defined more than once", e.message
|
77
77
|
end
|
78
78
|
|
79
79
|
def test_value_overwrite_with_table
|
80
80
|
str = "[a]\nb=1\n[a.b]\nc=2"
|
81
|
-
e = assert_raises(
|
81
|
+
e = assert_raises(TomlRB::ValueOverwriteError) { TomlRB.parse(str) }
|
82
82
|
assert_equal "Key \"b\" is defined more than once", e.message
|
83
83
|
|
84
84
|
str = "[a]\nb=1\n[a.b.c]\nd=3"
|
85
|
-
e = assert_raises(
|
85
|
+
e = assert_raises(TomlRB::ValueOverwriteError) { TomlRB.parse(str) }
|
86
86
|
assert_equal "Key \"b\" is defined more than once", e.message
|
87
87
|
end
|
88
88
|
end
|
data/test/example-v0.4.0.toml
CHANGED
@@ -22,7 +22,7 @@ key = "value" # Yeah, you can do this.
|
|
22
22
|
|
23
23
|
key = "another value"
|
24
24
|
|
25
|
-
# You don't need to specify all the super-tables if you don't want to.
|
25
|
+
# You don't need to specify all the super-tables if you don't want to. TomlRB
|
26
26
|
# knows how to do it for you.
|
27
27
|
|
28
28
|
# [x] you
|
data/test/example.toml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# This is a
|
1
|
+
# This is a TomlRB document. Boom.
|
2
2
|
|
3
|
-
title = "
|
3
|
+
title = "TomlRB Example"
|
4
4
|
|
5
5
|
[owner]
|
6
6
|
name = "Tom Preston-Werner"
|
@@ -16,7 +16,7 @@ enabled = true
|
|
16
16
|
|
17
17
|
[servers]
|
18
18
|
|
19
|
-
# You can indent as you please. Tabs or spaces.
|
19
|
+
# You can indent as you please. Tabs or spaces. TomlRB don't care.
|
20
20
|
[servers.alpha]
|
21
21
|
ip = "10.0.0.1"
|
22
22
|
dc = "eqdc10"
|
data/test/grammar_test.rb
CHANGED
@@ -3,50 +3,50 @@ require_relative 'helper'
|
|
3
3
|
|
4
4
|
class GrammarTest < Minitest::Test
|
5
5
|
def test_comment
|
6
|
-
match =
|
6
|
+
match = TomlRB::Document.parse(' # A comment', root: :comment)
|
7
7
|
assert_equal(nil, match.value)
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_key
|
11
|
-
match =
|
11
|
+
match = TomlRB::Document.parse('bad_key-', root: :key)
|
12
12
|
assert_equal('bad_key-', match.value)
|
13
13
|
|
14
|
-
match =
|
14
|
+
match = TomlRB::Document.parse('"123.ʎǝʞ.#?"', root: :key)
|
15
15
|
assert_equal('123.ʎǝʞ.#?', match.value)
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_keygroup
|
19
19
|
indentation_alternatives_for('[akey]') do |str|
|
20
|
-
match =
|
21
|
-
assert_equal(
|
20
|
+
match = TomlRB::Document.parse(str, root: :keygroup)
|
21
|
+
assert_equal(TomlRB::Keygroup, match.value.class)
|
22
22
|
assert_equal(['akey'], match.value.instance_variable_get('@nested_keys'))
|
23
23
|
end
|
24
24
|
|
25
|
-
match =
|
25
|
+
match = TomlRB::Document.parse('[owner.emancu]', root: :keygroup)
|
26
26
|
assert_equal(%w(owner emancu),
|
27
27
|
match.value.instance_variable_get('@nested_keys'))
|
28
28
|
|
29
|
-
match =
|
29
|
+
match = TomlRB::Document.parse('["owner.emancu"]', root: :keygroup)
|
30
30
|
assert_equal(%w(owner.emancu),
|
31
31
|
match.value.instance_variable_get('@nested_keys'))
|
32
32
|
|
33
|
-
match =
|
33
|
+
match = TomlRB::Document.parse('["first key"."second key"]', root: :keygroup)
|
34
34
|
assert_equal(['first key', 'second key'],
|
35
35
|
match.value.instance_variable_get('@nested_keys'))
|
36
36
|
|
37
|
-
match =
|
37
|
+
match = TomlRB::Document.parse('[ owner . emancu ]', root: :keygroup)
|
38
38
|
assert_equal(%w(owner emancu),
|
39
39
|
match.value.instance_variable_get('@nested_keys'))
|
40
40
|
|
41
41
|
assert_raises Citrus::ParseError do
|
42
|
-
|
42
|
+
TomlRB::Document.parse('[ owner emancu ]', root: :keygroup)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_keyvalue
|
47
47
|
indentation_alternatives_for('key = "value"') do |str|
|
48
|
-
match =
|
49
|
-
assert_equal(
|
48
|
+
match = TomlRB::Document.parse(str, root: :keyvalue)
|
49
|
+
assert_equal(TomlRB::Keyvalue, match.value.class)
|
50
50
|
|
51
51
|
keyvalue = match.value
|
52
52
|
assert_equal('key', keyvalue.instance_variable_get('@key'))
|
@@ -55,12 +55,12 @@ class GrammarTest < Minitest::Test
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_string
|
58
|
-
match =
|
59
|
-
assert_equal('
|
58
|
+
match = TomlRB::Document.parse('"TomlRB-Example, should work."', root: :string)
|
59
|
+
assert_equal('TomlRB-Example, should work.', match.value)
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_multiline_string
|
63
|
-
match =
|
63
|
+
match = TomlRB::Document.parse('"""\tOne\nTwo"""', root: :multiline_string)
|
64
64
|
assert_equal "\tOne\nTwo", match.value
|
65
65
|
|
66
66
|
to_parse = '"""\
|
@@ -68,161 +68,161 @@ class GrammarTest < Minitest::Test
|
|
68
68
|
Two\
|
69
69
|
"""'
|
70
70
|
|
71
|
-
match =
|
71
|
+
match = TomlRB::Document.parse(to_parse, root: :multiline_string)
|
72
72
|
assert_equal "One Two", match.value
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_empty_multiline_string
|
76
76
|
to_parse = '""""""'
|
77
77
|
|
78
|
-
match =
|
78
|
+
match = TomlRB::Document.parse(to_parse, root: :multiline_string)
|
79
79
|
assert_equal '', match.value
|
80
80
|
end
|
81
81
|
|
82
82
|
def test_special_characters
|
83
|
-
match =
|
83
|
+
match = TomlRB::Document.parse('"\0 \" \t \n \r"', root: :string)
|
84
84
|
assert_equal("\0 \" \t \n \r", match.value)
|
85
85
|
|
86
|
-
match =
|
86
|
+
match = TomlRB::Document.parse('"C:\\\\Documents\\\\nada.exe"', root: :string)
|
87
87
|
assert_equal('C:\\Documents\\nada.exe', match.value)
|
88
88
|
end
|
89
89
|
|
90
90
|
def test_bool
|
91
|
-
match =
|
91
|
+
match = TomlRB::Document.parse('true', root: :bool)
|
92
92
|
assert_equal(true, match.value)
|
93
93
|
|
94
|
-
match =
|
94
|
+
match = TomlRB::Document.parse('false', root: :bool)
|
95
95
|
assert_equal(false, match.value)
|
96
96
|
end
|
97
97
|
|
98
98
|
def test_integer
|
99
|
-
match =
|
99
|
+
match = TomlRB::Document.parse('26', root: :number)
|
100
100
|
assert_equal(26, match.value)
|
101
101
|
|
102
|
-
match =
|
102
|
+
match = TomlRB::Document.parse('1_200_000_999', root: :number)
|
103
103
|
assert_equal(1_200_000_999, match.value)
|
104
104
|
end
|
105
105
|
|
106
106
|
def test_float
|
107
|
-
match =
|
107
|
+
match = TomlRB::Document.parse('1.69', root: :number)
|
108
108
|
assert_equal(1.69, match.value)
|
109
109
|
|
110
|
-
match =
|
110
|
+
match = TomlRB::Document.parse('1_000.69', root: :number)
|
111
111
|
assert_equal(1000.69, match.value)
|
112
112
|
|
113
|
-
match =
|
113
|
+
match = TomlRB::Document.parse('1e6', root: :number)
|
114
114
|
assert_equal(1e6, match.value)
|
115
115
|
|
116
|
-
match =
|
116
|
+
match = TomlRB::Document.parse('1.02e-46', root: :number)
|
117
117
|
assert_equal(1.02e-46, match.value)
|
118
118
|
|
119
|
-
match =
|
119
|
+
match = TomlRB::Document.parse('+1e4_000_000', root: :number)
|
120
120
|
assert_equal(1e4_000_000, match.value)
|
121
121
|
end
|
122
122
|
|
123
123
|
def test_signed_numbers
|
124
|
-
match =
|
124
|
+
match = TomlRB::Document.parse('+26', root: :number)
|
125
125
|
assert_equal(26, match.value)
|
126
126
|
|
127
|
-
match =
|
127
|
+
match = TomlRB::Document.parse('-26', root: :number)
|
128
128
|
assert_equal(-26, match.value)
|
129
129
|
|
130
|
-
match =
|
130
|
+
match = TomlRB::Document.parse('1.69', root: :number)
|
131
131
|
assert_equal(1.69, match.value)
|
132
132
|
|
133
|
-
match =
|
133
|
+
match = TomlRB::Document.parse('-1.69', root: :number)
|
134
134
|
assert_equal(-1.69, match.value)
|
135
135
|
end
|
136
136
|
|
137
137
|
def test_expressions_with_comments
|
138
|
-
match =
|
138
|
+
match = TomlRB::Document.parse('[shouldwork] # with comment', root: :keygroup)
|
139
139
|
assert_equal(['shouldwork'],
|
140
140
|
match.value.instance_variable_get('@nested_keys'))
|
141
141
|
|
142
|
-
match =
|
142
|
+
match = TomlRB::Document.parse('works = true # with comment', root: :keyvalue).value
|
143
143
|
assert_equal('works', match.instance_variable_get('@key'))
|
144
144
|
assert_equal(true, match.instance_variable_get('@value'))
|
145
145
|
end
|
146
146
|
|
147
147
|
def test_array
|
148
|
-
match =
|
148
|
+
match = TomlRB::Document.parse('[]', root: :array)
|
149
149
|
assert_equal([], match.value)
|
150
150
|
|
151
|
-
match =
|
151
|
+
match = TomlRB::Document.parse('[ 2, 4]', root: :array)
|
152
152
|
assert_equal([2, 4], match.value)
|
153
153
|
|
154
|
-
match =
|
154
|
+
match = TomlRB::Document.parse('[ 2.4, 4.72]', root: :array)
|
155
155
|
assert_equal([2.4, 4.72], match.value)
|
156
156
|
|
157
|
-
match =
|
158
|
-
assert_equal(%w(hey
|
157
|
+
match = TomlRB::Document.parse('[ "hey", "TomlRB"]', root: :array)
|
158
|
+
assert_equal(%w(hey TomlRB), match.value)
|
159
159
|
|
160
|
-
match =
|
161
|
-
assert_equal([%w(hey
|
160
|
+
match = TomlRB::Document.parse('[ ["hey", "TomlRB"], [2,4] ]', root: :array)
|
161
|
+
assert_equal([%w(hey TomlRB), [2, 4]], match.value)
|
162
162
|
|
163
|
-
match =
|
163
|
+
match = TomlRB::Document.parse('[ { one = 1 }, { two = 2, three = 3} ]',
|
164
164
|
root: :inline_table_array)
|
165
165
|
assert_equal([{ 'one' => 1 }, { 'two' => 2, 'three' => 3 }], match.value)
|
166
166
|
end
|
167
167
|
|
168
168
|
def test_empty_array
|
169
169
|
# test that [] is parsed as array and not as inline table array
|
170
|
-
match =
|
170
|
+
match = TomlRB::Document.parse("a = []", root: :keyvalue).value
|
171
171
|
assert_equal [], match.value
|
172
172
|
end
|
173
173
|
|
174
174
|
def test_multiline_array
|
175
175
|
multiline_array = "[ \"hey\",\n \"ho\",\n\t \"lets\", \"go\",\n ]"
|
176
|
-
match =
|
176
|
+
match = TomlRB::Document.parse(multiline_array, root: :array)
|
177
177
|
assert_equal(%w(hey ho lets go), match.value)
|
178
178
|
|
179
179
|
multiline_array = "[\n#1,\n2,\n# 3\n]"
|
180
|
-
match =
|
180
|
+
match = TomlRB::Document.parse(multiline_array, root: :array)
|
181
181
|
assert_equal([2], match.value)
|
182
182
|
|
183
183
|
multiline_array = "[\n# comment\n#, more comments\n4]"
|
184
|
-
match =
|
184
|
+
match = TomlRB::Document.parse(multiline_array, root: :array)
|
185
185
|
assert_equal([4], match.value)
|
186
186
|
|
187
187
|
multiline_array = "[\n 1,\n # 2,\n 3 ,\n]"
|
188
|
-
match =
|
188
|
+
match = TomlRB::Document.parse(multiline_array, root: :array)
|
189
189
|
assert_equal([1, 3], match.value)
|
190
190
|
|
191
191
|
multiline_array = "[\n 1 , # useless comment\n # 2,\n 3 #other comment\n]"
|
192
|
-
match =
|
192
|
+
match = TomlRB::Document.parse(multiline_array, root: :array)
|
193
193
|
assert_equal([1, 3], match.value)
|
194
194
|
end
|
195
195
|
|
196
196
|
# Dates are really hard to test from JSON, due the imposibility to represent
|
197
197
|
# datetimes without quotes.
|
198
198
|
def test_datetime
|
199
|
-
match =
|
199
|
+
match = TomlRB::Document.parse('1986-08-28T15:15:00Z', root: :datetime)
|
200
200
|
assert_equal(Time.utc(1986, 8, 28, 15, 15), match.value)
|
201
201
|
|
202
|
-
match =
|
202
|
+
match = TomlRB::Document.parse('1986-08-28T15:15:00-03:00', root: :datetime)
|
203
203
|
assert_equal(Time.utc(1986, 8, 28, 18, 15), match.value)
|
204
204
|
|
205
|
-
match =
|
205
|
+
match = TomlRB::Document.parse('1986-08-28T15:15:00.123-03:00', root: :datetime)
|
206
206
|
assert_equal(Time.utc(1986, 8, 28, 18, 15, 0.123), match.value)
|
207
207
|
|
208
|
-
match =
|
208
|
+
match = TomlRB::Document.parse('1986-08-28', root: :datetime)
|
209
209
|
assert_equal(Time.utc(1986, 8, 28, 0, 0, 0), match.value)
|
210
210
|
|
211
|
-
match =
|
211
|
+
match = TomlRB::Document.parse('1986-08-28T15:15:00', root: :datetime)
|
212
212
|
assert_equal(Time.utc(1986, 8, 28, 15, 15), match.value)
|
213
213
|
|
214
|
-
match =
|
214
|
+
match = TomlRB::Document.parse('1986-08-28T15:15:00.999999', root: :datetime)
|
215
215
|
assert_equal(Time.utc(1986, 8, 28, 15, 15, 0.999999), match.value)
|
216
216
|
end
|
217
217
|
|
218
218
|
def test_inline_table
|
219
|
-
match =
|
219
|
+
match = TomlRB::Document.parse('{ }', root: :inline_table)
|
220
220
|
assert_equal({}, match.value.value)
|
221
221
|
|
222
|
-
match =
|
222
|
+
match = TomlRB::Document.parse('{ simple = true, params = 2 }', root: :inline_table)
|
223
223
|
assert_equal({ 'simple' => true, 'params' => 2 }, match.value.value)
|
224
224
|
|
225
|
-
match =
|
225
|
+
match = TomlRB::Document.parse('{ nest = { really = { hard = true } } }',
|
226
226
|
root: :inline_table)
|
227
227
|
assert_equal({ 'nest' => { 'really' => { 'hard' => true } } }, match.value.value)
|
228
228
|
assert_equal({ nest: { really: { hard: true } } }, match.value.value(true))
|
data/test/hard_example.toml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# Test file for
|
2
|
-
# Only this one tries to emulate a
|
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
3
|
# This part you'll really hate
|
4
4
|
|
5
5
|
[the]
|
data/test/helper.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
|
-
require_relative '../lib/toml'
|
2
|
+
require_relative '../lib/toml-rb'
|
data/test/toml_examples.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class TomlRB::Examples
|
2
2
|
def self.example_v_0_4_0
|
3
3
|
{
|
4
4
|
"table" => {
|
@@ -129,7 +129,7 @@ class TOML::Examples
|
|
129
129
|
|
130
130
|
def self.example
|
131
131
|
{
|
132
|
-
'title' => '
|
132
|
+
'title' => 'TomlRB Example',
|
133
133
|
'owner' => {
|
134
134
|
'name' => 'Tom Preston-Werner',
|
135
135
|
'organization' => 'GitHub',
|
data/test/toml_test.rb
CHANGED
@@ -5,8 +5,8 @@ require 'json'
|
|
5
5
|
class TomlTest < Minitest::Test
|
6
6
|
def test_file_v_0_4_0
|
7
7
|
path = File.join(File.dirname(__FILE__), 'example-v0.4.0.toml')
|
8
|
-
parsed =
|
9
|
-
hash =
|
8
|
+
parsed = TomlRB.load_file(path)
|
9
|
+
hash = TomlRB::Examples.example_v_0_4_0
|
10
10
|
|
11
11
|
assert_equal hash['Array'], parsed['Array']
|
12
12
|
assert_equal hash['Booleans'], parsed['Booleans']
|
@@ -21,24 +21,24 @@ class TomlTest < Minitest::Test
|
|
21
21
|
|
22
22
|
def test_file
|
23
23
|
path = File.join(File.dirname(__FILE__), 'example.toml')
|
24
|
-
parsed =
|
24
|
+
parsed = TomlRB.load_file(path)
|
25
25
|
|
26
|
-
assert_equal
|
26
|
+
assert_equal TomlRB::Examples.example, parsed
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_hard_example
|
30
30
|
path = File.join(File.dirname(__FILE__), 'hard_example.toml')
|
31
|
-
parsed =
|
31
|
+
parsed = TomlRB.load_file(path)
|
32
32
|
|
33
|
-
assert_equal
|
33
|
+
assert_equal TomlRB::Examples.hard_example, parsed
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_symbolize_keys
|
37
37
|
path = File.join(File.dirname(__FILE__), 'example.toml')
|
38
|
-
parsed =
|
38
|
+
parsed = TomlRB.load_file(path, symbolize_keys: true)
|
39
39
|
|
40
40
|
hash = {
|
41
|
-
title: '
|
41
|
+
title: 'TomlRB Example',
|
42
42
|
|
43
43
|
owner: {
|
44
44
|
name: 'Tom Preston-Werner',
|
@@ -82,7 +82,7 @@ class TomlTest < Minitest::Test
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def test_line_break
|
85
|
-
parsed =
|
85
|
+
parsed = TomlRB.parse("hello = 'world'\r\nline_break = true")
|
86
86
|
assert_equal({ 'hello' => 'world', 'line_break' => true }, parsed)
|
87
87
|
end
|
88
88
|
|
@@ -92,8 +92,8 @@ class TomlTest < Minitest::Test
|
|
92
92
|
toml_file = File.join(File.dirname(json_file),
|
93
93
|
File.basename(json_file, '.json')) + '.toml'
|
94
94
|
begin
|
95
|
-
toml =
|
96
|
-
rescue
|
95
|
+
toml = TomlRB.load_file(toml_file)
|
96
|
+
rescue TomlRB::Error => e
|
97
97
|
assert false, "Error: #{e} in #{toml_file}"
|
98
98
|
end
|
99
99
|
json = JSON.parse(File.read(json_file))
|
@@ -110,8 +110,8 @@ class TomlTest < Minitest::Test
|
|
110
110
|
def test_invalid_cases
|
111
111
|
file = '*'
|
112
112
|
Dir["test/examples/invalid/#{file}.toml"].each do |toml_file|
|
113
|
-
assert_raises(
|
114
|
-
|
113
|
+
assert_raises(TomlRB::Error, "For file #{toml_file}") do
|
114
|
+
TomlRB.load_file(toml_file)
|
115
115
|
end
|
116
116
|
end
|
117
117
|
end
|
data/toml-rb.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'toml-rb'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '1.0.0'
|
4
4
|
s.date = Time.now.strftime('%Y-%m-%d')
|
5
|
-
s.summary = '
|
6
|
-
s.description = 'A
|
5
|
+
s.summary = 'Toml parser in ruby, for ruby.'
|
6
|
+
s.description = 'A Toml parser using Citrus parsing library. '
|
7
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'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toml-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emiliano Mancuso
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-06-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: citrus
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
- - ">"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.0'
|
34
|
-
description: 'A
|
34
|
+
description: 'A Toml parser using Citrus parsing library. '
|
35
35
|
email:
|
36
36
|
- emiliano.mancuso@gmail.com
|
37
37
|
- lucas.tolchinsky@gmail.com
|
@@ -42,20 +42,20 @@ files:
|
|
42
42
|
- README.md
|
43
43
|
- Rakefile
|
44
44
|
- init.rb
|
45
|
-
- lib/toml.rb
|
46
|
-
- lib/toml/array.rb
|
47
|
-
- lib/toml/dumper.rb
|
48
|
-
- lib/toml/errors.rb
|
49
|
-
- lib/toml/grammars/array.citrus
|
50
|
-
- lib/toml/grammars/document.citrus
|
51
|
-
- lib/toml/grammars/helper.citrus
|
52
|
-
- lib/toml/grammars/primitive.citrus
|
53
|
-
- lib/toml/inline_table.rb
|
54
|
-
- lib/toml/keygroup.rb
|
55
|
-
- lib/toml/keyvalue.rb
|
56
|
-
- lib/toml/parser.rb
|
57
|
-
- lib/toml/string.rb
|
58
|
-
- lib/toml/table_array.rb
|
45
|
+
- lib/toml-rb.rb
|
46
|
+
- lib/toml-rb/array.rb
|
47
|
+
- lib/toml-rb/dumper.rb
|
48
|
+
- lib/toml-rb/errors.rb
|
49
|
+
- lib/toml-rb/grammars/array.citrus
|
50
|
+
- lib/toml-rb/grammars/document.citrus
|
51
|
+
- lib/toml-rb/grammars/helper.citrus
|
52
|
+
- lib/toml-rb/grammars/primitive.citrus
|
53
|
+
- lib/toml-rb/inline_table.rb
|
54
|
+
- lib/toml-rb/keygroup.rb
|
55
|
+
- lib/toml-rb/keyvalue.rb
|
56
|
+
- lib/toml-rb/parser.rb
|
57
|
+
- lib/toml-rb/string.rb
|
58
|
+
- lib/toml-rb/table_array.rb
|
59
59
|
- test/dumper_test.rb
|
60
60
|
- test/errors_test.rb
|
61
61
|
- test/example-v0.4.0.toml
|
@@ -89,5 +89,5 @@ rubyforge_project:
|
|
89
89
|
rubygems_version: 2.5.1
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
|
-
summary:
|
92
|
+
summary: Toml parser in ruby, for ruby.
|
93
93
|
test_files: []
|