The algorithm is relatively simple. We start from the position of the cursor
and try to deduce what test the user want to launch. If the cursor is inside
a test function, let’s launch only this function. If the cursor is in a file
that contains test, let’s launch all the tests of this file, etc.
Here is a simplified algorithm. First, we iterate over the blocks { … }
going from the narrower block containing the cursor, to the larger block
containing the cursor. During this iteration, we identify the block of the test
function (function annotated with #[test]
) if there is one, and all the
wrapping modules. Then we can iterate on the file path to deduce the rest of
the modules.
From the file path, we can also deduce if this is an integration test or not.
This will help to choose between --lib
or --test
options.
You can find the code in my vim script
here.