diff options
| -rw-r--r-- | lua/clever_f/direct_preview_planner.lua | 8 | ||||
| -rw-r--r-- | tests/run.lua | 11 |
2 files changed, 19 insertions, 0 deletions
diff --git a/lua/clever_f/direct_preview_planner.lua b/lua/clever_f/direct_preview_planner.lua index 8ccfa75..e81d941 100644 --- a/lua/clever_f/direct_preview_planner.lua +++ b/lua/clever_f/direct_preview_planner.lua @@ -48,6 +48,14 @@ function DirectPreviewPlanner:scan_current_line(view, origin, direction) return records end +function M.normalize_count(count) + return domain.Count.to_number(count) +end + +function DirectPreviewPlanner:normalize_count(count) + return M.normalize_count(count) +end + function M.direction_for_descriptor(descriptor) descriptor = domain.Descriptor.from_string(descriptor) if domain.Descriptor.is_uppercase(descriptor) then diff --git a/tests/run.lua b/tests/run.lua index cbca8d9..7c4c52d 100644 --- a/tests/run.lua +++ b/tests/run.lua @@ -4614,6 +4614,17 @@ test("Upper-case descriptors scan direct previews backward", function() ) end) +test("Direct preview count normalizes absent and entered values", function() + local planner = direct_preview_planner.new() + same(1, planner:normalize_count(nil)) + same(1, planner:normalize_count(domain.Count.ONE)) + same(2, planner:normalize_count(2)) + same(3, planner:normalize_count(domain.Count.new(3))) + fails(function() + planner:normalize_count(0) + end, "positive integer") +end) + for _, item in ipairs(tests) do local ok, failure = xpcall(item.body, debug.traceback) if not ok then |
