diff --git a/crates/codebook/src/queries/python.scm b/crates/codebook/src/queries/python.scm index 42f820a..ac9d590 100644 --- a/crates/codebook/src/queries/python.scm +++ b/crates/codebook/src/queries/python.scm @@ -1,5 +1,5 @@ (comment) @comment -(string) @string +(string_content) @string (function_definition name: (identifier) @identifier) (function_definition diff --git a/crates/codebook/tests/test_python.rs b/crates/codebook/tests/test_python.rs index f67e950..308642e 100644 --- a/crates/codebook/tests/test_python.rs +++ b/crates/codebook/tests/test_python.rs @@ -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)); + } +}