Mercurial > vim
annotate src/testdir/test_flatten.vim @ 26662:4b23672d1f0e v8.2.3860
patch 8.2.3860: Vim9: codecov struggles with the file size
Commit: https://github.com/vim/vim/commit/dc7c366f3aae65ee691010b08f37acfb26e0742b
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Dec 20 15:04:29 2021 +0000
patch 8.2.3860: Vim9: codecov struggles with the file size
Problem: Vim9: codecov struggles with the file size.
Solution: Split vim9compile.c into four files.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 20 Dec 2021 16:15:03 +0100 |
parents | 485c7c4afeb7 |
children | 18319c0c36f9 |
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 |
26211
485c7c4afeb7
patch 8.2.3637: typos in test files
Bram Moolenaar <Bram@vim.org>
parents:
23816
diff
changeset
|
57 " Tests for checking circular reference list can be flattened. |
20766
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 |
23816
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
84 func Test_flattennew() |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
85 let l = [1, [2, [3, 4]], 5] |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
86 call assert_equal([1, 2, 3, 4, 5], flattennew(l)) |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
87 call assert_equal([1, [2, [3, 4]], 5], l) |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
88 |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
89 call assert_equal([1, 2, [3, 4], 5], flattennew(l, 1)) |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
90 call assert_equal([1, [2, [3, 4]], 5], l) |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
91 endfunc |
525c9e218c69
patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
92 |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
20766
diff
changeset
|
93 " vim: shiftwidth=2 sts=2 expandtab |