Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/codebook/src/queries/python.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(comment) @comment
(string) @string
(string_content) @string
(function_definition
name: (identifier) @identifier)
(function_definition
Expand Down
79 changes: 79 additions & 0 deletions crates/codebook/tests/test_python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,82 @@ mesage = "Helllo Wolrd!"
assert_eq!(miss.locations, e.locations);
}
}

#[test]
fn test_python_f_strings() {
utils::init_logging();
let processor = utils::get_processor();
let sample_text = r#"
name = "John"
age = 25
message = f'Hello, my naem is {name} and I am {age} years oldd'
another = f"This is antoher examle with {name} varibles"
simple = f'check these wordz {but} {not} {the} {variables}'
"#;

let expected = vec![
WordLocation::new(
"naem".to_string(),
vec![TextRange {
start_byte: 46,
end_byte: 50,
}],
),
WordLocation::new(
"oldd".to_string(),
vec![TextRange {
start_byte: 82,
end_byte: 86,
}],
),
WordLocation::new(
"antoher".to_string(),
vec![TextRange {
start_byte: 108,
end_byte: 115,
}],
),
WordLocation::new(
"examle".to_string(),
vec![TextRange {
start_byte: 116,
end_byte: 122,
}],
),
WordLocation::new(
"varibles".to_string(),
vec![TextRange {
start_byte: 135,
end_byte: 143,
}],
),
WordLocation::new(
"wordz".to_string(),
vec![TextRange {
start_byte: 168,
end_byte: 173,
}],
),
];

let not_expected = vec!["name", "age", "but", "not", "the", "variables"];

let misspelled = processor
.spell_check(sample_text, Some(LanguageType::Python), None)
.to_vec();
println!("Misspelled words: {misspelled:?}");

for e in &expected {
let miss = misspelled
.iter()
.find(|r| r.word == e.word)
.unwrap_or_else(|| panic!("Word '{}' not found in misspelled list", e.word));
println!("Expecting: {e:?}");
assert_eq!(miss.locations, e.locations);
}

for word in not_expected {
println!("Not expecting: {word:?}");
assert!(!misspelled.iter().any(|r| r.word == word));
}
}