From ce694b0f13deb01a79c2af0f2e33374bc3aca8e3 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Sun, 27 Mar 2022 16:49:52 +0530 Subject: [PATCH] test: ini parser spec --- spec/fixtures/ini/all.ini | 9 ++++++++ spec/fixtures/ini/booleans.ini | 3 +++ spec/fixtures/ini/comments.ini | 4 ++++ spec/fixtures/ini/numbers.ini | 3 +++ spec/unit/parser_spec.lua | 40 ++++++++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+) create mode 100644 spec/fixtures/ini/all.ini create mode 100644 spec/fixtures/ini/booleans.ini create mode 100644 spec/fixtures/ini/comments.ini create mode 100644 spec/fixtures/ini/numbers.ini create mode 100644 spec/unit/parser_spec.lua diff --git a/spec/fixtures/ini/all.ini b/spec/fixtures/ini/all.ini new file mode 100644 index 0000000..0d3cbfd --- /dev/null +++ b/spec/fixtures/ini/all.ini @@ -0,0 +1,9 @@ +[section1] +one = 1 +nothing = + +[section2] +right=true + +[section3] +nope= diff --git a/spec/fixtures/ini/booleans.ini b/spec/fixtures/ini/booleans.ini new file mode 100644 index 0000000..c47028d --- /dev/null +++ b/spec/fixtures/ini/booleans.ini @@ -0,0 +1,3 @@ +[section] +good = true +bad = false diff --git a/spec/fixtures/ini/comments.ini b/spec/fixtures/ini/comments.ini new file mode 100644 index 0000000..2ab17af --- /dev/null +++ b/spec/fixtures/ini/comments.ini @@ -0,0 +1,4 @@ +; There is only a single comment in this file +; +; [section] +; key=value diff --git a/spec/fixtures/ini/numbers.ini b/spec/fixtures/ini/numbers.ini new file mode 100644 index 0000000..52d9a7d --- /dev/null +++ b/spec/fixtures/ini/numbers.ini @@ -0,0 +1,3 @@ +[section] +one = 1 +two = 2 diff --git a/spec/unit/parser_spec.lua b/spec/unit/parser_spec.lua new file mode 100644 index 0000000..ab8a78e --- /dev/null +++ b/spec/unit/parser_spec.lua @@ -0,0 +1,40 @@ +local ini = require "telescope._extensions.bookmarks.parser.ini" + +describe("ini parser", function() + it("should ignore comments", function() + assert.are.same(ini.load "spec/fixtures/ini/comments.ini", {}) + end) + + it("should parse numbers", function() + assert.are.same(ini.load "spec/fixtures/ini/numbers.ini", { + section = { + one = 1, + two = 2, + }, + }) + end) + + it("should parse booleans", function() + assert.are.same(ini.load "spec/fixtures/ini/booleans.ini", { + section = { + good = true, + bad = false, + }, + }) + end) + + it("should parse multiple sections and empty values", function() + assert.are.same(ini.load "spec/fixtures/ini/all.ini", { + section1 = { + one = 1, + nothing = "", + }, + section2 = { + right = true, + }, + section3 = { + nope = "", + }, + }) + end) +end)