mirror of https://github.com/kdl-org/kdl-rs.git
feat(error): Rename KdlParseFailure back to KdlError
This commit is contained in:
parent
c486cda7a5
commit
12b2fd2f4f
|
|
@ -2,7 +2,7 @@
|
||||||
use miette::SourceSpan;
|
use miette::SourceSpan;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
use crate::{FormatConfig, KdlNode, KdlParseFailure, KdlValue};
|
use crate::{FormatConfig, KdlError, KdlNode, KdlValue};
|
||||||
|
|
||||||
/// Represents a KDL
|
/// Represents a KDL
|
||||||
/// [`Document`](https://github.com/kdl-org/kdl/blob/main/SPEC.md#document).
|
/// [`Document`](https://github.com/kdl-org/kdl/blob/main/SPEC.md#document).
|
||||||
|
|
@ -341,7 +341,7 @@ impl KdlDocument {
|
||||||
/// parse the string as a KDL v2 document, and, if that fails, it will try
|
/// parse the string as a KDL v2 document, and, if that fails, it will try
|
||||||
/// to parse again as a KDL v1 document. If both fail, only the v2 parse
|
/// to parse again as a KDL v1 document. If both fail, only the v2 parse
|
||||||
/// errors will be returned.
|
/// errors will be returned.
|
||||||
pub fn parse(s: &str) -> Result<Self, KdlParseFailure> {
|
pub fn parse(s: &str) -> Result<Self, KdlError> {
|
||||||
#[cfg(not(feature = "v1-fallback"))]
|
#[cfg(not(feature = "v1-fallback"))]
|
||||||
{
|
{
|
||||||
crate::v2_parser::try_parse(crate::v2_parser::document, s)
|
crate::v2_parser::try_parse(crate::v2_parser::document, s)
|
||||||
|
|
@ -355,7 +355,7 @@ impl KdlDocument {
|
||||||
|
|
||||||
/// Parses a KDL v1 string into a document.
|
/// Parses a KDL v1 string into a document.
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
pub fn parse_v1(s: &str) -> Result<Self, KdlParseFailure> {
|
pub fn parse_v1(s: &str) -> Result<Self, KdlError> {
|
||||||
let ret: Result<kdlv1::KdlDocument, kdlv1::KdlError> = s.parse();
|
let ret: Result<kdlv1::KdlDocument, kdlv1::KdlError> = s.parse();
|
||||||
ret.map(|x| x.into()).map_err(|e| e.into())
|
ret.map(|x| x.into()).map_err(|e| e.into())
|
||||||
}
|
}
|
||||||
|
|
@ -363,7 +363,7 @@ impl KdlDocument {
|
||||||
/// Takes a KDL v1 document string and returns the same document, but
|
/// Takes a KDL v1 document string and returns the same document, but
|
||||||
/// autoformatted into valid KDL v2 syntax.
|
/// autoformatted into valid KDL v2 syntax.
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
pub fn v1_to_v2(s: &str) -> Result<String, KdlParseFailure> {
|
pub fn v1_to_v2(s: &str) -> Result<String, KdlError> {
|
||||||
let mut doc = KdlDocument::parse_v1(s)?;
|
let mut doc = KdlDocument::parse_v1(s)?;
|
||||||
doc.autoformat();
|
doc.autoformat();
|
||||||
Ok(doc.to_string())
|
Ok(doc.to_string())
|
||||||
|
|
@ -386,7 +386,7 @@ impl From<kdlv1::KdlDocument> for KdlDocument {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for KdlDocument {
|
impl std::str::FromStr for KdlDocument {
|
||||||
type Err = KdlParseFailure;
|
type Err = KdlError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
KdlDocument::parse(s)
|
KdlDocument::parse(s)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
use miette::SourceSpan;
|
use miette::SourceSpan;
|
||||||
use std::{fmt::Display, str::FromStr};
|
use std::{fmt::Display, str::FromStr};
|
||||||
|
|
||||||
use crate::{v2_parser, KdlIdentifier, KdlParseFailure, KdlValue};
|
use crate::{v2_parser, KdlError, KdlIdentifier, KdlValue};
|
||||||
|
|
||||||
/// KDL Entries are the "arguments" to KDL nodes: either a (positional)
|
/// KDL Entries are the "arguments" to KDL nodes: either a (positional)
|
||||||
/// [`Argument`](https://github.com/kdl-org/kdl/blob/main/SPEC.md#argument) or
|
/// [`Argument`](https://github.com/kdl-org/kdl/blob/main/SPEC.md#argument) or
|
||||||
|
|
@ -248,7 +248,7 @@ impl KdlEntry {
|
||||||
/// parse the string as a KDL v2 entry, and, if that fails, it will try
|
/// parse the string as a KDL v2 entry, and, if that fails, it will try
|
||||||
/// to parse again as a KDL v1 entry. If both fail, only the v2 parse
|
/// to parse again as a KDL v1 entry. If both fail, only the v2 parse
|
||||||
/// errors will be returned.
|
/// errors will be returned.
|
||||||
pub fn parse(s: &str) -> Result<Self, KdlParseFailure> {
|
pub fn parse(s: &str) -> Result<Self, KdlError> {
|
||||||
#[cfg(not(feature = "v1-fallback"))]
|
#[cfg(not(feature = "v1-fallback"))]
|
||||||
{
|
{
|
||||||
v2_parser::try_parse(v2_parser::padded_node_entry, s)
|
v2_parser::try_parse(v2_parser::padded_node_entry, s)
|
||||||
|
|
@ -262,7 +262,7 @@ impl KdlEntry {
|
||||||
|
|
||||||
/// Parses a KDL v1 string into an entry.
|
/// Parses a KDL v1 string into an entry.
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
pub fn parse_v1(s: &str) -> Result<Self, KdlParseFailure> {
|
pub fn parse_v1(s: &str) -> Result<Self, KdlError> {
|
||||||
let ret: Result<kdlv1::KdlEntry, kdlv1::KdlError> = s.parse();
|
let ret: Result<kdlv1::KdlEntry, kdlv1::KdlError> = s.parse();
|
||||||
ret.map(|x| x.into()).map_err(|e| e.into())
|
ret.map(|x| x.into()).map_err(|e| e.into())
|
||||||
}
|
}
|
||||||
|
|
@ -353,7 +353,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for KdlEntry {
|
impl FromStr for KdlEntry {
|
||||||
type Err = KdlParseFailure;
|
type Err = KdlError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
KdlEntry::parse(s)
|
KdlEntry::parse(s)
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ use {
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Diagnostic, Clone, Eq, PartialEq, Error)]
|
#[derive(Debug, Diagnostic, Clone, Eq, PartialEq, Error)]
|
||||||
#[error("Failed to parse KDL document")]
|
#[error("Failed to parse KDL document")]
|
||||||
pub struct KdlParseFailure {
|
pub struct KdlError {
|
||||||
/// Original input that this failure came from.
|
/// Original input that this failure came from.
|
||||||
#[source_code]
|
#[source_code]
|
||||||
pub input: Arc<String>,
|
pub input: Arc<String>,
|
||||||
|
|
@ -76,10 +76,10 @@ pub struct KdlDiagnostic {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
impl From<kdlv1::KdlError> for KdlParseFailure {
|
impl From<kdlv1::KdlError> for KdlError {
|
||||||
fn from(value: kdlv1::KdlError) -> Self {
|
fn from(value: kdlv1::KdlError) -> Self {
|
||||||
let input = Arc::new(value.input);
|
let input = Arc::new(value.input);
|
||||||
KdlParseFailure {
|
KdlError {
|
||||||
input: input.clone(),
|
input: input.clone(),
|
||||||
diagnostics: vec.
|
/// [Identifier](https://github.com/kdl-org/kdl/blob/main/SPEC.md#identifier).
|
||||||
|
|
@ -94,7 +94,7 @@ impl KdlIdentifier {
|
||||||
/// parse the string as a KDL v2 entry, and, if that fails, it will try
|
/// parse the string as a KDL v2 entry, and, if that fails, it will try
|
||||||
/// to parse again as a KDL v1 entry. If both fail, only the v2 parse
|
/// to parse again as a KDL v1 entry. If both fail, only the v2 parse
|
||||||
/// errors will be returned.
|
/// errors will be returned.
|
||||||
pub fn parse(s: &str) -> Result<Self, KdlParseFailure> {
|
pub fn parse(s: &str) -> Result<Self, KdlError> {
|
||||||
#[cfg(not(feature = "v1-fallback"))]
|
#[cfg(not(feature = "v1-fallback"))]
|
||||||
{
|
{
|
||||||
v2_parser::try_parse(v2_parser::identifier, s)
|
v2_parser::try_parse(v2_parser::identifier, s)
|
||||||
|
|
@ -108,7 +108,7 @@ impl KdlIdentifier {
|
||||||
|
|
||||||
/// Parses a KDL v1 string into an entry.
|
/// Parses a KDL v1 string into an entry.
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
pub fn parse_v1(s: &str) -> Result<Self, KdlParseFailure> {
|
pub fn parse_v1(s: &str) -> Result<Self, KdlError> {
|
||||||
let ret: Result<kdlv1::KdlIdentifier, kdlv1::KdlError> = s.parse();
|
let ret: Result<kdlv1::KdlIdentifier, kdlv1::KdlError> = s.parse();
|
||||||
ret.map(|x| x.into()).map_err(|e| e.into())
|
ret.map(|x| x.into()).map_err(|e| e.into())
|
||||||
}
|
}
|
||||||
|
|
@ -165,7 +165,7 @@ impl From<KdlIdentifier> for String {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for KdlIdentifier {
|
impl FromStr for KdlIdentifier {
|
||||||
type Err = KdlParseFailure;
|
type Err = KdlError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
KdlIdentifier::parse(s)
|
KdlIdentifier::parse(s)
|
||||||
|
|
|
||||||
10
src/node.rs
10
src/node.rs
|
|
@ -10,8 +10,8 @@ use std::{
|
||||||
use miette::SourceSpan;
|
use miette::SourceSpan;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
v2_parser, FormatConfig, KdlDocument, KdlDocumentFormat, KdlEntry, KdlIdentifier,
|
v2_parser, FormatConfig, KdlDocument, KdlDocumentFormat, KdlEntry, KdlError, KdlIdentifier,
|
||||||
KdlParseFailure, KdlValue,
|
KdlValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Represents an individual KDL
|
/// Represents an individual KDL
|
||||||
|
|
@ -332,7 +332,7 @@ impl KdlNode {
|
||||||
/// parse the string as a KDL v2 node, and, if that fails, it will try
|
/// parse the string as a KDL v2 node, and, if that fails, it will try
|
||||||
/// to parse again as a KDL v1 node. If both fail, only the v2 parse
|
/// to parse again as a KDL v1 node. If both fail, only the v2 parse
|
||||||
/// errors will be returned.
|
/// errors will be returned.
|
||||||
pub fn parse(s: &str) -> Result<Self, KdlParseFailure> {
|
pub fn parse(s: &str) -> Result<Self, KdlError> {
|
||||||
#[cfg(not(feature = "v1-fallback"))]
|
#[cfg(not(feature = "v1-fallback"))]
|
||||||
{
|
{
|
||||||
v2_parser::try_parse(v2_parser::padded_node, s)
|
v2_parser::try_parse(v2_parser::padded_node, s)
|
||||||
|
|
@ -346,7 +346,7 @@ impl KdlNode {
|
||||||
|
|
||||||
/// Parses a KDL v1 string into a document.
|
/// Parses a KDL v1 string into a document.
|
||||||
#[cfg(feature = "v1")]
|
#[cfg(feature = "v1")]
|
||||||
pub fn parse_v1(s: &str) -> Result<Self, KdlParseFailure> {
|
pub fn parse_v1(s: &str) -> Result<Self, KdlError> {
|
||||||
let ret: Result<kdlv1::KdlNode, kdlv1::KdlError> = s.parse();
|
let ret: Result<kdlv1::KdlNode, kdlv1::KdlError> = s.parse();
|
||||||
ret.map(|x| x.into()).map_err(|e| e.into())
|
ret.map(|x| x.into()).map_err(|e| e.into())
|
||||||
}
|
}
|
||||||
|
|
@ -753,7 +753,7 @@ impl IndexMut<&str> for KdlNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for KdlNode {
|
impl FromStr for KdlNode {
|
||||||
type Err = KdlParseFailure;
|
type Err = KdlError;
|
||||||
|
|
||||||
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
v2_parser::try_parse(v2_parser::padded_node, input)
|
v2_parser::try_parse(v2_parser::padded_node, input)
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ use winnow::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
KdlDiagnostic, KdlDocument, KdlDocumentFormat, KdlEntry, KdlEntryFormat, KdlIdentifier,
|
KdlDiagnostic, KdlDocument, KdlDocumentFormat, KdlEntry, KdlEntryFormat, KdlError,
|
||||||
KdlNode, KdlNodeFormat, KdlParseFailure, KdlValue,
|
KdlIdentifier, KdlNode, KdlNodeFormat, KdlValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
type Input<'a> = Recoverable<Located<&'a str>, KdlParseError>;
|
type Input<'a> = Recoverable<Located<&'a str>, KdlParseError>;
|
||||||
|
|
@ -30,7 +30,7 @@ type PResult<T> = winnow::PResult<T, KdlParseError>;
|
||||||
pub(crate) fn try_parse<'a, P: Parser<Input<'a>, T, KdlParseError>, T>(
|
pub(crate) fn try_parse<'a, P: Parser<Input<'a>, T, KdlParseError>, T>(
|
||||||
mut parser: P,
|
mut parser: P,
|
||||||
input: &'a str,
|
input: &'a str,
|
||||||
) -> Result<T, KdlParseFailure> {
|
) -> Result<T, KdlError> {
|
||||||
let (_, maybe_val, errs) = parser.recoverable_parse(Located::new(input));
|
let (_, maybe_val, errs) = parser.recoverable_parse(Located::new(input));
|
||||||
if let (Some(v), true) = (maybe_val, errs.is_empty()) {
|
if let (Some(v), true) = (maybe_val, errs.is_empty()) {
|
||||||
Ok(v)
|
Ok(v)
|
||||||
|
|
@ -39,9 +39,9 @@ pub(crate) fn try_parse<'a, P: Parser<Input<'a>, T, KdlParseError>, T>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn failure_from_errs(errs: Vec<KdlParseError>, input: &str) -> KdlParseFailure {
|
pub(crate) fn failure_from_errs(errs: Vec<KdlParseError>, input: &str) -> KdlError {
|
||||||
let src = Arc::new(String::from(input));
|
let src = Arc::new(String::from(input));
|
||||||
KdlParseFailure {
|
KdlError {
|
||||||
input: src.clone(),
|
input: src.clone(),
|
||||||
diagnostics: errs
|
diagnostics: errs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
@ -2050,13 +2050,13 @@ impl_negatable_unsigned!(u8, u16, u32, u64, u128, usize);
|
||||||
mod failure_tests {
|
mod failure_tests {
|
||||||
use miette::Severity;
|
use miette::Severity;
|
||||||
|
|
||||||
use crate::{KdlDiagnostic, KdlDocument, KdlParseFailure};
|
use crate::{KdlDiagnostic, KdlDocument, KdlError};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn bad_node_name_test() -> miette::Result<()> {
|
fn bad_node_name_test() -> miette::Result<()> {
|
||||||
let input = Arc::new("foo { bar; { baz; }; }".to_string());
|
let input = Arc::new("foo { bar; { baz; }; }".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
// super::_print_diagnostic(res);
|
// super::_print_diagnostic(res);
|
||||||
// return Ok(());
|
// return Ok(());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -2076,7 +2076,7 @@ mod failure_tests {
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
let input = Arc::new("no/de 1 {\n 1 2 foo\n bad#\n}".to_string());
|
let input = Arc::new("no/de 1 {\n 1 2 foo\n bad#\n}".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
// super::_print_diagnostic(res);
|
// super::_print_diagnostic(res);
|
||||||
// return Ok(());
|
// return Ok(());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -2133,7 +2133,7 @@ mod failure_tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn bad_entry_number_test() -> miette::Result<()> {
|
fn bad_entry_number_test() -> miette::Result<()> {
|
||||||
let input = Arc::new("node 1asdf 2".to_string());
|
let input = Arc::new("node 1asdf 2".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
// super::_print_diagnostic(res);
|
// super::_print_diagnostic(res);
|
||||||
// return Ok(());
|
// return Ok(());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -2152,7 +2152,7 @@ mod failure_tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = Arc::new("node 0x1asdf 2".to_string());
|
let input = Arc::new("node 0x1asdf 2".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
res,
|
res,
|
||||||
Err(mkfail(
|
Err(mkfail(
|
||||||
|
|
@ -2169,7 +2169,7 @@ mod failure_tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = Arc::new("node 0o1asdf 2".to_string());
|
let input = Arc::new("node 0o1asdf 2".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
res,
|
res,
|
||||||
Err(mkfail(
|
Err(mkfail(
|
||||||
|
|
@ -2186,7 +2186,7 @@ mod failure_tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = Arc::new("node 0b1asdf 2".to_string());
|
let input = Arc::new("node 0b1asdf 2".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
res,
|
res,
|
||||||
Err(mkfail(
|
Err(mkfail(
|
||||||
|
|
@ -2203,7 +2203,7 @@ mod failure_tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = Arc::new("node 1.0asdf 2".to_string());
|
let input = Arc::new("node 1.0asdf 2".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
res,
|
res,
|
||||||
Err(mkfail(
|
Err(mkfail(
|
||||||
|
|
@ -2220,7 +2220,7 @@ mod failure_tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = Arc::new("node 1.asdf 2".to_string());
|
let input = Arc::new("node 1.asdf 2".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
res,
|
res,
|
||||||
Err(mkfail(
|
Err(mkfail(
|
||||||
|
|
@ -2237,7 +2237,7 @@ mod failure_tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = Arc::new("node 1.0easdf 2".to_string());
|
let input = Arc::new("node 1.0easdf 2".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
res,
|
res,
|
||||||
Err(mkfail(
|
Err(mkfail(
|
||||||
|
|
@ -2263,7 +2263,7 @@ mod failure_tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn bad_string_test() -> miette::Result<()> {
|
fn bad_string_test() -> miette::Result<()> {
|
||||||
let input = Arc::new("node \" 1".to_string());
|
let input = Arc::new("node \" 1".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
res,
|
res,
|
||||||
Err(mkfail(
|
Err(mkfail(
|
||||||
|
|
@ -2280,7 +2280,7 @@ mod failure_tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = Arc::new("node \"foo\"1".to_string());
|
let input = Arc::new("node \"foo\"1".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
// if let Err(e) = res {
|
// if let Err(e) = res {
|
||||||
// println!("{:?}", miette::Report::from(e));
|
// println!("{:?}", miette::Report::from(e));
|
||||||
// }
|
// }
|
||||||
|
|
@ -2300,7 +2300,7 @@ mod failure_tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = Arc::new("node \"\nlet's do multiline!\"".to_string());
|
let input = Arc::new("node \"\nlet's do multiline!\"".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
res,
|
res,
|
||||||
Err(mkfail(
|
Err(mkfail(
|
||||||
|
|
@ -2331,7 +2331,7 @@ mod failure_tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn bad_child_test() -> miette::Result<()> {
|
fn bad_child_test() -> miette::Result<()> {
|
||||||
let input = Arc::new("node {".to_string());
|
let input = Arc::new("node {".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
// _print_diagnostic(res);
|
// _print_diagnostic(res);
|
||||||
// return Ok(());
|
// return Ok(());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -2350,7 +2350,7 @@ mod failure_tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = Arc::new("node {}}".to_string());
|
let input = Arc::new("node {}}".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
// _print_diagnostic(res);
|
// _print_diagnostic(res);
|
||||||
// return Ok(());
|
// return Ok(());
|
||||||
// println!("{res:#?}");
|
// println!("{res:#?}");
|
||||||
|
|
@ -2370,7 +2370,7 @@ mod failure_tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = Arc::new("node }{".to_string());
|
let input = Arc::new("node }{".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
// _print_diagnostic(res);
|
// _print_diagnostic(res);
|
||||||
// return Ok(());
|
// return Ok(());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -2421,7 +2421,7 @@ mod failure_tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = Arc::new("node {\n".to_string());
|
let input = Arc::new("node {\n".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
// _print_diagnostic(res);
|
// _print_diagnostic(res);
|
||||||
// return Ok(());
|
// return Ok(());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -2450,7 +2450,7 @@ mod failure_tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let input = Arc::new("node {\nnode2{{}}".to_string());
|
let input = Arc::new("node {\nnode2{{}}".to_string());
|
||||||
let res: Result<KdlDocument, KdlParseFailure> = input.parse();
|
let res: Result<KdlDocument, KdlError> = input.parse();
|
||||||
// _print_diagnostic(res);
|
// _print_diagnostic(res);
|
||||||
// return Ok(());
|
// return Ok(());
|
||||||
println!("{res:#?}");
|
println!("{res:#?}");
|
||||||
|
|
@ -2504,13 +2504,13 @@ mod failure_tests {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mkfail(input: Arc<String>, diagnostics: Vec<KdlDiagnostic>) -> KdlParseFailure {
|
fn mkfail(input: Arc<String>, diagnostics: Vec<KdlDiagnostic>) -> KdlError {
|
||||||
KdlParseFailure { input, diagnostics }
|
KdlError { input, diagnostics }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn _print_diagnostic<T>(res: Result<T, KdlParseFailure>) {
|
fn _print_diagnostic<T>(res: Result<T, KdlError>) {
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
println!("{:?}", miette::Report::from(e));
|
println!("{:?}", miette::Report::from(e));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
use kdl::{KdlDocument, KdlIdentifier, KdlParseFailure, KdlValue};
|
use kdl::{KdlDocument, KdlError, KdlIdentifier, KdlValue};
|
||||||
use miette::{Diagnostic, IntoDiagnostic};
|
use miette::{Diagnostic, IntoDiagnostic};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
|
@ -20,11 +20,11 @@ struct ComplianceSuiteFailure {
|
||||||
enum ComplianceDiagnostic {
|
enum ComplianceDiagnostic {
|
||||||
#[error("{}", PathBuf::from(.0.file_name().unwrap()).display())]
|
#[error("{}", PathBuf::from(.0.file_name().unwrap()).display())]
|
||||||
#[diagnostic(code(kdl::compliance::parse_failure))]
|
#[diagnostic(code(kdl::compliance::parse_failure))]
|
||||||
KdlParseFailure(
|
KdlError(
|
||||||
PathBuf,
|
PathBuf,
|
||||||
#[source]
|
#[source]
|
||||||
#[diagnostic_source]
|
#[diagnostic_source]
|
||||||
KdlParseFailure,
|
KdlError,
|
||||||
),
|
),
|
||||||
|
|
||||||
#[error("{}:\nExpected:\n{expected}\nActual:\n{actual}", PathBuf::from(file.file_name().unwrap()).display())]
|
#[error("{}:\nExpected:\n{expected}\nActual:\n{actual}", PathBuf::from(file.file_name().unwrap()).display())]
|
||||||
|
|
@ -74,7 +74,7 @@ fn spec_compliance() -> miette::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_res(
|
fn validate_res(
|
||||||
res: Result<KdlDocument, KdlParseFailure>,
|
res: Result<KdlDocument, KdlError>,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
src: &str,
|
src: &str,
|
||||||
) -> Result<(), ComplianceDiagnostic> {
|
) -> Result<(), ComplianceDiagnostic> {
|
||||||
|
|
@ -88,7 +88,7 @@ fn validate_res(
|
||||||
let expected_path = expected_dir.join(file_name);
|
let expected_path = expected_dir.join(file_name);
|
||||||
let underscored = expected_dir.join(format!("_{}", PathBuf::from(file_name).display()));
|
let underscored = expected_dir.join(format!("_{}", PathBuf::from(file_name).display()));
|
||||||
if expected_path.exists() {
|
if expected_path.exists() {
|
||||||
let doc = res.map_err(|e| ComplianceDiagnostic::KdlParseFailure(path.into(), e))?;
|
let doc = res.map_err(|e| ComplianceDiagnostic::KdlError(path.into(), e))?;
|
||||||
let expected = normalize_line_endings(fs::read_to_string(&expected_path)?);
|
let expected = normalize_line_endings(fs::read_to_string(&expected_path)?);
|
||||||
let actual = stringify_to_expected(doc);
|
let actual = stringify_to_expected(doc);
|
||||||
if actual != expected {
|
if actual != expected {
|
||||||
|
|
@ -105,7 +105,7 @@ fn validate_res(
|
||||||
PathBuf::from(file_name).display()
|
PathBuf::from(file_name).display()
|
||||||
);
|
);
|
||||||
// } else {
|
// } else {
|
||||||
// res.map_err(|e| ComplianceDiagnostic::KdlParseFailure(path.into(), e))?;
|
// res.map_err(|e| ComplianceDiagnostic::KdlError(path.into(), e))?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue