From 3ae785b55367ef25ccb35569915461b391becd75 Mon Sep 17 00:00:00 2001 From: Max Miliano Date: Thu, 19 Sep 2024 10:39:43 -0300 Subject: [PATCH] fix: prevent error when user pass a nil value to setup added more tests and makefile --- docker-compose.yml | 5 ----- lua/solarized/init.lua | 2 +- makefile | 4 ++++ tests/setup_spec.lua | 23 +++++++++++++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 makefile diff --git a/docker-compose.yml b/docker-compose.yml index f605310..9ebbb86 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,8 +1,3 @@ services: solarized: build: . - volumes: - - solarized:/solarized - -volumes: - solarized: diff --git a/lua/solarized/init.lua b/lua/solarized/init.lua index 04b3b60..0af820f 100644 --- a/lua/solarized/init.lua +++ b/lua/solarized/init.lua @@ -9,7 +9,7 @@ local M = {} M.config = require 'solarized.config' M.setup = function(config) - M.config = vim.tbl_deep_extend('force', M.config, config) + M.config = vim.tbl_deep_extend('force', M.config, config or {}) if M.config.styles.enabled == false then M.config.styles = { diff --git a/makefile b/makefile new file mode 100644 index 0000000..2fdc1bc --- /dev/null +++ b/makefile @@ -0,0 +1,4 @@ +fmt: + stylua -f ./stylua.toml . +test: + vusted ./tests diff --git a/tests/setup_spec.lua b/tests/setup_spec.lua index bb43193..6bcb312 100644 --- a/tests/setup_spec.lua +++ b/tests/setup_spec.lua @@ -46,4 +46,27 @@ describe('solarized.setup', function() assert.True(strings.italic) assert.True(comments.bold) end) + + test('styles.enabled', function() + local solarized = require 'solarized' + solarized.setup { + styles = { + enabled = false, + strings = { italic = true }, + comments = { bold = true }, + }, + } + vim.cmd 'colorscheme solarized' + + local strings = nvim_get_hl 'String' + local comments = nvim_get_hl 'Comment' + assert.Nil(strings.italic) + assert.Nil(comments.bold) + end) + + test('nil config', function() + local solarized = require 'solarized' + solarized.setup() + vim.cmd 'colorscheme solarized' + end) end)