Skip to content

Commit

Permalink
test: add tests for is_table() and is_list()
Browse files Browse the repository at this point in the history
  • Loading branch information
Padmamanickam authored and wincent committed Oct 21, 2022
1 parent 1b9d9b1 commit 181045f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lua/wincent/commandt/private/test/is_list.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- SPDX-FileCopyrightText: Copyright 2022-present Greg Hurrell and contributors.
-- SPDX-License-Identifier: BSD-2-Clause

local is_list = require('wincent.commandt.private.is_list')

describe('is_list()', function()
it('identifies an empty list', function()
expect(is_list({})).to_be(true)
end)

it('identifies a non-empty list', function()
expect(is_list({ 1, 2, 3 })).to_be(true)
expect(is_list({ 'foo', 'bar', 'baz' })).to_be(true)
end)

it('does not identify a non-empty table as a list', function()
expect(is_list({ foo = true })).to_be(false)
end)

it('does not identify other types as lists', function()
expect(is_list(0)).to_be(false)
expect(is_list('hello')).to_be(false)
expect(is_list(false)).to_be(false)
expect(is_list(nil)).to_be(false)
expect(is_list(true)).to_be(false)
end)
end)
27 changes: 27 additions & 0 deletions lua/wincent/commandt/private/test/is_table.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- SPDX-FileCopyrightText: Copyright 2022-present Greg Hurrell and contributors.
-- SPDX-License-Identifier: BSD-2-Clause

local is_table = require('wincent.commandt.private.is_table')

describe('is_table()', function()
it('identifies an empty table', function()
expect(is_table({})).to_be(true)
end)

it('identifies a non-empty table', function()
expect(is_table({ foo = 'bar' })).to_be(true)
end)

it('does not identify a list as a table', function()
expect(is_table({ 1, 2, 3 })).to_be(false)
expect(is_table({ 'foo', 'bar', 'baz' })).to_be(false)
end)

it('does not identify other types as tables', function()
expect(is_table(0)).to_be(false)
expect(is_table('hello')).to_be(false)
expect(is_table(false)).to_be(false)
expect(is_table(nil)).to_be(false)
expect(is_table(true)).to_be(false)
end)
end)

0 comments on commit 181045f

Please sign in to comment.