pax_global_header00006660000000000000000000000064124200102620014477gustar00rootroot0000000000000052 comment=47fd6ab8d7b3c80066b9b65f1576471cff5b8824 toml-0.1.2/000077500000000000000000000000001242001026200124525ustar00rootroot00000000000000toml-0.1.2/.gitignore000066400000000000000000000000551242001026200144420ustar00rootroot00000000000000pkg/* test.* coverage Gemfile.lock .DS_Store toml-0.1.2/.travis.yml000066400000000000000000000001031242001026200145550ustar00rootroot00000000000000language: ruby rvm: - 2.1.0 - 2.0.0 - 1.9.3 script: script/cibuild toml-0.1.2/CHANGELOG.md000066400000000000000000000006071242001026200142660ustar00rootroot00000000000000## 0.1.2 / 2014-10-16 - Add support for `CR` and `CRLF` newlines (#13) - Add support for generating TOML from Ruby `Hash`es (#36) - Add a script interface for @BurntSushi's `toml-test` utility (#38) ## 0.1.1 / 2014-02-17 - Add license to gemspec (#26) - Loosen `multi_json` dependency version specified (#27) - `Generator` should print empty hash tables but not keys without values (#28) toml-0.1.2/Gemfile000066400000000000000000000003611242001026200137450ustar00rootroot00000000000000source 'https://rubygems.org' # Specify your gem's dependencies in toml.gemspec gemspec group :test do gem 'multi_json', '~> 1.7' gem 'minitest' gem 'simplecov', :require => false gem 'simplecov-gem-adapter', :require => false end toml-0.1.2/LICENSE000066400000000000000000000020611242001026200134560ustar00rootroot00000000000000The MIT License Copyright (c) Tom Preston-Werner Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.toml-0.1.2/README.md000066400000000000000000000026711242001026200137370ustar00rootroot00000000000000# TOML A sane configuration format from @mojombo. More information here: https://github.com/mojombo/toml This is far superior to YAML and JSON because it doesn't suck. Really it doesn't. **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.** ## Usage Add to your Gemfile: ```ruby gem "toml", "~> 0.0.3" ``` It's simple, really. ```ruby content = <<-TOML # Hello, this is an example. [things] other = "things" what = 900000 TOML parser = TOML::Parser.new(content).parsed # => { "things" => { "other" => "things", "what" => 900000 } } ``` You can also use the same API as `YAML` if you'd like: ```ruby TOML.load("thing = 9") # => {"thing" => 9} TOML.load_file("my_file.toml") # => {"whatever" => "keys"} ``` There's also a beta feature for generating a TOML file from a Ruby hash. Please note this will likely not give beautiful output right now. ```ruby hash = { "integer" => 1, "float" => 3.14159, "true" => true, "false" => false, "string" => "hi", "array" => [[1], [2], [3]], "key" => { "group" => { "value" => "lol" } } } doc = TOML::Generator.new(hash).body # doc will be a string containing a proper TOML document. ``` ## Contributors Written by Jeremy McAnally (@jm) and Dirk Gadsden (@dirk) based on TOML from Tom Preston-Werner (@mojombo). toml-0.1.2/Rakefile000066400000000000000000000033241242001026200141210ustar00rootroot00000000000000require 'rubygems' require 'bundler/gem_tasks' require 'rake' require 'date' require './lib/toml/version' ############################################################################# # # Helper functions # ############################################################################# def name @name ||= Dir['*.gemspec'].first.split('.').first end def version TOML::VERSION end def date Date.today.to_s end ############################################################################# # # Standard tasks # ############################################################################# task :default => :test # require 'rake/testtask' # Rake::TestTask.new(:test) do |test| # test.libs << 'lib' << 'test' # test.pattern = 'test/**/test_*.rb' # test.verbose = true # end task :test do Dir['./test/**/test_*.rb'].each {|f| require f } end desc "Generate RCov test coverage and open in your browser" task :coverage do if RUBY_VERSION =~ /^1\./ require 'rubygems' require 'bundler' Bundler.setup(:test) require 'simplecov' require 'simplecov-gem-adapter' sh "rm -fr coverage" SimpleCov.command_name 'Unit Tests' SimpleCov.start 'gem' Rake::Task[:test].invoke SimpleCov.at_exit do SimpleCov.result.format! sh "open coverage/index.html" end else require 'rcov' sh "rm -fr coverage" sh "rcov test/test_*.rb" sh "open coverage/index.html" end end require 'rdoc/task' Rake::RDocTask.new do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = "#{name} #{version}" rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') end desc "Open an irb session preloaded with this library" task :console do sh "irb -rubygems -r ./lib/#{name}.rb" end toml-0.1.2/lib/000077500000000000000000000000001242001026200132205ustar00rootroot00000000000000toml-0.1.2/lib/toml.rb000066400000000000000000000010141242001026200145140ustar00rootroot00000000000000$:.unshift(File.dirname(__FILE__)) require 'time' require 'parslet' require 'toml/version' require 'toml/key' require 'toml/table' require 'toml/parslet' require 'toml/transformer' require 'toml/parser' require 'toml/generator' # Don't do monkey-patching by default. Only pulled in by TOML::Generator # if needed (see generator.rb line 27). # require 'toml/monkey_patch module TOML def self.load(content) Parser.new(content).parsed end def self.load_file(path) Parser.new(File.read(path)).parsed end end toml-0.1.2/lib/toml/000077500000000000000000000000001242001026200141735ustar00rootroot00000000000000toml-0.1.2/lib/toml/generator.rb000066400000000000000000000014501242001026200165060ustar00rootroot00000000000000 module TOML class Generator attr_reader :body, :doc def initialize(doc) # Ensure all the to_toml methods are injected into the base Ruby classes # used by TOML. self.class.inject! @doc = doc @body = doc.to_toml return @body end # Whether or not the injections have already been done. @@injected = false # Inject to_toml methods into the Ruby classes used by TOML (booleans, # String, Numeric, Array). You can add to_toml methods to your own classes # to allow them to be easily serialized by the generator (and it will shout # if something doesn't have a to_toml method). def self.inject! return if @@injected require 'toml/monkey_patch' @@injected = true end end#Generator end#TOML toml-0.1.2/lib/toml/key.rb000066400000000000000000000002201242001026200153020ustar00rootroot00000000000000module TOML class Key attr_reader :key, :value def initialize(key, value) @key = key @value = value end end endtoml-0.1.2/lib/toml/monkey_patch.rb000066400000000000000000000035521242001026200172060ustar00rootroot00000000000000# Adds to_toml methods to base Ruby classes used by the generator. class Object def toml_table? self.kind_of?(Hash) end def toml_table_array? self.kind_of?(Array) && self.first.toml_table? end end class Hash def to_toml(path = "") return "" if self.empty? tables = {} values = {} self.keys.sort.each do |key| val = self[key] if val.kind_of?(NilClass) next elsif val.toml_table? || val.toml_table_array? tables[key] = val else values[key] = val end end toml = "" values.each do |key, val| toml << "#{key} = #{val.to_toml(key)}\n" end tables.each do |key, val| key = "#{path}.#{key}" unless path.empty? toml_val = val.to_toml(key) unless toml_val.empty? if val.toml_table? non_table_vals = val.values.reject do |v| v.toml_table? || v.toml_table_array? end # Only add the table key if there are non table values. if non_table_vals.length > 0 toml << "\n[#{key}]\n" end end toml << toml_val end end toml end end class Array def to_toml(path = "") unless self.map(&:class).uniq.length == 1 raise "All array values must be the same type" end if self.first.toml_table? toml = "" self.each do |val| toml << "\n[[#{path}]]\n" toml << val.to_toml(path) end return toml else "[" + self.map {|v| v.to_toml(path) }.join(",") + "]" end end end class TrueClass def to_toml(path = ""); "true"; end end class FalseClass def to_toml(path = ""); "false"; end end class String def to_toml(path = ""); self.inspect; end end class Numeric def to_toml(path = ""); self.to_s; end end class DateTime def to_toml(path = "") self.to_time.utc.strftime("%Y-%m-%dT%H:%M:%SZ") end end toml-0.1.2/lib/toml/parser.rb000066400000000000000000000056521242001026200160240ustar00rootroot00000000000000module TOML class Parser attr_reader :parsed def initialize(markup) # Make sure we have a newline on the end markup += "\n" unless markup.end_with?("\n") || markup.length == 0 begin tree = Parslet.new.parse(markup) rescue Parslet::ParseFailed => failure puts failure.cause.ascii_tree end parts = Transformer.new.apply(tree) || [] @parsed = {} @current = @parsed @current_path = '' parts.each do |part| if part.is_a? Key # If @current is an array then we're in a key-group if @current.is_a? Array # Make sure there's a table to work with. @current << {} if @current.last.nil? # Set the key on the table. @current.last[part.key] = part.value next end # Make sure the key isn't already set if !@current.is_a?(Hash) || @current.has_key?(part.key) err = "Cannot override key '#{part.key}'" unless @current_path.empty? err += " at path '#{@current_path}'" end raise err end # Set the key-value into the current hash @current[part.key] = part.value elsif part.is_a?(TableArray) resolve_table_array(part) elsif part.is_a?(Table) resolve_table(part) else raise "Unrecognized part: #{part.inspect}" end end end def resolve_table_array(t) @current = @parsed path = t.name.dup @current_path = path.join('.') while n = path.shift # If it's a table-array then get the last item. @current = @current.last if @current.is_a? Array # If it's the last item: if path.length == 0 # If the current table has an item: if @current.has_key?(n) # And that item is already a table-array: if @current[n].is_a? Array # Then add an item to that table-array. @current[n] << {} else raise "Cannot override table array '#{t.name.join '.'}'" end else # Create a new table array if nothing exists here. @current[n] = [] end elsif @current.has_key? n # Don't do anything if we're just moving into tables. else @current[n] = {} end @current = @current[n] end end def resolve_table(t) @current = @parsed path = t.name.dup @current_path = path.join('.') while k = path.shift # If it's a table-array then get the last item. @current = @current.last if @current.is_a? Array # Create a new table if one doesn't exist. @current[k] = {} if !@current.has_key? k # Move into the table. @current = @current[k] end end#/resolve_key_group end end toml-0.1.2/lib/toml/parslet.rb000066400000000000000000000055621242001026200162020ustar00rootroot00000000000000module TOML class Parslet < ::Parslet::Parser rule(:document) { all_space >> (table | table_array | key_value | comment_line).repeat >> all_space } root :document rule(:value) { array | string | datetime.as(:datetime) | float.as(:float) | integer.as(:integer) | boolean } # Finding comments in multiline arrays requires accepting a bunch of # possible newlines and stuff before the comment rule(:array_comments) { (all_space >> comment_line).repeat } rule(:array) { str("[") >> all_space >> array_comments >> ( array_comments >> # Match any comments on first line all_space >> value >> array_comments >> ( # Separator followed by any comments all_space >> str(",") >> array_comments >> # Value followed by any comments all_space >> value >> array_comments ).repeat >> (all_space >> str(",")).maybe >> # possible trailing comma all_space >> array_comments # Grab any remaining comments just in case ).maybe.as(:array) >> str("]") } rule(:key_value) { space >> key.as(:key) >> space >> str("=") >> space >> value.as(:value) >> space >> comment.maybe >> newline >> all_space } rule(:table) { space >> str("[") >> table_name.as(:table) >> str("]") >> space >> comment.maybe >> newline >> all_space } rule(:table_array) { space >> str("[[") >> table_name.as(:table_array) >> str("]]") >> space >> comment.maybe >> str("\n") >> all_space } rule(:key) { match["^. \t\\]"].repeat(1) } rule(:table_name) { key.as(:key) >> (str(".") >> key.as(:key)).repeat } rule(:comment_line) { comment >> newline >> all_space } rule(:comment) { str("#") >> match["^\n"].repeat } rule(:space) { match[" \t"].repeat } rule(:all_space) { match[" \t\r\n"].repeat } rule(:newline) { str("\r").maybe >> str("\n") | str("\r") >> str("\n").maybe } rule(:string) { str('"') >> ( match["^\"\\\\"] | (str("\\") >> match["0tnr\"\\\\"]) ).repeat.as(:string) >> str('"') } rule(:sign) { str("-") } rule(:sign?) { sign.maybe } rule(:integer) { str("0") | (sign? >> match["1-9"] >> match["0-9"].repeat) } rule(:float) { sign? >> match["0-9"].repeat(1) >> str(".") >> match["0-9"].repeat(1) } rule(:boolean) { str("true").as(:true) | str("false").as(:false) } rule(:date) { match["0-9"].repeat(4,4) >> str("-") >> match["0-9"].repeat(2,2) >> str("-") >> match["0-9"].repeat(2,2) } rule(:time) { match["0-9"].repeat(2,2) >> str(":") >> match["0-9"].repeat(2,2) >> str(":") >> match["0-9"].repeat(2,2) } rule(:datetime) { date >> str("T") >> time >> str("Z") } end endtoml-0.1.2/lib/toml/table.rb000066400000000000000000000002561242001026200156120ustar00rootroot00000000000000module TOML class Table # :name is array of strings attr_reader :name def initialize(name) @name = name end end class TableArray < Table; end end toml-0.1.2/lib/toml/transformer.rb000066400000000000000000000056731242001026200170750ustar00rootroot00000000000000module TOML class Transformer < ::Parslet::Transform # Utility to properly handle escape sequences in parsed string. def self.parse_string(val) e = val.length s = 0 o = [] while s < e if val[s].chr == "\\" s += 1 case val[s].chr when "t" o << "\t" when "n" o << "\n" when "\\" o << "\\" when '"' o << '"' when "r" o << "\r" when "0" o << "\0" else raise "Unexpected escape character: '\\#{val[s]}'" end else o << val[s].chr end s += 1 end o.join end # Clean up arrays # rule(:array => subtree(:ar)) { ar.is_a?(Array) ? ar : [ar] } # Empty file rule('') { nil } # Clean up simple value hashes rule(:integer => simple(:i)) { i.to_i } rule(:float => simple(:f)) { f.to_f } rule(:string => simple(:s)) { Transformer.parse_string(s.to_s) } rule(:string => sequence(:s)) { raise "Unexpected string-sequence: #{s.inspect}" unless s.empty? "" } rule(:datetime => simple(:d)) { DateTime.iso8601(d) } rule(:true => simple(:b)) { true } rule(:false => simple(:b)) { false } rule(:key => simple(:k), :value => simple(:v)) { Key.new(k.to_s, v) } # New array cleanup # TODO: Make this more readable/understandable. def self.visit_array(h) if h.is_a? Hash # If it's an {:array => ...} hash a = h[:array] if a.is_a? Array # If the value is already an array a = a.map {|v| visit_array(v) } classes = a.map {|v| # Grab the class, with a little exception for true and false since # they're different classes (TrueClass and FalseClass). (v == true || v == false) ? true : v.class } if classes.uniq.length != 1 raise "Conflicting types in array: " + \ classes.map(&:to_s).join(", ") end return a else # Turn the value into an array return [visit_array(a)].compact end else # Plain old non-hash value return h end end rule(:key => simple(:k), :value => subtree(:v)) { Key.new(k.to_s, Transformer.visit_array(v)) } # Make key hashes (inside key_groups) just be strings rule(:key => simple(:k)) { k } # Then objectify the key_groups rule(:table => simple(:kg)) { Table.new([kg.to_s]) } # Captures array-like key-groups rule(:table => subtree(:kg)) { Table.new(kg.map &:to_s) } # Single name table-arrays rule(:table_array => simple(:name)) { TableArray.new([name.to_s]) } # Multi-part (a.b.c) table-arrays rule(:table_array => subtree(:names)) { TableArray.new(names.map &:to_s) } end end toml-0.1.2/lib/toml/version.rb000066400000000000000000000000441242001026200162030ustar00rootroot00000000000000module TOML VERSION = '0.1.2' end toml-0.1.2/script/000077500000000000000000000000001242001026200137565ustar00rootroot00000000000000toml-0.1.2/script/bootstrap000077500000000000000000000000351242001026200157170ustar00rootroot00000000000000#! /bin/bash bundle install toml-0.1.2/script/cibuild000077500000000000000000000000441242001026200153150ustar00rootroot00000000000000#! /bin/bash bundle exec rake test toml-0.1.2/script/console000077500000000000000000000000431242001026200153430ustar00rootroot00000000000000#! /bin/bash irb -r ./lib/toml.rb toml-0.1.2/script/toml-test-decoder-interface.rb000077500000000000000000000022421242001026200215770ustar00rootroot00000000000000#!/usr/bin/env ruby # # This is an interface for: https://github.com/BurntSushi/toml-test require 'json' require '../lib/toml' # This converts a ruby obj to an obj that can be ran through the json encoder # to create json for toml-test. def obj_to_toml_test(obj) if obj.kind_of?(Hash) toml_test = {} obj.each do |key, value| toml_test[key] = obj_to_toml_test(value) end elsif obj.kind_of?(Array) toml_test = obj.map do |value| value = obj_to_toml_test(value) end unless obj.first.kind_of?(Hash) toml_test = {"type" => "array", "value" => toml_test} end else type = obj.class.name.downcase value = obj.to_s if obj.kind_of?(FalseClass) type = "bool" value = "false" elsif obj.kind_of?(TrueClass) type = "bool" value = "true" elsif obj.kind_of?(DateTime) value = obj.to_time.utc.strftime("%Y-%m-%dT%H:%M:%SZ") elsif obj.kind_of?(Integer) type = "integer" elsif obj.kind_of?(Float) type = "float" end toml_test = {"type" => type, "value" => value} end toml_test end hash = obj_to_toml_test(TOML::Parser.new(ARGF.read).parsed) print JSON.dump(hash) toml-0.1.2/script/toml-test-encoder-interface.rb000077500000000000000000000017151242001026200216150ustar00rootroot00000000000000#!/usr/bin/env ruby # # This is an interface for: https://github.com/BurntSushi/toml-test require 'json' require '../lib/toml' def toml_test_to_ruby(toml_obj) if toml_obj.kind_of?(Array) return toml_obj.map do |value| value = toml_test_to_ruby(value) end elsif toml_obj.has_key?("type") case toml_obj["type"] when "string" return toml_obj["value"] when "integer" return toml_obj["value"].to_i when "float" return toml_obj["value"].to_f when "datetime" return DateTime.iso8601(toml_obj["value"]) when "bool" case toml_obj["value"] when "true" return true when "false" return false end when "array" return toml_test_to_ruby(toml_obj["value"]) end else obj = {} toml_obj.each do |key, value| obj[key] = toml_test_to_ruby(value) end obj end end obj = toml_test_to_ruby(JSON.load(ARGF.read)) print TOML::Generator.new(obj).body toml-0.1.2/test/000077500000000000000000000000001242001026200134315ustar00rootroot00000000000000toml-0.1.2/test/empty.toml000066400000000000000000000000001242001026200154520ustar00rootroot00000000000000toml-0.1.2/test/hard_example.toml000066400000000000000000000026061242001026200167630ustar00rootroot00000000000000# Test file for TOML # Only this one tries to emulate a TOML file written by a user of the kind of parser writers probably hate # This part you'll really hate [the] test_string = "You'll hate me after this - #" # " Annoying, isn't it? [the.hard] test_array = [ "] ", " # "] # ] There you go, parse this! test_array2 = [ "Test #11 ]proved that", "Experiment #9 was a success" ] # You didn't think it'd as easy as chucking out the last #, did you? another_test_string = " Same thing, but with a string #" harder_test_string = " And when \"'s are in the string, along with # \"" # "and comments are there too" # Things will get harder [the.hard.bit#] what? = "You don't think some user won't do that?" multi_line_array = [ "]", # ] Oh yes I did ] # Each of the following keygroups/key value pairs should produce an error. Uncomment to them to test #[error] if you didn't catch this, your parser is broken #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 #array = [ # "This might most likely happen in multiline arrays", # Like here, # "or here, # and here" # ] End of array comment, forgot the # #number = 3.14 pi <--again forgot the # toml-0.1.2/test/spec.toml000066400000000000000000000015651242001026200152670ustar00rootroot00000000000000# Comment # Booleans true = true false = false [strings] # String string = "string\n\t\"string" empty = "" [ints] simple = 42 negative = -42 [floats] pi = 3.14159 negative = -10.0 [datetimes] # DateTime simple = 1979-05-27T07:32:00Z # Keygroups [a.b.c] d = "test" [e] f = "test" # Post line comment [comments] on = "a line" # with markup # Multi-line arrays [arrays] # Simple array simple = [1, 2, 3] # Nested array nested = [[1, 2], [3]] # Empty array empty = [] # Multiline empty multiline_empty = [ ] # Multiline empty with comment multiline_empty_comment = [ # You look nice today ] # Multiline array multiline = [ 1, 2, 3 ] # Multiline array multiline_trailing_comma = [ 1, 2, 3, ] # With comments multiline_comments = [ # 0 1, # 1 2, # 2 3 # 3 ] multi = ["lines", "are", "super", "cool", "lol", "amirite"] # Uneven spacing uneven = [1, 2, 3, 4, 5 ] toml-0.1.2/test/test_empty.rb000066400000000000000000000005401242001026200161520ustar00rootroot00000000000000require 'rubygems' require 'bundler/setup' require 'toml' require 'minitest/autorun' class TestEmpty < MiniTest::Test def setup filepath = File.join(File.dirname(__FILE__), "empty.toml") @doc = TOML::Parser.new(File.read(filepath)).parsed end def test_empty assert_equal ({}), @doc, "Empty document parsed incorrectly" end end toml-0.1.2/test/test_generator.rb000066400000000000000000000026571242001026200170150ustar00rootroot00000000000000 require 'rubygems' require 'bundler/setup' require 'toml' require 'minitest/autorun' class TestGenerator < MiniTest::Test def setup @doc = { "integer" => 1, "float" => 3.14159, "true" => true, "false" => false, "string" => "hi", "array" => [[1], [2], [3]], "table_array" => [ { "name" => "first" }, { "name" => "second", "sub_table_array" => [ { "sub_name" => "sub first", }, { "sub_name" => "sub second" } ] } ], "key" => { "group" => { "value" => "lol" }, "nil_table" => {} }, "date" => DateTime.now, "nil" => nil } end def test_generator doc = @doc.clone body = TOML::Generator.new(doc).body doc_parsed = TOML::Parser.new(body).parsed # removing the nil value remove_nil = doc.delete "nil" remove_nil_table = doc["key"].delete "nil_table" # Extracting dates since Ruby's DateTime equality testing sucks. original_date = doc.delete "date" parsed_date = doc_parsed.delete "date" assert_equal original_date.to_time.to_s, parsed_date.to_time.to_s refute doc_parsed.length > doc.length, "Parsed doc has more items than we started with." doc.each do |key, val| assert_equal val, doc_parsed[key] end end end toml-0.1.2/test/test_parser.rb000066400000000000000000000040341242001026200163120ustar00rootroot00000000000000 require 'rubygems' require 'bundler/setup' require 'toml' require 'minitest/autorun' class TestParser < MiniTest::Test def setup filepath = File.join(File.dirname(__FILE__), 'spec.toml') @doc = TOML::Parser.new(File.read(filepath)).parsed end def test_string assert_equal "string\n\t\"string", @doc["strings"]["string"] assert_equal "", @doc["strings"]["empty"] end def test_integer assert_equal 42, @doc["ints"]["simple"] end def test_negative_integer assert_equal -42, @doc["ints"]["negative"] end def test_float assert_equal 3.14159, @doc["floats"]["pi"] end def test_negative_float assert_equal -10.0, @doc["floats"]["negative"] end def test_datetime assert_equal DateTime.iso8601("1979-05-27T07:32:00Z"), @doc["datetimes"]["simple"] end def test_booleans assert_equal true, @doc["true"] assert_equal false, @doc["false"] end def test_simple_array assert_equal [1, 2, 3], @doc["arrays"]["simple"] end def test_nested_array assert_equal [[1, 2], [3]], @doc["arrays"]["nested"] end def test_empty_array assert_equal [], @doc["arrays"]["empty"] end def test_empty_multiline_array assert_equal [], @doc["arrays"]["multiline_empty"] end def test_empty_multiline_array_with_comment assert_equal [], @doc["arrays"]["multiline_empty_comment"] end def test_multiline_arrays assert_equal ["lines", "are", "super", "cool", "lol", "amirite"], @doc["arrays"]["multi"] end def test_multiline_array assert_equal @doc["arrays"]["multiline"], [1, 2, 3] end def test_multiline_array_with_trailing_comma assert_equal @doc["arrays"]["multiline_trailing_comma"], [1, 2, 3] end def test_multiline_array_with_comments assert_equal @doc["arrays"]["multiline_comments"], [1, 2, 3] end def test_simple_keygroup assert_equal "test", @doc["e"]["f"] end def test_nested_keygroup assert_equal "test", @doc["a"]["b"]["c"]["d"] end def test_inline_comment assert_equal "a line", @doc["comments"]["on"] end end toml-0.1.2/test/test_parser_hard.rb000066400000000000000000000006541242001026200173140ustar00rootroot00000000000000require 'rubygems' require 'bundler/setup' require 'toml' require 'minitest/autorun' class TestParserHardExample < MiniTest::Test def setup filepath = File.join(File.dirname(__FILE__), 'hard_example.toml') # @doc = TOML::Parser.new(File.read(filepath)).parsed @doc = TOML.load_file(filepath) end def test_the_test_string assert_equal @doc["the"]["test_string"], "You'll hate me after this - #" end end toml-0.1.2/test/test_table_arrays.rb000066400000000000000000000014121242001026200174630ustar00rootroot00000000000000require 'rubygems' require 'bundler/setup' require 'toml' require 'minitest/autorun' class TestParserTableArrays < MiniTest::Test def setup doc = ' [[fruit]] name = "apple" [fruit.physical] color = "red" shape = "round" [[fruit.variety]] name = "red delicious" [[fruit.variety]] name = "granny smith" [[fruit]] name = "banana" [[fruit.variety]] name = "plantain" ' @doc = TOML.load(doc) #require 'pp' #PP.pp @doc end def test_doc assert_equal @doc, { "fruit"=> [{"name"=>"apple", "physical"=>{"color"=>"red", "shape"=>"round"}, "variety"=>[{"name"=>"red delicious"}, {"name"=>"granny smith"}]}, {"name"=>"banana", "variety"=>[{"name"=>"plantain"}]}] } end end toml-0.1.2/test/tmp.rb000066400000000000000000000007411242001026200145600ustar00rootroot00000000000000 require 'rubygems' require 'bundler/setup' require 'toml' doc = " a = [true, false] " puts TOML.load(doc).inspect # puts TOML.load("a = [[[[1]]]]")["a"].inspect # puts "[[[[1]]]] <- expected" # # puts TOML.load("a = [1]")["a"].inspect # puts "[1] <- expected" # # puts TOML.load("a = [1, 2, 3]")["a"].inspect # puts "[1, 2, 3] <- expected" # # puts TOML.load("a = [[[1], 2], 3]")["a"].inspect # puts "[[[1], 2], 3] <- expected" # # puts TOML.load("a = [[]]")["a"].inspect toml-0.1.2/toml.gemspec000066400000000000000000000025601242001026200147750ustar00rootroot00000000000000require './lib/toml/version' Gem::Specification.new do |s| s.specification_version = 2 if s.respond_to? :specification_version= s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.rubygems_version = '1.3.5' s.name = 'toml' s.version = TOML::VERSION ## Make sure your summary is short. The description may be as long ## as you like. s.summary = "Parse your TOML." s.description = "Parse your TOML, seriously." ## List the primary authors. If there are a bunch of authors, it's probably ## better to set the email to an email list or something. If you don't have ## a custom homepage, consider using your GitHub URL or the like. s.authors = ["Jeremy McAnally", "Dirk Gadsden"] s.email = 'jeremy@github.com' s.homepage = 'http://github.com/jm/toml' s.license = 'MIT' ## Specify any RDoc options here. You'll want to add your README and ## LICENSE files to the extra_rdoc_files list. s.rdoc_options = ["--charset=UTF-8"] s.extra_rdoc_files = %w[README.md LICENSE CHANGELOG.md] s.add_dependency "parslet", "~> 1.5.0" s.add_development_dependency "rake" all_files = `git ls-files -z`.split("\x0") s.files = all_files.grep(%r{^(bin|lib)/}) s.executables = all_files.grep(%r{^bin/}) { |f| File.basename(f) } s.require_paths = ["lib"] end