Fix a panic when parsing node summaries
This commit is contained in:
parent
3fa399c317
commit
3c0de5ca32
2 changed files with 17 additions and 13 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
use crate::syntax::content::parser::{
|
use crate::syntax::content::parser::{
|
||||||
state::State,
|
state::State,
|
||||||
token::{Token, paragraph::Paragraph, preformat::PreFormat},
|
token::{
|
||||||
|
Token, header::Header, paragraph::Paragraph, preformat::PreFormat,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod block;
|
pub mod block;
|
||||||
|
|
@ -31,7 +33,7 @@ pub enum Inline {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// # Panics
|
/// # Panics
|
||||||
/// Panics if there is an open header at end of input.
|
/// Panics if there is an open header or list at end of input.
|
||||||
pub fn close(state: &State, tokens: &mut Vec<Token>) {
|
pub fn close(state: &State, tokens: &mut Vec<Token>) {
|
||||||
match state.context.block {
|
match state.context.block {
|
||||||
Block::PreFormat => {
|
Block::PreFormat => {
|
||||||
|
|
@ -43,7 +45,9 @@ pub fn close(state: &State, tokens: &mut Vec<Token>) {
|
||||||
Block::List => {
|
Block::List => {
|
||||||
panic!("End of input with open list")
|
panic!("End of input with open list")
|
||||||
},
|
},
|
||||||
Block::Header(_) => panic!("End of input with open header"),
|
Block::Header(level) => {
|
||||||
|
tokens.push(Token::Header(Header::from_u8(level, false, None)));
|
||||||
|
},
|
||||||
Block::None => (),
|
Block::None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,16 +90,15 @@ pub fn parse(
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
types::Graph,
|
syntax::content::parser::{
|
||||||
syntax::content::{
|
self, Block, Token, context,
|
||||||
parser,
|
|
||||||
parser::{
|
|
||||||
token::{preformat::PreFormat},
|
|
||||||
state::State,
|
state::State,
|
||||||
token::header::Level,
|
token::{
|
||||||
Block, context, Token,
|
header::{Header, Level},
|
||||||
|
preformat::PreFormat,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
types::Graph,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn read(input: &str) -> String {
|
fn read(input: &str) -> String {
|
||||||
|
|
@ -125,12 +124,13 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "End of input with open header")]
|
|
||||||
fn end_with_open_header() {
|
fn end_with_open_header() {
|
||||||
let mut state = State::default();
|
let mut state = State::default();
|
||||||
state.context.block = Block::Header(1);
|
state.context.block = Block::Header(1);
|
||||||
|
|
||||||
context::close(&state, &mut vec![]);
|
let mut vec: Vec<Token> = vec![];
|
||||||
|
context::close(&state, &mut vec);
|
||||||
|
assert_eq!(vec, vec![Token::Header(Header::from_u8(1, false, None))]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue