Skip to content

Commit

Permalink
fix: Loading entire file when no code blocks are selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Blackman committed Mar 2, 2024
1 parent 7ea8b00 commit 3655871
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/domain/models/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl EditorContext {
let language = &self.language;
let code = &self.code;

if code.is_empty() {
if code.is_empty() || self.end_line.is_none() {
return format!("File: {file_path}");
}

Expand Down
15 changes: 14 additions & 1 deletion src/domain/models/editor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn it_renders_with_no_code() {
}

#[test]
fn it_renders_with_code() {
fn it_renders_with_file_path() {
let context = EditorContext {
file_path: "file.rs".to_string(),
language: "rust".to_string(),
Expand All @@ -23,6 +23,19 @@ fn it_renders_with_code() {
end_line: None,
};

insta::assert_snapshot!(context.format(), @"File: file.rs");
}

#[test]
fn it_renders_with_code() {
let context = EditorContext {
file_path: "file.rs".to_string(),
language: "rust".to_string(),
code: "let x = 5;".to_string(),
start_line: 0,
end_line: Some(1),
};

insta::assert_snapshot!(context.format(), @r###"
File: file.rs
Expand Down

0 comments on commit 3655871

Please sign in to comment.