Skip to content

Commit fb1290e

Browse files
authored
Merge pull request #7 from Marcondiro/master
Add CI and fix clippy warnings
2 parents a05043b + 9924df8 commit fb1290e

File tree

4 files changed

+93
-24
lines changed

4 files changed

+93
-24
lines changed

.github/workflows/rust.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
env:
10+
CARGO_INCREMENTAL: 0
11+
CARGO_TERM_COLOR: always
12+
RUST_BACKTRACE: 1
13+
RUSTFLAGS: -D warnings
14+
RUSTDOCFLAGS: -D warnings --cfg docsrs
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
rust:
22+
- stable
23+
- beta
24+
- nightly
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: Install toolchain
28+
uses: actions-rs/toolchain@v1
29+
with:
30+
toolchain: ${{ matrix.rust }}
31+
override: true
32+
components: rustfmt, clippy
33+
- name: Build
34+
run: cargo build --verbose
35+
- name: Run tests with all features
36+
run: cargo test --all-features --verbose
37+
- name: Run tests without features
38+
run: cargo test --lib --no-default-features --verbose
39+
- name: Package
40+
run: cargo package
41+
- name: Test package
42+
run: cd $(find target/package/ -maxdepth 1 -mindepth 1 -type d) && cargo test
43+
- name: Test package without features
44+
run: cd $(find target/package/ -maxdepth 1 -mindepth 1 -type d) && cargo test --lib --no-default-features
45+
- name: Build docs
46+
if: matrix.rust == 'nightly'
47+
run: cargo doc --all-features --verbose
48+
- name: Check formatting
49+
if: matrix.rust == 'stable'
50+
run: cargo fmt --all --check
51+
- name: Check clippy
52+
if: matrix.rust == 'stable'
53+
run: cargo clippy --all-features --lib --tests --examples --verbose
54+
- name: Check benchmarks with clippy
55+
if: matrix.rust == 'nightly'
56+
run: cargo clippy --all-features --benches --verbose
57+
msrv:
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v2
61+
- name: Install msrv toolchain
62+
uses: actions-rs/toolchain@v1
63+
with:
64+
toolchain: 1.56
65+
override: true
66+
- name: Build
67+
run: cargo build --verbose --all-features
68+
regen:
69+
runs-on: ubuntu-latest
70+
steps:
71+
- uses: actions/checkout@v3
72+
- name: Regen
73+
run: cd scripts && python3 unicode.py
74+
- name: Diff tables
75+
run: diff src/tables.rs scripts/tables.rs

scripts/unicode.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,7 @@ def emit_general_category_module(f):
275275
276276
#[inline]
277277
pub(crate) fn general_category_of_char(c: char) -> GeneralCategory {
278-
match c as usize {
279-
_ => super::util::bsearch_range_value_table(c, GENERAL_CATEGORY).unwrap_or(GeneralCategory::Unassigned)
280-
}
278+
super::util::bsearch_range_value_table(c, GENERAL_CATEGORY).unwrap_or(GeneralCategory::Unassigned)
281279
}
282280
283281
#[inline]
@@ -369,7 +367,7 @@ def emit_general_category_module(f):
369367
general_category_char_table[input_idx][1], general_category_group_table[existing_group_count - 1][2])
370368
else:
371369
general_category_group_table.append(general_category_char_table[input_idx])
372-
emit_table(f, "GENERAL_CATEGORY", general_category_group_table, "&'static [(char, char, GeneralCategory)]", is_pub=False,
370+
emit_table(f, "GENERAL_CATEGORY", general_category_group_table, "&[(char, char, GeneralCategory)]", is_pub=False,
373371
pfun=lambda x: "(%s,%s,%s)" % (escape_char(x[0]), escape_char(x[1]), gc_variants[x[2]]))
374372
f.write("}\n\n")
375373

@@ -405,9 +403,7 @@ def emit_emoji_module(f):
405403
#[inline]
406404
pub(crate) fn emoji_status(c: char) -> EmojiStatus {
407405
// FIXME: do we want to special case ASCII here?
408-
match c as usize {
409-
_ => super::util::bsearch_range_value_table(c, EMOJI_STATUS).unwrap()
410-
}
406+
super::util::bsearch_range_value_table(c, EMOJI_STATUS).unwrap()
411407
}
412408
#[inline]
413409
pub(crate) fn is_emoji_status_for_emoji_char_or_emoji_component(s: EmojiStatus) -> bool {
@@ -491,7 +487,7 @@ def group_text(s):
491487
emoji_prop_list_pos[prop_list_idx] += 1
492488
cur_group_first = cur_group_last + 1
493489

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

src/lib.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@
2121
//! use unicode_properties::UnicodeEmoji;
2222
//! use unicode_properties::UnicodeGeneralCategory;
2323
//!
24-
//! fn main() {
25-
//! let ch = '🦀'; // U+1F980 CRAB
26-
//! let is_emoji = ch.is_emoji_char();
27-
//! let group = ch.general_category_group();
28-
//! println!("{}({:?})", ch, group);
29-
//! println!("The above char {} for use as emoji char.",
30-
//! if is_emoji { "is recommended" } else { "is not recommended" });
31-
//! }
24+
//! let ch = '🦀'; // U+1F980 CRAB
25+
//! let is_emoji = ch.is_emoji_char();
26+
//! let group = ch.general_category_group();
27+
//! println!("{}({:?})", ch, group);
28+
//! println!("The above char {} for use as emoji char.",
29+
//! if is_emoji { "is recommended" } else { "is not recommended" });
3230
//! ```
3331
//!
3432
//! # Features
@@ -59,17 +57,20 @@ pub mod emoji {
5957
fn emoji_status(self) -> EmojiStatus;
6058

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

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

7272
/// Checks whether this character occurs in emoji sequences, i.e. `Emoji=YES | Emoji_Component=YES`
73+
#[allow(clippy::wrong_self_convention)]
7374
fn is_emoji_char_or_emoji_component(self) -> bool {
7475
crate::tables::emoji::is_emoji_status_for_emoji_char_or_emoji_component(
7576
self.emoji_status(),
@@ -144,6 +145,7 @@ pub mod general_category {
144145
///
145146
/// The `LetterCased` group includes `LetterUppercase`, `LetterLowercase`, and `LetterTitlecase`
146147
/// categories, and is a subset of the `Letter` group.
148+
#[allow(clippy::wrong_self_convention)]
147149
fn is_letter_cased(self) -> bool {
148150
crate::tables::general_category::general_category_is_letter_cased(
149151
self.general_category(),

src/tables.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ pub mod general_category {
127127

128128
#[inline]
129129
pub(crate) fn general_category_of_char(c: char) -> GeneralCategory {
130-
match c as usize {
131-
_ => super::util::bsearch_range_value_table(c, GENERAL_CATEGORY).unwrap_or(GeneralCategory::Unassigned)
132-
}
130+
super::util::bsearch_range_value_table(c, GENERAL_CATEGORY).unwrap_or(GeneralCategory::Unassigned)
133131
}
134132

135133
#[inline]
@@ -173,7 +171,7 @@ pub mod general_category {
173171
}
174172
}
175173
// General category table:
176-
const GENERAL_CATEGORY: &'static [(char, char, GeneralCategory)] = &[
174+
const GENERAL_CATEGORY: &[(char, char, GeneralCategory)] = &[
177175
('\u{0}', '\u{1f}', GeneralCategory::Control), ('\u{20}', '\u{20}',
178176
GeneralCategory::SpaceSeparator), ('\u{21}', '\u{23}', GeneralCategory::OtherPunctuation),
179177
('\u{24}', '\u{24}', GeneralCategory::CurrencySymbol), ('\u{25}', '\u{27}',
@@ -2743,9 +2741,7 @@ pub mod emoji {
27432741
#[inline]
27442742
pub(crate) fn emoji_status(c: char) -> EmojiStatus {
27452743
// FIXME: do we want to special case ASCII here?
2746-
match c as usize {
2747-
_ => super::util::bsearch_range_value_table(c, EMOJI_STATUS).unwrap()
2748-
}
2744+
super::util::bsearch_range_value_table(c, EMOJI_STATUS).unwrap()
27492745
}
27502746
#[inline]
27512747
pub(crate) fn is_emoji_status_for_emoji_char_or_emoji_component(s: EmojiStatus) -> bool {
@@ -2762,7 +2758,7 @@ pub mod emoji {
27622758
EmojiStatus::EmojiOtherAndEmojiComponent)
27632759
}
27642760
// Emoji status table:
2765-
const EMOJI_STATUS: &'static [(char, char, EmojiStatus)] = &[
2761+
const EMOJI_STATUS: &[(char, char, EmojiStatus)] = &[
27662762
('\u{0}', '\u{22}', EmojiStatus::NonEmoji), ('\u{23}', '\u{23}',
27672763
EmojiStatus::EmojiOtherAndEmojiComponent), ('\u{24}', '\u{29}', EmojiStatus::NonEmoji),
27682764
('\u{2a}', '\u{2a}', EmojiStatus::EmojiOtherAndEmojiComponent), ('\u{2b}', '\u{2f}',

0 commit comments

Comments
 (0)