toml 0.0.4 → 0.1.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.
- data/Gemfile +3 -0
- data/README.md +2 -0
- data/Rakefile +29 -9
- data/lib/toml.rb +2 -2
- data/lib/toml/generator.rb +3 -0
- data/lib/toml/monkey_patch.rb +5 -0
- data/lib/toml/parser.rb +56 -14
- data/lib/toml/parslet.rb +30 -22
- data/lib/toml/table.rb +10 -0
- data/lib/toml/transformer.rb +21 -7
- data/test/empty.toml +0 -0
- data/test/hard_example.toml +33 -0
- data/test/spec.toml +19 -0
- data/test/test_empty.rb +18 -0
- data/test/test_generator.rb +11 -4
- data/test/test_parser.rb +19 -3
- data/test/test_parser_hard.rb +16 -0
- data/test/test_table_arrays.rb +42 -0
- data/toml.gemspec +9 -4
- metadata +15 -7
- data/lib/toml/key_group.rb +0 -9
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,8 @@ A sane configuration format from @mojombo. More information here: https://githu
|
|
4
4
|
|
5
5
|
This is far superior to YAML and JSON because it doesn't suck. Really it doesn't.
|
6
6
|
|
7
|
+
**There is a bug in Rails 2.3's vendored version of BlankSlate (a dependency of Parslet which is used for parsing TOML) that breaks Parslet; please see this [Gist](https://gist.github.com/dirk/5264004) for a workaround.**
|
8
|
+
|
7
9
|
## Usage
|
8
10
|
|
9
11
|
Add to your Gemfile:
|
data/Rakefile
CHANGED
@@ -45,19 +45,39 @@ end
|
|
45
45
|
|
46
46
|
task :default => :test
|
47
47
|
|
48
|
-
require 'rake/testtask'
|
49
|
-
Rake::TestTask.new(:test) do |test|
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
# require 'rake/testtask'
|
49
|
+
# Rake::TestTask.new(:test) do |test|
|
50
|
+
# test.libs << 'lib' << 'test'
|
51
|
+
# test.pattern = 'test/**/test_*.rb'
|
52
|
+
# test.verbose = true
|
53
|
+
# end
|
54
|
+
task :test do
|
55
|
+
Dir['./test/**/test_*.rb'].each {|f| require f }
|
53
56
|
end
|
54
57
|
|
55
58
|
desc "Generate RCov test coverage and open in your browser"
|
56
59
|
task :coverage do
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
60
|
+
if RUBY_VERSION =~ /^1\./
|
61
|
+
require 'rubygems'
|
62
|
+
require 'bundler'
|
63
|
+
Bundler.setup(:test)
|
64
|
+
require 'simplecov'
|
65
|
+
require 'simplecov-gem-adapter'
|
66
|
+
|
67
|
+
sh "rm -fr coverage"
|
68
|
+
SimpleCov.command_name 'Unit Tests'
|
69
|
+
SimpleCov.start 'gem'
|
70
|
+
Rake::Task[:test].invoke
|
71
|
+
SimpleCov.at_exit do
|
72
|
+
SimpleCov.result.format!
|
73
|
+
sh "open coverage/index.html"
|
74
|
+
end
|
75
|
+
else
|
76
|
+
require 'rcov'
|
77
|
+
sh "rm -fr coverage"
|
78
|
+
sh "rcov test/test_*.rb"
|
79
|
+
sh "open coverage/index.html"
|
80
|
+
end
|
61
81
|
end
|
62
82
|
|
63
83
|
require 'rdoc/task'
|
data/lib/toml.rb
CHANGED
@@ -4,7 +4,7 @@ require 'time'
|
|
4
4
|
require 'parslet'
|
5
5
|
|
6
6
|
require 'toml/key'
|
7
|
-
require 'toml/
|
7
|
+
require 'toml/table'
|
8
8
|
require 'toml/parslet'
|
9
9
|
require 'toml/transformer'
|
10
10
|
require 'toml/parser'
|
@@ -14,7 +14,7 @@ require 'toml/generator'
|
|
14
14
|
# require 'toml/monkey_patch
|
15
15
|
|
16
16
|
module TOML
|
17
|
-
VERSION = '0.0
|
17
|
+
VERSION = '0.1.0'
|
18
18
|
|
19
19
|
def self.load(content)
|
20
20
|
Parser.new(content).parsed
|
data/lib/toml/generator.rb
CHANGED
@@ -48,6 +48,9 @@ module TOML
|
|
48
48
|
end
|
49
49
|
other_pairs.each do |pair|
|
50
50
|
key, val = pair
|
51
|
+
if key.include? '.'
|
52
|
+
raise SyntaxError, "Periods are not allowed in keys (failed on key: #{key.inspect})"
|
53
|
+
end
|
51
54
|
@body += "#{key} = #{format(val)}\n"
|
52
55
|
end
|
53
56
|
@body += "\n" unless other_pairs.empty?
|
data/lib/toml/monkey_patch.rb
CHANGED
data/lib/toml/parser.rb
CHANGED
@@ -4,22 +4,30 @@ module TOML
|
|
4
4
|
|
5
5
|
def initialize(markup)
|
6
6
|
# Make sure we have a newline on the end
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
markup += "\n" unless markup.end_with?("\n") || markup.length == 0
|
9
9
|
begin
|
10
10
|
tree = Parslet.new.parse(markup)
|
11
11
|
rescue Parslet::ParseFailed => failure
|
12
12
|
puts failure.cause.ascii_tree
|
13
13
|
end
|
14
14
|
|
15
|
-
parts = Transformer.new.apply(tree)
|
16
15
|
|
16
|
+
parts = Transformer.new.apply(tree) || []
|
17
17
|
@parsed = {}
|
18
18
|
@current = @parsed
|
19
19
|
@current_path = ''
|
20
20
|
|
21
21
|
parts.each do |part|
|
22
22
|
if part.is_a? Key
|
23
|
+
# If @current is an array then we're in a key-group
|
24
|
+
if @current.is_a? Array
|
25
|
+
# Make sure there's a table to work with.
|
26
|
+
@current << {} if @current.last.nil?
|
27
|
+
# Set the key on the table.
|
28
|
+
@current.last[part.key] = part.value
|
29
|
+
next
|
30
|
+
end
|
23
31
|
# Make sure the key isn't already set
|
24
32
|
if !@current.is_a?(Hash) || @current.has_key?(part.key)
|
25
33
|
err = "Cannot override key '#{part.key}'"
|
@@ -30,28 +38,62 @@ module TOML
|
|
30
38
|
end
|
31
39
|
# Set the key-value into the current hash
|
32
40
|
@current[part.key] = part.value
|
33
|
-
elsif part.is_a?
|
34
|
-
|
41
|
+
elsif part.is_a?(TableArray)
|
42
|
+
resolve_table_array(part)
|
43
|
+
elsif part.is_a?(Table)
|
44
|
+
resolve_table(part)
|
35
45
|
else
|
36
46
|
raise "Unrecognized part: #{part.inspect}"
|
37
47
|
end
|
38
48
|
end
|
39
49
|
end
|
40
50
|
|
41
|
-
def
|
51
|
+
def resolve_table_array(t)
|
42
52
|
@current = @parsed
|
43
|
-
|
44
|
-
path = kg.keys.dup
|
53
|
+
path = t.name.dup
|
45
54
|
@current_path = path.join('.')
|
46
|
-
|
47
|
-
|
48
|
-
if @current.
|
49
|
-
|
55
|
+
while n = path.shift
|
56
|
+
# If it's a table-array then get the last item.
|
57
|
+
@current = @current.last if @current.is_a? Array
|
58
|
+
|
59
|
+
# If it's the last item:
|
60
|
+
if path.length == 0
|
61
|
+
# If the current table has an item:
|
62
|
+
if @current.has_key?(n)
|
63
|
+
# And that item is already a table-array:
|
64
|
+
if @current[n].is_a? Array
|
65
|
+
# Then add an item to that table-array.
|
66
|
+
@current[n] << {}
|
67
|
+
else
|
68
|
+
raise "Cannot override table array '#{t.name.join '.'}'"
|
69
|
+
end
|
70
|
+
else
|
71
|
+
# Create a new table array if nothing exists here.
|
72
|
+
@current[n] = []
|
73
|
+
end
|
74
|
+
elsif @current.has_key? n
|
75
|
+
# Don't do anything if we're just moving into tables.
|
50
76
|
else
|
51
|
-
@current[
|
77
|
+
@current[n] = {}
|
52
78
|
end
|
53
|
-
@current = @current[
|
79
|
+
@current = @current[n]
|
54
80
|
end
|
55
81
|
end
|
82
|
+
|
83
|
+
def resolve_table(t)
|
84
|
+
@current = @parsed
|
85
|
+
|
86
|
+
path = t.name.dup
|
87
|
+
@current_path = path.join('.')
|
88
|
+
while k = path.shift
|
89
|
+
# If it's a table-array then get the last item.
|
90
|
+
@current = @current.last if @current.is_a? Array
|
91
|
+
# Create a new table if one doesn't exist.
|
92
|
+
@current[k] = {} if !@current.has_key? k
|
93
|
+
# Move into the table.
|
94
|
+
@current = @current[k]
|
95
|
+
end
|
96
|
+
end#/resolve_key_group
|
97
|
+
|
56
98
|
end
|
57
99
|
end
|
data/lib/toml/parslet.rb
CHANGED
@@ -2,7 +2,7 @@ module TOML
|
|
2
2
|
class Parslet < ::Parslet::Parser
|
3
3
|
rule(:document) {
|
4
4
|
all_space >>
|
5
|
-
(
|
5
|
+
(table | table_array | key_value | comment_line).repeat >>
|
6
6
|
all_space
|
7
7
|
}
|
8
8
|
root :document
|
@@ -18,17 +18,19 @@ module TOML
|
|
18
18
|
|
19
19
|
# Finding comments in multiline arrays requires accepting a bunch of
|
20
20
|
# possible newlines and stuff before the comment
|
21
|
-
rule(:array_comments) { (all_space >> comment_line).repeat
|
21
|
+
rule(:array_comments) { (all_space >> comment_line).repeat }
|
22
22
|
|
23
23
|
rule(:array) {
|
24
|
-
str("[") >>
|
24
|
+
str("[") >> all_space >> array_comments >>
|
25
|
+
( array_comments >> # Match any comments on first line
|
25
26
|
all_space >> value >> array_comments >>
|
26
27
|
(
|
27
28
|
# Separator followed by any comments
|
28
29
|
all_space >> str(",") >> array_comments >>
|
29
30
|
# Value followed by any comments
|
30
31
|
all_space >> value >> array_comments
|
31
|
-
).repeat
|
32
|
+
).repeat >>
|
33
|
+
(all_space >> str(",")).maybe >> # possible trailing comma
|
32
34
|
all_space >> array_comments # Grab any remaining comments just in case
|
33
35
|
).maybe.as(:array) >> str("]")
|
34
36
|
}
|
@@ -39,51 +41,57 @@ module TOML
|
|
39
41
|
space >> value.as(:value) >>
|
40
42
|
space >> comment.maybe >> str("\n") >> all_space
|
41
43
|
}
|
42
|
-
rule(:
|
44
|
+
rule(:table) {
|
43
45
|
space >> str("[") >>
|
44
|
-
|
46
|
+
table_name.as(:table) >>
|
45
47
|
str("]") >>
|
46
48
|
space >> comment.maybe >> str("\n") >> all_space
|
47
49
|
}
|
50
|
+
rule(:table_array) {
|
51
|
+
space >> str("[[") >>
|
52
|
+
table_name.as(:table_array) >>
|
53
|
+
str("]]") >>
|
54
|
+
space >> comment.maybe >> str("\n") >> all_space
|
55
|
+
}
|
48
56
|
|
49
|
-
rule(:key) { match
|
50
|
-
rule(:
|
57
|
+
rule(:key) { match["^. \t\\]"].repeat(1) }
|
58
|
+
rule(:table_name) { key.as(:key) >> (str(".") >> key.as(:key)).repeat }
|
51
59
|
|
52
60
|
rule(:comment_line) { comment >> str("\n") >> all_space }
|
53
|
-
rule(:comment) { str("#") >> match
|
61
|
+
rule(:comment) { str("#") >> match["^\n"].repeat }
|
54
62
|
|
55
|
-
rule(:space) { match
|
56
|
-
rule(:all_space) { match
|
63
|
+
rule(:space) { match[" \t"].repeat }
|
64
|
+
rule(:all_space) { match[" \t\r\n"].repeat }
|
57
65
|
|
58
66
|
rule(:string) {
|
59
67
|
str('"') >> (
|
60
|
-
match
|
61
|
-
(str("\\") >> match
|
62
|
-
).repeat
|
68
|
+
match["^\"\\\\"] |
|
69
|
+
(str("\\") >> match["0tnr\"\\\\"])
|
70
|
+
).repeat.as(:string) >> str('"')
|
63
71
|
}
|
64
72
|
|
65
73
|
rule(:sign) { str("-") }
|
66
74
|
rule(:sign?) { sign.maybe }
|
67
75
|
|
68
76
|
rule(:integer) {
|
69
|
-
str("0") | (sign? >> match
|
77
|
+
str("0") | (sign? >> match["1-9"] >> match["0-9"].repeat)
|
70
78
|
}
|
71
79
|
rule(:float) {
|
72
|
-
sign? >> match
|
80
|
+
sign? >> match["0-9"].repeat(1) >> str(".") >> match["0-9"].repeat(1)
|
73
81
|
}
|
74
82
|
|
75
83
|
rule(:boolean) { str("true").as(:true) | str("false").as(:false) }
|
76
84
|
|
77
85
|
rule(:date) {
|
78
|
-
match
|
79
|
-
match
|
80
|
-
match
|
86
|
+
match["0-9"].repeat(4,4) >> str("-") >>
|
87
|
+
match["0-9"].repeat(2,2) >> str("-") >>
|
88
|
+
match["0-9"].repeat(2,2)
|
81
89
|
}
|
82
90
|
|
83
91
|
rule(:time) {
|
84
|
-
match
|
85
|
-
match
|
86
|
-
match
|
92
|
+
match["0-9"].repeat(2,2) >> str(":") >>
|
93
|
+
match["0-9"].repeat(2,2) >> str(":") >>
|
94
|
+
match["0-9"].repeat(2,2)
|
87
95
|
}
|
88
96
|
|
89
97
|
rule(:datetime) { date >> str("T") >> time >> str("Z") }
|
data/lib/toml/table.rb
ADDED
data/lib/toml/transformer.rb
CHANGED
@@ -7,9 +7,9 @@ module TOML
|
|
7
7
|
s = 0
|
8
8
|
o = []
|
9
9
|
while s < e
|
10
|
-
if val[s] == "\\"
|
10
|
+
if val[s].chr == "\\"
|
11
11
|
s += 1
|
12
|
-
case val[s]
|
12
|
+
case val[s].chr
|
13
13
|
when "t"
|
14
14
|
o << "\t"
|
15
15
|
when "n"
|
@@ -26,7 +26,7 @@ module TOML
|
|
26
26
|
raise "Unexpected escape character: '\\#{val[s]}'"
|
27
27
|
end
|
28
28
|
else
|
29
|
-
o << val[s]
|
29
|
+
o << val[s].chr
|
30
30
|
end
|
31
31
|
s += 1
|
32
32
|
end
|
@@ -36,6 +36,11 @@ module TOML
|
|
36
36
|
# Clean up arrays
|
37
37
|
# rule(:array => subtree(:ar)) { ar.is_a?(Array) ? ar : [ar] }
|
38
38
|
|
39
|
+
# Empty file
|
40
|
+
rule('') {
|
41
|
+
nil
|
42
|
+
}
|
43
|
+
|
39
44
|
# Clean up simple value hashes
|
40
45
|
rule(:integer => simple(:i)) { i.to_i }
|
41
46
|
rule(:float => simple(:f)) { f.to_f }
|
@@ -88,13 +93,22 @@ module TOML
|
|
88
93
|
rule(:key => simple(:k)) { k }
|
89
94
|
|
90
95
|
# Then objectify the key_groups
|
91
|
-
rule(:
|
92
|
-
|
96
|
+
rule(:table => simple(:kg)) {
|
97
|
+
Table.new([kg.to_s])
|
93
98
|
}
|
94
99
|
|
95
100
|
# Captures array-like key-groups
|
96
|
-
rule(:
|
97
|
-
|
101
|
+
rule(:table => subtree(:kg)) {
|
102
|
+
Table.new(kg.map &:to_s)
|
103
|
+
}
|
104
|
+
|
105
|
+
# Single name table-arrays
|
106
|
+
rule(:table_array => simple(:name)) {
|
107
|
+
TableArray.new([name.to_s])
|
108
|
+
}
|
109
|
+
# Multi-part (a.b.c) table-arrays
|
110
|
+
rule(:table_array => subtree(:names)) {
|
111
|
+
TableArray.new(names.map &:to_s)
|
98
112
|
}
|
99
113
|
end
|
100
114
|
end
|
data/test/empty.toml
ADDED
File without changes
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Test file for TOML
|
2
|
+
# Only this one tries to emulate a TOML 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
|
+
# Each of the following keygroups/key value pairs should produce an error. Uncomment to them to test
|
24
|
+
|
25
|
+
#[error] if you didn't catch this, your parser is broken
|
26
|
+
#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
|
27
|
+
#array = [
|
28
|
+
# "This might most likely happen in multiline arrays",
|
29
|
+
# Like here,
|
30
|
+
# "or here,
|
31
|
+
# and here"
|
32
|
+
# ] End of array comment, forgot the #
|
33
|
+
#number = 3.14 pi <--again forgot the #
|
data/test/spec.toml
CHANGED
@@ -40,6 +40,18 @@ simple = [1, 2, 3]
|
|
40
40
|
# Nested array
|
41
41
|
nested = [[1, 2], [3]]
|
42
42
|
|
43
|
+
# Empty array
|
44
|
+
empty = []
|
45
|
+
|
46
|
+
# Multiline empty
|
47
|
+
multiline_empty = [
|
48
|
+
]
|
49
|
+
|
50
|
+
# Multiline empty with comment
|
51
|
+
multiline_empty_comment = [
|
52
|
+
# You look nice today
|
53
|
+
]
|
54
|
+
|
43
55
|
# Multiline array
|
44
56
|
multiline = [
|
45
57
|
1,
|
@@ -47,6 +59,13 @@ multiline = [
|
|
47
59
|
3
|
48
60
|
]
|
49
61
|
|
62
|
+
# Multiline array
|
63
|
+
multiline_trailing_comma = [
|
64
|
+
1,
|
65
|
+
2,
|
66
|
+
3,
|
67
|
+
]
|
68
|
+
|
50
69
|
# With comments
|
51
70
|
multiline_comments = [ # 0
|
52
71
|
1, # 1
|
data/test/test_empty.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'toml'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
|
7
|
+
class TestEmpty < MiniTest::Test
|
8
|
+
|
9
|
+
def setup
|
10
|
+
filepath = File.join(File.dirname(__FILE__), "empty.toml")
|
11
|
+
@doc = TOML::Parser.new(File.read(filepath)).parsed
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_empty
|
15
|
+
assert_equal ({}), @doc, "Empty document parsed incorrectly"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/test/test_generator.rb
CHANGED
@@ -5,7 +5,7 @@ require 'bundler/setup'
|
|
5
5
|
require 'toml'
|
6
6
|
require 'minitest/autorun'
|
7
7
|
|
8
|
-
class TestGenerator < MiniTest::
|
8
|
+
class TestGenerator < MiniTest::Test
|
9
9
|
def setup
|
10
10
|
@doc = {
|
11
11
|
"integer" => 1,
|
@@ -18,16 +18,23 @@ class TestGenerator < MiniTest::Unit::TestCase
|
|
18
18
|
"group" => {
|
19
19
|
"value" => "lol"
|
20
20
|
}
|
21
|
-
}
|
21
|
+
},
|
22
|
+
"date" => DateTime.now
|
22
23
|
}
|
23
24
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def test_generator
|
27
|
-
|
28
|
+
doc = @doc.clone
|
29
|
+
body = TOML::Generator.new(doc).body
|
28
30
|
|
29
31
|
doc_parsed = TOML::Parser.new(body).parsed
|
30
32
|
|
31
|
-
|
33
|
+
# Extracting dates since Ruby's DateTime equality testing sucks.
|
34
|
+
original_date = doc.delete "date"
|
35
|
+
parsed_date = doc_parsed.delete "date"
|
36
|
+
|
37
|
+
assert_equal doc, doc_parsed
|
38
|
+
assert_equal original_date.to_time.to_s, parsed_date.to_time.to_s
|
32
39
|
end
|
33
40
|
end
|
data/test/test_parser.rb
CHANGED
@@ -5,7 +5,7 @@ require 'bundler/setup'
|
|
5
5
|
require 'toml'
|
6
6
|
require 'minitest/autorun'
|
7
7
|
|
8
|
-
class TestParser < MiniTest::
|
8
|
+
class TestParser < MiniTest::Test
|
9
9
|
def setup
|
10
10
|
filepath = File.join(File.dirname(__FILE__), 'spec.toml')
|
11
11
|
@doc = TOML::Parser.new(File.read(filepath)).parsed
|
@@ -49,14 +49,30 @@ class TestParser < MiniTest::Unit::TestCase
|
|
49
49
|
assert_equal [[1, 2], [3]], @doc["arrays"]["nested"]
|
50
50
|
end
|
51
51
|
|
52
|
+
def test_empty_array
|
53
|
+
assert_equal [], @doc["arrays"]["empty"]
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_empty_multiline_array
|
57
|
+
assert_equal [], @doc["arrays"]["multiline_empty"]
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_empty_multiline_array_with_comment
|
61
|
+
assert_equal [], @doc["arrays"]["multiline_empty_comment"]
|
62
|
+
end
|
63
|
+
|
52
64
|
def test_multiline_arrays
|
53
65
|
assert_equal ["lines", "are", "super", "cool", "lol", "amirite"], @doc["arrays"]["multi"]
|
54
66
|
end
|
55
|
-
|
67
|
+
|
56
68
|
def test_multiline_array
|
57
69
|
assert_equal @doc["arrays"]["multiline"], [1, 2, 3]
|
58
70
|
end
|
59
|
-
|
71
|
+
|
72
|
+
def test_multiline_array_with_trailing_comma
|
73
|
+
assert_equal @doc["arrays"]["multiline_trailing_comma"], [1, 2, 3]
|
74
|
+
end
|
75
|
+
|
60
76
|
def test_multiline_array_with_comments
|
61
77
|
assert_equal @doc["arrays"]["multiline_comments"], [1, 2, 3]
|
62
78
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'toml'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
class TestParserHardExample < MiniTest::Test
|
7
|
+
def setup
|
8
|
+
filepath = File.join(File.dirname(__FILE__), 'hard_example.toml')
|
9
|
+
# @doc = TOML::Parser.new(File.read(filepath)).parsed
|
10
|
+
@doc = TOML.load_file(filepath)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_the_test_string
|
14
|
+
assert_equal @doc["the"]["test_string"], "You'll hate me after this - #"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'toml'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
|
6
|
+
class TestParserTableArrays < MiniTest::Test
|
7
|
+
def setup
|
8
|
+
doc = '
|
9
|
+
[[fruit]]
|
10
|
+
name = "apple"
|
11
|
+
|
12
|
+
[fruit.physical]
|
13
|
+
color = "red"
|
14
|
+
shape = "round"
|
15
|
+
|
16
|
+
[[fruit.variety]]
|
17
|
+
name = "red delicious"
|
18
|
+
|
19
|
+
[[fruit.variety]]
|
20
|
+
name = "granny smith"
|
21
|
+
|
22
|
+
[[fruit]]
|
23
|
+
name = "banana"
|
24
|
+
|
25
|
+
[[fruit.variety]]
|
26
|
+
name = "plantain"
|
27
|
+
'
|
28
|
+
@doc = TOML.load(doc)
|
29
|
+
#require 'pp'
|
30
|
+
#PP.pp @doc
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_doc
|
34
|
+
assert_equal @doc, {
|
35
|
+
"fruit"=>
|
36
|
+
[{"name"=>"apple",
|
37
|
+
"physical"=>{"color"=>"red", "shape"=>"round"},
|
38
|
+
"variety"=>[{"name"=>"red delicious"}, {"name"=>"granny smith"}]},
|
39
|
+
{"name"=>"banana", "variety"=>[{"name"=>"plantain"}]}]
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
data/toml.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'toml'
|
16
|
-
s.version = '0.0
|
17
|
-
s.date = '2013-
|
16
|
+
s.version = '0.1.0'
|
17
|
+
s.date = '2013-12-05'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
20
20
|
## as you like.
|
@@ -37,7 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
s.rdoc_options = ["--charset=UTF-8"]
|
38
38
|
s.extra_rdoc_files = %w[README.md LICENSE]
|
39
39
|
|
40
|
-
s.add_dependency
|
40
|
+
s.add_dependency "parslet", "~> 1.5.0"
|
41
41
|
|
42
42
|
## Leave this section as-is. It will be automatically generated from the
|
43
43
|
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
@@ -51,14 +51,19 @@ Gem::Specification.new do |s|
|
|
51
51
|
lib/toml.rb
|
52
52
|
lib/toml/generator.rb
|
53
53
|
lib/toml/key.rb
|
54
|
-
lib/toml/key_group.rb
|
55
54
|
lib/toml/monkey_patch.rb
|
56
55
|
lib/toml/parser.rb
|
57
56
|
lib/toml/parslet.rb
|
57
|
+
lib/toml/table.rb
|
58
58
|
lib/toml/transformer.rb
|
59
|
+
test/empty.toml
|
60
|
+
test/hard_example.toml
|
59
61
|
test/spec.toml
|
62
|
+
test/test_empty.rb
|
60
63
|
test/test_generator.rb
|
61
64
|
test/test_parser.rb
|
65
|
+
test/test_parser_hard.rb
|
66
|
+
test/test_table_arrays.rb
|
62
67
|
test/tmp.rb
|
63
68
|
toml.gemspec
|
64
69
|
]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,24 +10,24 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-12-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: parslet
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
|
-
- -
|
20
|
+
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 1.5.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
27
27
|
requirements:
|
28
|
-
- -
|
28
|
+
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version:
|
30
|
+
version: 1.5.0
|
31
31
|
description: Parse your TOML, seriously.
|
32
32
|
email: jeremy@github.com
|
33
33
|
executables: []
|
@@ -43,14 +43,19 @@ files:
|
|
43
43
|
- lib/toml.rb
|
44
44
|
- lib/toml/generator.rb
|
45
45
|
- lib/toml/key.rb
|
46
|
-
- lib/toml/key_group.rb
|
47
46
|
- lib/toml/monkey_patch.rb
|
48
47
|
- lib/toml/parser.rb
|
49
48
|
- lib/toml/parslet.rb
|
49
|
+
- lib/toml/table.rb
|
50
50
|
- lib/toml/transformer.rb
|
51
|
+
- test/empty.toml
|
52
|
+
- test/hard_example.toml
|
51
53
|
- test/spec.toml
|
54
|
+
- test/test_empty.rb
|
52
55
|
- test/test_generator.rb
|
53
56
|
- test/test_parser.rb
|
57
|
+
- test/test_parser_hard.rb
|
58
|
+
- test/test_table_arrays.rb
|
54
59
|
- test/tmp.rb
|
55
60
|
- toml.gemspec
|
56
61
|
homepage: http://github.com/jm/toml
|
@@ -79,5 +84,8 @@ signing_key:
|
|
79
84
|
specification_version: 2
|
80
85
|
summary: Parse your TOML.
|
81
86
|
test_files:
|
87
|
+
- test/test_empty.rb
|
82
88
|
- test/test_generator.rb
|
83
89
|
- test/test_parser.rb
|
90
|
+
- test/test_parser_hard.rb
|
91
|
+
- test/test_table_arrays.rb
|