-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix_count_code_block_tokens'
- Loading branch information
Showing
2 changed files
with
115 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#[cfg(test)] | ||
mod calculate_code_block_token_count { | ||
use pulldown_cmark::{CodeBlockKind, CowStr, Event, Tag}; | ||
use pulldown_cmark_to_cmark::calculate_code_block_token_count; | ||
|
||
const CODE_BLOCK_START: Event<'_> = Event::Start(Tag::CodeBlock(CodeBlockKind::Fenced(CowStr::Borrowed("")))); | ||
const CODE_BLOCK_END: Event<'_> = Event::End(Tag::CodeBlock(CodeBlockKind::Fenced(CowStr::Borrowed("")))); | ||
|
||
#[test] | ||
fn no_token() { | ||
let events = &[CODE_BLOCK_START, Event::Text("text".into()), CODE_BLOCK_END]; | ||
assert_eq!(calculate_code_block_token_count(events.iter()), None); | ||
} | ||
|
||
#[test] | ||
fn backtick() { | ||
let events = &[CODE_BLOCK_START, Event::Text("```".into()), CODE_BLOCK_END]; | ||
assert_eq!(calculate_code_block_token_count(events.iter()), Some(4)); | ||
|
||
let events = &[CODE_BLOCK_START, Event::Text("````".into()), CODE_BLOCK_END]; | ||
assert_eq!(calculate_code_block_token_count(events.iter()), Some(5)); | ||
|
||
let events = &[CODE_BLOCK_START, Event::Text("``````````".into()), CODE_BLOCK_END]; | ||
assert_eq!(calculate_code_block_token_count(events.iter()), Some(11)); | ||
} | ||
|
||
#[test] | ||
fn tilde() { | ||
let events = &[CODE_BLOCK_START, Event::Text("~~~".into()), CODE_BLOCK_END]; | ||
assert_eq!(calculate_code_block_token_count(events.iter()), Some(4)); | ||
|
||
let events = &[CODE_BLOCK_START, Event::Text("~~~~".into()), CODE_BLOCK_END]; | ||
assert_eq!(calculate_code_block_token_count(events.iter()), Some(5)); | ||
|
||
let events = &[CODE_BLOCK_START, Event::Text("~~~~~~~~~~".into()), CODE_BLOCK_END]; | ||
assert_eq!(calculate_code_block_token_count(events.iter()), Some(11)); | ||
} | ||
|
||
#[test] | ||
fn mix() { | ||
let events = &[CODE_BLOCK_START, Event::Text("```~~~~".into()), CODE_BLOCK_END]; | ||
assert_eq!(calculate_code_block_token_count(events.iter()), Some(5)); | ||
|
||
let events = &[CODE_BLOCK_START, Event::Text("~~~~`````~~".into()), CODE_BLOCK_END]; | ||
assert_eq!(calculate_code_block_token_count(events.iter()), Some(6)); | ||
|
||
let events = &[ | ||
CODE_BLOCK_START, | ||
Event::Text("~~~```````~~~```~~".into()), | ||
CODE_BLOCK_END, | ||
]; | ||
assert_eq!(calculate_code_block_token_count(events.iter()), Some(8)); | ||
} | ||
|
||
#[test] | ||
fn splitted_text() { | ||
let events = &[ | ||
CODE_BLOCK_START, | ||
Event::Text("~~~".into()), | ||
Event::Text("~~~".into()), | ||
CODE_BLOCK_END, | ||
]; | ||
assert_eq!(calculate_code_block_token_count(events.iter()), Some(7)); | ||
|
||
let events = &[ | ||
CODE_BLOCK_START, | ||
Event::Text("````".into()), | ||
Event::Text("````".into()), | ||
CODE_BLOCK_END, | ||
]; | ||
assert_eq!(calculate_code_block_token_count(events.iter()), Some(9)); | ||
} | ||
} |