5 个不稳定版本

使用旧的 Rust 2015

0.3.0 2017年11月25日
0.2.2 2017年11月12日
0.2.1 2017年11月12日
0.2.0 2017年11月12日
0.1.0 2017年10月11日

测试 中排名第 723

MIT 许可证

14KB
267

morq 构建状态

像人类一样编写单元测试

安装

cargo install morq

Morq Crate: https://crates.io/crates/morq

语法

由于我们在这里使用宏,因此需要将以下规则包裹在 morq! 宏中。

示例

morq!(
  expect(3).to.be.an(i32);
);

链式调用

您可以使用以下链式调用使断言更加用户友好且易于阅读。

  • to
  • be
  • have

Equal

expect(30).to.be.equal(10 * 3);
expect(3).to.be.equal(1 + 2);

Close

用于比较两个给定的 float

expect(3f32).to.be.close(3.0001f32);
expect(3f32).to.be.close_to(3.0001f32);

Not

否定链式调用。

expect(30).to.not.be.equal(10);
expect(3).to.not.be.equal(1);
expect(vec![1, 2, 3]).to.not.be.a(Vec<char>);

A / An

检查数据类型。

expect(30).to.be.an(i32);
expect("hola".to_string()).to.not.be.a(f32);
expect(vec![1, 2, 3]).to.be.a(Vec<i32>);

Empty

检查并查看迭代器是否为空。

expect(vec![1, 2, 3]).to.not.be.empty();
expect(0..2).to.not.be.empty();

LengthOf

检查迭代器中的元素数量。

expect(vec![1, 2, 3]).to.not.have.length_of(1usize);
expect(0..3).to.have.length_of(3usize);

Contain

给定迭代器必须包含该元素。

expect(vec![1, 2, 3]).to.contain(2);
expect(vec![false, false]).to.not.contain(true);

Ok / Err

检查 Result 枚举。

let res: Result<String, String> = Ok(format!("boo"));

morq!(
    expect(res).to.be.ok();
);
let res: Result<String, String> = Err(format!("boo"));

morq!(
    expect(res).to.be.err();
);

当然,您可以将其与 not 结合使用。

let res: Result<String, String> = Err(format!("boo"));

morq!(
    expect(res).to.not.be.ok();
);

路线图

  • 添加更多链式规则

  • 添加更多断言(终端)

  • 在一条链中添加两个或更多断言的能力

    expect("hello").to.be.equal("hello").and.not.be.a(i32);
    

常见问题解答

morq?

波斯语中的“鸡”。就像一个懒惰的鸡,你知道。

插图:clipart-library.com

作者

Afshin Mehrabani

许可证

MIT

http://chaijs.comhttps://github.com/carllerche/hamcrest-rust 的启发

依赖项

~240KB