Skip to content

Commit 0686bb1

Browse files
sei40krclaude
andcommitted
feat: add is_success and is_failure methods for ParseResult
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f3f9590 commit 0686bb1

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

  • rust/ruby-prism/src/parse_result

rust/ruby-prism/src/parse_result/mod.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ impl<'pr> ParseResult<'pr> {
175175
pub fn node(&self) -> Node<'_> {
176176
Node::new(self.parser, self.node.as_ptr())
177177
}
178+
179+
/// Returns true if there were no errors during parsing and false if there
180+
/// were.
181+
#[must_use]
182+
pub fn is_success(&self) -> bool {
183+
self.errors().next().is_none()
184+
}
185+
186+
/// Returns true if there were errors during parsing and false if there were
187+
/// not.
188+
#[must_use]
189+
pub fn is_failure(&self) -> bool {
190+
!self.is_success()
191+
}
178192
}
179193

180194
impl Drop for ParseResult<'_> {
@@ -186,3 +200,22 @@ impl Drop for ParseResult<'_> {
186200
}
187201
}
188202
}
203+
204+
#[cfg(test)]
205+
mod tests {
206+
use crate::parse;
207+
208+
#[test]
209+
fn test_is_success() {
210+
let result = parse(b"1 + 1");
211+
assert!(result.is_success());
212+
assert!(!result.is_failure());
213+
}
214+
215+
#[test]
216+
fn test_is_failure() {
217+
let result = parse(b"<>");
218+
assert!(result.is_failure());
219+
assert!(!result.is_success());
220+
}
221+
}

0 commit comments

Comments
 (0)