Mercurial > vim
annotate src/testdir/test_flatten.vim @ 23446:b1dbbc81a011 v8.2.2266
patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Commit: https://github.com/vim/vim/commit/e7a73e07625b64a40671a0007ad38a34cbe9d1ee
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jan 1 19:17:55 2021 +0100
patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Problem: Vim9: it can be hard to see where white space is missing.
Solution: Mention the text where the error was seen. (closes https://github.com/vim/vim/issues/7580)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 01 Jan 2021 19:30:04 +0100 |
parents | 08940efa6b4e |
children | 525c9e218c69 |
rev | line source |
---|---|
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " Test for flatting list. |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
20766
diff
changeset
|
2 |
20766
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 func Test_flatten() |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 call assert_fails('call flatten(1)', 'E686:') |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 call assert_fails('call flatten({})', 'E686:') |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 call assert_fails('call flatten("string")', 'E686:') |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 call assert_fails('call flatten([], [])', 'E745:') |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 call assert_fails('call flatten([], -1)', 'E900: maxdepth') |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 call assert_equal([], flatten([])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 call assert_equal([], flatten([[]])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 call assert_equal([], flatten([[[]]])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 call assert_equal([1, 2, 3], flatten([1, 2, 3])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 call assert_equal([1, 2, 3], flatten([[1], 2, 3])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 call assert_equal([1, 2, 3], flatten([1, [2], 3])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 call assert_equal([1, 2, 3], flatten([1, 2, [3]])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 call assert_equal([1, 2, 3], flatten([[1], [2], 3])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 call assert_equal([1, 2, 3], flatten([1, [2], [3]])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 call assert_equal([1, 2, 3], flatten([[1], 2, [3]])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 call assert_equal([1, 2, 3], flatten([[1], [2], [3]])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 call assert_equal([1, 2, 3], flatten([[1, 2, 3], []])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 call assert_equal([1, 2, 3], flatten([[], [1, 2, 3]])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 call assert_equal([1, 2, 3], flatten([[1, 2], [], [3]])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 call assert_equal([1, 2, 3], flatten([[], [1, 2, 3], []])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 call assert_equal([1, 2, 3, 4], flatten(range(1, 4))) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 " example in the help |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 call assert_equal([1, 2, 3, 4, 5], flatten([1, [2, [3, 4]], 5])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 call assert_equal([1, 2, [3, 4], 5], flatten([1, [2, [3, 4]], 5], 1)) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 call assert_equal([0, [1], 2, [3], 4], flatten([[0, [1]], 2, [[3], 4]], 1)) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 call assert_equal([1, 2, 3], flatten([[[[1]]], [2], [3]], 3)) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 call assert_equal([[1], [2], [3]], flatten([[[1], [2], [3]]], 1)) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 call assert_equal([[1]], flatten([[1]], 0)) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 " Make it flatten if the given maxdepth is larger than actual depth. |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 call assert_equal([1, 2, 3], flatten([[1, 2, 3]], 1)) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 call assert_equal([1, 2, 3], flatten([[1, 2, 3]], 2)) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 let l:list = [[1], [2], [3]] |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 call assert_equal([1, 2, 3], flatten(l:list)) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 call assert_equal([1, 2, 3], l:list) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 " Tests for checking reference counter works well. |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 let l:x = {'foo': 'bar'} |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 call assert_equal([1, 2, l:x, 3], flatten([1, [2, l:x], 3])) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 call test_garbagecollect_now() |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 call assert_equal('bar', l:x.foo) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 let l:list = [[1], [2], [3]] |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 call assert_equal([1, 2, 3], flatten(l:list)) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 call test_garbagecollect_now() |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 call assert_equal([1, 2, 3], l:list) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 " Tests for checking circular reference list can be flatten. |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 let l:x = [1] |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 let l:y = [x] |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 let l:z = flatten(l:y) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 call assert_equal([1], l:z) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 call test_garbagecollect_now() |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 let l:x[0] = 2 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 call assert_equal([2], l:x) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 call assert_equal([1], l:z) " NOTE: primitive types are copied. |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 call assert_equal([1], l:y) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 let l:x = [2] |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 let l:y = [1, [l:x], 3] " [1, [[2]], 3] |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 let l:z = flatten(l:y, 1) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 call assert_equal([1, [2], 3], l:z) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 let l:x[0] = 9 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 call assert_equal([1, [9], 3], l:z) " Reference to l:x is kept. |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 call assert_equal([1, [9], 3], l:y) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 let l:x = [1] |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 let l:y = [2] |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 call add(x, y) " l:x = [1, [2]] |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 call add(y, x) " l:y = [2, [1, [...]]] |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 call assert_equal([1, 2, 1, 2], flatten(l:x, 2)) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 call assert_equal([2, l:x], l:y) |
821925509d8c
patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 endfunc |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
20766
diff
changeset
|
83 |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
20766
diff
changeset
|
84 " vim: shiftwidth=2 sts=2 expandtab |