Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Commit 1de902a

Browse files
Merge pull request #23 from whatisinternet/hotfix/clippy
Hotfix/style
2 parents 5a5ab1d + b95ed51 commit 1de902a

File tree

25 files changed

+786
-1227
lines changed

25 files changed

+786
-1227
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
target
22
Cargo.lock
3+
*.rs.bk

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Thank you!
2+
3+
## Is this an issues?
4+
5+
- Please ensure you fill out an [issue](https://github.com/whatisinternet/inflector/issues)
6+
- Be available for questions.
7+
8+
## Are you submitting documentation?
9+
10+
- Awesome!
11+
- Has everything been run through spell check?
12+
13+
## Are you submitting code?
14+
15+
- Have all files been run through [rustfmt](https://github.com/rust-lang-nursery/rustfmt)?
16+
- Have you added doc tests and do they pass?
17+
- Do all other tests pass?
18+
- Have you filled out the pull request template?
19+
20+
21+
Thank you for your help! :heart:

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,3 @@ path = "src/lib.rs"
2222
[dependencies]
2323
regex = "0.1.41"
2424
lazy_static = "0.2.1"
25-
clippy = {version = "0.0.76", optional = true}
26-
27-
[features]
28-
default=[]

PULL_REQUEST_TEMPLATE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# What it does:
2+
3+
4+
# Why it does it:
5+
6+
7+
# Related issues:
8+
9+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Rust Inflector
22

33

4-
[![Build Status](https://travis-ci.org/whatisinternet/inflector.svg?branch=master)](https://travis-ci.org/whatisinternet/inflector) [![Crates.io](https://img.shields.io/crates/v/inflector.svg)](https://crates.io/crates/inflector)[![Clippy Linting Result](https://clippy.bashy.io/github/whatisinternet/inflector/master/badge.svg)](https://clippy.bashy.io/github/whatisinternet/inflector/master/log)
4+
[![Build Status](https://travis-ci.org/whatisinternet/inflector.svg?branch=master)](https://travis-ci.org/whatisinternet/inflector) [![Crates.io](https://img.shields.io/crates/v/inflector.svg)](https://crates.io/crates/inflector)
55

66
Adds String based inflections for Rust. Snake, kebab, camel,
77
sentence, class, title, upper, and lower cases as well as ordinalize,

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
- Resolves issues with pluralize not always correctly pluralizing strings.
66
Thanks, @weiznich!
7+
- Resolves issues with silently failing test on table case
8+
- Replaces complex code used for is_*_case checks with simple conversion and
9+
check equality.
710

811
## Breaking changes:
912

src/cases/camelcase/mod.rs

Lines changed: 36 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8,79 +8,63 @@ use cases::snakecase::to_snake_case;
88
///
99
/// #Examples
1010
/// ```
11-
/// use inflector::cases::camelcase::to_camel_case;
12-
///
13-
/// // camelize_fooBar_as_fooBar() {
11+
/// use inflector::cases::camelcase::to_camel_case;
1412
/// let mock_string: String = "fooBar".to_string();
1513
/// let expected_string: String = "fooBar".to_string();
1614
/// let asserted_string: String = to_camel_case(mock_string);
1715
/// assert!(asserted_string == expected_string);
1816
///
1917
/// ```
2018
/// ```
21-
/// use inflector::cases::camelcase::to_camel_case;
22-
///
23-
/// // camelize_FOO_BAR_as_fooBar() {
19+
/// use inflector::cases::camelcase::to_camel_case;
2420
/// let mock_string: String = "FOO_BAR".to_string();
2521
/// let expected_string: String = "fooBar".to_string();
2622
/// let asserted_string: String = to_camel_case(mock_string);
2723
/// assert!(asserted_string == expected_string);
2824
///
2925
/// ```
3026
/// ```
31-
/// use inflector::cases::camelcase::to_camel_case;
32-
///
33-
/// // camelize_Foo_Bar_as_fooBar() {
27+
/// use inflector::cases::camelcase::to_camel_case;
3428
/// let mock_string: String = "Foo Bar".to_string();
3529
/// let expected_string: String = "fooBar".to_string();
3630
/// let asserted_string: String = to_camel_case(mock_string);
3731
/// assert!(asserted_string == expected_string);
3832
///
3933
/// ```
4034
/// ```
41-
/// use inflector::cases::camelcase::to_camel_case;
42-
///
43-
/// // camelize_foo_bar_as_fooBar() {
35+
/// use inflector::cases::camelcase::to_camel_case;
4436
/// let mock_string: String = "foo_bar".to_string();
4537
/// let expected_string: String = "fooBar".to_string();
4638
/// let asserted_string: String = to_camel_case(mock_string);
4739
/// assert!(asserted_string == expected_string);
4840
///
4941
/// ```
5042
/// ```
51-
/// use inflector::cases::camelcase::to_camel_case;
52-
///
53-
/// // camelize_Foo_space_bar_as_fooBar() {
43+
/// use inflector::cases::camelcase::to_camel_case;
5444
/// let mock_string: String = "Foo bar".to_string();
5545
/// let expected_string: String = "fooBar".to_string();
5646
/// let asserted_string: String = to_camel_case(mock_string);
5747
/// assert!(asserted_string == expected_string);
5848
///
5949
/// ```
6050
/// ```
61-
/// use inflector::cases::camelcase::to_camel_case;
62-
///
63-
/// // camelize_foo_dash_bar_as_fooBar() {
51+
/// use inflector::cases::camelcase::to_camel_case;
6452
/// let mock_string: String = "foo-bar".to_string();
6553
/// let expected_string: String = "fooBar".to_string();
6654
/// let asserted_string: String = to_camel_case(mock_string);
6755
/// assert!(asserted_string == expected_string);
6856
///
6957
/// ```
7058
/// ```
71-
/// use inflector::cases::camelcase::to_camel_case;
72-
///
73-
/// // camelize_FooBar_as_fooBar() {
59+
/// use inflector::cases::camelcase::to_camel_case;
7460
/// let mock_string: String = "FooBar".to_string();
7561
/// let expected_string: String = "fooBar".to_string();
7662
/// let asserted_string: String = to_camel_case(mock_string);
7763
/// assert!(asserted_string == expected_string);
7864
///
7965
/// ```
8066
/// ```
81-
/// use inflector::cases::camelcase::to_camel_case;
82-
///
83-
/// // camelize_FooBar3_as_fooBar3() {
67+
/// use inflector::cases::camelcase::to_camel_case;
8468
/// let mock_string: String = "FooBar3".to_string();
8569
/// let expected_string: String = "fooBar3".to_string();
8670
/// let asserted_string: String = to_camel_case(mock_string);
@@ -91,132 +75,110 @@ pub fn to_camel_case(non_camelized_string: String) -> String {
9175
to_camel_from_snake(to_snake_case(non_camelized_string))
9276
}
9377

94-
fn to_camel_from_snake(non_camelized_string: String) -> String{
95-
let mut result:String = "".to_string();
96-
let mut new_word: bool = false;
78+
fn to_camel_from_snake(non_camelized_string: String) -> String {
79+
let mut result: String = "".to_string();
80+
let mut new_word: bool = false;
9781

98-
for character in non_camelized_string.chars() {
99-
if character.to_string() == "_" {
100-
new_word = true;
101-
} else if new_word {
102-
result = format!("{}{}", result, character.to_ascii_uppercase());
103-
new_word = false;
104-
} else {
105-
result = format!("{}{}", result, character.to_ascii_lowercase());
106-
}
82+
for character in non_camelized_string.chars() {
83+
if character.to_string() == "_" {
84+
new_word = true;
85+
} else if new_word {
86+
result = format!("{}{}", result, character.to_ascii_uppercase());
87+
new_word = false;
88+
} else {
89+
result = format!("{}{}", result, character.to_ascii_lowercase());
10790
}
108-
result
10991
}
92+
result
93+
}
11094

11195
/// Determines if a `String` is camelCase bool``
11296
///
11397
/// #Examples
11498
/// ```
115-
/// use inflector::cases::camelcase::is_camel_case;
116-
///
117-
/// // returns_falsey_value_for_is_camel_case_when_start_cased() {
99+
/// use inflector::cases::camelcase::is_camel_case;
118100
/// let mock_string: String = "Foo".to_string();
119101
/// let asserted_bool: bool = is_camel_case(mock_string);
120102
/// assert!(asserted_bool == false);
121103
///
122104
///
123105
/// ```
124106
/// ```
125-
/// use inflector::cases::camelcase::is_camel_case;
126-
///
127-
///
128-
/// // returns_falsey_value_for_is_camel_case_when_lower_case() {
107+
/// use inflector::cases::camelcase::is_camel_case;
129108
/// let mock_string: String = "foo".to_string();
130109
/// let asserted_bool: bool = is_camel_case(mock_string);
131110
/// assert!(asserted_bool == false);
132111
///
133112
///
134113
/// ```
135114
/// ```
136-
/// use inflector::cases::camelcase::is_camel_case;
137-
///
138-
/// // returns_falsey_value_for_is_camel_case_when_kebab() {
115+
/// use inflector::cases::camelcase::is_camel_case;
139116
/// let mock_string: String = "foo-bar-string-that-is-really-really-long".to_string();
140117
/// let asserted_bool: bool = is_camel_case(mock_string);
141118
/// assert!(asserted_bool == false);
142119
///
143120
///
144121
/// ```
145122
/// ```
146-
/// use inflector::cases::camelcase::is_camel_case;
147-
///
148-
/// // returns_falsey_value_for_is_camel_case_when_class() {
123+
/// use inflector::cases::camelcase::is_camel_case;
149124
/// let mock_string: String = "FooBarIsAReallyReallyLongString".to_string();
150125
/// let asserted_bool: bool = is_camel_case(mock_string);
151126
/// assert!(asserted_bool == false);
152127
///
153128
///
154129
/// ```
155130
/// ```
156-
/// use inflector::cases::camelcase::is_camel_case;
157-
///
158-
/// // returns_truthy_value_for_is_camel_case_when_camel_with_number() {
131+
/// use inflector::cases::camelcase::is_camel_case;
159132
/// let mock_string: String = "fooBarIsAReallyReally3LongString".to_string();
160133
/// let asserted_bool: bool = is_camel_case(mock_string);
161134
/// assert!(asserted_bool == true);
162135
///
163136
///
164137
/// ```
165138
/// ```
166-
/// use inflector::cases::camelcase::is_camel_case;
167-
///
168-
/// // returns_truthy_value_for_is_camel_case_when_camel() {
139+
/// use inflector::cases::camelcase::is_camel_case;
169140
/// let mock_string: String = "fooBarIsAReallyReallyLongString".to_string();
170141
/// let asserted_bool: bool = is_camel_case(mock_string);
171142
/// assert!(asserted_bool == true);
172143
///
173144
///
174145
/// ```
175146
/// ```
176-
/// use inflector::cases::camelcase::is_camel_case;
177-
///
178-
/// // returns_falsey_value_for_is_camel_case_when_screaming_snake() {
147+
/// use inflector::cases::camelcase::is_camel_case;
179148
/// let mock_string: String = "FOO_BAR_STRING_THAT_IS_REALLY_REALLY_LONG".to_string();
180149
/// let asserted_bool: bool = is_camel_case(mock_string);
181150
/// assert!(asserted_bool == false);
182151
///
183152
///
184153
/// ```
185154
/// ```
186-
/// use inflector::cases::camelcase::is_camel_case;
187-
///
188-
/// // returns_falsey_value_for_is_camel_case_when_snake() {
155+
/// use inflector::cases::camelcase::is_camel_case;
189156
/// let mock_string: String = "foo_bar_string_that_is_really_really_long".to_string();
190157
/// let asserted_bool: bool = is_camel_case(mock_string);
191158
/// assert!(asserted_bool == false);
192159
///
193160
///
194161
/// ```
195162
/// ```
196-
/// use inflector::cases::camelcase::is_camel_case;
197-
///
198-
/// // returns_falsey_value_for_is_camel_case_when_sentence() {
163+
/// use inflector::cases::camelcase::is_camel_case;
199164
/// let mock_string: String = "Foo bar string that is really really long".to_string();
200165
/// let asserted_bool: bool = is_camel_case(mock_string);
201166
/// assert!(asserted_bool == false);
202167
///
203168
///
204169
/// ```
205170
/// ```
206-
/// use inflector::cases::camelcase::is_camel_case;
207-
///
208-
/// // returns_falsey_value_for_is_camel_case_when_title() {
171+
/// use inflector::cases::camelcase::is_camel_case;
209172
/// let mock_string: String = "Foo Bar Is A Really Really Long String".to_string();
210173
/// let asserted_bool: bool = is_camel_case(mock_string);
211174
/// assert!(asserted_bool == false);
212175
/// ```
213-
pub fn is_camel_case(test_string: String) -> bool{
176+
pub fn is_camel_case(test_string: String) -> bool {
214177
let camel_matcher = Regex::new(r"(^|[A-Z])([^-|^_|^ ]*[a-z0-9]+[A-Z][a-z0-9]+)").unwrap();
215178
let kebab_snake_matcher = Regex::new(r"[-|_| ]").unwrap();
216-
if camel_matcher.is_match(test_string.as_ref())
217-
&& !kebab_snake_matcher.is_match(test_string.as_ref())
218-
&& !is_class_case(test_string){
219-
return true;
220-
}
179+
if camel_matcher.is_match(test_string.as_ref()) &&
180+
!kebab_snake_matcher.is_match(test_string.as_ref()) && !is_class_case(test_string) {
181+
return true;
182+
}
221183
false
222184
}

0 commit comments

Comments
 (0)