diff options
author | Jonatan Pettersson | 2023-03-12 17:41:07 +0000 |
---|---|---|
committer | GitHub | 2023-03-12 17:41:07 +0000 |
commit | 1126af53b4daa2123ae13d71500cdf5dfd85f386 (patch) | |
tree | cbb08c93529a02071ee15a775b64aca5c5b47a05 /helix-core/tests | |
parent | 39052433edd4dcbd3a9714e6e3036cbd46ebc959 (diff) |
Test indentation level calculation (#6281)
Co-authored-by: Jonatan Pettersson <jonatan.pettersson@proton.me>
Diffstat (limited to 'helix-core/tests')
-rw-r--r-- | helix-core/tests/indent.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/helix-core/tests/indent.rs b/helix-core/tests/indent.rs index b3c543d6..f558f86f 100644 --- a/helix-core/tests/indent.rs +++ b/helix-core/tests/indent.rs @@ -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, }; @@ -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"); |