• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pomsky-lang / pomsky / 12301483439

12 Dec 2024 05:19PM UTC coverage: 80.275% (-0.2%) from 80.471%
12301483439

push

github

Aloso
feat: test command

360 of 593 new or added lines in 11 files covered. (60.71%)

20 existing lines in 7 files now uncovered.

4607 of 5739 relevant lines covered (80.28%)

374427.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

43.86
/pomsky-lib/src/diagnose/diagnostic_kind.rs
1
use std::{fmt::Display, str::FromStr};
2

3
use pomsky_syntax::diagnose::{ParseErrorKind, ParseWarningKind};
4

5
use super::CompileErrorKind;
6

7
/// The kind or origin of the error/warning
8
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9
#[non_exhaustive]
10
pub enum DiagnosticKind {
11
    /// Invalid syntax error
12
    Syntax,
13
    /// Error during name resolution
14
    Resolve,
15
    /// Diagnostic related to regex flavor compatibility
16
    Compat,
17
    /// Diagnostic indicating something is not implemented/allowed in Pomsky
18
    Unsupported,
19
    /// Deprecated syntax or feature was used
20
    Deprecated,
21
    /// A limitation that was deliberately enforced
22
    Limits,
23
    /// The generated regex is invalid (detected after variable expansion)
24
    Invalid,
25
    /// Unit test failure
26
    Test,
27
    /// Other unspecified error
28
    Other,
29
}
30

31
impl From<&CompileErrorKind> for DiagnosticKind {
32
    fn from(kind: &CompileErrorKind) -> Self {
62✔
33
        use CompileErrorKind as K;
34
        match kind {
62✔
35
            K::ParseError(p) => DiagnosticKind::from(p),
×
36
            K::Unsupported(..) => DiagnosticKind::Compat,
25✔
37
            K::UnsupportedPomskySyntax(_) | K::HugeReference => DiagnosticKind::Syntax,
2✔
38
            K::UnknownReferenceNumber(_)
39
            | K::UnknownReferenceName { .. }
40
            | K::NameUsedMultipleTimes(_)
41
            | K::UnknownVariable { .. }
42
            | K::RelativeRefZero => DiagnosticKind::Resolve,
7✔
43
            K::EmptyClassNegated { .. } | K::IllegalNegation { .. } => DiagnosticKind::Invalid,
12✔
44
            K::CaptureInLet
45
            | K::ReferenceInLet
46
            | K::RecursiveVariable
47
            | K::NegativeShorthandInAsciiMode
48
            | K::UnicodeInAsciiMode
49
            | K::NestedTest
50
            | K::NegatedHorizVertSpace
51
            | K::DotNetNumberedRefWithMixedGroups
52
            | K::RubyLookaheadInLookbehind { .. }
53
            | K::UnsupportedInLookbehind { .. }
54
            | K::LookbehindNotConstantLength { .. }
55
            | K::BadIntersection => DiagnosticKind::Unsupported,
15✔
56
            K::RangeIsTooBig(_) => DiagnosticKind::Limits,
1✔
57
        }
58
    }
62✔
59
}
60

61
impl From<&ParseErrorKind> for DiagnosticKind {
62
    fn from(kind: &ParseErrorKind) -> Self {
123✔
63
        match kind {
123✔
64
            ParseErrorKind::LetBindingExists => DiagnosticKind::Resolve,
1✔
65
            ParseErrorKind::Deprecated(_) => DiagnosticKind::Deprecated,
×
66
            ParseErrorKind::RecursionLimit => DiagnosticKind::Limits,
2✔
67
            _ => DiagnosticKind::Syntax,
120✔
68
        }
69
    }
123✔
70
}
71

72
impl From<&ParseWarningKind> for DiagnosticKind {
73
    fn from(kind: &ParseWarningKind) -> Self {
2✔
74
        match kind {
2✔
75
            ParseWarningKind::Deprecation(_) => DiagnosticKind::Deprecated,
2✔
76
        }
2✔
77
    }
2✔
78
}
79

80
impl Display for DiagnosticKind {
81
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6✔
82
        f.write_str(match self {
6✔
83
            DiagnosticKind::Syntax => "(syntax)",
2✔
84
            DiagnosticKind::Resolve => "(resolve)",
×
85
            DiagnosticKind::Compat => "(compat)",
×
86
            DiagnosticKind::Unsupported => "(unsupported)",
×
87
            DiagnosticKind::Deprecated => "(deprecated)",
×
88
            DiagnosticKind::Limits => "(limits)",
×
89
            DiagnosticKind::Invalid => "(invalid)",
×
90
            DiagnosticKind::Test => "(test)",
4✔
UNCOV
91
            DiagnosticKind::Other => "",
×
92
        })
93
    }
6✔
94
}
95

96
impl From<DiagnosticKind> for &'static str {
97
    fn from(val: DiagnosticKind) -> Self {
×
98
        match val {
×
99
            DiagnosticKind::Syntax => "syntax",
×
100
            DiagnosticKind::Resolve => "resolve",
×
101
            DiagnosticKind::Compat => "compat",
×
102
            DiagnosticKind::Unsupported => "unsupported",
×
103
            DiagnosticKind::Deprecated => "deprecated",
×
104
            DiagnosticKind::Limits => "limits",
×
105
            DiagnosticKind::Invalid => "invalid",
×
106
            DiagnosticKind::Test => "test",
×
107
            DiagnosticKind::Other => "other",
×
108
        }
109
    }
×
110
}
111

112
impl FromStr for DiagnosticKind {
113
    type Err = ();
114

115
    fn from_str(s: &str) -> Result<Self, Self::Err> {
×
116
        Ok(match s {
×
117
            "syntax" => DiagnosticKind::Syntax,
×
118
            "resolve" => DiagnosticKind::Resolve,
×
119
            "compat" => DiagnosticKind::Compat,
×
120
            "unsupported" => DiagnosticKind::Unsupported,
×
121
            "deprecated" => DiagnosticKind::Deprecated,
×
122
            "limits" => DiagnosticKind::Limits,
×
123
            "other" => DiagnosticKind::Other,
×
124
            _ => return Err(()),
×
125
        })
126
    }
×
127
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc