Skip to content

Commit 4e79674

Browse files
committed
CrateScope: Implement Serialize trait
1 parent b8b78c7 commit 4e79674

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/models/token/scopes.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ impl FromSql<Text, Pg> for EndpointScope {
5454
}
5555
}
5656

57-
#[derive(Clone, Debug, PartialEq, Eq)]
57+
#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
58+
#[serde(transparent)]
5859
pub struct CrateScope {
5960
pattern: String,
6061
}
@@ -138,6 +139,22 @@ mod tests {
138139
assert(EndpointScope::Yank, "\"yank\"");
139140
}
140141

142+
#[test]
143+
fn crate_scope_serialization() {
144+
fn assert(scope: &str, expected: &str) {
145+
let scope = assert_ok!(CrateScope::try_from(scope));
146+
assert_ok_eq!(serde_json::to_string(&scope), expected);
147+
}
148+
149+
assert("foo", "\"foo\"");
150+
assert("foo*", "\"foo*\"");
151+
assert("f*", "\"f*\"");
152+
assert("*", "\"*\"");
153+
assert("foo-bar", "\"foo-bar\"");
154+
assert("foo_bar", "\"foo_bar\"");
155+
assert("FooBar", "\"FooBar\"");
156+
}
157+
141158
#[test]
142159
fn crate_scope_validation() {
143160
assert_ok!(CrateScope::try_from("foo"));

0 commit comments

Comments
 (0)