Use error's description for snapshot assertions + sort reported expected tokens
Turns out the snapshot test would randomly fail because the expected tokens are a HashSet, which is unordered by construction. So, using the auto-derived `Debug` instance to compare it with snapshot would only succeed if the tokens happened to be in the same order in the HashSet, which only happens by accident. Signed-off-by: KtorZ <matthias.benkort@gmail.com>
This commit is contained in:
parent
eadbc60a72
commit
862fc490c1
|
@ -3,6 +3,7 @@ use crate::{
|
|||
parser::token::Token,
|
||||
};
|
||||
use indoc::formatdoc;
|
||||
use itertools::Itertools;
|
||||
use miette::Diagnostic;
|
||||
use owo_colors::{OwoColorize, Stream::Stdout};
|
||||
use std::collections::HashSet;
|
||||
|
@ -18,6 +19,7 @@ use std::collections::HashSet;
|
|||
"I am looking for one of the following patterns:\n{}",
|
||||
expected
|
||||
.iter()
|
||||
.sorted()
|
||||
.map(|x| format!(
|
||||
"→ {}",
|
||||
x.to_aiken()
|
||||
|
@ -320,7 +322,7 @@ fn fmt_unknown_curve(curve: &String, point: &Option<String>) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Diagnostic, thiserror::Error)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Diagnostic, thiserror::Error)]
|
||||
pub enum Pattern {
|
||||
#[error("I found an unexpected char '{0:?}'.")]
|
||||
#[diagnostic(help("Try removing it!"))]
|
||||
|
|
|
@ -2,14 +2,4 @@
|
|||
source: crates/aiken-lang/src/parser/expr/assignment.rs
|
||||
description: "Invalid code (parse error):\n\nlet a =\n// foo\nlet b = 42\n"
|
||||
---
|
||||
[
|
||||
ParseError {
|
||||
kind: UnfinishedAssignmentRightHandSide,
|
||||
span: 0..25,
|
||||
while_parsing: None,
|
||||
expected: {},
|
||||
label: Some(
|
||||
"invalid assignment right-hand side",
|
||||
),
|
||||
},
|
||||
]
|
||||
I spotted an unfinished assignment.
|
||||
|
|
|
@ -2,71 +2,4 @@
|
|||
source: crates/aiken-lang/src/parser/expr/fail_todo_trace.rs
|
||||
description: "Invalid code (parse error):\n\nlet debug = fn() {\n trace \"foo\":\n}\n"
|
||||
---
|
||||
[
|
||||
ParseError {
|
||||
kind: Unexpected(
|
||||
Token(
|
||||
RightBrace,
|
||||
),
|
||||
),
|
||||
span: 34..35,
|
||||
while_parsing: None,
|
||||
expected: {
|
||||
Token(
|
||||
If,
|
||||
),
|
||||
Token(
|
||||
Expect,
|
||||
),
|
||||
Token(
|
||||
Minus,
|
||||
),
|
||||
Token(
|
||||
When,
|
||||
),
|
||||
Token(
|
||||
And,
|
||||
),
|
||||
Token(
|
||||
Or,
|
||||
),
|
||||
Token(
|
||||
LeftParen,
|
||||
),
|
||||
Token(
|
||||
Todo,
|
||||
),
|
||||
Token(
|
||||
LeftSquare,
|
||||
),
|
||||
Token(
|
||||
NewLineMinus,
|
||||
),
|
||||
Token(
|
||||
Bang,
|
||||
),
|
||||
Token(
|
||||
Fail,
|
||||
),
|
||||
Token(
|
||||
NewLineLeftParen,
|
||||
),
|
||||
Token(
|
||||
LeftBrace,
|
||||
),
|
||||
Token(
|
||||
Trace,
|
||||
),
|
||||
Token(
|
||||
Let,
|
||||
),
|
||||
Token(
|
||||
Hash,
|
||||
),
|
||||
Token(
|
||||
Fn,
|
||||
),
|
||||
},
|
||||
label: None,
|
||||
},
|
||||
]
|
||||
I found an unexpected token '}'.
|
||||
|
|
|
@ -2,14 +2,4 @@
|
|||
source: crates/aiken-lang/src/parser/expr/when/mod.rs
|
||||
description: "Invalid code (parse error):\n\nwhen a is {\n 2 if x > 1 -> 3\n _ -> 1\n}\n"
|
||||
---
|
||||
[
|
||||
ParseError {
|
||||
kind: DeprecatedWhenClause,
|
||||
span: 14..29,
|
||||
while_parsing: None,
|
||||
expected: {},
|
||||
label: Some(
|
||||
"deprecated",
|
||||
),
|
||||
},
|
||||
]
|
||||
I found a now-deprecated clause guard in a when/is expression.
|
||||
|
|
|
@ -2,14 +2,4 @@
|
|||
source: crates/aiken-lang/src/parser/pattern/bytearray.rs
|
||||
description: "Invalid code (parse error):\n\nwhen foo is {\n #<Bls12_381, G1>\"950dfd33da2682260c76038dfb8bad6e84ae9d599a3c151815945ac1e6ef6b1027cd917f3907479d20d636ce437a41f5\" -> False\n _ -> True\n}\n"
|
||||
---
|
||||
[
|
||||
ParseError {
|
||||
kind: PatternMatchOnCurvePoint,
|
||||
span: 18..132,
|
||||
while_parsing: None,
|
||||
expected: {},
|
||||
label: Some(
|
||||
"cannot pattern-match on curve point",
|
||||
),
|
||||
},
|
||||
]
|
||||
I choked on a curve point in a bytearray pattern.
|
||||
|
|
|
@ -2,14 +2,4 @@
|
|||
source: crates/aiken-lang/src/parser/pattern/bytearray.rs
|
||||
description: "Invalid code (parse error):\n\nwhen foo is {\n #<Bls12_381, G2>\"b0629fa1158c2d23a10413fe91d381a84d25e31d041cd0377d25828498fd02011b35893938ced97535395e4815201e67108bcd4665e0db25d602d76fa791fab706c54abf5e1a9e44b4ac1e6badf3d2ac0328f5e30be341677c8bac5dda7682f1\" -> False\n _ -> True\n}\n"
|
||||
---
|
||||
[
|
||||
ParseError {
|
||||
kind: PatternMatchOnCurvePoint,
|
||||
span: 18..228,
|
||||
while_parsing: None,
|
||||
expected: {},
|
||||
label: Some(
|
||||
"cannot pattern-match on curve point",
|
||||
),
|
||||
},
|
||||
]
|
||||
I choked on a curve point in a bytearray pattern.
|
||||
|
|
|
@ -2,14 +2,4 @@
|
|||
source: crates/aiken-lang/src/parser/pattern/string.rs
|
||||
description: "Invalid code (parse error):\n\nwhen foo is {\n @\"foo\" -> True\n}\n"
|
||||
---
|
||||
[
|
||||
ParseError {
|
||||
kind: PatternMatchOnString,
|
||||
span: 16..22,
|
||||
while_parsing: None,
|
||||
expected: {},
|
||||
label: Some(
|
||||
"cannot pattern-match on string",
|
||||
),
|
||||
},
|
||||
]
|
||||
I refuse to cooperate and match a utf-8 string.
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
use std::fmt;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Hash, Eq, Copy, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(
|
||||
Clone, Debug, PartialEq, PartialOrd, Ord, Hash, Eq, Copy, serde::Serialize, serde::Deserialize,
|
||||
)]
|
||||
pub enum Base {
|
||||
Decimal { numeric_underscore: bool },
|
||||
Hexadecimal,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Hash, Eq)]
|
||||
#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Hash, Eq)]
|
||||
pub enum Token {
|
||||
Error(char),
|
||||
Name { name: String },
|
||||
|
|
|
@ -45,7 +45,7 @@ macro_rules! assert_expr {
|
|||
prepend_module_to_snapshot => false,
|
||||
omit_expression => true
|
||||
}, {
|
||||
insta::assert_debug_snapshot!(err);
|
||||
insta::assert_snapshot!(err.into_iter().map(|e| e.to_string()).collect::<Vec<_>>().join("\n"));
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue