chore: impl Debug for all struct and enum

This commit is contained in:
PoiScript 2019-01-11 23:11:07 +08:00
parent 128825f148
commit 6b1e2a26be
17 changed files with 64 additions and 28 deletions

View file

@ -1,4 +1,5 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct Block;
impl Block {

View file

@ -1,4 +1,5 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct DynBlock<'a> {
pub name: &'a str,
pub para: &'a str,

View file

@ -1,4 +1,5 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct FnDef<'a> {
pub label: &'a str,
pub contents: &'a str,

View file

@ -1,4 +1,5 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct Keyword<'a> {
pub key: &'a str,
pub value: &'a str,
@ -6,11 +7,14 @@ pub struct Keyword<'a> {
impl<'a> Keyword<'a> {
pub fn parse(src: &'a str) -> Option<(Keyword<'a>, usize)> {
starts_with!(src, "#+");
if cfg!(test) {
starts_with!(src, "#+");
}
let key = until_while!(src, 2, b':', |c: u8| c.is_ascii_uppercase() || c == b'_');
let end = eol!(src);
// includes the eol character
let end = src.find('\n').map(|i| i + 1).unwrap_or(src.len());
Some((
Keyword {
@ -22,14 +26,16 @@ impl<'a> Keyword<'a> {
}
}
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct AffKeyword<'a> {
pub key: AffKeywordKey<'a>,
pub option: Option<&'a str>,
pub value: &'a str,
}
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub enum AffKeywordKey<'a> {
Caption,
Header,
@ -141,13 +147,13 @@ fn parse() {
)
);
assert_eq!(
Keyword::parse("#+KEY:VALUE").unwrap(),
Keyword::parse("#+KEY:VALUE\n").unwrap(),
(
Keyword {
key: "KEY",
value: "VALUE",
},
"#+KEY:VALUE".len()
"#+KEY:VALUE\n".len()
)
);
assert!(Keyword::parse("#+KE Y: VALUE").is_none());

View file

@ -1,4 +1,5 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct Rule;
impl Rule {

View file

@ -1,4 +1,5 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct Headline<'a> {
pub level: usize,
pub priority: Option<char>,

View file

@ -1,11 +1,14 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct Cookie<'a> {
value: &'a str,
}
impl<'a> Cookie<'a> {
pub fn parse(src: &'a str) -> Option<(Cookie<'a>, usize)> {
starts_with!(src, '[');
if cfg!(test) {
starts_with!(src, '[');
}
let num1 = until_while!(src, 1, |c| c == b'%' || c == b'/', |c: u8| c
.is_ascii_digit());

View file

@ -1,4 +1,5 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct FnRef<'a> {
label: Option<&'a str>,
definition: Option<&'a str>,

View file

@ -1,4 +1,5 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct Fragment<'a> {
value: &'a str,
}

View file

@ -1,4 +1,5 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct InlineCall<'a> {
pub name: &'a str,
pub args: &'a str,

View file

@ -1,4 +1,5 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct InlineSrc<'a> {
pub lang: &'a str,
pub option: Option<&'a str>,

View file

@ -1,4 +1,5 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct Link<'a> {
pub path: &'a str,
pub desc: Option<&'a str>,
@ -6,7 +7,9 @@ pub struct Link<'a> {
impl<'a> Link<'a> {
pub fn parse(src: &'a str) -> Option<(Link<'a>, usize)> {
starts_with!(src, "[[");
if cfg!(test) {
starts_with!(src, "[[");
}
let path = until_while!(src, 2, b']', |c| c != b']'
&& c != b'<'

View file

@ -1,6 +1,7 @@
use jetscii::Substring;
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct Macros<'a> {
pub name: &'a str,
pub args: Option<&'a str>,

View file

@ -1,6 +1,7 @@
use jetscii::Substring;
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct Snippet<'a> {
pub name: &'a str,
pub value: &'a str,
@ -8,7 +9,9 @@ pub struct Snippet<'a> {
impl<'a> Snippet<'a> {
pub fn parse(src: &'a str) -> Option<(Snippet<'a>, usize)> {
starts_with!(src, "@@");
if cfg!(test) {
starts_with!(src, "@@");
}
let name = until_while!(src, 2, b':', |c: u8| c.is_ascii_alphanumeric() || c == b'-');

View file

@ -1,10 +1,14 @@
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
// TODO: text-markup, entities, latex-fragments, subscript and superscript
pub struct RadioTarget<'a>(&'a str);
impl<'a> RadioTarget<'a> {
pub fn parse(src: &'a str) -> Option<(RadioTarget<'a>, usize)> {
starts_with!(src, "<<<");
if cfg!(test) {
starts_with!(src, "<<<");
}
expect!(src, 3, |c| c != b' ');
let end = until_while!(src, 3, b'>', |c| c != b'<' && c != b'\n');
@ -17,12 +21,16 @@ impl<'a> RadioTarget<'a> {
}
}
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct Target<'a>(&'a str);
impl<'a> Target<'a> {
pub fn parse(src: &'a str) -> Option<(Target<'a>, usize)> {
starts_with!(src, "<<");
if cfg!(test) {
starts_with!(src, "<<");
}
expect!(src, 2, |c| c != b' ');
let end = until_while!(src, 2, b'>', |c| c != b'<' && c != b'\n');

View file

@ -1,3 +1,5 @@
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub struct Time<'a> {
pub date: &'a str,
}

View file

@ -24,7 +24,8 @@ pub enum Container {
Underline { end: usize },
}
#[cfg_attr(test, derive(PartialEq, Debug))]
#[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)]
pub enum Event<'a> {
StartHeadline(Headline<'a>),
EndHeadline,