9 个稳定版本 (3 个主要版本)
6.1.3 | 2021年3月25日 |
---|---|
6.1.2 | 2021年1月6日 |
3.0.0 | 2017年5月12日 |
2.0.0 | 2016年11月28日 |
1.0.1 | 2016年11月2日 |
#1601 在 解析器实现
在 3 个 crate 中使用
19KB
407 行
Nom TestHelpers
用法
将以下内容放入您的 Cargo.toml 文件中
[source,toml]
[dev-dependencies]
nom-test-helpers = "6"
示例
这个 crate 中的宏主要关注断言来自 IResult
的 nom
解析器的值。
例如,以下是如何测试 IResult
是 Ok,并具有特定的输出值
[source,rust]
use nom::{named, tag};
use nom_test_helpers::{assert_done_and_eq, assert_finished_and_eq};
named!(abcd<&str, &str>, tag!("abcd"));
fn main() {
let r = abcd("abcd");
assert_done_and_eq!(r, "abcd");
// Additionally, if you want to assert that the I value of the IResult is empty,
// you can use `assert_finished_and_eq!` instead:
assert_finished_and_eq!(r, "abcd");
}
lib.rs
:
测试 nom
解析器的宏
当我在测试 nom
解析器时,我经常定义很多这样的小宏,所以我将它们打包成一个 crate,这样我就不必反复定义它们。
这个 crate 最初是在 nom 有 "Done" 与 "Finished" 概念的时候创建的,这现在可能有点过时,但我仍然在测试时发现它很有用。基本上,测试 "Done" 的宏检查解析器是否成功完成,而测试 "Finished" 的宏则检查解析器在输入为空的情况下是否成功完成。
依赖项
~2MB
~45K SLoC