diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-05-02 15:37:12 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-05-02 16:24:58 +0530 |
| commit | 8f974223f4318ed9a0d3035b4c11d0f5b015efec (patch) | |
| tree | 028782193fa5c3cfa20a32b83b8f22e948c3ed9d /spec/lua/utils_spec.lua | |
| parent | 398b1a4b398324311b6e0f15d2e4ede5ad8500ff (diff) | |
| download | null-browser-8f974223f4318ed9a0d3035b4c11d0f5b015efec.tar.gz null-browser-8f974223f4318ed9a0d3035b4c11d0f5b015efec.zip | |
Refactor dmenu to be instantiable + add luassert for assertions
Diffstat (limited to 'spec/lua/utils_spec.lua')
| -rw-r--r-- | spec/lua/utils_spec.lua | 60 |
1 files changed, 30 insertions, 30 deletions
diff --git a/spec/lua/utils_spec.lua b/spec/lua/utils_spec.lua index 5ea2d78..de90ef5 100644 --- a/spec/lua/utils_spec.lua +++ b/spec/lua/utils_spec.lua @@ -1,36 +1,36 @@ describe('web.utils.string_trim', function() it('trims whitespace from the start and end of string', function() - expect(web.utils.string_trim(' hello')).to_equal 'hello' - expect(web.utils.string_trim('hello ')).to_equal 'hello' - expect(web.utils.string_trim(' hello ')).to_equal 'hello' + assert.are.equal(web.utils.string_trim(' hello'), 'hello') + assert.are.equal(web.utils.string_trim('hello '), 'hello') + assert.are.equal(web.utils.string_trim(' hello '), 'hello') end) end) describe('web.utils.table_merge', function() context('when both tables have integer keys', function() it('returns merged table', function() - expect(web.utils.table_merge({ a = 0 }, { b = 1 }, { c = 2 })) - .to_equal { a = 0, b = 1, c = 2 } + local result = web.utils.table_merge({ a = 0 }, { b = 1 }, { c = 2 }) + assert.are.same(result, { a = 0, b = 1, c = 2 }) end) end) context('when both tables unique keys', function() it('returns merged table', function() - expect(web.utils.table_merge({ a = 0 }, { b = 1 }, { c = 2 })) - .to_equal { a = 0, b = 1, c = 2 } + local result = web.utils.table_merge({ a = 0 }, { b = 1 }, { c = 2 }) + assert.are.same(result, { a = 0, b = 1, c = 2 }) end) end) context('when both tables have a key in common', function() it('returns merged table', function() - expect(web.utils.table_merge({ foo = 1, a = 0 }, { foo = 2 }, { foo = 3 })) - .to_equal { foo = 3, a = 0 } + local result = web.utils.table_merge({ foo = 1, a = 0 }, { foo = 2 }, { foo = 3 }) + assert.are.same(result, { foo = 3, a = 0 }) end) it('mutates the first table', function() local tbl = { foo = 1, a = 0 } web.utils.table_merge(tbl, { foo = 2 }) - expect(tbl).to_equal { foo = 2, a = 0 } + assert.are.same(tbl, { foo = 2, a = 0 }) end) end) end) @@ -38,29 +38,29 @@ end) describe('web.utils.equals', function() context('when values are primitives', function() it('checks for equality', function() - expect(web.utils.equals(1, 1)).to_be_true() - expect(web.utils.equals(3, 1)).to_be_false() - expect(web.utils.equals(nil, 1)).to_be_false() - expect(web.utils.equals(1, nil)).to_be_false() - expect(web.utils.equals(nil, nil)).to_be_true() + assert.is_true(web.utils.equals(1, 1)) + assert.is_false(web.utils.equals(3, 1)) + assert.is_false(web.utils.equals(nil, 1)) + assert.is_false(web.utils.equals(1, nil)) + assert.is_true(web.utils.equals(nil, nil)) end) end) context('when values are tables', function() it('checks for equality', function() - expect(web.utils.equals({}, 0)).to_be_false() - expect(web.utils.equals(0, {})).to_be_false() - expect(web.utils.equals({}, {})).to_be_true() - expect(web.utils.equals({ a = 1 }, { a = 1 })).to_be_true() - expect(web.utils.equals({ a = 2 }, { a = 1 })).to_be_false() - expect(web.utils.equals({}, { a = 1 })).to_be_false() - expect(web.utils.equals({ a = 1 }, {})).to_be_false() + assert.is_false(web.utils.equals({}, 0)) + assert.is_false(web.utils.equals(0, {})) + assert.is_true(web.utils.equals({}, {})) + assert.is_true(web.utils.equals({ a = 1 }, { a = 1 })) + assert.is_false(web.utils.equals({ a = 2 }, { a = 1 })) + assert.is_false(web.utils.equals({}, { a = 1 })) + assert.is_false(web.utils.equals({ a = 1 }, {})) end) context('when tables are deeply nested', function() it('checks for equality', function() - expect(web.utils.equals({ a = { b = 2 } }, { a = { b = 2 } })).to_be_true() - expect(web.utils.equals({ a = { b = 3 } }, { a = { b = 2 } })).to_be_false() + assert.is_true(web.utils.equals({ a = { b = 2 } }, { a = { b = 2 } })) + assert.is_false(web.utils.equals({ a = { b = 3 } }, { a = { b = 2 } })) end) end) end) @@ -70,21 +70,21 @@ describe('web.utils.table_keys', function() it('returns keys of given table', function() local result = web.utils.table_keys({ a = 1, b = 2 }) table.sort(result) -- Sort for deterministic ordering - expect(result).to_equal({ 'a', 'b' }) + assert.are.same(result, { 'a', 'b' }) end) context('with index keys', function() it('returns indexes of given table', function() - expect(web.utils.table_keys({ 'hello', 'world' })).to_equal({ 1, 2 }) - expect(web.utils.table_keys({ 'hello', a = 1, 'world' })).to_equal({ 1, 2, 'a' }) + assert.are.same(web.utils.table_keys({ 'hello', 'world' }), { 1, 2 }) + assert.are.same(web.utils.table_keys({ 'hello', a = 1, 'world' }), { 1, 2, 'a' }) end) end) end) describe('web.inspect', function() it('returns string representation of value', function() - expect(web.inspect('hello')).to_equal '"hello"' - expect(web.inspect(5)).to_equal '5' - expect(web.inspect({ a = '200', b = 5 })).to_equal '{\n a = "200",\n b = 5\n}' + assert.are.equal(web.inspect('hello'), '"hello"') + assert.are.equal(web.inspect(5), '5') + assert.are.equal(web.inspect({ a = '200', b = 5 }), '{\n a = "200",\n b = 5\n}') end) end) |
