5
5
from vimdoc import error
6
6
from vimdoc import module
7
7
8
- class TestVimPlugin (unittest .TestCase ):
8
+ class TestVimModule (unittest .TestCase ):
9
9
10
10
def test_section (self ):
11
11
plugin = module .VimPlugin ('myplugin' )
12
12
main_module = module .Module ('myplugin' , plugin )
13
13
intro = Block (vimdoc .SECTION )
14
14
intro .Local (name = 'Introduction' , id = 'intro' )
15
15
main_module .Merge (intro )
16
- self .assertEquals (list (main_module .Chunks ()), [intro ])
16
+ main_module .Close ()
17
+ self .assertEqual ([intro ], list (main_module .Chunks ()))
17
18
18
19
def test_duplicate_section (self ):
19
20
plugin = module .VimPlugin ('myplugin' )
@@ -25,4 +26,67 @@ def test_duplicate_section(self):
25
26
intro2 .Local (name = 'Intro' , id = 'intro' )
26
27
with self .assertRaises (error .DuplicateSection ) as cm :
27
28
main_module .Merge (intro2 )
28
- self .assertEquals (cm .exception .args , ('Duplicate section intro defined.' ,))
29
+ self .assertEqual (('Duplicate section intro defined.' ,), cm .exception .args )
30
+
31
+ def test_default_section_ordering (self ):
32
+ """Sections should be ordered according to documented built-in ordering."""
33
+ plugin = module .VimPlugin ('myplugin' )
34
+ main_module = module .Module ('myplugin' , plugin )
35
+ intro = Block (vimdoc .SECTION )
36
+ intro .Local (name = 'Introduction' , id = 'intro' )
37
+ commands = Block (vimdoc .SECTION )
38
+ commands .Local (name = 'Commands' , id = 'commands' )
39
+ about = Block (vimdoc .SECTION )
40
+ about .Local (name = 'About' , id = 'about' )
41
+ # Merge in arbitrary order.
42
+ main_module .Merge (commands )
43
+ main_module .Merge (about )
44
+ main_module .Merge (intro )
45
+ main_module .Close ()
46
+ self .assertEqual ([intro , commands , about ], list (main_module .Chunks ()))
47
+
48
+ def test_manual_section_ordering (self ):
49
+ """Sections should be ordered according to explicitly configured order."""
50
+ plugin = module .VimPlugin ('myplugin' )
51
+ main_module = module .Module ('myplugin' , plugin )
52
+ intro = Block (vimdoc .SECTION )
53
+ intro .Local (name = 'Introduction' , id = 'intro' )
54
+ # Configure explicit order.
55
+ intro .Global (order = ['commands' , 'about' , 'intro' ])
56
+ commands = Block (vimdoc .SECTION )
57
+ commands .Local (name = 'Commands' , id = 'commands' )
58
+ about = Block (vimdoc .SECTION )
59
+ about .Local (name = 'About' , id = 'about' )
60
+ # Merge in arbitrary order.
61
+ main_module .Merge (commands )
62
+ main_module .Merge (about )
63
+ main_module .Merge (intro )
64
+ main_module .Close ()
65
+ self .assertEqual ([commands , about , intro ], list (main_module .Chunks ()))
66
+
67
+ def test_partial_ordering (self ):
68
+ """Always respect explicit order and prefer built-in ordering.
69
+
70
+ Undeclared built-in sections will be inserted into explicit order according
71
+ to default built-in ordering. The about section should come after custom
72
+ sections unless explicitly ordered."""
73
+ plugin = module .VimPlugin ('myplugin' )
74
+ main_module = module .Module ('myplugin' , plugin )
75
+ intro = Block (vimdoc .SECTION )
76
+ intro .Local (name = 'Introduction' , id = 'intro' )
77
+ # Configure explicit order.
78
+ intro .Global (order = ['custom1' , 'intro' , 'custom2' ])
79
+ commands = Block (vimdoc .SECTION )
80
+ commands .Local (name = 'Commands' , id = 'commands' )
81
+ about = Block (vimdoc .SECTION )
82
+ about .Local (name = 'About' , id = 'about' )
83
+ custom1 = Block (vimdoc .SECTION )
84
+ custom1 .Local (name = 'Custom1' , id = 'custom1' )
85
+ custom2 = Block (vimdoc .SECTION )
86
+ custom2 .Local (name = 'Custom2' , id = 'custom2' )
87
+ # Merge in arbitrary order.
88
+ for section in [commands , custom2 , about , intro , custom1 ]:
89
+ main_module .Merge (section )
90
+ main_module .Close ()
91
+ self .assertEqual ([custom1 , intro , commands , custom2 , about ],
92
+ list (main_module .Chunks ()))
0 commit comments