Skip to content

Commit 9f81356

Browse files
committed
Add more tests for the first ch of the feature name
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
1 parent c2c82dd commit 9f81356

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/tests/krate/publish/features.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ fn feature_name_with_dot() {
3333
assert_json_snapshot!(crates);
3434
}
3535

36+
#[test]
37+
fn feature_name_start_with_number_and_underscore() {
38+
let (app, _, _, token) = TestApp::full().with_token();
39+
let crate_to_publish = PublishBuilder::new("foo", "1.0.0")
40+
.feature("0foo1.bar", &[])
41+
.feature("_foo2.bar", &[]);
42+
token.publish_crate(crate_to_publish).good();
43+
let crates = app.crates_from_index_head("foo");
44+
assert_json_snapshot!(crates);
45+
}
46+
3647
#[test]
3748
fn empty_feature_name() {
3849
let (app, _, _, token) = TestApp::full().with_token();
@@ -65,6 +76,16 @@ fn invalid_feature_name2() {
6576
assert!(app.stored_files().is_empty());
6677
}
6778

79+
#[test]
80+
fn invalid_feature_name_start_with_hyphen() {
81+
let (app, _, _, token) = TestApp::full().with_token();
82+
let crate_to_publish = PublishBuilder::new("foo", "1.0.0").feature("-foo1.bar", &[]);
83+
let response = token.publish_crate(crate_to_publish);
84+
assert_eq!(response.status(), StatusCode::OK);
85+
assert_json_snapshot!(response.into_json());
86+
assert!(app.stored_files().is_empty());
87+
}
88+
6889
#[test]
6990
fn too_many_features() {
7091
let (app, _, _, token) = TestApp::full()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
source: src/tests/krate/publish/features.rs
3+
expression: crates
4+
---
5+
[
6+
{
7+
"name": "foo",
8+
"vers": "1.0.0",
9+
"deps": [],
10+
"cksum": "6f73fad556c46cdb740173ccc7a5f5bf64b8d954966be16963a08eb138e3c69c",
11+
"features": {
12+
"0foo1.bar": [],
13+
"_foo2.bar": []
14+
},
15+
"yanked": false
16+
}
17+
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
source: src/tests/krate/publish/features.rs
3+
expression: response.into_json()
4+
---
5+
{
6+
"errors": [
7+
{
8+
"detail": "invalid character `-` in feature `-foo1.bar`, the first character must be a Unicode XID start character or digit (most letters or `_` or `0` to `9`)"
9+
}
10+
]
11+
}

0 commit comments

Comments
 (0)