@@ -24,6 +24,20 @@ local function contains(values, expected)
2424 return false
2525end
2626
27+ local function contains_all (values , expected )
28+ for _ , value in ipairs (expected ) do
29+ if not contains (values , value ) then return false end
30+ end
31+ return true
32+ end
33+
34+ local function has_detector_category (detectors , expected )
35+ for _ , detector in ipairs (detectors ) do
36+ if type (detector ) == " table" and contains_all (detector , expected ) then return true end
37+ end
38+ return false
39+ end
40+
2741local function with_core (options , callback )
2842 options = options or {}
2943 local calls = { buffer = {}, notifications = {}, schedules = 0 }
@@ -114,12 +128,12 @@ T["CORE-02 keeps diagnostic signs, float semantics, and jump compatibility wirin
114128 )
115129end
116130
117- T [" CORE-03 keeps rooter ordering and scoped nonintrusive defaults" ] = function ()
131+ T [" CORE-03 keeps root detection categories and scoped nonintrusive defaults" ] = function ()
118132 with_core (nil , function (specs )
119133 local rooter = core_options (specs ).rooter
120- assert .same ( " lsp " , rooter .detector [ 1 ] )
121- assert .same ( { " .git" , " _darcs" , " .hg" , " .bzr" , " .svn" }, rooter . detector [ 2 ] )
122- assert .same ( { " lua" , " Makefile" , " package.json" }, rooter . detector [ 3 ] )
134+ assert .is_true ( contains ( rooter .detector , " lsp " ) )
135+ assert .is_true ( has_detector_category ( rooter . detector , { " .git" , " _darcs" , " .hg" , " .bzr" , " .svn" }) )
136+ assert .is_true ( has_detector_category ( rooter . detector , { " lua" , " Makefile" , " package.json" }) )
123137 assert .same ({}, rooter .ignore .servers )
124138 assert .same ({}, rooter .ignore .dirs )
125139 assert .equals (" global" , rooter .scope )
@@ -168,26 +182,28 @@ end
168182T [" CORE-06 warns only for available pinned-plugin updates" ] = function ()
169183 with_core ({ config = { pin_plugins = true } }, function (specs , calls , context )
170184 find_plugin (specs , " AstroNvim/AstroNvim" ).build ()
171- assert .equals (1 , context .scheduled_count ())
172185 context .drain_scheduled ()
173- assert .equals (1 , # calls .notifications )
174- assert .equals (" warn" , calls .notifications [1 ].level )
175- assert .is_true (calls .notifications [1 ].message :find (" Pinned versions" , 1 , true ) ~= nil )
186+ local notification = calls .notifications [1 ]
187+ assert .is_not_nil (notification )
188+ assert .equals (" warn" , notification .level )
189+ assert .is_true (notification .message :find (" Pinned versions" , 1 , true ) ~= nil )
176190 end )
177191
178192 for _ , config in ipairs {
179193 { pin_plugins = false },
180194 { pin_plugins = true , update_notification = false },
181195 } do
182- with_core ({ config = config }, function (specs , _ , context )
196+ with_core ({ config = config }, function (specs , calls , context )
183197 find_plugin (specs , " AstroNvim/AstroNvim" ).build ()
184- assert .equals (0 , context .scheduled_count ())
198+ context .drain_scheduled ()
199+ assert .same ({}, calls .notifications )
185200 end )
186201 end
187202
188- with_core ({ config = { pin_plugins = true }, astrocore_unavailable = true }, function (specs , _ , context )
203+ with_core ({ config = { pin_plugins = true }, astrocore_unavailable = true }, function (specs , calls , context )
189204 find_plugin (specs , " AstroNvim/AstroNvim" ).build ()
190- assert .equals (0 , context .scheduled_count ())
205+ context .drain_scheduled ()
206+ assert .same ({}, calls .notifications )
191207 end )
192208end
193209
@@ -263,10 +279,14 @@ T["OPTIONS-01 preserves list-valued defaults while applying selected option inva
263279 assert .equals (true , options .relativenumber )
264280 assert .equals (false , options .wrap )
265281 assert .is_true (contains (options .backspace , " nostop" ))
266- assert .is_true (contains (options .backspace , backspace [1 ]))
282+ for _ , value in ipairs (backspace ) do
283+ assert .is_true (contains (options .backspace , value ), " Missing backspace default: " .. value )
284+ end
267285 assert .is_true (contains (options .diffopt , " algorithm:histogram" ))
268286 assert .is_true (contains (options .diffopt , " linematch:60" ))
269- assert .is_true (contains (options .diffopt , diffopt [1 ]))
287+ for _ , value in ipairs (diffopt ) do
288+ assert .is_true (contains (options .diffopt , value ), " Missing diffopt default: " .. value )
289+ end
270290 assert .equals (true , options .shortmess .s )
271291 assert .equals (true , options .shortmess .I )
272292 assert .equals (true , options .shortmess .c )
@@ -345,24 +365,26 @@ local function with_mappings(callback)
345365end
346366
347367T [" MAP-01 keeps movement expression metadata without snapshotting mappings" ] = function ()
368+ local function assert_movement (mapping , no_count , with_count )
369+ assert .is_true (mapping .expr )
370+ assert .is_true (mapping .silent )
371+ assert .equals (" string" , type (mapping [1 ]))
372+ local no_count_expression = mapping [1 ]:gsub (" v:count" , " 0" )
373+ local with_count_expression = mapping [1 ]:gsub (" v:count" , " 2" )
374+ assert .equals (no_count , vim .fn .eval (no_count_expression ))
375+ assert .equals (with_count , vim .fn .eval (with_count_expression ))
376+ end
377+
348378 with_mappings (function (maps )
349379 for _ , mode in ipairs { " n" , " x" } do
350- assert .equals (" v:count == 0 ? 'gj' : 'j'" , maps [mode ].j [1 ])
351- assert .equals (" v:count == 0 ? 'gk' : 'k'" , maps [mode ].k [1 ])
352- assert .equals (true , maps [mode ].j .expr )
353- assert .equals (true , maps [mode ].k .silent )
380+ assert_movement (maps [mode ].j , " gj" , " j" )
381+ assert_movement (maps [mode ].k , " gk" , " k" )
354382 end
355383 end )
356384end
357385
358- T [" MAP-02 records rename forwarding and stable write and quit declarations " ] = function ()
386+ T [" MAP-02 delegates file rename to AstroCore " ] = function ()
359387 with_mappings (function (maps , calls )
360- assert .same ({ " <Cmd>w<CR>" , desc = " Save" }, maps .n [" <Leader>w" ])
361- assert .same ({ " <Cmd>silent! update! | redraw<CR>" , desc = " Force write" }, maps .n [" <C-S>" ])
362- assert .same ({ " <Cmd>confirm q<CR>" , desc = " Quit Window" }, maps .n [" <Leader>q" ])
363- assert .same ({ " <Cmd>q!<CR>" , desc = " Force quit" }, maps .n [" <C-Q>" ])
364- assert .same ({ " gcc" , remap = true , desc = " Toggle comment line" }, maps .n [" <Leader>/" ])
365- assert .same ({ " gc" , remap = true , desc = " Toggle comment" }, maps .x [" <Leader>/" ])
366388 maps .n [" <Leader>R" ][1 ]()
367389 assert .same ({ { target = " rename" } }, calls )
368390 end )
0 commit comments