annotate src/testdir/test_flatten.vim @ 32679:1b9a29f7fe86 v9.0.1670

patch 9.0.1670: resetting local option to global value is inconsistent Commit: https://github.com/vim/vim/commit/bf5f189e449d6517239b79804d7a422a46946838 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jun 27 21:51:07 2023 +0100 patch 9.0.1670: resetting local option to global value is inconsistent Problem: Resetting local option to global value is inconsistent. Solution: Handle "<" specifically for 'scrolloff' and 'sidescrolloff'. (closes #12594)
author Bram Moolenaar <Bram@vim.org>
date Tue, 27 Jun 2023 23:00:04 +0200
parents 18319c0c36f9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)
28203
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
82
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
83 let l4 = [ 1, [ 11, [ 101, [ 1001 ] ] ] ]
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
84 call assert_equal(l4, flatten(deepcopy(l4), 0))
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
85 call assert_equal([1, 11, [101, [1001]]], flatten(deepcopy(l4), 1))
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
86 call assert_equal([1, 11, 101, [1001]], flatten(deepcopy(l4), 2))
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
87 call assert_equal([1, 11, 101, 1001], flatten(deepcopy(l4), 3))
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
88 call assert_equal([1, 11, 101, 1001], flatten(deepcopy(l4), 4))
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
89 call assert_equal([1, 11, 101, 1001], flatten(deepcopy(l4)))
20766
821925509d8c patch 8.2.0935: flattening a list with existing code is slow
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 endfunc
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 20766
diff changeset
91
23816
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
92 func Test_flattennew()
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
93 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
94 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
95 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
96
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
97 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
98 call assert_equal([1, [2, [3, 4]], 5], l)
28203
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
99
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
100 let l4 = [ 1, [ 11, [ 101, [ 1001 ] ] ] ]
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
101 call assert_equal(l4, flatten(deepcopy(l4), 0))
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
102 call assert_equal([1, 11, [101, [1001]]], flattennew(l4, 1))
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
103 call assert_equal([1, 11, 101, [1001]], flattennew(l4, 2))
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
104 call assert_equal([1, 11, 101, 1001], flattennew(l4, 3))
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
105 call assert_equal([1, 11, 101, 1001], flattennew(l4, 4))
18319c0c36f9 patch 8.2.4627: flatten() does not use maxdepth correctly
Bram Moolenaar <Bram@vim.org>
parents: 26211
diff changeset
106 call assert_equal([1, 11, 101, 1001], flattennew(l4))
23816
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
107 endfunc
525c9e218c69 patch 8.2.2449: Vim9: flatten() always changes the list type
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
108
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 20766
diff changeset
109 " vim: shiftwidth=2 sts=2 expandtab