Sha256: 4e052b02582398a71badedfb77a7a9295e9d3f7760e1f8f4790202c11d0ebff1

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

require 'helper'
require 'dr/parse/simple_parser'

describe DR::SimpleParser do
	describe "parse_namevalue" do
		it "parses a simple name value" do
			_(DR::SimpleParser.parse_namevalue("foo:bar")).must_equal([:foo,"bar"])
		end
		it "can let the name be a string" do
			_(DR::SimpleParser.parse_namevalue("foo:bar",symbolize:false)).must_equal(["foo","bar"])
		end
		it "only splits on the first ':'" do
			_(DR::SimpleParser.parse_namevalue("foo:bar:baz")).must_equal([:foo,"bar:baz"])
		end
		it "can change the separation" do
			_(DR::SimpleParser.parse_namevalue("foo:bar!baz", sep: "!",symbolize:false)).must_equal(["foo:bar","baz"])
		end
		it "can set a default" do
			_(DR::SimpleParser.parse_namevalue("foo", default: 0)).must_equal([:foo,0])
		end
		it "If the default is true then support 'no-foo'" do
			_(DR::SimpleParser.parse_namevalue("no-foo", default: true)).must_equal([:foo,false])
		end
		it "can set the default to true" do
			_(DR::SimpleParser.parse_namevalue("foo", default: true, symbolize:false)).must_equal(["foo",true])
		end
	end

	describe "parse_strings" do
		it "can parse several name values" do
			_(DR::SimpleParser.parse_string("foo:bar,ploum:plim")[:values]).must_equal({foo: "bar", ploum: "plim"})
		end
		it "can handle options" do
			_(DR::SimpleParser.parse_string("name1:value1!option1=ploum!option2=plam!option3,name2:value2!!globalopt1=foo,globalopt2=bar")).must_equal({
			values: {name1: "value1", name2: "value2"},
			local_opts: {name1: {option1:"ploum",option2:"plam",option3:true}, name2: {}},
			global_opts: {globalopt1: "foo", globalopt2: "bar"},
			opts: {name1: {option1:"ploum",option2:"plam",option3:true,globalopt1:"foo", globalopt2: "bar"}, name2:{globalopt1: "foo", globalopt2: "bar"}}})
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
drain-0.7.0 test/test_simple_parser.rb
drain-0.6.0 test/test_simple_parser.rb