Skip to content

HighlightingAssets: Extract new public API method get_syntax_for_path()#1862

Merged
Enselic merged 3 commits into
sharkdp:masterfrom
Enselic:add-get_syntax_for_path-helper
Sep 28, 2021
Merged

HighlightingAssets: Extract new public API method get_syntax_for_path()#1862
Enselic merged 3 commits into
sharkdp:masterfrom
Enselic:add-get_syntax_for_path-helper

Conversation

@Enselic
Copy link
Copy Markdown
Collaborator

@Enselic Enselic commented Sep 25, 2021

We do this mainly to reduce duplication of logic. The move to adjust the public API is more of a side effect. It so happens that adjusting the public API also simplifies the code.

One of the reasons this refactoring works is that the .file_name() of a file_name is file_name unchanged:

    #[test]
    fn file_name_of_file_name_is_same() {
        let path = Path::new("test.rs");
        let expected = Path::new("test.rs");
        assert_eq!(path.file_name().unwrap_or_default(), expected);
    }

To make the code easier to refactor further.
…tax_for_path()

We can do this since the file_name() of a file_name is file_name.
Comment thread src/assets.rs Outdated
@Enselic Enselic changed the title HighlightingAssets: Add get_syntax_for_path() helper HighlightingAssets: Extract new public API method get_syntax_for_path() Sep 25, 2021
Comment thread CHANGELOG.md Outdated
Comment thread src/assets.rs
@Enselic Enselic force-pushed the add-get_syntax_for_path-helper branch from 055538d to 972bbcf Compare September 28, 2021 04:47
@Enselic Enselic merged commit 405a80f into sharkdp:master Sep 28, 2021
@Enselic Enselic deleted the add-get_syntax_for_path-helper branch September 28, 2021 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants