Skip to content

Commit

Permalink
Check clippy and formatting in CI
Browse files Browse the repository at this point in the history
And also mass-reformat.
`tables.rs` is ignored for now
  • Loading branch information
Jules-Bertholet committed Feb 29, 2024
1 parent 771ddda commit 0b9b162
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 40 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ on:
branches: [ master ]

env:
CARGO_INCREMENTAL: 0
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings --cfg docsrs

jobs:
Expand All @@ -21,17 +24,17 @@ jobs:
- nightly
steps:
- uses: actions/checkout@v2
- name: Install latest nightly
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: Run tests with all features
run: cargo test --all-features --verbose
- name: Run tests without features
run: cargo test --verbose --no-default-features
run: cargo test --no-default-features --verbose
- name: Package
run: cargo package
- name: Test package
Expand All @@ -41,6 +44,12 @@ jobs:
- name: Build docs
if: matrix.rust == 'nightly'
run: cargo doc --all-features --verbose
- name: Check formatting
if: matrix.rust == 'stable'
run: cargo fmt --all --check
- name: Check clippy
if: matrix.rust == 'stable'
run: cargo clippy --all-features --all --verbose
msrv:
runs-on: ubuntu-latest
steps:
Expand Down
15 changes: 12 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@

name = "unicode-normalization"
version = "0.1.23"
authors = ["kwantam <kwantam@gmail.com>", "Manish Goregaokar <manishsmail@gmail.com>"]
authors = [
"kwantam <kwantam@gmail.com>",
"Manish Goregaokar <manishsmail@gmail.com>",
]

homepage = "https://github.com/unicode-rs/unicode-normalization"
repository = "https://github.com/unicode-rs/unicode-normalization"
documentation = "https://docs.rs/unicode-normalization/"

license = "MIT/Apache-2.0"
keywords = ["text", "unicode", "normalization", "decomposition", "recomposition"]
keywords = [
"text",
"unicode",
"normalization",
"decomposition",
"recomposition",
]
readme = "README.md"
description = """
This crate provides functions for normalization of
Expand All @@ -22,7 +31,7 @@ rust-version = "1.36"

edition = "2018"

exclude = [ "target/*", "Cargo.lock", "scripts/tmp", "*.txt", "tests/*" ]
exclude = ["target/*", "Cargo.lock", "scripts/tmp", "*.txt", "tests/*"]

[dependencies.tinyvec]
version = "1"
Expand Down
1 change: 1 addition & 0 deletions scripts/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ def minimal_perfect_hash(d):
data = UnicodeData()
with open("tables.rs", "w", newline = "\n") as out:
out.write(PREAMBLE)
out.write("#![cfg_attr(rustfmt, rustfmt::skip)]\n")
out.write("use crate::quick_check::IsNormalized;\n")
out.write("use crate::quick_check::IsNormalized::*;\n")
out.write("\n")
Expand Down
2 changes: 1 addition & 1 deletion src/__test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// If you're caught using this outside this crates tests/, you get to clean up the mess.

#[cfg(not(feature = "std"))]
use crate::no_std_prelude::*;
use alloc::string::String;

use crate::stream_safe::StreamSafe;

Expand Down
4 changes: 3 additions & 1 deletion src/decompose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::fmt::{self, Write};
use core::iter::Fuse;
use core::iter::{Fuse, FusedIterator};
use core::ops::Range;
use tinyvec::TinyVec;

Expand Down Expand Up @@ -151,6 +151,8 @@ impl<I: Iterator<Item = char>> Iterator for Decompositions<I> {
}
}

impl<I: Iterator<Item = char> + FusedIterator> FusedIterator for Decompositions<I> {}

impl<I: Iterator<Item = char> + Clone> fmt::Display for Decompositions<I> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for c in self.clone() {
Expand Down
8 changes: 1 addition & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ pub use crate::recompose::Recompositions;
pub use crate::replace::Replacements;
pub use crate::stream_safe::StreamSafe;
pub use crate::tables::UNICODE_VERSION;
use core::{
str::Chars,
option,
};

mod no_std_prelude;
use core::{option, str::Chars};

mod decompose;
mod lookups;
Expand Down Expand Up @@ -169,7 +164,6 @@ impl<'a> UnicodeNormalization<Chars<'a>> for &'a str {
}
}


impl UnicodeNormalization<option::IntoIter<char>> for char {
#[inline]
fn nfd(self) -> Decompositions<option::IntoIter<char>> {
Expand Down
6 changes: 0 additions & 6 deletions src/no_std_prelude.rs

This file was deleted.

7 changes: 6 additions & 1 deletion src/recompose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
// except according to those terms.

use crate::decompose::Decompositions;
use core::fmt::{self, Write};
use core::{
fmt::{self, Write},
iter::FusedIterator,
};
use tinyvec::TinyVec;

#[derive(Clone)]
Expand Down Expand Up @@ -144,6 +147,8 @@ impl<I: Iterator<Item = char>> Iterator for Recompositions<I> {
}
}

impl<I: Iterator<Item = char> + FusedIterator> FusedIterator for Recompositions<I> {}

impl<I: Iterator<Item = char> + Clone> fmt::Display for Recompositions<I> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for c in self.clone() {
Expand Down
7 changes: 6 additions & 1 deletion src/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::fmt::{self, Write};
use core::{
fmt::{self, Write},
iter::FusedIterator,
};
use tinyvec::ArrayVec;

/// External iterator for replacements for a string's characters.
Expand Down Expand Up @@ -51,6 +54,8 @@ impl<I: Iterator<Item = char>> Iterator for Replacements<I> {
}
}

impl<I: Iterator<Item = char> + FusedIterator> FusedIterator for Replacements<I> {}

impl<I: Iterator<Item = char> + Clone> fmt::Display for Replacements<I> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for c in self.clone() {
Expand Down
6 changes: 5 additions & 1 deletion src/stream_safe.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::iter::FusedIterator;

use crate::lookups::{
canonical_combining_class, canonical_fully_decomposed, compatibility_fully_decomposed,
stream_safe_trailing_nonstarters,
Expand Down Expand Up @@ -59,6 +61,8 @@ impl<I: Iterator<Item = char>> Iterator for StreamSafe<I> {
}
}

impl<I: Iterator<Item = char> + FusedIterator> FusedIterator for StreamSafe<I> {}

#[derive(Debug)]
pub(crate) struct Decomposition {
pub(crate) leading_nonstarters: usize,
Expand Down Expand Up @@ -110,7 +114,7 @@ mod tests {
use crate::normalize::decompose_compatible;

#[cfg(not(feature = "std"))]
use crate::no_std_prelude::*;
use alloc::{string::String, vec::Vec};

use core::char;

Expand Down
1 change: 1 addition & 0 deletions src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// NOTE: The following code was generated by "scripts/unicode.py", do not edit directly

#![allow(missing_docs)]
#![cfg_attr(rustfmt, rustfmt::skip)]
use crate::quick_check::IsNormalized;
use crate::quick_check::IsNormalized::*;

Expand Down
2 changes: 1 addition & 1 deletion src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::UnicodeNormalization;
use core::char;

#[cfg(not(feature = "std"))]
use crate::no_std_prelude::*;
use alloc::string::{String, ToString};

#[test]
fn test_nfd() {
Expand Down
26 changes: 12 additions & 14 deletions tests/test_streamsafe_regression.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use unicode_normalization::{
is_nfc, is_nfc_stream_safe, UnicodeNormalization,
};

#[test]
fn test_streamsafe_regression(){
let input = "\u{342}".repeat(55) + &"\u{344}".repeat(3);
let nfc_ss = input.chars().nfc().stream_safe().collect::<String>();

// The result should be NFC:
assert!(is_nfc(&nfc_ss));
// and should be stream-safe:
assert!(is_nfc_stream_safe(&nfc_ss))
}
use unicode_normalization::{is_nfc, is_nfc_stream_safe, UnicodeNormalization};

#[test]
fn test_streamsafe_regression() {
let input = "\u{342}".repeat(55) + &"\u{344}".repeat(3);
let nfc_ss = input.chars().nfc().stream_safe().collect::<String>();

// The result should be NFC:
assert!(is_nfc(&nfc_ss));
// and should be stream-safe:
assert!(is_nfc_stream_safe(&nfc_ss))
}

0 comments on commit 0b9b162

Please sign in to comment.