Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pretty_assertions_sorted #16

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ rust-version = "1.72.0"
nom = "7.1"
nom-span = "0.1.1"
thiserror = "1.0.50"

[dev-dependencies]
pretty_assertions_sorted = "1.2.3"
1 change: 1 addition & 0 deletions src/tests/blocks/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod simple {
error::{Error, ErrorKind},
Err,
};
use pretty_assertions_sorted::assert_eq;

use crate::{
blocks::Block,
Expand Down
1 change: 1 addition & 0 deletions src/tests/blocks/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use nom::{
error::{Error, ErrorKind},
Err,
};
use pretty_assertions_sorted::assert_eq;

use crate::{
blocks::SimpleBlock,
Expand Down
2 changes: 2 additions & 0 deletions src/tests/document.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use pretty_assertions_sorted::assert_eq;

use crate::{
tests::fixtures::{
blocks::{TBlock, TSimpleBlock},
Expand Down
15 changes: 14 additions & 1 deletion src/tests/fixtures/blocks/simple.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
use std::fmt;

use crate::{blocks::SimpleBlock, tests::fixtures::TSpan};

#[derive(Debug, Eq, PartialEq)]
#[derive(Eq, PartialEq)]
pub(crate) struct TSimpleBlock {
pub inlines: Vec<TSpan>,
}

impl fmt::Debug for TSimpleBlock {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Intentionally mimic the output of nom_span::Spanned
// so diffs point the unit test author to the important
// differences.
f.debug_struct("SimpleBlock")
.field("inlines", &self.inlines)
.finish()
}
}

impl<'a> PartialEq<SimpleBlock<'a>> for TSimpleBlock {
fn eq(&self, other: &SimpleBlock<'a>) -> bool {
tsimple_block_eq(self, other)
Expand Down
16 changes: 14 additions & 2 deletions src/tests/fixtures/document.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::cmp::PartialEq;
use std::{cmp::PartialEq, fmt};

use crate::{
tests::fixtures::{blocks::TBlock, TSpan},
Expand All @@ -10,12 +10,24 @@ use crate::{
//
// Primary difference is that the data members are public
// so we can declare them inline.
#[derive(Debug, Eq, PartialEq)]
#[derive(Eq, PartialEq)]
pub(crate) struct TDocument {
pub blocks: Vec<TBlock>,
pub source: TSpan,
}

impl fmt::Debug for TDocument {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Intentionally mimic the output of nom_span::Spanned
// so diffs point the unit test author to the important
// differences.
f.debug_struct("Document")
.field("blocks", &self.blocks)
.field("source", &self.source)
.finish()
}
}

impl<'a> PartialEq<Document<'a>> for TDocument {
fn eq(&self, other: &Document<'a>) -> bool {
tdocument_eq(self, other)
Expand Down
19 changes: 17 additions & 2 deletions src/tests/fixtures/span.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::cmp::PartialEq;
use std::{cmp::PartialEq, fmt};

use crate::Span;

Expand All @@ -7,14 +7,29 @@ use crate::Span;
//
// Primary difference is that the data members are public
// so we can declare them inline.
#[derive(Debug, Eq, PartialEq)]
#[derive(Eq, PartialEq)]
pub(crate) struct TSpan {
pub data: &'static str,
pub line: usize,
pub col: usize,
pub offset: usize,
}

impl fmt::Debug for TSpan {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Intentionally mimic the output of nom_span::Spanned
// so diffs point the unit test author to the important
// differences.
f.debug_struct("Spanned")
.field("data", &self.data)
.field("line", &self.line)
.field("col", &self.col)
.field("offset", &self.offset)
.field("handle_utf8", &true)
.finish()
}
}

impl<'a> PartialEq<Span<'a>> for TSpan {
fn eq(&self, other: &Span<'a>) -> bool {
tspan_eq(self, other)
Expand Down
8 changes: 8 additions & 0 deletions src/tests/primitives/line.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
mod fn_line {
use pretty_assertions_sorted::assert_eq;

use crate::{primitives::line, tests::fixtures::TSpan, Span};

#[test]
Expand Down Expand Up @@ -186,6 +188,8 @@ mod fn_line {
}

mod normalized_line {
use pretty_assertions_sorted::assert_eq;

use crate::{primitives::normalized_line, tests::fixtures::TSpan, Span};

#[test]
Expand Down Expand Up @@ -402,6 +406,7 @@ mod non_empty_line {
error::{Error, ErrorKind},
Err,
};
use pretty_assertions_sorted::assert_eq;

use crate::{primitives::non_empty_line, tests::fixtures::TSpan, Span};

Expand Down Expand Up @@ -589,6 +594,7 @@ mod empty_line {
error::{Error, ErrorKind},
Err,
};
use pretty_assertions_sorted::assert_eq;

use crate::{primitives::empty_line, tests::fixtures::TSpan, Span};

Expand Down Expand Up @@ -786,6 +792,8 @@ mod empty_line {
}

mod consume_empty_lines {
use pretty_assertions_sorted::assert_eq;

use crate::{primitives::consume_empty_lines, tests::fixtures::TSpan, Span};

#[test]
Expand Down
Loading