From 1126af53b4daa2123ae13d71500cdf5dfd85f386 Mon Sep 17 00:00:00 2001 From: Jonatan Pettersson Date: Sun, 12 Mar 2023 18:41:07 +0100 Subject: [PATCH] Test indentation level calculation (#6281) Co-authored-by: Jonatan Pettersson --- helix-core/tests/indent.rs | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/helix-core/tests/indent.rs b/helix-core/tests/indent.rs index b3c543d6c..f558f86f3 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");