" Tests for the List and Dict types
scriptencoding utf-8
import './vim9.vim' as v9
func TearDown()
" Run garbage collection after every test
call test_garbagecollect_now()
endfunc
" Tests for List type
" List creation
func Test_list_create()
" Creating List directly with different types
let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
call assert_equal("[1, 'as''d', [1, 2, function('strlen')], {'a': 1}]", string(l))
call assert_equal({'a' : 1}, l[-1])
call assert_equal(1, l[-4])
let x = 10
try
let x = l[-5]
catch
call assert_match('E684:', v:exception)
endtry
call assert_equal(10, x)
endfunc
" This was allowed in legacy Vim script
let s:list_with_spaces = [1 , 2 , 3]
" List slices
func Test_list_slice()
let l = [1, 'as''d', [1, 2, function("strlen")], {'a': 1},]
call assert_equal([1, 'as''d', [1, 2, function('strlen')], {'a': 1}], l[:])
call assert_equal(['as''d', [1, 2, function('strlen')], {'a': 1}], l[1:])
call assert_equal([1, 'as''d', [1, 2, function('strlen')]], l[:-2])
call assert_equal([1, 'as''d', [1, 2, function('strlen')], {'a': 1}], l[0:8])
call assert_equal([], l[8:-1])
call assert_equal([], l[0:-10])
" perform an operation on a list slice
let l = [1, 2, 3]
let l[:1] += [1, 2]
let l[2:] -= [1]
call assert_equal([