toml 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/toml.rb +1 -2
- data/lib/toml/generator.rb +1 -49
- data/lib/toml/monkey_patch.rb +74 -13
- data/lib/toml/parslet.rb +4 -3
- data/lib/toml/version.rb +3 -0
- metadata +14 -31
- data/Gemfile +0 -11
- data/Rakefile +0 -170
- data/script/bootstrap +0 -3
- data/script/cibuild +0 -3
- data/script/console +0 -3
- data/test/empty.toml +0 -0
- data/test/hard_example.toml +0 -33
- data/test/spec.toml +0 -81
- data/test/test_empty.rb +0 -18
- data/test/test_generator.rb +0 -45
- data/test/test_parser.rb +0 -91
- data/test/test_parser_hard.rb +0 -16
- data/test/test_table_arrays.rb +0 -42
- data/test/tmp.rb +0 -25
- data/toml.gemspec +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 765d0d79f39516761562706d4d93ec02642434e4
|
4
|
+
data.tar.gz: 73b7cdcec4d5723fd366bdf3aca4376b7b55f542
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ceb6c2569ca6ea3ed8df7afc0ff0b3a820870d4484cde54443bb422bbe24c19b5ab783e34cce67074e50e85293651fe90339c2b16a8ce7f3c6b79567460f3307
|
7
|
+
data.tar.gz: a3b725ef82c13108d43b37f81d9880c2feff37e15f4c4c4d48b73ea2dd3ca88174d51642db10f2f2f7c099069f734ffb2a0adfb35fda11d19aaef7e2c2ec03bd
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
## 0.1.2 / 2014-10-16
|
2
|
+
|
3
|
+
- Add support for `CR` and `CRLF` newlines (#13)
|
4
|
+
- Add support for generating TOML from Ruby `Hash`es (#36)
|
5
|
+
- Add a script interface for @BurntSushi's `toml-test` utility (#38)
|
6
|
+
|
7
|
+
## 0.1.1 / 2014-02-17
|
8
|
+
|
9
|
+
- Add license to gemspec (#26)
|
10
|
+
- Loosen `multi_json` dependency version specified (#27)
|
11
|
+
- `Generator` should print empty hash tables but not keys without values (#28)
|
data/lib/toml.rb
CHANGED
@@ -3,6 +3,7 @@ $:.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'time'
|
4
4
|
require 'parslet'
|
5
5
|
|
6
|
+
require 'toml/version'
|
6
7
|
require 'toml/key'
|
7
8
|
require 'toml/table'
|
8
9
|
require 'toml/parslet'
|
@@ -14,8 +15,6 @@ require 'toml/generator'
|
|
14
15
|
# require 'toml/monkey_patch
|
15
16
|
|
16
17
|
module TOML
|
17
|
-
VERSION = '0.1.1'
|
18
|
-
|
19
18
|
def self.load(content)
|
20
19
|
Parser.new(content).parsed
|
21
20
|
end
|
data/lib/toml/generator.rb
CHANGED
@@ -8,10 +8,8 @@ module TOML
|
|
8
8
|
# used by TOML.
|
9
9
|
self.class.inject!
|
10
10
|
|
11
|
-
@body = ""
|
12
11
|
@doc = doc
|
13
|
-
|
14
|
-
visit(@doc)
|
12
|
+
@body = doc.to_toml
|
15
13
|
|
16
14
|
return @body
|
17
15
|
end
|
@@ -27,51 +25,5 @@ module TOML
|
|
27
25
|
require 'toml/monkey_patch'
|
28
26
|
@@injected = true
|
29
27
|
end
|
30
|
-
|
31
|
-
def visit(hash, path = "")
|
32
|
-
hash_pairs = [] # Sub-hashes
|
33
|
-
other_pairs = []
|
34
|
-
|
35
|
-
hash.keys.sort.each do |key|
|
36
|
-
val = hash[key]
|
37
|
-
# TODO: Refactor for other hash-likes (OrderedHash)
|
38
|
-
if val.is_a? Hash
|
39
|
-
hash_pairs << [key, val]
|
40
|
-
else
|
41
|
-
other_pairs << [key, val]
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Handle all the key-values
|
46
|
-
if !path.empty? && !other_pairs.empty?
|
47
|
-
@body += "[#{path}]\n"
|
48
|
-
end
|
49
|
-
other_pairs.each do |pair|
|
50
|
-
key, val = pair
|
51
|
-
if key.include? '.'
|
52
|
-
raise SyntaxError, "Periods are not allowed in keys (failed on key: #{key.inspect})"
|
53
|
-
end
|
54
|
-
unless val.nil?
|
55
|
-
@body += "#{key} = #{format(val)}\n"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
@body += "\n" unless other_pairs.empty?
|
59
|
-
|
60
|
-
# Then deal with sub-hashes
|
61
|
-
hash_pairs.each do |pair|
|
62
|
-
key, hash = pair
|
63
|
-
if hash.empty?
|
64
|
-
@body += "[#{path.empty? ? key : [path, key].join(".")}]\n"
|
65
|
-
else
|
66
|
-
visit(hash, (path.empty? ? key : [path, key].join(".")))
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end#visit
|
70
|
-
|
71
|
-
# Returns the value formatted for TOML.
|
72
|
-
def format(val)
|
73
|
-
val.to_toml
|
74
|
-
end
|
75
|
-
|
76
28
|
end#Generator
|
77
29
|
end#TOML
|
data/lib/toml/monkey_patch.rb
CHANGED
@@ -1,26 +1,87 @@
|
|
1
1
|
# Adds to_toml methods to base Ruby classes used by the generator.
|
2
|
+
class Object
|
3
|
+
def toml_table?
|
4
|
+
self.kind_of?(Hash)
|
5
|
+
end
|
6
|
+
def toml_table_array?
|
7
|
+
self.kind_of?(Array) && self.first.toml_table?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
class Hash
|
11
|
+
def to_toml(path = "")
|
12
|
+
return "" if self.empty?
|
13
|
+
|
14
|
+
tables = {}
|
15
|
+
values = {}
|
16
|
+
self.keys.sort.each do |key|
|
17
|
+
val = self[key]
|
18
|
+
if val.kind_of?(NilClass)
|
19
|
+
next
|
20
|
+
elsif val.toml_table? || val.toml_table_array?
|
21
|
+
tables[key] = val
|
22
|
+
else
|
23
|
+
values[key] = val
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
toml = ""
|
28
|
+
values.each do |key, val|
|
29
|
+
toml << "#{key} = #{val.to_toml(key)}\n"
|
30
|
+
end
|
31
|
+
|
32
|
+
tables.each do |key, val|
|
33
|
+
key = "#{path}.#{key}" unless path.empty?
|
34
|
+
toml_val = val.to_toml(key)
|
35
|
+
unless toml_val.empty?
|
36
|
+
if val.toml_table?
|
37
|
+
non_table_vals = val.values.reject do |v|
|
38
|
+
v.toml_table? || v.toml_table_array?
|
39
|
+
end
|
40
|
+
|
41
|
+
# Only add the table key if there are non table values.
|
42
|
+
if non_table_vals.length > 0
|
43
|
+
toml << "\n[#{key}]\n"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
toml << toml_val
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
toml
|
51
|
+
end
|
52
|
+
end
|
53
|
+
class Array
|
54
|
+
def to_toml(path = "")
|
55
|
+
unless self.map(&:class).uniq.length == 1
|
56
|
+
raise "All array values must be the same type"
|
57
|
+
end
|
58
|
+
|
59
|
+
if self.first.toml_table?
|
60
|
+
toml = ""
|
61
|
+
self.each do |val|
|
62
|
+
toml << "\n[[#{path}]]\n"
|
63
|
+
toml << val.to_toml(path)
|
64
|
+
end
|
65
|
+
return toml
|
66
|
+
else
|
67
|
+
"[" + self.map {|v| v.to_toml(path) }.join(",") + "]"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
2
71
|
class TrueClass
|
3
|
-
def to_toml; "true"; end
|
72
|
+
def to_toml(path = ""); "true"; end
|
4
73
|
end
|
5
74
|
class FalseClass
|
6
|
-
def to_toml; "false"; end
|
75
|
+
def to_toml(path = ""); "false"; end
|
7
76
|
end
|
8
77
|
class String
|
9
|
-
def to_toml; self.inspect; end
|
78
|
+
def to_toml(path = ""); self.inspect; end
|
10
79
|
end
|
11
80
|
class Numeric
|
12
|
-
def to_toml; self.to_s; end
|
13
|
-
end
|
14
|
-
class Array
|
15
|
-
def to_toml
|
16
|
-
unless self.map(&:class).uniq.length < 2
|
17
|
-
raise "All array values must be the same type"
|
18
|
-
end
|
19
|
-
"[" + self.map {|v| v.to_toml }.join(",") + "]"
|
20
|
-
end
|
81
|
+
def to_toml(path = ""); self.to_s; end
|
21
82
|
end
|
22
83
|
class DateTime
|
23
|
-
def to_toml
|
84
|
+
def to_toml(path = "")
|
24
85
|
self.to_time.utc.strftime("%Y-%m-%dT%H:%M:%SZ")
|
25
86
|
end
|
26
87
|
end
|
data/lib/toml/parslet.rb
CHANGED
@@ -39,13 +39,13 @@ module TOML
|
|
39
39
|
space >> key.as(:key) >>
|
40
40
|
space >> str("=") >>
|
41
41
|
space >> value.as(:value) >>
|
42
|
-
space >> comment.maybe >>
|
42
|
+
space >> comment.maybe >> newline >> all_space
|
43
43
|
}
|
44
44
|
rule(:table) {
|
45
45
|
space >> str("[") >>
|
46
46
|
table_name.as(:table) >>
|
47
47
|
str("]") >>
|
48
|
-
space >> comment.maybe >>
|
48
|
+
space >> comment.maybe >> newline >> all_space
|
49
49
|
}
|
50
50
|
rule(:table_array) {
|
51
51
|
space >> str("[[") >>
|
@@ -57,11 +57,12 @@ module TOML
|
|
57
57
|
rule(:key) { match["^. \t\\]"].repeat(1) }
|
58
58
|
rule(:table_name) { key.as(:key) >> (str(".") >> key.as(:key)).repeat }
|
59
59
|
|
60
|
-
rule(:comment_line) { comment >>
|
60
|
+
rule(:comment_line) { comment >> newline >> all_space }
|
61
61
|
rule(:comment) { str("#") >> match["^\n"].repeat }
|
62
62
|
|
63
63
|
rule(:space) { match[" \t"].repeat }
|
64
64
|
rule(:all_space) { match[" \t\r\n"].repeat }
|
65
|
+
rule(:newline) { str("\r").maybe >> str("\n") | str("\r") >> str("\n").maybe }
|
65
66
|
|
66
67
|
rule(:string) {
|
67
68
|
str('"') >> (
|
data/lib/toml/version.rb
ADDED
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy McAnally
|
@@ -9,34 +9,34 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: parslet
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 1.5.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - ~>
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 1.5.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
description: Parse your TOML, seriously.
|
@@ -46,11 +46,11 @@ extensions: []
|
|
46
46
|
extra_rdoc_files:
|
47
47
|
- README.md
|
48
48
|
- LICENSE
|
49
|
+
- CHANGELOG.md
|
49
50
|
files:
|
50
|
-
-
|
51
|
+
- CHANGELOG.md
|
51
52
|
- LICENSE
|
52
53
|
- README.md
|
53
|
-
- Rakefile
|
54
54
|
- lib/toml.rb
|
55
55
|
- lib/toml/generator.rb
|
56
56
|
- lib/toml/key.rb
|
@@ -59,47 +59,30 @@ files:
|
|
59
59
|
- lib/toml/parslet.rb
|
60
60
|
- lib/toml/table.rb
|
61
61
|
- lib/toml/transformer.rb
|
62
|
-
-
|
63
|
-
- script/cibuild
|
64
|
-
- script/console
|
65
|
-
- test/empty.toml
|
66
|
-
- test/hard_example.toml
|
67
|
-
- test/spec.toml
|
68
|
-
- test/test_empty.rb
|
69
|
-
- test/test_generator.rb
|
70
|
-
- test/test_parser.rb
|
71
|
-
- test/test_parser_hard.rb
|
72
|
-
- test/test_table_arrays.rb
|
73
|
-
- test/tmp.rb
|
74
|
-
- toml.gemspec
|
62
|
+
- lib/toml/version.rb
|
75
63
|
homepage: http://github.com/jm/toml
|
76
64
|
licenses:
|
77
65
|
- MIT
|
78
66
|
metadata: {}
|
79
67
|
post_install_message:
|
80
68
|
rdoc_options:
|
81
|
-
- --charset=UTF-8
|
69
|
+
- "--charset=UTF-8"
|
82
70
|
require_paths:
|
83
71
|
- lib
|
84
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
73
|
requirements:
|
86
|
-
- -
|
74
|
+
- - ">="
|
87
75
|
- !ruby/object:Gem::Version
|
88
76
|
version: '0'
|
89
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
78
|
requirements:
|
91
|
-
- -
|
79
|
+
- - ">="
|
92
80
|
- !ruby/object:Gem::Version
|
93
81
|
version: '0'
|
94
82
|
requirements: []
|
95
83
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
84
|
+
rubygems_version: 2.2.2
|
97
85
|
signing_key:
|
98
86
|
specification_version: 2
|
99
87
|
summary: Parse your TOML.
|
100
|
-
test_files:
|
101
|
-
- test/test_empty.rb
|
102
|
-
- test/test_generator.rb
|
103
|
-
- test/test_parser.rb
|
104
|
-
- test/test_parser_hard.rb
|
105
|
-
- test/test_table_arrays.rb
|
88
|
+
test_files: []
|
data/Gemfile
DELETED
data/Rakefile
DELETED
@@ -1,170 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'date'
|
4
|
-
|
5
|
-
#############################################################################
|
6
|
-
#
|
7
|
-
# Helper functions
|
8
|
-
#
|
9
|
-
#############################################################################
|
10
|
-
|
11
|
-
def name
|
12
|
-
@name ||= Dir['*.gemspec'].first.split('.').first
|
13
|
-
end
|
14
|
-
|
15
|
-
def version
|
16
|
-
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
17
|
-
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
18
|
-
end
|
19
|
-
|
20
|
-
def date
|
21
|
-
Date.today.to_s
|
22
|
-
end
|
23
|
-
|
24
|
-
def rubyforge_project
|
25
|
-
name
|
26
|
-
end
|
27
|
-
|
28
|
-
def gemspec_file
|
29
|
-
"#{name}.gemspec"
|
30
|
-
end
|
31
|
-
|
32
|
-
def gem_file
|
33
|
-
"#{name}-#{version}.gem"
|
34
|
-
end
|
35
|
-
|
36
|
-
def replace_header(head, header_name)
|
37
|
-
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
38
|
-
end
|
39
|
-
|
40
|
-
#############################################################################
|
41
|
-
#
|
42
|
-
# Standard tasks
|
43
|
-
#
|
44
|
-
#############################################################################
|
45
|
-
|
46
|
-
task :default => :test
|
47
|
-
|
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 }
|
56
|
-
end
|
57
|
-
|
58
|
-
desc "Generate RCov test coverage and open in your browser"
|
59
|
-
task :coverage do
|
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
|
81
|
-
end
|
82
|
-
|
83
|
-
require 'rdoc/task'
|
84
|
-
Rake::RDocTask.new do |rdoc|
|
85
|
-
rdoc.rdoc_dir = 'rdoc'
|
86
|
-
rdoc.title = "#{name} #{version}"
|
87
|
-
rdoc.rdoc_files.include('README*')
|
88
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
89
|
-
end
|
90
|
-
|
91
|
-
desc "Open an irb session preloaded with this library"
|
92
|
-
task :console do
|
93
|
-
sh "irb -rubygems -r ./lib/#{name}.rb"
|
94
|
-
end
|
95
|
-
|
96
|
-
#############################################################################
|
97
|
-
#
|
98
|
-
# Custom tasks (add your own tasks here)
|
99
|
-
#
|
100
|
-
#############################################################################
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
#############################################################################
|
105
|
-
#
|
106
|
-
# Packaging tasks
|
107
|
-
#
|
108
|
-
#############################################################################
|
109
|
-
|
110
|
-
desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
|
111
|
-
task :release => :build do
|
112
|
-
unless `git branch` =~ /^\* master$/
|
113
|
-
puts "You must be on the master branch to release!"
|
114
|
-
exit!
|
115
|
-
end
|
116
|
-
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
117
|
-
sh "git tag v#{version}"
|
118
|
-
sh "git push origin master"
|
119
|
-
sh "git push origin v#{version}"
|
120
|
-
sh "gem push pkg/#{name}-#{version}.gem"
|
121
|
-
end
|
122
|
-
|
123
|
-
desc "Build #{gem_file} into the pkg directory"
|
124
|
-
task :build => :gemspec do
|
125
|
-
sh "mkdir -p pkg"
|
126
|
-
sh "gem build #{gemspec_file}"
|
127
|
-
sh "mv #{gem_file} pkg"
|
128
|
-
end
|
129
|
-
|
130
|
-
desc "Generate #{gemspec_file}"
|
131
|
-
task :gemspec => :validate do
|
132
|
-
# read spec file and split out manifest section
|
133
|
-
spec = File.read(gemspec_file)
|
134
|
-
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
135
|
-
|
136
|
-
# replace name version and date
|
137
|
-
replace_header(head, :name)
|
138
|
-
replace_header(head, :version)
|
139
|
-
replace_header(head, :date)
|
140
|
-
#comment this out if your rubyforge_project has a different name
|
141
|
-
replace_header(head, :rubyforge_project)
|
142
|
-
|
143
|
-
# determine file list from git ls-files
|
144
|
-
files = `git ls-files`.
|
145
|
-
split("\n").
|
146
|
-
sort.
|
147
|
-
reject { |file| file =~ /^\./ }.
|
148
|
-
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
149
|
-
map { |file| " #{file}" }.
|
150
|
-
join("\n")
|
151
|
-
|
152
|
-
# piece file back together and write
|
153
|
-
manifest = " s.files = %w[\n#{files}\n ]\n"
|
154
|
-
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
155
|
-
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
156
|
-
puts "Updated #{gemspec_file}"
|
157
|
-
end
|
158
|
-
|
159
|
-
desc "Validate #{gemspec_file}"
|
160
|
-
task :validate do
|
161
|
-
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
162
|
-
unless libfiles.empty?
|
163
|
-
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
164
|
-
exit!
|
165
|
-
end
|
166
|
-
unless Dir['VERSION*'].empty?
|
167
|
-
puts "A `VERSION` file at root level violates Gem best practices."
|
168
|
-
exit!
|
169
|
-
end
|
170
|
-
end
|
data/script/bootstrap
DELETED
data/script/cibuild
DELETED
data/script/console
DELETED
data/test/empty.toml
DELETED
File without changes
|
data/test/hard_example.toml
DELETED
@@ -1,33 +0,0 @@
|
|
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
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# Comment
|
2
|
-
|
3
|
-
# Booleans
|
4
|
-
true = true
|
5
|
-
false = false
|
6
|
-
|
7
|
-
[strings]
|
8
|
-
# String
|
9
|
-
string = "string\n\t\"string"
|
10
|
-
empty = ""
|
11
|
-
|
12
|
-
[ints]
|
13
|
-
simple = 42
|
14
|
-
negative = -42
|
15
|
-
|
16
|
-
[floats]
|
17
|
-
pi = 3.14159
|
18
|
-
negative = -10.0
|
19
|
-
|
20
|
-
[datetimes]
|
21
|
-
# DateTime
|
22
|
-
simple = 1979-05-27T07:32:00Z
|
23
|
-
|
24
|
-
# Keygroups
|
25
|
-
[a.b.c]
|
26
|
-
d = "test"
|
27
|
-
|
28
|
-
[e]
|
29
|
-
f = "test"
|
30
|
-
|
31
|
-
# Post line comment
|
32
|
-
[comments]
|
33
|
-
on = "a line" # with markup
|
34
|
-
|
35
|
-
# Multi-line arrays
|
36
|
-
[arrays]
|
37
|
-
# Simple array
|
38
|
-
simple = [1, 2, 3]
|
39
|
-
|
40
|
-
# Nested array
|
41
|
-
nested = [[1, 2], [3]]
|
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
|
-
|
55
|
-
# Multiline array
|
56
|
-
multiline = [
|
57
|
-
1,
|
58
|
-
2,
|
59
|
-
3
|
60
|
-
]
|
61
|
-
|
62
|
-
# Multiline array
|
63
|
-
multiline_trailing_comma = [
|
64
|
-
1,
|
65
|
-
2,
|
66
|
-
3,
|
67
|
-
]
|
68
|
-
|
69
|
-
# With comments
|
70
|
-
multiline_comments = [ # 0
|
71
|
-
1, # 1
|
72
|
-
2, # 2
|
73
|
-
3 # 3
|
74
|
-
]
|
75
|
-
|
76
|
-
multi = ["lines", "are",
|
77
|
-
"super", "cool", "lol",
|
78
|
-
"amirite"]
|
79
|
-
|
80
|
-
# Uneven spacing
|
81
|
-
uneven = [1, 2, 3, 4, 5 ]
|
data/test/test_empty.rb
DELETED
@@ -1,18 +0,0 @@
|
|
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
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rubygems'
|
3
|
-
require 'bundler/setup'
|
4
|
-
|
5
|
-
require 'toml'
|
6
|
-
require 'minitest/autorun'
|
7
|
-
|
8
|
-
class TestGenerator < MiniTest::Test
|
9
|
-
def setup
|
10
|
-
@doc = {
|
11
|
-
"integer" => 1,
|
12
|
-
"float" => 3.14159,
|
13
|
-
"true" => true,
|
14
|
-
"false" => false,
|
15
|
-
"string" => "hi",
|
16
|
-
"array" => [[1], [2], [3]],
|
17
|
-
"key" => {
|
18
|
-
"group" => {
|
19
|
-
"value" => "lol"
|
20
|
-
},
|
21
|
-
"nil_table" => {}
|
22
|
-
},
|
23
|
-
"date" => DateTime.now,
|
24
|
-
"nil" => nil
|
25
|
-
}
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_generator
|
30
|
-
doc = @doc.clone
|
31
|
-
body = TOML::Generator.new(doc).body
|
32
|
-
|
33
|
-
doc_parsed = TOML::Parser.new(body).parsed
|
34
|
-
|
35
|
-
# Extracting dates since Ruby's DateTime equality testing sucks.
|
36
|
-
original_date = doc.delete "date"
|
37
|
-
parsed_date = doc_parsed.delete "date"
|
38
|
-
|
39
|
-
# removing the nil value
|
40
|
-
remove_nil = doc.delete "nil"
|
41
|
-
|
42
|
-
assert_equal doc, doc_parsed
|
43
|
-
assert_equal original_date.to_time.to_s, parsed_date.to_time.to_s
|
44
|
-
end
|
45
|
-
end
|
data/test/test_parser.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rubygems'
|
3
|
-
require 'bundler/setup'
|
4
|
-
|
5
|
-
require 'toml'
|
6
|
-
require 'minitest/autorun'
|
7
|
-
|
8
|
-
class TestParser < MiniTest::Test
|
9
|
-
def setup
|
10
|
-
filepath = File.join(File.dirname(__FILE__), 'spec.toml')
|
11
|
-
@doc = TOML::Parser.new(File.read(filepath)).parsed
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_string
|
15
|
-
assert_equal "string\n\t\"string", @doc["strings"]["string"]
|
16
|
-
assert_equal "", @doc["strings"]["empty"]
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_integer
|
20
|
-
assert_equal 42, @doc["ints"]["simple"]
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_negative_integer
|
24
|
-
assert_equal -42, @doc["ints"]["negative"]
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_float
|
28
|
-
assert_equal 3.14159, @doc["floats"]["pi"]
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_negative_float
|
32
|
-
assert_equal -10.0, @doc["floats"]["negative"]
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_datetime
|
36
|
-
assert_equal DateTime.iso8601("1979-05-27T07:32:00Z"), @doc["datetimes"]["simple"]
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_booleans
|
40
|
-
assert_equal true, @doc["true"]
|
41
|
-
assert_equal false, @doc["false"]
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_simple_array
|
45
|
-
assert_equal [1, 2, 3], @doc["arrays"]["simple"]
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_nested_array
|
49
|
-
assert_equal [[1, 2], [3]], @doc["arrays"]["nested"]
|
50
|
-
end
|
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
|
-
|
64
|
-
def test_multiline_arrays
|
65
|
-
assert_equal ["lines", "are", "super", "cool", "lol", "amirite"], @doc["arrays"]["multi"]
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_multiline_array
|
69
|
-
assert_equal @doc["arrays"]["multiline"], [1, 2, 3]
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_multiline_array_with_trailing_comma
|
73
|
-
assert_equal @doc["arrays"]["multiline_trailing_comma"], [1, 2, 3]
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_multiline_array_with_comments
|
77
|
-
assert_equal @doc["arrays"]["multiline_comments"], [1, 2, 3]
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_simple_keygroup
|
81
|
-
assert_equal "test", @doc["e"]["f"]
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_nested_keygroup
|
85
|
-
assert_equal "test", @doc["a"]["b"]["c"]["d"]
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_inline_comment
|
89
|
-
assert_equal "a line", @doc["comments"]["on"]
|
90
|
-
end
|
91
|
-
end
|
data/test/test_parser_hard.rb
DELETED
@@ -1,16 +0,0 @@
|
|
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
|
data/test/test_table_arrays.rb
DELETED
@@ -1,42 +0,0 @@
|
|
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/test/tmp.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rubygems'
|
3
|
-
require 'bundler/setup'
|
4
|
-
|
5
|
-
require 'toml'
|
6
|
-
|
7
|
-
doc = "
|
8
|
-
a = [true, false]
|
9
|
-
"
|
10
|
-
|
11
|
-
puts TOML.load(doc).inspect
|
12
|
-
|
13
|
-
# puts TOML.load("a = [[[[1]]]]")["a"].inspect
|
14
|
-
# puts "[[[[1]]]] <- expected"
|
15
|
-
#
|
16
|
-
# puts TOML.load("a = [1]")["a"].inspect
|
17
|
-
# puts "[1] <- expected"
|
18
|
-
#
|
19
|
-
# puts TOML.load("a = [1, 2, 3]")["a"].inspect
|
20
|
-
# puts "[1, 2, 3] <- expected"
|
21
|
-
#
|
22
|
-
# puts TOML.load("a = [[[1], 2], 3]")["a"].inspect
|
23
|
-
# puts "[[[1], 2], 3] <- expected"
|
24
|
-
#
|
25
|
-
# puts TOML.load("a = [[]]")["a"].inspect
|
data/toml.gemspec
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
## This is the rakegem gemspec template. Make sure you read and understand
|
2
|
-
## all of the comments. Some sections require modification, and others can
|
3
|
-
## be deleted if you don't need them. Once you understand the contents of
|
4
|
-
## this file, feel free to delete any comments that begin with two hash marks.
|
5
|
-
## You can find comprehensive Gem::Specification documentation, at
|
6
|
-
## http://docs.rubygems.org/read/chapter/20
|
7
|
-
Gem::Specification.new do |s|
|
8
|
-
s.specification_version = 2 if s.respond_to? :specification_version=
|
9
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
-
s.rubygems_version = '1.3.5'
|
11
|
-
|
12
|
-
## Leave these as is they will be modified for you by the rake gemspec task.
|
13
|
-
## If your rubyforge_project name is different, then edit it and comment out
|
14
|
-
## the sub! line in the Rakefile
|
15
|
-
s.name = 'toml'
|
16
|
-
s.version = '0.1.1'
|
17
|
-
s.date = '2014-02-17'
|
18
|
-
|
19
|
-
## Make sure your summary is short. The description may be as long
|
20
|
-
## as you like.
|
21
|
-
s.summary = "Parse your TOML."
|
22
|
-
s.description = "Parse your TOML, seriously."
|
23
|
-
|
24
|
-
## List the primary authors. If there are a bunch of authors, it's probably
|
25
|
-
## better to set the email to an email list or something. If you don't have
|
26
|
-
## a custom homepage, consider using your GitHub URL or the like.
|
27
|
-
s.authors = ["Jeremy McAnally", "Dirk Gadsden"]
|
28
|
-
s.email = 'jeremy@github.com'
|
29
|
-
s.homepage = 'http://github.com/jm/toml'
|
30
|
-
s.license = 'MIT'
|
31
|
-
|
32
|
-
## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
|
33
|
-
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
34
|
-
s.require_paths = %w[lib]
|
35
|
-
|
36
|
-
## Specify any RDoc options here. You'll want to add your README and
|
37
|
-
## LICENSE files to the extra_rdoc_files list.
|
38
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
-
s.extra_rdoc_files = %w[README.md LICENSE]
|
40
|
-
|
41
|
-
s.add_dependency "parslet", "~> 1.5.0"
|
42
|
-
|
43
|
-
s.add_development_dependency "rake"
|
44
|
-
|
45
|
-
## Leave this section as-is. It will be automatically generated from the
|
46
|
-
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
47
|
-
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
48
|
-
# = MANIFEST =
|
49
|
-
s.files = %w[
|
50
|
-
Gemfile
|
51
|
-
LICENSE
|
52
|
-
README.md
|
53
|
-
Rakefile
|
54
|
-
lib/toml.rb
|
55
|
-
lib/toml/generator.rb
|
56
|
-
lib/toml/key.rb
|
57
|
-
lib/toml/monkey_patch.rb
|
58
|
-
lib/toml/parser.rb
|
59
|
-
lib/toml/parslet.rb
|
60
|
-
lib/toml/table.rb
|
61
|
-
lib/toml/transformer.rb
|
62
|
-
script/bootstrap
|
63
|
-
script/cibuild
|
64
|
-
script/console
|
65
|
-
test/empty.toml
|
66
|
-
test/hard_example.toml
|
67
|
-
test/spec.toml
|
68
|
-
test/test_empty.rb
|
69
|
-
test/test_generator.rb
|
70
|
-
test/test_parser.rb
|
71
|
-
test/test_parser_hard.rb
|
72
|
-
test/test_table_arrays.rb
|
73
|
-
test/tmp.rb
|
74
|
-
toml.gemspec
|
75
|
-
]
|
76
|
-
# = MANIFEST =
|
77
|
-
|
78
|
-
## Test files will be grabbed from the file list. Make sure the path glob
|
79
|
-
## matches what you actually use.
|
80
|
-
s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
|
81
|
-
end
|