pub struct TestCase { /* private fields */ }Expand description
Declarative test builder for inline plugin tests.
Chain expectations and then call run() to execute:
use nginx_lint_plugin::prelude::*;
use nginx_lint_plugin::testing::TestCase;
TestCase::new("http {\n autoindex on;\n}")
.expect_error_count(1)
.expect_error_on_line(2)
.expect_message_contains("autoindex")
.expect_has_fix()
.expect_fix_produces("http {\n autoindex off;\n}")
.run(&MyPlugin);§Available Expectations
| Method | Description |
|---|---|
expect_error_count(n) | Exact error count |
expect_no_errors() | No errors |
expect_error_on_line(n) | Error on specific line |
expect_message_contains(s) | Error message substring |
expect_has_fix() | At least one error has a fix |
expect_fix_on_line(n) | Fix targets specific line |
expect_fix_produces(s) | Verify fix output |
Implementations§
Source§impl TestCase
impl TestCase
Sourcepub fn new(content: impl Into<String>) -> Self
pub fn new(content: impl Into<String>) -> Self
Create a new test case with the given config content
Sourcepub fn expect_error_count(self, count: usize) -> Self
pub fn expect_error_count(self, count: usize) -> Self
Expect a specific number of errors
Sourcepub fn expect_no_errors(self) -> Self
pub fn expect_no_errors(self) -> Self
Expect no errors
Sourcepub fn expect_error_on_line(self, line: usize) -> Self
pub fn expect_error_on_line(self, line: usize) -> Self
Expect at least one error on the given line
Sourcepub fn expect_message_contains(self, substring: impl Into<String>) -> Self
pub fn expect_message_contains(self, substring: impl Into<String>) -> Self
Expect error messages to contain the given substring
Sourcepub fn expect_has_fix(self) -> Self
pub fn expect_has_fix(self) -> Self
Expect at least one error to have a fix
Sourcepub fn expect_fix_on_line(self, line: usize) -> Self
pub fn expect_fix_on_line(self, line: usize) -> Self
Expect a fix on a specific line
Sourcepub fn expect_fix_produces(self, expected: impl Into<String>) -> Self
pub fn expect_fix_produces(self, expected: impl Into<String>) -> Self
Expect that applying all fixes produces the given output
Auto Trait Implementations§
impl Freeze for TestCase
impl RefUnwindSafe for TestCase
impl Send for TestCase
impl Sync for TestCase
impl Unpin for TestCase
impl UnsafeUnpin for TestCase
impl UnwindSafe for TestCase
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more