Skip to content

Commit

Permalink
Merge pull request #7 from Marcondiro/master
Browse files Browse the repository at this point in the history
Add CI and fix clippy warnings
  • Loading branch information
Manishearth authored May 28, 2024
2 parents a05043b + 9924df8 commit fb1290e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 24 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Rust

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

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

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- beta
- nightly
steps:
- uses: actions/checkout@v2
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt, clippy
- name: Build
run: cargo build --verbose
- name: Run tests with all features
run: cargo test --all-features --verbose
- name: Run tests without features
run: cargo test --lib --no-default-features --verbose
- name: Package
run: cargo package
- name: Test package
run: cd $(find target/package/ -maxdepth 1 -mindepth 1 -type d) && cargo test
- name: Test package without features
run: cd $(find target/package/ -maxdepth 1 -mindepth 1 -type d) && cargo test --lib --no-default-features
- 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 --lib --tests --examples --verbose
- name: Check benchmarks with clippy
if: matrix.rust == 'nightly'
run: cargo clippy --all-features --benches --verbose
msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install msrv toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.56
override: true
- name: Build
run: cargo build --verbose --all-features
regen:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Regen
run: cd scripts && python3 unicode.py
- name: Diff tables
run: diff src/tables.rs scripts/tables.rs
12 changes: 4 additions & 8 deletions scripts/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ def emit_general_category_module(f):
#[inline]
pub(crate) fn general_category_of_char(c: char) -> GeneralCategory {
match c as usize {
_ => super::util::bsearch_range_value_table(c, GENERAL_CATEGORY).unwrap_or(GeneralCategory::Unassigned)
}
super::util::bsearch_range_value_table(c, GENERAL_CATEGORY).unwrap_or(GeneralCategory::Unassigned)
}
#[inline]
Expand Down Expand Up @@ -369,7 +367,7 @@ def emit_general_category_module(f):
general_category_char_table[input_idx][1], general_category_group_table[existing_group_count - 1][2])
else:
general_category_group_table.append(general_category_char_table[input_idx])
emit_table(f, "GENERAL_CATEGORY", general_category_group_table, "&'static [(char, char, GeneralCategory)]", is_pub=False,
emit_table(f, "GENERAL_CATEGORY", general_category_group_table, "&[(char, char, GeneralCategory)]", is_pub=False,
pfun=lambda x: "(%s,%s,%s)" % (escape_char(x[0]), escape_char(x[1]), gc_variants[x[2]]))
f.write("}\n\n")

Expand Down Expand Up @@ -405,9 +403,7 @@ def emit_emoji_module(f):
#[inline]
pub(crate) fn emoji_status(c: char) -> EmojiStatus {
// FIXME: do we want to special case ASCII here?
match c as usize {
_ => super::util::bsearch_range_value_table(c, EMOJI_STATUS).unwrap()
}
super::util::bsearch_range_value_table(c, EMOJI_STATUS).unwrap()
}
#[inline]
pub(crate) fn is_emoji_status_for_emoji_char_or_emoji_component(s: EmojiStatus) -> bool {
Expand Down Expand Up @@ -491,7 +487,7 @@ def group_text(s):
emoji_prop_list_pos[prop_list_idx] += 1
cur_group_first = cur_group_last + 1

emit_table(f, "EMOJI_STATUS", emoji_table, "&'static [(char, char, EmojiStatus)]", is_pub=False,
emit_table(f, "EMOJI_STATUS", emoji_table, "&[(char, char, EmojiStatus)]", is_pub=False,
pfun=lambda x: "(%s,%s,%s)" % (escape_char(x[0]), escape_char(x[1]), x[2]))
f.write("}\n\n")

Expand Down
18 changes: 10 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
//! use unicode_properties::UnicodeEmoji;
//! use unicode_properties::UnicodeGeneralCategory;
//!
//! fn main() {
//! let ch = '🦀'; // U+1F980 CRAB
//! let is_emoji = ch.is_emoji_char();
//! let group = ch.general_category_group();
//! println!("{}({:?})", ch, group);
//! println!("The above char {} for use as emoji char.",
//! if is_emoji { "is recommended" } else { "is not recommended" });
//! }
//! let ch = '🦀'; // U+1F980 CRAB
//! let is_emoji = ch.is_emoji_char();
//! let group = ch.general_category_group();
//! println!("{}({:?})", ch, group);
//! println!("The above char {} for use as emoji char.",
//! if is_emoji { "is recommended" } else { "is not recommended" });
//! ```
//!
//! # Features
Expand Down Expand Up @@ -59,17 +57,20 @@ pub mod emoji {
fn emoji_status(self) -> EmojiStatus;

/// Checks whether this character is recommended for use as emoji, i.e. `Emoji=YES`.
#[allow(clippy::wrong_self_convention)]
fn is_emoji_char(self) -> bool {
crate::tables::emoji::is_emoji_status_for_emoji_char(self.emoji_status())
}

/// Checks whether this character are used in emoji sequences where they're not
/// intended for independent, direct input, i.e. `Emoji_Component=YES`.
#[allow(clippy::wrong_self_convention)]
fn is_emoji_component(self) -> bool {
crate::tables::emoji::is_emoji_status_for_emoji_component(self.emoji_status())
}

/// Checks whether this character occurs in emoji sequences, i.e. `Emoji=YES | Emoji_Component=YES`
#[allow(clippy::wrong_self_convention)]
fn is_emoji_char_or_emoji_component(self) -> bool {
crate::tables::emoji::is_emoji_status_for_emoji_char_or_emoji_component(
self.emoji_status(),
Expand Down Expand Up @@ -144,6 +145,7 @@ pub mod general_category {
///
/// The `LetterCased` group includes `LetterUppercase`, `LetterLowercase`, and `LetterTitlecase`
/// categories, and is a subset of the `Letter` group.
#[allow(clippy::wrong_self_convention)]
fn is_letter_cased(self) -> bool {
crate::tables::general_category::general_category_is_letter_cased(
self.general_category(),
Expand Down
12 changes: 4 additions & 8 deletions src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ pub mod general_category {

#[inline]
pub(crate) fn general_category_of_char(c: char) -> GeneralCategory {
match c as usize {
_ => super::util::bsearch_range_value_table(c, GENERAL_CATEGORY).unwrap_or(GeneralCategory::Unassigned)
}
super::util::bsearch_range_value_table(c, GENERAL_CATEGORY).unwrap_or(GeneralCategory::Unassigned)
}

#[inline]
Expand Down Expand Up @@ -173,7 +171,7 @@ pub mod general_category {
}
}
// General category table:
const GENERAL_CATEGORY: &'static [(char, char, GeneralCategory)] = &[
const GENERAL_CATEGORY: &[(char, char, GeneralCategory)] = &[
('\u{0}', '\u{1f}', GeneralCategory::Control), ('\u{20}', '\u{20}',
GeneralCategory::SpaceSeparator), ('\u{21}', '\u{23}', GeneralCategory::OtherPunctuation),
('\u{24}', '\u{24}', GeneralCategory::CurrencySymbol), ('\u{25}', '\u{27}',
Expand Down Expand Up @@ -2743,9 +2741,7 @@ pub mod emoji {
#[inline]
pub(crate) fn emoji_status(c: char) -> EmojiStatus {
// FIXME: do we want to special case ASCII here?
match c as usize {
_ => super::util::bsearch_range_value_table(c, EMOJI_STATUS).unwrap()
}
super::util::bsearch_range_value_table(c, EMOJI_STATUS).unwrap()
}
#[inline]
pub(crate) fn is_emoji_status_for_emoji_char_or_emoji_component(s: EmojiStatus) -> bool {
Expand All @@ -2762,7 +2758,7 @@ pub mod emoji {
EmojiStatus::EmojiOtherAndEmojiComponent)
}
// Emoji status table:
const EMOJI_STATUS: &'static [(char, char, EmojiStatus)] = &[
const EMOJI_STATUS: &[(char, char, EmojiStatus)] = &[
('\u{0}', '\u{22}', EmojiStatus::NonEmoji), ('\u{23}', '\u{23}',
EmojiStatus::EmojiOtherAndEmojiComponent), ('\u{24}', '\u{29}', EmojiStatus::NonEmoji),
('\u{2a}', '\u{2a}', EmojiStatus::EmojiOtherAndEmojiComponent), ('\u{2b}', '\u{2f}',
Expand Down

0 comments on commit fb1290e

Please sign in to comment.