wfxr / minimap.vim

πŸ“‘ Blazing fast minimap / scrollbar for vim, powered by code-minimap written in Rust.
MIT License
1.2k stars 24 forks source link

fix: search_tests now uses writefile() function and platform-agnostic temp folder #137

Closed rabirabirara closed 2 years ago

rabirabirara commented 2 years ago

Check list

Description

Fixes #129, partially.

I also ran the tests on my Linux installation, and they had the same problems.

First error: there is no 'max_width' key present in the dictionary. This error was extremely puzzling, given that the code betrays no possible way such an error could occur. So, I added the max_width key in, manually, to the value of working_width, and it just seems to work. Needs to be investigated more to actually solve the problem. Error output pictured below:

√ Search setup
βœ— Search - Beginning of file
    Vim(let):E716: Key not present in Dictionary: "max_width"
        <SNR>81_minimap_test_search_beginning_of_file:4
βœ— Search - Beginning of line
    Vim(let):E716: Key not present in Dictionary: "max_width"
        <SNR>81_minimap_test_search_beginning_of_line:6
...

Second: after making that change, I inspected the file that was actually being written to, and found that Vimscript was not actually putting in newlines where they should be. Instead the buffer was all written on one line, displaying \n directly as a string rather than as a newline. I changed the script to instead use writefile(), which automatically puts newlines in between its string arguments. It seems to work. Old output buffer:

This is a test line and it needs to be long enough to register as multiple braille characters.\npad height\npad height\npad height\npad height\npad height\npad height\npad height\npad height\npad height\nAnd another, this one is shorter\nand flows to the numbers line, this one, this one has some numbers 1234 numbers

Third: Windows was not able to create the folder /tmp/minimap... on my machine, so I added a check for the OS type to ensure that Unix users could use /tmp and Windows users would default to the %TEMP% environment variable. Error output:

Vim(call):E482: Can't open file /tmp/minimap_search_unit_test_file for writing: no such file or directory

In total, these got the tests to work on my Windows and Linux machines alike.

√ Search setup
√ Search - Beginning of file
√ Search - Beginning of line
√ Search - End of line
√ Search - Multi match per line
√ Search - Spanning a line
√ Search - Many results
√ Search - Long Match
√ Search - History
√ Search tear down
* Test Summary
* ------------
* All tests successful
* Tests=10
* Result: PASS

Type of change

Test environment

ZNielsen commented 2 years ago

Gave this a run on Mac and I'm seeing errors. Don't have time to investigate now. It might be worth trading away Mac unit tests to get Win/Lin working properly.

ZNielsen commented 2 years ago

Oh, looks like my whole minimap plugin was missing (#138). I got it re-installed, now tests pass on MacOS.