Skip to content

Commit

Permalink
Test indentation level calculation (helix-editor#6281)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonatan Pettersson <[email protected]>
  • Loading branch information
2 people authored and Sagnik Bhattacharya committed Mar 21, 2023
1 parent 0925599 commit 252fb44
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion helix-core/tests/indent.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use helix_core::{
indent::{treesitter_indent_for_pos, IndentStyle},
indent::{indent_level_for_line, treesitter_indent_for_pos, IndentStyle},
syntax::Loader,
Syntax,
};
Expand All @@ -17,6 +17,39 @@ fn test_treesitter_indent_rust_2() {
// test_treesitter_indent("commands.rs", "source.rust");
}

#[test]
fn test_indent_level_for_line_with_spaces() {
let tab_width: usize = 4;
let indent_width: usize = 4;

let line = ropey::Rope::from_str(" Indented with 8 spaces");

let indent_level = indent_level_for_line(line.slice(0..), tab_width, indent_width);
assert_eq!(indent_level, 2)
}

#[test]
fn test_indent_level_for_line_with_tabs() {
let tab_width: usize = 4;
let indent_width: usize = 4;

let line = ropey::Rope::from_str("\t\tIndented with 2 tabs");

let indent_level = indent_level_for_line(line.slice(0..), tab_width, indent_width);
assert_eq!(indent_level, 2)
}

#[test]
fn test_indent_level_for_line_with_spaces_and_tabs() {
let tab_width: usize = 4;
let indent_width: usize = 4;

let line = ropey::Rope::from_str(" \t \tIndented with mix of spaces and tabs");

let indent_level = indent_level_for_line(line.slice(0..), tab_width, indent_width);
assert_eq!(indent_level, 2)
}

fn test_treesitter_indent(file_name: &str, lang_scope: &str) {
let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
test_dir.push("tests/data/indent");
Expand Down

0 comments on commit 252fb44

Please sign in to comment.