summaryrefslogtreecommitdiff
path: root/src/tests
AgeCommit message (Collapse)Author
2025-08-03Styled zero lines fixmainThomas Otto
With `interactive.diffFilter = delta --color-only` delta is called by e.g. `git add -p`, but in this mode git hides the terminal from the pager. Plus/minus lines correctly use ANSI sequences to paint up to to the end of the line, but zero lines always use spaces. This needs the terminal width, but it is not available for diffFilter. So the fallback of 80 is used, and zero styles did not extend to the full terminal width. Since zero lines are only rarely styled (e.g. via `--zero-style='syntax "#1d1f21" dim'`), this was never noticed. This also crashed delta when a zero line was longer than 80.
2024-07-22Add --max-syntax-highlighting-length, set to 400Thomas Otto
--max-line-length increased to 3000, highlighting now stops after 400 characters. In that case the highlighting may be incorrect until it is reset for the next hunk.
2024-07-09Make relative-paths work with binary filesThomas Otto
`relativize_path_maybe()` was not called in this case. Added test and converted a few existing ones to insta.
2024-07-07tests: set terminal width to 43 (#1741)Thomas Otto
Make tests more deterministic by not allowing them to "see" the current terminal width.
2024-07-06tests: add insta for snapshot testing (#1739)Thomas Otto
Insta makes writing new tests or performing changes which update the expected value(s) easier. The new reference data can be reviewed and inserted/updated automatically by `cargo insta review` (after `cargo install cargo-insta`, but that tool is optional). The snapshots are stored inline using the `@""` syntax and not in separate files because the delta test output is small and designed to be human readable. See https://insta.rs/#hello-snapshot-testing and https://docs.rs/insta/1.39.0/insta/
2024-06-24Don't read git files when --no-gitconfig is given + unused variables (#1728)Thomas Otto
* Fix unused variables * Don't read git files when --no-gitconfig is given Despite starting delta with `--no-gitconfig`, strace still shows that `.git/config` etc. files are accessed. By no longer doing that it is very clear that no config options are read from there.
2024-05-04clippy (#1686)Dan Davison
2024-05-04Repair --default-language, and highlight using full filename (#1549)Thomas Otto
* Fix clippy warnings * Repair --default-language, and highlight using full filename Fixed that the "txt" fallback was used instead of --default-language And when looking for syntax highlighting, keep the filename around as long as possible. Using simple custom logic (filename > 4) a Makefile can be highlighted with make syntax, but a 'cc' or 'ini' file does not get treated like a *.cc or *.ini file. Currently the underlying highlighting lib syntect and the sublime syntax definitions can not make this distinction (<http://www.sublimetext.com/docs/syntax.html>).
2024-03-16Honor default-language option (#1655)Pawel Dominiak
* Honor default-language option * Add tests for default-language option --------- Co-authored-by: Dan Davison <dandavison7@gmail.com>
2024-03-12Preserve "Binary files" line in color_only mode (#1649)Pawel Dominiak
Closes #320
2024-03-02Fix headers of modified binary files, closes #1621 (#1629)Paul
2024-02-19Accept clippy suggestions (#1632)Dan Davison
2023-11-20Make hunk header code fragment display optional (#1568)Zack Cerza
Fixes: #1032
2023-08-05Improve binary file added output (#1502)Sondeyy
* added binary file cases tests * add binary file cases handling * remove unnecessary return and comma
2023-06-02Increase number of characters shown in submodule hashesDan Davison
Fixes #1408
2023-05-17Fix warning highlight for trailing whitespace (#1037)William Escande
Fix #137
2023-05-08Fix submodule diff parsing (#1413)Thomas Otto
Added support for an optional -dirty hash suffix which is present in `git diff` output when files were changed in a submodule.
2023-03-09Add methods for getting `GitConfig` as reference (#1336)nickelc
2023-03-03Spelling (#1257)Josh Soref
Corrects misspellings identified by https://github.com/marketplace/actions/check-spelling Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-02-28Fix clippy warnings (#1298)nickelc
* Fix clippy warnings - `clippy::uninlined_format_args` * Fix clippy warnings - `clippy::clone_on_copy` - `clippy::explicit_auto_deref` - `clippy::iter_cloned_collect` - `clippy::map_clone` - `clippy::needless_borrow` - `clippy::needless_lifetimes` - `clippy::needless_return` - `clippy::redundant_clone` - `clippy::redundant_field_names` - `clippy::seek_to_start_instead_of_rewind` - `clippy::unnecessary_cast` - `clippy::unused_unit`
2022-06-22Fix whole-file changes being attributed to the wrong commit in "git log" outputBjörn Steinbrink
The pending buffer for whole-file changes is currently only flushed when encountering a new diff header. This leads to it being carried over across commit boundaries in cases where multiple commits are shown. To fix this, we simply need to flush the buffered data on a commit boundary as well. Fixes #1089
2022-03-30Add custom env struct to store env at init (#1025)William Escande
This allow to no longer ignore some tests (marked previously as FIXME) by storing the env at the start of the program (Or creating a custom env for test purpose) This centralize almost alls calls to std::env inside one wrapper Add a test profile to increase speed for testing (5min -> 20sec on my machine) clean a few code style like this: ``` if Some(value) = ... if value ``` to ``` if Some(true) = ... ``` Co-authored-by: William Escande <wescande@google.com>
2022-03-30Add support for irreversible-deleteWilliam Escande
Fix #128 Add support for `git diff -D` (aka irreversible delete) The patch is adding a title for removed file, even when there is no file content in the diff output Without the patch, there was no output related to the file at all
2022-03-07Add failing test for #1002Dan Davison
2022-02-14Fix hyperlink absolute paths (#939)Dan Davison
Fix file paths and hyperlinks With this commit the target of a hyperlink should always be an absolute path. This should be true for all file hyperlinks, e.g. - File hyperlink - Hunk header hyperlink - Line number hyperlink Fixes #890
2022-01-18Center Align numbers right-ish (#883)Thomas Otto
There is no such thing as "Center Align" with discrete terminal cells. In some cases a decision has to be made whether to use the left or the right cell, e.g. when centering one char in 4 cells: "_X__" or "__X_". The format!() center/^ default is left, but when padding numbers these are now aligned to the right if required. Strings remain left-aligned.
2022-01-16Drop deprecated options (#914)Dan Davison
Drop deprecated options Fixes #891
2022-01-05Handle a mode change on a renamed file. (#875)Wayne Davison
* Handle a mode change on a renamed file. I changed the diff parsing to cache the mode info from the old/new mode lines until the parsing bumps into the start of the actual related diff, finds the diff line for an unrelated diff, or runs out of input. This allows the mode info to be output in conjunction with a file event instead of as a separate heading (that used to have an empty name when the mode change was for a rename). The mode info is passed down into the draw routines as a separate "addendum" string that the draw code can use as it likes. Currently that means that it appends the addendum string to the non-raw string in parens. I imagine that future draw routines could decide to put it in a separate box or some other per-routine method. There is currently a single function in src/handlers/draw.rs that joins the strings in the same way for everyone. A couple examples of how the new code looks: Δ foo.rs (mode +x) ─────────────────────────────────────────────────── renamed: old-longer-name → shorter-name (mode +x) ─────────────────────────────────────────────────── Would it look better on its own line? Δ foo.rs • mode +x ─────────────────────────────────────────────────── renamed: old-longer-name → shorter-name • mode +x ─────────────────────────────────────────────────── Would it look better appended after a "•" character? Δ foo.rs • mode +x ─────────────────────────────────────────────────── renamed: old-longer-name → shorter-name • mode +x ─────────────────────────────────────────────────── Should it be a user option? If so, we can do that later.
2022-01-04Make Config cloneable for DeltaTest, store as Cow<Config> thereThomas Otto
Only cloneable when testing, the types git2::Config and git2::Repository in GitConfig contain C pointers and can't really be cloned.
2022-01-04DeltaTest improvements (#876)Wayne Davison
* DeltaTest improvements - Added .expect_contains(), .expect_raw_contains(), and .expect_contains_once() member functions to DeltaTestOutput. These functions also output some helpful debug info when the assert fails. - Separated .with_config_and_input() into .with_config() and (the tweaked) .with_input(). - Made .with_config() create a DeltaTest object (like .with() does). - Renamed .with() as .with_args(). - Moved .explain_ansi() from DeltaTestOutput to DeltaTest, which must now be called prior to .with_input() since the latter stashes off both the raw_output & the processed output in the object. - Changed .expect() and .expect_skip() to return Self so that they can continue a chain of multiple expect calls (e.g. a series of partial matches with different skip values). - The processed output text can be accessed via `test_obj.output` (see also `test_obj.raw_output`). - Renamed .expect_skip() to .expect_after_skip(). - Changed .expect() to start at the first line. - Added .expect_after_header() that works like the old .expect(). - Renamed lines_match() to assert_lines_match() and made it match all lines (no skip number). - Added assert_lines_match_after_skip() to work like the old lines_match() function, but with the .expect_after_skip() arg order. - Converted some old-style tests into DeltaTest style tests. - Renamed set_cfg as set_config
2022-01-01Put file-modified label in front of mode changes.Wayne Davison
When using `--navigate` with files that get their mode modified, the file-modified label was not being prefixed, so these changes were not being marked as skip destinations. This is particularly bad if a file has line changes along with the mode change AND the user has an empty hunk label (since that would make the entire file's changes get skipped with an "n"). I added a test of a mode-change with a line-change, and a test for a mode change where the old & new mode values are not one of the two expected value-pairs. I also used format_file() on the mode filenames since the other format() calls were using it.
2021-12-14Delete calls printing output in testsDan Davison
2021-12-14Add inspect_raw method to DeltaTestDan Davison
2021-12-14Add markers surrounding DeltaTest::inspect() outputDan Davison
2021-12-12Allow calling process to be specified in DeltaTest builder methodsDan Davison
2021-12-12Refactor: factor out a helper function in DeltaTestDan Davison
2021-12-09Store raw_line in HunkZero, as HunkMinus and HunkPlusDan Davison
ref #829
2021-12-07Add DeltaTest to speed up adding and fixing testsThomas Otto
Using a syntax similar to the builder pattern: `DeltaTest::with([config options]).with_input(DIFF).expect(lines)` plus `.explain_ansi()` to pretty-print ansi codes and `.inspect()` to print the to-be-tested output. Rewrite a few tests using it and add ansi tests for --line-fill-method=<spaces|ansi>
2021-12-05Gracefully handle failure to parse hunk headerDan Davison
Fixes #765
2021-12-05Display merge conflictsDan Davison
2021-12-05Refactor: paint_minus_and_plus_lines functionDan Davison
2021-12-05Handle combined diff formatDan Davison
With this commit combined diff format (https://git-scm.com/docs/git-diff#_combined_diff_format) is handled appropriately. However, there is no special handling of merge conflict markers. Fixes #189, #736
2021-11-29Rename: FileMeta => DiffHeaderDan Davison
2021-11-28Do not fill entirely new/removed lines with non-emph styleDan Davison
2021-11-28Refactor: hunk style sections handlingDan Davison
- Factor out a new function update_diff_style_sections - Use MinusPlus construct more
2021-11-23New option to map raw styles encountered in inputDan Davison
Unify handling of styles parsed from raw line and computed diff styles. This enables syntax highlighting to be used in color-moved sections. Fixes #72
2021-11-22Allow custom colors to be defined in gitconfig (#788)Dan Davison
Similar to 7a64fa5a26314c05c811d7c1276388a4963fa0bd which allowed custom styles. Custom styles must end in -style, but colors can be anything. It unfortunately seems not to be possible currently to store a global reference to git config, hence the size of this commit (passing the reference down the call stack).
2021-11-21Set is_emph explicitly on *-emph-stylesDan Davison
This addresses a bug triggered by doing things like minus-style = minus-emph-style That was causing the is_emph bit to be set on minus-style, with undesirable consequences.
2021-11-17Use file-modified-label consistently.Wayne Davison
When filtering a diff and when directly diffing files/dirs, use the modified label that is output when interpreting git diffs. This gets rid of the "comparing:" prefix (which was otherwise missing from the --navigate regex) and ensures that a direct diff has a label to stop at when --navigate is enabled. One of the unified-diff tests now uses --file-modified-label=comparing: to generate the same output as before, while the other now uses --navigate to get a delta char label.
2021-11-10Remove +/- line prefix instead of substituting a spaceThomas Otto
Simplifies line handling and printing by removing a "magical" 1-offset previously required in various locations. Now explicitly prepend "" in `tokenize()`.