Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/class_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local class = require('CopilotChat.utils.class')

describe('CopilotChat.utils.class', function()
it('creates a simple class', function()
local Foo = class(function(self, x)
self.x = x
end)
local obj = Foo(42)
assert.equals(42, obj.x)
end)

it('supports init method', function()
local Bar = class(function(self, y)
self.y = y
end)
local obj = Bar.new(7)
assert.equals(7, obj.y)
obj:init(8)
assert.equals(8, obj.y)
end)

it('supports inheritance', function()
local Parent = class(function(self)
self.val = 1
end)
local Child = class(function(self)
self.val = 2
end, Parent)
local obj = Child()
assert.equals(2, obj.val)
assert.equals(Parent, getmetatable(Child).__index)
end)
end)
28 changes: 28 additions & 0 deletions tests/orderedmap_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
local orderedmap = require('CopilotChat.utils.orderedmap')

describe('CopilotChat.utils.orderedmap', function()
it('sets and gets values', function()
local map = orderedmap()
map:set('a', 1)
map:set('b', 2)
assert.equals(1, map:get('a'))
assert.equals(2, map:get('b'))
end)

it('preserves insertion order', function()
local map = orderedmap()
map:set('x', 10)
map:set('y', 20)
map:set('z', 30)
assert.are.same({ 'x', 'y', 'z' }, map:keys())
assert.are.same({ 10, 20, 30 }, map:values())
end)

it('overwrites value but not order', function()
local map = orderedmap()
map:set('a', 1)
map:set('a', 2)
assert.are.same({ 'a' }, map:keys())
assert.are.same({ 2 }, map:values())
end)
end)
23 changes: 23 additions & 0 deletions tests/stringbuffer_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
local stringbuffer = require('CopilotChat.utils.stringbuffer')

describe('CopilotChat.utils.stringbuffer', function()
it('concatenates strings with put', function()
local buf = stringbuffer()
buf:put('hello')
buf:put(' ')
buf:put('world')
assert.equals('hello world', buf:tostring())
end)

it('sets buffer with set', function()
local buf = stringbuffer()
buf:put('foo')
buf:set('bar')
assert.equals('bar', buf:tostring())
end)

it('handles empty buffer', function()
local buf = stringbuffer()
assert.equals('', buf:tostring())
end)
end)
Loading