summaryrefslogtreecommitdiff
path: root/src/testdir/test_method.vim
blob: e0631e638ded299068c7cdefc1cf5bee2bbc7844 (plain)
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
" Tests for ->method()

func Test_list()
  let l = [1, 2, 3]
  call assert_equal([1, 2, 3, 4], [1, 2, 3]->add(4))
  call assert_equal(l, l->copy())
  call assert_equal(1, l->count(2))
  call assert_false(l->empty())
  call assert_true([]->empty())
  call assert_equal([1, 2, 3, 4, 5], [1, 2, 3]->extend([4, 5]))
  call assert_equal([1, 3], [1, 2, 3]->filter('v:val != 2'))
  call assert_equal(2, l->get(1))
  call assert_equal(1, l->index(2))
  call assert_equal([0, 1, 2, 3], [1, 2, 3]->insert(0))
  call assert_fails('let x = l->items()', 'E715:')
  call assert_equal('1 2 3', l->join())
  call assert_fails('let x = l->keys()', 'E715:')
  call assert_equal(3, l->len())
  call assert_equal([2, 3, 4], [1, 2, 3]->map('v:val + 1'))
  call assert_equal(3, l->max())
  call assert_equal(1, l->min())
  call assert_equal(2, [1, 2, 3]->remove(1))
  call assert_equal([1, 2, 3, 1, 2, 3], l->repeat(2))
  call assert_equal([3, 2, 1], [1, 2, 3]->reverse())
  call assert_equal([1, 2, 3, 4], [4, 2, 3, 1]->sort())
  call assert_equal('[1, 2, 3]', l->string())
  call assert_equal(v:t_list, l->type())
  call assert_equal([1, 2, 3], [1, 1, 2, 3, 3]->uniq())
  call assert_fails('let x = l->values()', 'E715:')
endfunc

func Test_dict()
  let d = #{one: 1, two: 2, three: 3}

  call assert_equal(d, d->copy())
  call assert_equal(1, d->count(2))
  call assert_false(d->empty())
  call assert_true({}->empty())
  call assert_equal(#{one: 1, two: 2, three: 3, four: 4}, d->extend(#{four: 4}))
  call assert_equal(#{one: 1, two: 2, three: 3}, d->filter('v:val != 4'))
  call assert_equal(2, d->get('two'))
  call assert_fails("let x = d->index(2)", 'E897:')
  call assert_fails("let x = d->insert(0)", 'E899:')
  call assert_equal([['one', 1], ['two', 2], ['three', 3]], d->items())
  call assert_fails("let x = d->join()", 'E714:')
  call assert_equal(['one', 'two', 'three'], d->keys())
  call assert_equal(3, d->len())
  call assert_equal(#{one: 2, two: 3, three: 4}, d->map('v:val + 1'))
  call assert_equal(#{one: 1, two: 2, three: 3}, d->map('v:val - 1'))
  call assert_equal(3, d->max())
  call assert_equal(1, d->min())
  call assert_equal(2, d->remove("two"))
  let d.two = 2
  call assert_fails('let x = d->repeat(2)', 'E731:')
  call assert_fails('let x = d->reverse()', 'E899:')
  call assert_fails('let x = d->sort()', 'E686:')
  call assert_equal("{'one': 1, 'two': 2, 'three': 3}", d->string())
  call assert_equal(v:t_dict, d->type())
  call assert_fails('let x = d->uniq()', 'E686:')
  call assert_equal([1, 2, 3], d->values())
endfunc