Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Lint & Test
on:
pull_request:
types: [opened, edited, reopened, synchronize]
jobs:
test:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Rust Stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Install Cargo
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy

- name: Checkout code
uses: actions/checkout@v2

- name: Cache cargo registry
uses: actions/cache@v1
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v1
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo build
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Lint
uses: actions-rs/clippy@master
with:
args: --all-features --all-targets

- name: Test
run: cargo test --all-features
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ authors = ["Dean Karn <dean.karn@gmail.com>"]
license = "MIT OR Apache-2.0"
edition = "2018"
name = "snakecase"
version = "0.1.0"
version = "0.2.0"
description = "Snakecase is a general purpose snakecase implementation supporting both ascii and unicode."
repository = "https://github.com/rust-playground/snakecase"
readme = "README.md"
keywords = ["snakecase"]

[badges]
travis-ci = { repository = "go-playground/snakecase" }

[[bench]]
harness = false
name = "bench"

[dependencies]

[dev-dependencies]
criterion = "0.2.11"
criterion = { version = "0.3.4", features = ["html_reports"] }

[lib]
bench = false
bench = false
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Snakecase &emsp; [![Build Status]][travis] [![Latest Version]][crates.io]
# Snakecase &emsp; ![Build Status] [![Latest Version]][crates.io]

[Build Status]: https://api.travis-ci.org/rust-playground/snakecase.svg?branch=master
[travis]: https://travis-ci.org/rust-playground/snakecase
[Build Status]: https://github.com/rust-playground/snakecase/workflows/Lint%20&%20Test/badge.svg
[Latest Version]: https://img.shields.io/crates/v/snakecase.svg
[crates.io]: https://crates.io/crates/snakecase

Expand Down
100 changes: 55 additions & 45 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,56 +1,66 @@
#[macro_use]
extern crate criterion;

use criterion::{Benchmark, Criterion, Throughput};
use criterion::{BenchmarkId, Criterion, Throughput};
use snakecase::ascii::to_snakecase as to_snakecase_ascii;
use snakecase::unicode::to_snakecase as to_snakecase_unicode;

fn criterion_benchmark(c: &mut Criterion) {
macro_rules! snakecase_ascii_bench {
($name:expr,$s:expr) => {
c.bench(
"ascii",
Benchmark::new($name, |b| b.iter(|| to_snakecase_ascii($s)))
.throughput(Throughput::Bytes($s.as_bytes().len() as u32)),
);
};
fn bench_ascii(c: &mut Criterion) {
let mut group = c.benchmark_group("ascii");

for (name, input) in [
("ascii_owned_simple", "sample text"),
("ascii_borrowed_simple", "sample_text"),
("ascii_owned_long", "inviteYourCustomersAddInvites"),
("ascii_borrowed_long", "invite_your_customers_add_invites"),
(
"ascii_owned_long_special_chars",
"FOO:BAR$BAZ__Sample Text___",
),
("ascii_owned_unicode", "ẞ•¶§ƒ˚foo˙∆˚¬"),
("ascii_borrowed_unicode", "ß_ƒ_foo"),
("ascii_digit_uppercase", "5TEst"),
("ascii_starts_with_garbage", "@%#&5TEst"),
("ascii_complex_random", "lk0B@bFmjrLQ_Z6YL"),
]
.iter()
{
group.throughput(Throughput::Bytes(input.len() as u64));
group.bench_with_input(BenchmarkId::new(*name, input), input, |b, input| {
b.iter(|| to_snakecase_ascii(*input))
});
}
snakecase_ascii_bench!("ascii_owned_simple", "sample text");
snakecase_ascii_bench!("ascii_borrowed_simple", "sample_text");
snakecase_ascii_bench!("ascii_owned_long", "inviteYourCustomersAddInvites");
snakecase_ascii_bench!("ascii_borrowed_long", "invite_your_customers_add_invites");
snakecase_ascii_bench!(
"ascii_owned_long_special_chars",
"FOO:BAR$BAZ__Sample Text___"
);
snakecase_ascii_bench!("ascii_owned_unicode", "ẞ•¶§ƒ˚foo˙∆˚¬");
snakecase_ascii_bench!("ascii_borrowed_unicode", "ß_ƒ_foo");
snakecase_ascii_bench!("ascii_digit_uppercase", "5TEst");
snakecase_ascii_bench!("ascii_starts_with_garbage", "@%#&5TEst");
snakecase_ascii_bench!("ascii_complex_random", "lk0B@bFmjrLQ_Z6YL");

macro_rules! snakecase_bench {
($name:expr,$s:expr) => {
c.bench(
"unicode",
Benchmark::new($name, |b| b.iter(|| to_snakecase_unicode($s)))
.throughput(Throughput::Bytes($s.as_bytes().len() as u32)),
);
};

group.finish();
}

fn bench_unicode(c: &mut Criterion) {
let mut group = c.benchmark_group("unicode");

for (name, input) in [
("unicode_owned_simple", "sample text"),
("unicode_borrowed_simple", "sample_text"),
("unicode_borrowed_long", "invite_your_customers_add_invites"),
(
"unicode_owned_long_special_chars",
"FOO:BAR$BAZ__Sample Text___",
),
("unicode_owned_unicode", "ẞ•¶§ƒ˚foo˙∆˚¬"),
("unicode_borrowed_unicode", "ß_ƒ_foo"),
("unicode_digit_uppercase", "5TEst"),
("unicode_starts_with_garbage", "@%#&5TEst"),
("unicode_complex_random", "lk0B@bFmjrLQ_Z6YL"),
]
.iter()
{
group.throughput(Throughput::Bytes(input.len() as u64));
group.bench_with_input(BenchmarkId::new(*name, input), input, |b, input| {
b.iter(|| to_snakecase_unicode(*input))
});
}
snakecase_bench!("unicode_owned_simple", "sample text");
snakecase_bench!("unicode_borrowed_simple", "sample_text");
snakecase_bench!("unicode_borrowed_long", "invite_your_customers_add_invites");
snakecase_bench!(
"unicode_owned_long_special_chars",
"FOO:BAR$BAZ__Sample Text___"
);
snakecase_bench!("unicode_owned_unicode", "ẞ•¶§ƒ˚foo˙∆˚¬");
snakecase_bench!("unicode_borrowed_unicode", "ß_ƒ_foo");
snakecase_bench!("unicode_digit_uppercase", "5TEst");
snakecase_bench!("unicode_starts_with_garbage", "@%#&5TEst");
snakecase_bench!("unicode_complex_random", "lk0B@bFmjrLQ_Z6YL");

group.finish();
}

criterion_group!(benches, criterion_benchmark);
criterion_group!(benches, bench_ascii, bench_unicode);
criterion_main!(benches);
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@
//! ```rust
//! use snakecase::ascii::to_snakecase;
//!
//! fn main() {
//! let input = "sample text";
//! println!("{} => {}", input, to_snakecase(input));
//! }
//! ```
//!
//! or when you need unicode support
//!
//! ```rust
//! use snakecase::unicode::to_snakecase;
//!
//! fn main() {
//! let input = "ƒun sample text";
//! println!("{} => {}", input, to_snakecase(input));
//! }
//! ```
//!

Expand Down
11 changes: 3 additions & 8 deletions src/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ where
} else if i > 0 && c == UNDERSCORE_CHAR {
if let Some((_, c)) = chars.peek() {
if c.is_lowercase() {
chars.nth(0);
chars.next();
has_lower = true;
has_underscore = true;
has_lower_since_underscore = true;
continue;
} else if c.is_numeric() {
chars.nth(0);
chars.next();
has_underscore = true;
has_lower_since_underscore = false;
continue;
Expand Down Expand Up @@ -197,12 +197,7 @@ mod tests {
false
);
snakecase_test!(camel_case, "CStringRef", "cstring_ref", false);
snakecase_test!(
unicode_mixed,
"ẞ•¶§ƒ˚foo˙∆˚¬",
"ß_ƒ_foo",
false
);
snakecase_test!(unicode_mixed, "ẞ•¶§ƒ˚foo˙∆˚¬", "ß_ƒ_foo", false);
snakecase_test!(unicode_uppercase, "ẞ", "ß", false); // capitol unicode german to lowercase
snakecase_test!(
special_chars_long,
Expand Down