From b366ef7066f63df2e19bd93e34de202f34a1c282 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Thu, 27 Apr 2017 14:53:13 +0200 Subject: Initial commit --- .gitignore | 2 ++ META6.json | 26 ++++++++++++++++++++++++++ lib/Config/Parser/toml.pm6 | 21 +++++++++++++++++++++ readme.md | 22 ++++++++++++++++++++++ t/01-read.t | 33 +++++++++++++++++++++++++++++++++ t/02-write.t | 34 ++++++++++++++++++++++++++++++++++ t/files/config.toml | 3 +++ t/files/merge.toml | 5 +++++ t/files/write.toml | 6 ++++++ 9 files changed, 152 insertions(+) create mode 100644 .gitignore create mode 100644 META6.json create mode 100644 lib/Config/Parser/toml.pm6 create mode 100644 readme.md create mode 100644 t/01-read.t create mode 100644 t/02-write.t create mode 100644 t/files/config.toml create mode 100644 t/files/merge.toml create mode 100644 t/files/write.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d4fdb9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.precomp + diff --git a/META6.json b/META6.json new file mode 100644 index 0000000..d2653ec --- /dev/null +++ b/META6.json @@ -0,0 +1,26 @@ +{ + "perl": "6", + "name": "Config::Parser::toml", + "version": "1.0.0", + "auth": "github:scriptkitties", + "description": "TOML parser for Config", + "license": "GPL-3.0", + "depends": [ + "Config" + ], + "provides": { + "Config::Parser::toml": "lib/Config/Parser/toml.pm6", + }, + "authors": [ + "Patrick Spek " + ], + "tags": [ + "config", + "configuration" + ], + "test-depends": [ + "File::Temp", + "Test::META" + ], + "source-url": "https://github.com/scriptkitties/p6-Config-Parser-toml.git" +} diff --git a/lib/Config/Parser/toml.pm6 b/lib/Config/Parser/toml.pm6 new file mode 100644 index 0000000..7d63593 --- /dev/null +++ b/lib/Config/Parser/toml.pm6 @@ -0,0 +1,21 @@ +#! /usr/bin/env false + +use v6.c; + +use Config::Parser; +use Config::TOML; + +class Config::Parser::toml is Config::Parser +{ + method read(Str $path --> Hash) + { + from-toml(slurp $path); + } + + method write(Str $path, Hash $config --> Bool) + { + spurt $path, to-toml($config); + + True; + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..8828821 --- /dev/null +++ b/readme.md @@ -0,0 +1,22 @@ +# Config::Parser::toml +A TOML parser for [Config](https://github.com/scriptkitties/p6-Config). + +[![Build Status](https://travis-ci.org/scriptkitties/p6-Config-Parser-toml.svg?branch=master)](https://travis-ci.org/scriptkitties/p6-Config-Parser-toml) + +## Installation +```sh +zef install Config::Parser::toml +``` + +## License +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . diff --git a/t/01-read.t b/t/01-read.t new file mode 100644 index 0000000..fa5a75b --- /dev/null +++ b/t/01-read.t @@ -0,0 +1,33 @@ +#! /usr/bin/env perl6 + +use v6.c; +use Test; +use lib "lib"; + +use Config; +use Config::Parser::toml; + +plan 4; + +my $config = Config.new(); + +ok $config.read("t/files/config.toml"), "File reading throws no error"; + +subtest "Contents match" => { + plan 2; + + is $config.get("header.a"), "a", "a = a"; + is $config.get("header.b"), "b", "b = b"; +}; + +ok $config.read("t/files/merge.toml"), "File merging throws no error"; + +subtest "Contents match after merging" => { + plan 4; + + is $config.get("header.a"), "a", "a = a"; + is $config.get("header.b"), "b", "b = b"; + is $config.get("header.c"), "c", "c = c"; + + is $config.get("merge-header.a"), "a", "a = a"; +}; diff --git a/t/02-write.t b/t/02-write.t new file mode 100644 index 0000000..5eb7d92 --- /dev/null +++ b/t/02-write.t @@ -0,0 +1,34 @@ +#! /usr/bin/env perl6 + +use v6.c; +use Test; +use lib "lib"; + +use Config; +use Config::Parser::toml; +use File::Temp; + +plan 4; + +my $config = Config.new(); + +$config.read({ + first => { + a => "a", + b => "b" + }, + second => { + a => "a", + c => "c" + } +}); + +my ($filename, $fh) = tempfile; + +ok $config.write($filename, "Config::Parser::toml"), "Write succeeded"; + +is slurp("t/files/write.toml"), slurp($filename), "Written config is correct"; + +ok $config.write($filename, "Config::Parser::toml"), "Write over non-empty file"; + +is slurp("t/files/write.toml"), slurp($filename), "Written config is still correct"; diff --git a/t/files/config.toml b/t/files/config.toml new file mode 100644 index 0000000..2e411d3 --- /dev/null +++ b/t/files/config.toml @@ -0,0 +1,3 @@ +[header] +a = "a" +b = "b" diff --git a/t/files/merge.toml b/t/files/merge.toml new file mode 100644 index 0000000..fee4bc5 --- /dev/null +++ b/t/files/merge.toml @@ -0,0 +1,5 @@ +[header] +c = "c" + +[merge-header] +a = "a" diff --git a/t/files/write.toml b/t/files/write.toml new file mode 100644 index 0000000..bb8d31a --- /dev/null +++ b/t/files/write.toml @@ -0,0 +1,6 @@ +[first] +a = "a" +b = "b" +[second] +a = "a" +c = "c" \ No newline at end of file -- cgit v1.1