Files
hanzo.vim/test/vim/test_config.vader

178 lines
5.3 KiB
Plaintext

Before:
Save g:neural
Save g:time
unlet! g:neural
After:
unlet! g:time
Restore
Execute(The default keybind setting should be correct):
call neural#config#Load()
AssertEqual v:true, get(g:neural, 'set_default_keybinds')
Execute(The default prompt settings should be correct):
call neural#config#Load()
call filter(g:neural.ui, {key -> key =~ 'prompt'})
AssertEqual {'prompt_enabled': v:true, 'prompt_icon': '🗲'}, g:neural.ui
Execute(The default animated sign settings should be correct):
call neural#config#Load()
call filter(g:neural.ui, {key -> key =~ 'animated'})
AssertEqual {'animated_sign_enabled': v:true}, g:neural.ui
Execute(The default echo settings should be correct):
call neural#config#Load()
call filter(g:neural.ui, {key -> key =~ 'echo'})
AssertEqual {'echo_enabled': v:true}, g:neural.ui
Execute(The default openai settings should be correct):
let g:neural = {'providers': [{'type': 'openai'}]}
call neural#config#Load()
AssertEqual
\ [{
\ 'type': 'openai',
\ 'url': 'https://api.openai.com',
\ 'api_key': '',
\ 'frequency_penalty': 0.1,
\ 'max_tokens': 1024,
\ 'model': 'gpt-3.5-turbo-instruct',
\ 'use_chat_api': v:false,
\ 'presence_penalty': 0.1,
\ 'temperature': 0.2,
\ 'top_p': 1,
\ }],
\ get(g:neural, 'providers')
Execute(The default neural buffer settings should be correct):
call neural#config#Load()
" call filter(g:neural.buffer, {key -> key =~ 'completion'})
"
" AssertEqual {'echo_enabled': v:true}, g:neural.ui
AssertEqual
\ {
\ 'completion_key': '<C-CR>',
\ 'create_mode': 'vertical',
\ 'wrap': v:true,
\ },
\ get(g:neural, 'buffer')
Execute(Settings should be merged correctly):
for s:i in range(2)
if s:i == 0
" Try the method of setting g:neural the first time.
let g:neural = {
\ 'ui': {'echo_enabled': v:true},
\ 'providers': [
\ {'type': 'openai', 'api_key': 'mykey'},
\ ],
\}
else
" Try calling Set with no global like Lua will the second time.
call neural#config#Set(remove(g:, 'neural'))
endif
" The results should be the same in each case.
call neural#config#Load()
call filter(g:neural, {key -> key =~ '\v^ui$|^providers$'})
call filter(g:neural.ui, {key -> key is# 'echo_enabled'})
AssertEqual
\ {
\ 'ui': {'echo_enabled': v:true},
\ 'providers': [{
\ 'type': 'openai',
\ 'url': 'https://api.openai.com',
\ 'api_key': 'mykey',
\ 'frequency_penalty': 0.1,
\ 'max_tokens': 1024,
\ 'model': 'gpt-3.5-turbo-instruct',
\ 'use_chat_api': v:false,
\ 'presence_penalty': 0.1,
\ 'temperature': 0.2,
\ 'top_p': 1,
\ }],
\ },
\ g:neural
endfor
Execute(Settings should load quickly after the first merge):
let g:time = localtime()
for s:i in range(1000)
call neural#config#Load()
endfor
Assert localtime() - g:time <= 2
Execute(Settings should update when g:neural is changed):
call neural#config#Load()
let g:neural = {'providers': [{'type': 'openai', 'api_key': 'mykey'}]}
call neural#config#Load()
AssertEqual 1, len(g:neural.providers)
AssertEqual 'mykey', g:neural.providers[0].api_key
AssertEqual 0.2, g:neural.providers[0].temperature
Execute(Settings migrated from an old configuration with a default selection should work):
let g:neural = {'source': {'openai': {'api_key': 'mykey'}}}
call neural#config#Load()
call map(g:neural.providers, {_, val -> filter(val, {key -> key =~ '\v^api_key$|^type|use_chat_api$'})})
AssertEqual
\ [{'type': 'openai', 'api_key': 'mykey', 'use_chat_api': v:false}],
\ g:neural.providers
Assert !has_key(g:neural, 'selected')
Assert !has_key(g:neural, 'source')
Execute(Settings migrated from an old configuration with an openai selection should work):
let g:neural = {
\ 'source': {
\ 'openai': {'api_key': 'mykey'},
\ 'chatgpt': {'api_key': 'otherkey'}
\ },
\ 'selected': 'openai'
\}
call neural#config#Load()
call map(g:neural.providers, {_, val -> filter(val, {key -> key =~ '\v^api_key$|^type|use_chat_api$'})})
AssertEqual
\ [{'type': 'openai', 'api_key': 'mykey', 'use_chat_api': v:false}],
\ g:neural.providers
Assert !has_key(g:neural, 'selected')
Assert !has_key(g:neural, 'source')
Execute(Settings migrated from an old configuration with chatgpt should work):
let g:neural = {'source': {'chatgpt': {'api_key': 'mykey'}}, 'selected': 'chatgpt'}
call neural#config#Load()
call map(g:neural.providers, {_, val -> filter(val, {key -> key =~ '\v^api_key$|^type|use_chat_api$'})})
AssertEqual
\ [{'type': 'chatgpt', 'api_key': 'mykey', 'use_chat_api': v:true}],
\ g:neural.providers
Assert !has_key(g:neural, 'selected')
Assert !has_key(g:neural, 'source')
Execute(Settings migrated from an old configuration with chatgpt and the key set once for openai should work):
let g:neural = {
\ 'source': {
\ 'openai': {'api_key': 'mykey'},
\ },
\ 'selected': 'chatgpt'
\}
call neural#config#Load()
call map(g:neural.providers, {_, val -> filter(val, {key -> key =~ '\v^api_key$|^type|use_chat_api$'})})
AssertEqual
\ [{'type': 'chatgpt', 'api_key': 'mykey', 'use_chat_api': v:true}],
\ g:neural.providers
Assert !has_key(g:neural, 'selected')
Assert !has_key(g:neural, 'source')