Skip to content

Commit 1ccb522

Browse files
authored
Feature/release 1.0 (#11)
* add code coverage * update badges * update actions * start fixing clippy lints * fix lints * strict lints, but allow bool asserts * display correct badges * better optional comma parsing * lift trailing comma restriction * apply fmt * macro expansion without formatting * bump versions, skip macro expansion for test cov
1 parent bf380cc commit 1ccb522

22 files changed

+153
-187
lines changed

.github/workflows/approval-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
name: Approval Tests for Macro Expansion
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
1818
- uses: actions-rs/toolchain@v1
1919
with:
2020
profile: minimal

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
name: Check
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
1818
- uses: actions-rs/toolchain@v1
1919
with:
2020
profile: minimal

.github/workflows/coverage.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: coverage
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main, dmz ]
8+
9+
env:
10+
RUST_BACKTRACE: 1
11+
12+
jobs:
13+
test:
14+
name: coverage
15+
runs-on: ubuntu-latest
16+
container:
17+
image: xd009642/tarpaulin:develop-nightly
18+
options: --security-opt seccomp=unconfined
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v3
22+
23+
- name: Generate code coverage
24+
run: |
25+
cargo +nightly tarpaulin --force-clean --verbose --all-features --engine llvm --timeout 120 --out Lcov -- --skip macro_expansion
26+
27+
- name: upload to Coveralls
28+
uses: coverallsapp/github-action@master
29+
with:
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
path-to-lcov: './lcov.info'
32+
33+
# - name: Upload to codecov.io
34+
# uses: codecov/codecov-action@v2
35+
# with:
36+
# token: ${{secrets.CODECOV_TOKEN}} # not required for public repos
37+
# fail_ci_if_error: true

.github/workflows/lints.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
name: Rustfmt
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
1818
- uses: actions-rs/toolchain@v1
1919
with:
2020
profile: minimal
@@ -30,7 +30,7 @@ jobs:
3030
name: Clippy
3131
runs-on: ubuntu-latest
3232
steps:
33-
- uses: actions/checkout@v2
33+
- uses: actions/checkout@v3
3434
- uses: actions-rs/toolchain@v1
3535
with:
3636
profile: minimal

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
name: Test Suite
1515
runs-on: ubuntu-latest
1616
steps:
17-
- uses: actions/checkout@v2
17+
- uses: actions/checkout@v3
1818
- uses: actions-rs/toolchain@v1
1919
with:
2020
profile: minimal

Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[package]
22
name = "fluent-comparisons"
3-
version = "0.3.1"
3+
version = "1.0.0"
44
authors = ["geo-ant <geos.blog@posteo.de>"]
5-
edition = "2018"
5+
edition = "2021"
66
homepage = "https://github.com/geo-ant/fluent-comparisons"
77
repository = "https://github.com/geo-ant/fluent-comparisons"
88
categories = ["algorithms", "development tools"]
99
description = "Boost readability by writing multicomparison expressions like `if any_of!({a,b,c}>=5) {...}` while keeping the benefits of hand-written code."
1010
readme = "README.md"
1111
license = "MIT"
12-
keywords = ["fluent","DRY","multi","comparison","expressions"]
12+
keywords = ["fluent", "DRY", "multi", "comparison", "expressions"]
1313

1414
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1515

@@ -18,11 +18,11 @@ keywords = ["fluent","DRY","multi","comparison","expressions"]
1818
# be used, but on crates.io the version dependency will be used, which is just extremely helpful for development.
1919
# See this Reddit post: https://www.reddit.com/r/rust/comments/a39er8/how_do_you_publish_your_cargo_workspace_packages/
2020
# And the Rust Doc: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-path-dependencies
21-
fluent-comparisons-macros = {version = "0.3.0", path = "fluent-comparisons-macros"}
21+
fluent-comparisons-macros = { version = "1.0.0", path = "fluent-comparisons-macros" }
2222

2323
[workspace]
2424
members = ["fluent-comparisons-macros"]
2525

2626
[dev-dependencies]
2727
rand = "0.8"
28-
macrotest = "1.0"
28+
macrotest = "1.0"

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# fluent-comparisons
2+
23
![build](https://github.com/geo-ant/fluent-comparisons/workflows/build/badge.svg?branch=main)
3-
![lints](https://github.com/geo-ant/fluent-comparisons/workflows/lints/badge.svg?branch=main)
44
![tests](https://github.com/geo-ant/fluent-comparisons/workflows/tests/badge.svg?branch=main)
5-
![approval-tests](https://github.com/geo-ant/fluent-comparisons/workflows/approval-tests/badge.svg?branch=main)
5+
![lints](https://github.com/geo-ant/fluent-comparisons/workflows/lints/badge.svg?branch=main)
6+
[![Coverage Status](https://coveralls.io/repos/github/geo-ant/fluent-comparisons/badge.svg?branch=main)](https://coveralls.io/github/geo-ant/fluent-comparisons?branch=main)
7+
![maintenance-status](https://img.shields.io/badge/maintenance-passively--maintained-yellowgreen.svg)
68

79
**Fluent syntax for multi-comparisons.**
810

@@ -53,7 +55,7 @@ And finally, you can rest assured in the warm and fuzzy feeling that this crate
5355
Use the macros by writing `any_of!({/*list of expressions*/} operator rhs)`,
5456
where operator can be any of the binary comparison operators,
5557
i.e. `==`, `!=`, `<=`, `<`, `>`, and `>=`. The list of expressions on the left hand side
56-
is comma separated without a trailing comma. The right hand side is an expression as well.
58+
is comma separated. The right hand side of the comparison is an expression as well.
5759

5860
The list of expressions can have a variadic number of elements but must have at least one.
5961
It must always be enclosed in curly braces. The expressions on the left hand side need not be
@@ -64,4 +66,4 @@ The same goes for the `all_of` and `none_of` macros. Check the docs for more inf
6466

6567
## Links
6668

67-
This library is inspired by Björn Fahller's [DRY comparisons](https://github.com/rollbear/dry-comparisons) Modern C++ library, which I read about [in this blog post](https://www.fluentcpp.com/2020/01/03/dry-comparisons-a-c-library-to-shorten-redundant-if-statements/) on Jonathan Boccara's blog.
69+
This library is inspired by Björn Fahller's [DRY comparisons](https://github.com/rollbear/dry-comparisons) Modern C++ library, which I read about [in this blog post](https://www.fluentcpp.com/2020/01/03/dry-comparisons-a-c-library-to-shorten-redundant-if-statements/) on Jonathan Boccara's blog.

fluent-comparisons-macros/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fluent-comparisons-macros"
3-
version = "0.3.0"
3+
version = "1.0.0"
44
authors = ["geo-ant <geos.blog@posteo.de>"]
55
edition = "2018"
66
homepage = "https://github.com/geo-ant/fluent-comparisons"

fluent-comparisons-macros/src/lib.rs

+11-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
///! This crate contains the macros for the fluent-comparisons crate
1+
//! This crate contains the macros for the fluent-comparisons crate
22
33
#[macro_export]
44
#[doc(hidden)]
@@ -39,7 +39,7 @@ macro_rules! __check_operator {
3939
///
4040
/// For the basic use case we compare a set of values against a common right hand side. Invoke the macro using
4141
/// `any_of!({/*list of expressions*/} operator rhs)`, where operator can be any of the binary comparison operators, i.e.
42-
/// `==`, `!=`, `<=`, `<`, `>`, and `>=`. The list of expressions on the left hand side is comma separated without a trailing comma. The right hand side
42+
/// `==`, `!=`, `<=`, `<`, `>`, and `>=`. The list of expressions on the left hand side is comma separated. The right hand side
4343
/// is an expression as well.
4444
///
4545
/// The list of expressions can have a variadic number of elements but must have at least one. It must always be enclosed in
@@ -97,12 +97,12 @@ macro_rules! __check_operator {
9797
#[macro_export]
9898
macro_rules! any_of {
9999
// variant with a predicate (does not use a comparison operator and rhs)
100-
( {$($lh_sides:expr),+}.satisfy($($func:tt)+) ) => {
100+
( {$($lh_sides:expr),+ $(,)?}.satisfy($($func:tt)+) ) => {
101101
any_of!({$($lh_sides),+}.map($($func)+)==true)
102102
};
103103

104104
// variant with a transformation of the set
105-
( {$($lh_sides:expr),+}.map($($func:tt)+) $operator:tt $rhs:expr) => {
105+
( {$($lh_sides:expr),+ $(,)?}.map($($func:tt)+) $operator:tt $rhs:expr) => {
106106
{
107107
$crate::__check_operator!($operator);
108108
//by fixing this here, we have more type deduction powers but also less
@@ -119,7 +119,7 @@ macro_rules! any_of {
119119
};
120120

121121
//variant without map (requires a comparison operator and rhs)
122-
( {$($lh_sides:expr),+} $operator:tt $rhs:expr)=> {
122+
( {$($lh_sides:expr),+ $(,)?} $operator:tt $rhs:expr)=> {
123123
{
124124
$crate::__check_operator!($operator);
125125
$( ($lh_sides $operator $rhs) )||+
@@ -149,19 +149,19 @@ macro_rules! any_of {
149149
#[macro_export]
150150
macro_rules! all_of {
151151

152-
( {$($lh_sides:expr),+}.satisfy($($func:tt)+) ) => {
152+
( {$($lh_sides:expr),+ $(,)?}.satisfy($($func:tt)+) ) => {
153153
all_of!({$($lh_sides),+}.map($($func)+)==true)
154154
};
155155

156-
( {$($lh_sides:expr),+}.map($($func:tt)+) $operator:tt $rhs:expr) => {
156+
( {$($lh_sides:expr),+ $(,)?}.map($($func:tt)+) $operator:tt $rhs:expr) => {
157157
{
158158
$crate::__check_operator!($operator);
159159
let map_func = $($func)+;
160160
$( (map_func($lh_sides) $operator $rhs) )&&+
161161
}
162162
};
163163

164-
( {$($lh_sides:expr),+} $operator:tt $rhs:expr)=> {
164+
( {$($lh_sides:expr),+ $(,)?} $operator:tt $rhs:expr)=> {
165165
{
166166
$crate::__check_operator!($operator);
167167
$( ($lh_sides $operator $rhs) )&&+
@@ -190,48 +190,22 @@ macro_rules! all_of {
190190
/// ```
191191
#[macro_export]
192192
macro_rules! none_of {
193-
( {$($lh_sides:expr),+}.satisfy($($func:tt)+) ) => {
193+
( {$($lh_sides:expr),+ $(,)?}.satisfy($($func:tt)+) ) => {
194194
none_of!({$($lh_sides),+}.map($($func)+)==true)
195195
};
196196

197-
( {$($lh_sides:expr),+}.map($($func:tt)+) $operator:tt $rhs:expr) => {
197+
( {$($lh_sides:expr),+ $(,)?}.map($($func:tt)+) $operator:tt $rhs:expr) => {
198198
{
199199
$crate::__check_operator!($operator);
200200
let map_func = $($func)+;
201201
$( !(map_func($lh_sides) $operator $rhs) )&&+
202202
}
203203
};
204204

205-
( {$($lh_sides:expr),+} $operator:tt $rhs:expr)=> {
205+
( {$($lh_sides:expr),+ $(,)?} $operator:tt $rhs:expr)=> {
206206
{
207207
$crate::__check_operator!($operator);
208208
$( !($lh_sides $operator $rhs) )&&+
209209
}
210210
};
211211
}
212-
213-
// TODO FINISH THIS UP, TEST IT AND DOCUMENT IT
214-
// TODO: make this as simple as the ones above w/o recursion
215-
// TODO maybe make the syntax exactly!( 12 of {a,b,...} <= 5) possible. Maybe we can even allow
216-
// an ident instead of the literal. We probably can't allow an expression, but that is fine...
217-
// #[macro_export]
218-
// macro_rules! exactly_one_of {
219-
// //TODO CAUTION: THIS COULD BE CALLED WITH ONE ARGUMENT. MAKE SURE THAT THIS PRODUCES A VALID RESULT
220-
// // expression like any_of!( {1,v.len(),4} < 3)
221-
// ( {$($lh_sides:expr),+} $operator:tt $rhs:expr)=> {
222-
// {
223-
// $crate::__check_operator!($operator);
224-
// 1u32 == exactly_one_of!(@internal lhs={$($lh_sides),+}, op=[$operator], rhs = $rhs, expanded = {0u32})
225-
// }
226-
// };
227-
//
228-
// // internal rules, recursion final case
229-
// (@internal lhs = {$head:expr},op = [$op:tt], rhs = $rhs:expr, expanded = {$expanded:expr}) => {
230-
// $expanded + {if $head $op $rhs {1u32}else{0u32}}
231-
// };
232-
//
233-
// // internal rules, recursion case
234-
// (@internal lhs = {$head:expr, $($tail:expr),*}, op = [$op:tt], rhs = $rhs:expr, expanded = {$expanded:expr}) =>{
235-
// exactly_one_of!(@internal lhs={$($tail),*}, op=[$op], rhs = $rhs, expanded = {$expanded + {if $head $op $rhs {1u32}else{0u32}}})
236-
// };
237-
// }

macro_expansion_tests/all_of_expansion.expanded.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ struct Dummy {
33
pub length: usize,
44
}
55
pub fn something() {
6-
let first = {
7-
(1 < 4) && (2 < 4) && (3 < 4)
8-
};
6+
let first = { (1 < 4) && (2 < 4) && (3 < 4) };
97
let v = Dummy { length: 2 };
108
let second = {
119
(v.length == v.length) && (2_usize.pow(2) == v.length) && (3 * 4 + 1 == v.length)
1210
};
1311
let square = |x| x * x;
14-
let third = {
15-
(4 + 4 + 1 <= 8) && (square(7 * 2) <= 8) && (120_i32.pow(2) <= 8)
16-
};
12+
let third = { (4 + 4 + 1 <= 8) && (square(7 * 2) <= 8) && (120_i32.pow(2) <= 8) };
1713
}

macro_expansion_tests/all_of_with_map_or_satisfies_expansion.expanded.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@ struct Dummy {
33
pub length: usize,
44
}
55
#[automatically_derived]
6-
#[allow(unused_qualifications)]
76
impl ::core::marker::Copy for Dummy {}
87
#[automatically_derived]
9-
#[allow(unused_qualifications)]
108
impl ::core::clone::Clone for Dummy {
119
#[inline]
1210
fn clone(&self) -> Dummy {
13-
{
14-
let _: ::core::clone::AssertParamIsClone<usize>;
15-
*self
16-
}
11+
let _: ::core::clone::AssertParamIsClone<usize>;
12+
*self
1713
}
1814
}
1915
pub fn something() {

macro_expansion_tests/any_of_expansion.expanded.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ struct Dummy {
33
pub length: usize,
44
}
55
pub fn something() {
6-
let first = {
7-
(1 < 4) || (2 < 4) || (3 < 4)
8-
};
6+
let first = { (1 < 4) || (2 < 4) || (3 < 4) };
97
let v = Dummy { length: 2 };
108
let second = {
119
(v.length == v.length) || (2_usize.pow(2) == v.length) || (3 * 4 + 1 == v.length)
1210
};
1311
let square = |x| x * x;
14-
let third = {
15-
(4 + 4 + 1 <= 8) || (square(7 * 2) <= 8) || (120_i32.pow(2) <= 8)
16-
};
12+
let third = { (4 + 4 + 1 <= 8) || (square(7 * 2) <= 8) || (120_i32.pow(2) <= 8) };
1713
}

macro_expansion_tests/any_of_with_map_or_satisfies_expansion.expanded.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@ struct Dummy {
33
pub length: usize,
44
}
55
#[automatically_derived]
6-
#[allow(unused_qualifications)]
76
impl ::core::marker::Copy for Dummy {}
87
#[automatically_derived]
9-
#[allow(unused_qualifications)]
108
impl ::core::clone::Clone for Dummy {
119
#[inline]
1210
fn clone(&self) -> Dummy {
13-
{
14-
let _: ::core::clone::AssertParamIsClone<usize>;
15-
*self
16-
}
11+
let _: ::core::clone::AssertParamIsClone<usize>;
12+
*self
1713
}
1814
}
1915
pub fn something() {

macro_expansion_tests/none_of_expansion.expanded.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@ struct Dummy {
33
pub length: usize,
44
}
55
pub fn something() {
6-
let first = {
7-
!(1 < 4) && !(2 < 4) && !(3 < 4)
8-
};
6+
let first = { !(1 < 4) && !(2 < 4) && !(3 < 4) };
97
let v = Dummy { length: 2 };
108
let second = {
11-
!(v.length == v.length) && !(2_usize.pow(2) == v.length) && !(3 * 4 + 1 == v.length)
9+
!(v.length == v.length) && !(2_usize.pow(2) == v.length)
10+
&& !(3 * 4 + 1 == v.length)
1211
};
1312
let square = |x| x * x;
14-
let third = {
15-
!(4 + 4 + 1 <= 8) && !(square(7 * 2) <= 8) && !(120_i32.pow(2) <= 8)
16-
};
13+
let third = { !(4 + 4 + 1 <= 8) && !(square(7 * 2) <= 8) && !(120_i32.pow(2) <= 8) };
1714
}

macro_expansion_tests/none_of_with_map_or_satisfies_expansion.expanded.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,13 @@ struct Dummy {
33
pub length: usize,
44
}
55
#[automatically_derived]
6-
#[allow(unused_qualifications)]
76
impl ::core::marker::Copy for Dummy {}
87
#[automatically_derived]
9-
#[allow(unused_qualifications)]
108
impl ::core::clone::Clone for Dummy {
119
#[inline]
1210
fn clone(&self) -> Dummy {
13-
{
14-
let _: ::core::clone::AssertParamIsClone<usize>;
15-
*self
16-
}
11+
let _: ::core::clone::AssertParamIsClone<usize>;
12+
*self
1713
}
1814
}
1915
pub fn something() {

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ pub use fluent_comparisons_macros::all_of;
6565
pub use fluent_comparisons_macros::none_of;
6666

6767
#[cfg(test)]
68+
#[allow(clippy::bool_assert_comparison)]
6869
mod tests;

0 commit comments

Comments
 (0)