forked from CopilotC-Nvim/CopilotChat.nvim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions_spec.lua
More file actions
62 lines (58 loc) · 2.26 KB
/
functions_spec.lua
File metadata and controls
62 lines (58 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
local functions = require('CopilotChat.functions')
describe('CopilotChat.functions', function()
describe('uri_to_url', function()
it('replaces parameters in uri template', function()
local uri = 'file://{path}'
local input = { path = '/tmp/test.txt' }
assert.equals('file:///tmp/test.txt', functions.uri_to_url(uri, input))
end)
it('leaves missing params empty', function()
local uri = 'file://{path}/{id}'
local input = { path = '/tmp' }
assert.equals('file:///tmp/', functions.uri_to_url(uri, input))
end)
end)
describe('match_uri', function()
it('matches uri and extracts parameters', function()
local uri = 'file:///tmp/test.txt'
local pattern = 'file://{path}'
local result = functions.match_uri(uri, pattern)
assert.are.same({ path = '/tmp/test.txt' }, result)
end)
it('returns nil for non-matching uri', function()
assert.is_nil(functions.match_uri('abc', 'file://{path}'))
end)
it('returns empty table for exact match with no params', function()
assert.are.same({}, functions.match_uri('abc', 'abc'))
end)
end)
describe('parse_schema', function()
it('returns schema if present', function()
local fn = { schema = { type = 'object', properties = { foo = { type = 'string' } } } }
assert.equals(fn.schema, functions.parse_schema(fn))
end)
it('generates schema from uri if missing', function()
local fn = { uri = 'file://{path}/{id}' }
local schema = functions.parse_schema(fn)
assert.are.same({
type = 'object',
properties = { path = { type = 'string' }, id = { type = 'string' } },
required = { 'path', 'id' },
}, schema)
end)
end)
describe('parse_input', function()
it('parses input string into table', function()
local schema = { properties = { a = {}, b = {} }, required = { 'a', 'b' } }
local input = 'foo;;bar'
assert.are.same({ a = 'foo', b = 'bar' }, functions.parse_input(input, schema))
end)
it('returns input if already table', function()
local input = { a = 1 }
assert.equals(input, functions.parse_input(input))
end)
it('returns empty table if no schema', function()
assert.are.same({}, functions.parse_input('foo'))
end)
end)
end)