Skip to content

Commit

Permalink
more scope tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Jan 6, 2025
1 parent 469b4d1 commit f555c05
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ hyper-rustls = { version = "0.27.5", default-features = false, features = [
] }
icu_normalizer = "1.5.0"
img-parts = "0.3.2"
indexmap = { version = "2.7.0", features = ["serde"] }
insta = { version = "1.42.0", default-features = false, features = [
"glob",
"json",
Expand Down
1 change: 1 addition & 0 deletions lib/komainu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ compact_str.workspace = true
http.workspace = true
http-body.workspace = true
http-body-util.workspace = true
indexmap.workspace = true
itertools.workspace = true
memchr.workspace = true
serde.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions lib/komainu/src/scope.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use compact_str::CompactString;
use indexmap::{set, IndexSet};
use serde::Deserialize;
use std::{
collections::{hash_set, HashSet},
convert::Infallible,
fmt::{self, Display},
str::FromStr,
Expand All @@ -10,7 +10,7 @@ use std::{
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(transparent)]
pub struct Scope {
inner: HashSet<CompactString>,
inner: IndexSet<CompactString>,
}

impl FromStr for Scope {
Expand Down Expand Up @@ -86,7 +86,7 @@ where

impl IntoIterator for Scope {
type Item = CompactString;
type IntoIter = hash_set::IntoIter<Self::Item>;
type IntoIter = set::IntoIter<Self::Item>;

#[inline]
fn into_iter(self) -> Self::IntoIter {
Expand Down
21 changes: 21 additions & 0 deletions lib/komainu/tests/scope.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use compact_str::CompactString;
use komainu::scope::Scope;
use rstest::rstest;

Expand Down Expand Up @@ -45,3 +46,23 @@ fn cant_access(#[case] endpoint: &str, #[case] client: &str) {

assert!(!endpoint.can_be_accessed_by(&client));
}

#[test]
fn display_impl() {
let raw_scopes = "read write follow push";
let scope: Scope = raw_scopes.parse().unwrap();

assert_eq!(scope.to_string(), raw_scopes);
}

#[test]
fn iter_impls() {
let raw_scopes = "read write follow";
let scope: Scope = raw_scopes.parse().unwrap();

let borrowed_iter: Vec<String> = scope.iter().map(ToString::to_string).collect();
let owned_iter: Vec<CompactString> = scope.into_iter().collect();

assert_eq!(borrowed_iter, owned_iter);
assert_eq!(borrowed_iter, ["read", "write", "follow"]);
}

0 comments on commit f555c05

Please sign in to comment.