mirror of
https://github.com/neovim/neovim.git
synced 2025-12-07 07:02:46 +00:00
garray: add unit tests for ga_concat_strings_sep
This commit is contained in:
committed by
Thiago de Arruda
parent
104000eff6
commit
b737b27e6a
@@ -55,6 +55,8 @@ ga_append = (garr, b) ->
|
|||||||
garray.ga_append(garr, b)
|
garray.ga_append(garr, b)
|
||||||
ga_concat_strings = (garr) ->
|
ga_concat_strings = (garr) ->
|
||||||
internalize(garray.ga_concat_strings(garr))
|
internalize(garray.ga_concat_strings(garr))
|
||||||
|
ga_concat_strings_sep = (garr, sep) ->
|
||||||
|
internalize(garray.ga_concat_strings_sep(garr, to_cstr(sep)))
|
||||||
ga_remove_duplicate_strings = (garr) ->
|
ga_remove_duplicate_strings = (garr) ->
|
||||||
garray.ga_remove_duplicate_strings(garr)
|
garray.ga_remove_duplicate_strings(garr)
|
||||||
|
|
||||||
@@ -236,16 +238,26 @@ describe 'garray', ->
|
|||||||
result = ffi.string(ga_data_as_bytes(garr))
|
result = ffi.string(ga_data_as_bytes(garr))
|
||||||
eq string.rep(str, loop), result
|
eq string.rep(str, loop), result
|
||||||
|
|
||||||
|
test_concat_fn = (input, fn, sep) ->
|
||||||
|
garr = new_string_garray()
|
||||||
|
ga_append_strings(garr, unpack(input))
|
||||||
|
if sep == nil
|
||||||
|
eq table.concat(input, ','), fn(garr)
|
||||||
|
else
|
||||||
|
eq table.concat(input, sep), fn(garr, sep)
|
||||||
|
|
||||||
describe 'ga_concat_strings', ->
|
describe 'ga_concat_strings', ->
|
||||||
it 'returns an empty string when concatenating an empty array', ->
|
it 'returns an empty string when concatenating an empty array', ->
|
||||||
garr = new_string_garray()
|
test_concat_fn({}, ga_concat_strings)
|
||||||
eq '', ga_concat_strings(garr)
|
|
||||||
|
|
||||||
it 'can concatenate a non-empty array', ->
|
it 'can concatenate a non-empty array', ->
|
||||||
garr = new_string_garray()
|
test_concat_fn({'oh', 'my', 'neovim'}, ga_concat_strings)
|
||||||
input = {'oh', 'my', 'neovim'}
|
|
||||||
ga_append_strings(garr, unpack(input))
|
describe 'ga_concat_strings_sep', ->
|
||||||
eq table.concat(input, ','), ga_concat_strings(garr)
|
it 'returns an empty string when concatenating an empty array', ->
|
||||||
|
test_concat_fn({}, ga_concat_strings_sep, '---')
|
||||||
|
it 'can concatenate a non-empty array', ->
|
||||||
|
sep = '-●●-'
|
||||||
|
test_concat_fn({'oh', 'my', 'neovim'}, ga_concat_strings_sep, sep)
|
||||||
|
|
||||||
describe 'ga_remove_duplicate_strings', ->
|
describe 'ga_remove_duplicate_strings', ->
|
||||||
it 'sorts and removes duplicate strings', ->
|
it 'sorts and removes duplicate strings', ->
|
||||||
|
|||||||
Reference in New Issue
Block a user