use codebook::queries::LanguageType;
use super::utils::{assert_spelling, assert_spelling_at};
#[test]
fn test_markdown_paragraph() {
assert_spelling(
LanguageType::Markdown,
"Some paragraph text with a misspeled word.\n",
&["misspeled"],
&[],
);
}
#[test]
fn test_markdown_heading() {
assert_spelling(
LanguageType::Markdown,
"# A headng with a tyypo\n",
&["headng", "tyypo"],
&[],
);
}
#[test]
fn test_markdown_fenced_code_block_known_lang() {
let sample_text = r#"# Hello World
Some correct text here.
```bash
mkdir some_dir
```
More correct text here.
"#;
assert_spelling(LanguageType::Markdown, sample_text, &[], &["mkdir", "dir"]);
}
#[test]
fn test_markdown_fenced_code_block_unknown_lang_skipped() {
let sample_text = r#"Some text.
```unknownlang
badwwword_in_code
```
More text.
"#;
assert_spelling(LanguageType::Markdown, sample_text, &[], &["badwwword"]);
}
#[test]
fn test_markdown_fenced_code_block_no_lang_skipped() {
let sample_text = r#"Some text.
```
badwwword_in_code
```
More text.
"#;
assert_spelling(LanguageType::Markdown, sample_text, &[], &["badwwword"]);
}
#[test]
fn test_markdown_code_block_uses_language_grammar() {
let sample_text = r#"A paragrap with a tyypo.
```python
def some_functin():
pass
```
Another paragrap with a tyypo.
"#;
assert_spelling_at(
LanguageType::Markdown,
sample_text,
&[("paragrap", &[0, 1]), ("tyypo", &[0, 1]), ("functin", &[0])],
);
}
#[test]
fn test_markdown_multiple_code_blocks() {
let sample_text = r#"Some text with a tyypo.
```bash
mkdir somedir
```
Middle text is corect.
```unknownlang
badspel = True
```
End text is also corect.
"#;
assert_spelling_at(
LanguageType::Markdown,
sample_text,
&[("tyypo", &[0]), ("corect", &[0, 1])],
);
}
#[test]
fn test_markdown_block_quote() {
assert_spelling(
LanguageType::Markdown,
"> A block quoet with a tyypo.\n",
&["quoet", "tyypo"],
&[],
);
}
#[test]
fn test_markdown_code_block_alias_resolution() {
let sample_text = r#"Some text.
```py
def hello_wrld():
pass
```
```js
function hello_wrld() {}
```
More text.
"#;
assert_spelling_at(LanguageType::Markdown, sample_text, &[("wrld", &[0, 1])]);
}
#[test]
fn test_markdown_injected_region_offsets_multibyte_anchor() {
let sample_text =
"# OK ๐\n\nProse ๐จโ๐ฉโ๐งโ๐ฆ with a tyypo.\n\n```python\ndef some_functin(): pass\n```\n";
assert_spelling_at(
LanguageType::Markdown,
sample_text,
&[("tyypo", &[0]), ("functin", &[0])],
);
}
#[test]
fn test_markdown_no_duplicate_spans() {
assert_spelling_at(
LanguageType::Markdown,
"> A tyypo in a block quoet.\n",
&[("tyypo", &[0]), ("quoet", &[0])],
);
}