Remove PartialEq from Object.
Some checks failed
rustfmt Build rustfmt has succeeded
clippy Build clippy has failed
rust-foreign-document-test Build rust-foreign-document-test has succeeded
rust-test Build rust-test has succeeded
rust-build Build rust-build has succeeded

This commit is contained in:
Tom Alexander 2023-10-31 16:25:52 -04:00
parent 10aa0956ee
commit f5699ce830
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 136 additions and 97 deletions

View File

@ -128,7 +128,7 @@ pub struct DiffResult<'b, 's> {
emacs_token: &'b Token<'s>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub(crate) enum DiffStatus {
Good,
Bad,
@ -164,7 +164,7 @@ impl<'b, 's> DiffEntry<'b, 's> {
fn is_immediately_bad(&self) -> bool {
match self {
DiffEntry::DiffResult(diff) => diff.status == DiffStatus::Bad,
DiffEntry::DiffResult(diff) => matches!(diff.status, DiffStatus::Bad),
DiffEntry::DiffLayer(_) => false,
}
}

View File

@ -225,7 +225,7 @@ fn impl_balanced_bracket<
let contents_end = remaining;
let (remaining, _) = end_parser(remaining)?;
let contents = if contents_start != contents_end {
let contents = if Into::<&str>::into(contents_start) != Into::<&str>::into(contents_end) {
Some(contents_start.get_until(contents_end))
} else {
None
@ -244,7 +244,7 @@ mod tests {
let input = OrgSource::new("()");
let (remaining, call) = opt(babel_call_call)(input)?;
assert_eq!(Into::<&str>::into(remaining), "()");
assert_eq!(call, None);
assert!(matches!(call, None));
Ok(())
}
}

View File

@ -210,12 +210,12 @@ mod tests {
use crate::context::GlobalSettings;
use crate::context::List;
use crate::parser::element_parser::element;
use crate::types::CitationReference;
use crate::types::Element;
use crate::types::GetStandardProperties;
use crate::types::StandardProperties;
#[test]
fn citation_simple() {
fn citation_simple() -> Result<(), Box<dyn std::error::Error>> {
let input = OrgSource::new("[cite:@foo]");
let global_settings = GlobalSettings::default();
let initial_context = ContextElement::document_context();
@ -232,23 +232,31 @@ mod tests {
"[cite:@foo]"
);
assert_eq!(first_paragraph.children.len(), 1);
assert_eq!(
first_paragraph
.children
.first()
.expect("Len already asserted to be 1"),
&Object::Citation(Citation {
source: "[cite:@foo]",
style: None,
prefix: vec![],
suffix: vec![],
children: vec![CitationReference {
source: "@foo",
key: "foo",
prefix: vec![],
suffix: vec![]
}]
})
);
match first_paragraph
.children
.first()
.expect("Len already asserted to be 1.")
{
Object::Citation(inner) => {
assert_eq!(inner.get_source(), "[cite:@foo]");
assert_eq!(inner.children.len(), 1);
assert!(inner.prefix.is_empty());
assert!(inner.suffix.is_empty());
assert!(inner.style.is_none());
let citation_reference = inner
.children
.first()
.expect("Len already asserted to be 1.");
assert_eq!(citation_reference.get_source(), "@foo");
assert_eq!(citation_reference.key, "foo");
assert!(citation_reference.prefix.is_empty());
assert!(citation_reference.suffix.is_empty());
}
_ => {
return Err("Child should be a citation.".into());
}
};
Ok(())
}
}

View File

@ -12,7 +12,7 @@ use nom::Slice;
pub(crate) type BracketDepth = i16;
#[derive(Copy, Clone, PartialEq)]
#[derive(Copy, Clone)]
pub(crate) struct OrgSource<'s> {
full_source: &'s str,
start: usize,

View File

@ -179,7 +179,7 @@ mod tests {
use crate::types::PlainText;
#[test]
fn plain_text_radio_target() {
fn plain_text_radio_target() -> Result<(), Box<dyn std::error::Error>> {
let input = OrgSource::new("foo bar baz");
let radio_target_match = vec![Object::PlainText(PlainText { source: "bar" })];
let global_settings = GlobalSettings {
@ -200,21 +200,31 @@ mod tests {
"foo bar baz"
);
assert_eq!(first_paragraph.children.len(), 3);
assert_eq!(
first_paragraph
.children
.get(1)
.expect("Len already asserted to be 3"),
&Object::RadioLink(RadioLink {
source: "bar ",
children: vec![Object::PlainText(PlainText { source: "bar" })],
path: "bar"
})
);
match first_paragraph
.children
.get(1)
.expect("Len already asserted to be 3.")
{
Object::RadioLink(inner) => {
assert_eq!(inner.get_standard_properties().get_source(), "bar ");
assert_eq!(inner.path, "bar");
assert_eq!(inner.children.len(), 1);
let child = inner
.children
.get(0)
.expect("Length already asserted to be 1.");
assert!(matches!(child, Object::PlainText(_)));
assert_eq!(child.get_standard_properties().get_source(), "bar");
}
_ => {
return Err("Child should be a radio link.".into());
}
};
Ok(())
}
#[test]
fn bold_radio_target() {
fn bold_radio_target() -> Result<(), Box<dyn std::error::Error>> {
let input = OrgSource::new("foo *bar* baz");
let radio_target_match = vec![Object::Bold(Bold {
source: "*bar*",
@ -239,19 +249,41 @@ mod tests {
"foo *bar* baz"
);
assert_eq!(first_paragraph.children.len(), 3);
assert_eq!(
first_paragraph
.children
.get(1)
.expect("Len already asserted to be 3"),
&Object::RadioLink(RadioLink {
source: "*bar* ",
children: vec![Object::Bold(Bold {
source: "*bar* ",
children: vec![Object::PlainText(PlainText { source: "bar" })]
})],
path: "*bar* "
})
);
match first_paragraph
.children
.get(1)
.expect("Len already asserted to be 3.")
{
Object::RadioLink(inner) => {
assert_eq!(inner.get_standard_properties().get_source(), "*bar* ");
assert_eq!(inner.path, "*bar* ");
assert_eq!(inner.children.len(), 1);
let child = inner
.children
.get(0)
.expect("Length already asserted to be 1.");
assert!(matches!(child, Object::Bold(_)));
assert_eq!(child.get_standard_properties().get_source(), "*bar* ");
}
_ => {
return Err("Child should be a radio link.".into());
}
};
Ok(())
// assert_eq!(
// first_paragraph
// .children
// .get(1)
// .expect("Len already asserted to be 3"),
// &Object::RadioLink(RadioLink {
// source: "*bar* ",
// children: vec![Object::Bold(Bold {
// source: "*bar* ",
// children: vec![Object::PlainText(PlainText { source: "bar" })]
// })],
// path: "*bar* "
// })
// );
}
}

View File

@ -9,8 +9,7 @@ use super::util::to_lowercase;
use super::GetStandardProperties;
use super::StandardProperties;
// TODO: Why did we make Object implement PartialEq again? Was it just for tests?
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub enum Object<'s> {
Bold(Bold<'s>),
Italic(Italic<'s>),
@ -41,48 +40,48 @@ pub enum Object<'s> {
Timestamp(Timestamp<'s>),
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct Bold<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct Italic<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct Underline<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct StrikeThrough<'s> {
pub source: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct Code<'s> {
pub source: &'s str,
pub contents: &'s str,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct Verbatim<'s> {
pub source: &'s str,
pub contents: &'s str,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct PlainText<'s> {
pub source: &'s str,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct RegularLink<'s> {
pub source: &'s str,
pub link_type: LinkType<'s>,
@ -105,21 +104,21 @@ pub struct RegularLink<'s> {
pub application: Option<Cow<'s, str>>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct RadioTarget<'s> {
pub source: &'s str,
pub value: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct RadioLink<'s> {
pub source: &'s str,
pub path: &'s str,
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct PlainLink<'s> {
pub source: &'s str,
pub link_type: LinkType<'s>,
@ -129,7 +128,7 @@ pub struct PlainLink<'s> {
pub application: Option<&'s str>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct AngleLink<'s> {
pub source: &'s str,
pub link_type: LinkType<'s>,
@ -147,7 +146,7 @@ pub struct AngleLink<'s> {
pub application: Option<&'s str>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct OrgMacro<'s> {
pub source: &'s str,
@ -164,7 +163,7 @@ pub struct OrgMacro<'s> {
pub value: &'s str,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct Entity<'s> {
pub source: &'s str,
pub name: &'s str,
@ -177,27 +176,27 @@ pub struct Entity<'s> {
pub use_brackets: bool,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct LatexFragment<'s> {
pub source: &'s str,
pub value: &'s str,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct ExportSnippet<'s> {
pub source: &'s str,
pub backend: &'s str,
pub contents: Option<&'s str>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct FootnoteReference<'s> {
pub source: &'s str,
pub label: Option<&'s str>,
pub definition: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct Citation<'s> {
pub source: &'s str,
pub style: Option<&'s str>,
@ -206,7 +205,7 @@ pub struct Citation<'s> {
pub children: Vec<CitationReference<'s>>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct CitationReference<'s> {
pub source: &'s str,
pub key: &'s str,
@ -214,7 +213,7 @@ pub struct CitationReference<'s> {
pub suffix: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct InlineBabelCall<'s> {
pub source: &'s str,
pub value: &'s str,
@ -224,7 +223,7 @@ pub struct InlineBabelCall<'s> {
pub end_header: Option<&'s str>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct InlineSourceBlock<'s> {
pub source: &'s str,
pub language: &'s str,
@ -232,31 +231,31 @@ pub struct InlineSourceBlock<'s> {
pub value: &'s str,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct LineBreak<'s> {
pub source: &'s str,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct Target<'s> {
pub source: &'s str,
pub value: &'s str,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct StatisticsCookie<'s> {
pub source: &'s str,
pub value: &'s str,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct Subscript<'s> {
pub source: &'s str,
pub use_brackets: bool,
pub children: Vec<Object<'s>>,
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub struct Superscript<'s> {
pub source: &'s str,
pub use_brackets: bool,
@ -264,7 +263,7 @@ pub struct Superscript<'s> {
}
// TODO: Perhaps there is an optimization of converting to unix time we can do to shrink this struct. (ref: clippy::large_enum_variant on Element)
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub struct Timestamp<'s> {
pub source: &'s str,
pub timestamp_type: TimestampType,
@ -277,7 +276,7 @@ pub struct Timestamp<'s> {
pub warning_delay: Option<WarningDelay>,
}
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub enum TimestampType {
Diary,
Active,
@ -286,7 +285,7 @@ pub enum TimestampType {
InactiveRange,
}
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub enum TimestampRangeType {
None,
DateRange,
@ -299,19 +298,19 @@ pub type DayOfMonthInner = u8;
pub type HourInner = u8;
pub type MinuteInner = u8;
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub struct Year(YearInner);
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub struct Month(MonthInner);
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub struct DayOfMonth(DayOfMonthInner);
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub struct Hour(HourInner);
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub struct Minute(MinuteInner);
impl Year {
@ -386,7 +385,7 @@ impl Minute {
}
}
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub struct Date<'s> {
year: Year,
month: Month,
@ -444,7 +443,7 @@ impl<'s> Date<'s> {
}
}
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub struct Time<'s> {
hour: Hour,
minute: Minute,
@ -478,20 +477,20 @@ impl<'s> Time<'s> {
}
}
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub enum RepeaterType {
Cumulative,
CatchUp,
Restart,
}
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub enum WarningDelayType {
All,
First,
}
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub enum TimeUnit {
Hour,
Day,
@ -502,14 +501,14 @@ pub enum TimeUnit {
pub type RepeaterWarningDelayValueType = u16;
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub struct Repeater {
pub repeater_type: RepeaterType,
pub value: RepeaterWarningDelayValueType,
pub unit: TimeUnit,
}
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, Clone)]
pub struct WarningDelay {
pub warning_delay_type: WarningDelayType,
pub value: RepeaterWarningDelayValueType,
@ -718,7 +717,7 @@ impl<'s> Timestamp<'s> {
}
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub enum LinkType<'s> {
File,
Protocol(Cow<'s, str>),
@ -787,7 +786,7 @@ impl<'s> OrgMacro<'s> {
}
}
#[derive(Debug, PartialEq)]
#[derive(Debug)]
pub enum FootnoteReferenceType {
Standard,
Inline,