Skip to content

Commit 9d2a331

Browse files
0xPoeTurbo87
authored andcommitted
Add more tests for the first ch of the feature name
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
1 parent a512487 commit 9d2a331

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
@@ -34,6 +34,17 @@ fn feature_name_with_dot() {
3434
assert_json_snapshot!(crates);
3535
}
3636

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

80+
#[test]
81+
fn invalid_feature_name_start_with_hyphen() {
82+
let (app, _, _, token) = TestApp::full().with_token();
83+
let crate_to_publish = PublishBuilder::new("foo", "1.0.0").feature("-foo1.bar", &[]);
84+
let response = token.publish_crate(crate_to_publish);
85+
assert_eq!(response.status(), StatusCode::OK);
86+
assert_json_snapshot!(response.into_json());
87+
assert!(app.stored_files().is_empty());
88+
}
89+
6990
#[test]
7091
fn too_many_features() {
7192
let (app, _, _, token) = TestApp::full()
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+
]
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)