Test indentation level calculation (#6281)

Co-authored-by: Jonatan Pettersson <jonatan.pettersson@proton.me>
This commit is contained in:
Jonatan Pettersson 2023-03-12 18:41:07 +01:00 committed by GitHub
parent 39052433ed
commit 1126af53b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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");