-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
430 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2024 Aliaksei Bialiauski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
/// Cursor. | ||
#[derive(Clone)] | ||
pub struct Cursor { | ||
/// Base. | ||
pub base: String, | ||
} | ||
|
||
impl Cursor { | ||
/// As string. | ||
pub fn as_string(self) -> String { | ||
self.base | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use crate::handlers::cursor::Cursor; | ||
use anyhow::Result; | ||
use hamcrest::{equal_to, is, HamcrestMatcher}; | ||
|
||
#[test] | ||
fn prints_current() -> Result<()> { | ||
let expected = String::from("test"); | ||
let cursor = Cursor { | ||
base: expected.clone(), | ||
}; | ||
assert_that!(cursor.as_string(), is(equal_to(expected))); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2024 Aliaksei Bialiauski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
use crate::handlers::cursor::Cursor; | ||
|
||
/// Slashed cursor with complete value. | ||
/// ``` | ||
/// use hamcrest::assert_that; | ||
/// use hamcrest::{equal_to, is, HamcrestMatcher}; | ||
/// use server::handlers::cursor::Cursor; | ||
/// use server::handlers::sh_cursor::ShCursor; | ||
/// | ||
/// let url = ShCursor::new( | ||
/// Cursor {base: String::from("http://localhost:3000") }, | ||
/// String::from("repos") | ||
/// ).as_string(); | ||
/// assert_that!(url, is(equal_to(String::from("http://localhost:3000/repos")))); | ||
/// ``` | ||
pub struct ShCursor { | ||
origin: Cursor, | ||
complete: String, | ||
} | ||
|
||
impl ShCursor { | ||
/// New. | ||
pub fn new(origin: Cursor, complete: String) -> ShCursor { | ||
ShCursor { origin, complete } | ||
} | ||
|
||
/// Format as string. | ||
pub fn as_string(self) -> String { | ||
format!("{}/{}", self.origin.as_string(), self.complete) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use crate::handlers::cursor::Cursor; | ||
use crate::handlers::sh_cursor::ShCursor; | ||
use anyhow::Result; | ||
use hamcrest::{equal_to, is, HamcrestMatcher}; | ||
|
||
#[test] | ||
fn prints_formatted() -> Result<()> { | ||
let url = ShCursor::new( | ||
Cursor { | ||
base: String::from("http://localhost:3000"), | ||
}, | ||
String::from("repos"), | ||
) | ||
.as_string(); | ||
assert_that!( | ||
url, | ||
is(equal_to(String::from("http://localhost:3000/repos"))) | ||
); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2024 Aliaksei Bialiauski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
use crate::objects::user::User; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::{Map, Value}; | ||
|
||
/// JSON User. | ||
#[derive(Serialize, Deserialize)] | ||
pub struct JsonUser { | ||
origin: User, | ||
} | ||
|
||
impl JsonUser { | ||
/// New. | ||
pub fn new(origin: User) -> JsonUser { | ||
JsonUser { origin } | ||
} | ||
|
||
/// Print it as JSON document. | ||
pub fn as_json(self) -> Value { | ||
let mut map = Map::new(); | ||
map.insert(String::from("login"), Value::from(self.origin.login)); | ||
for (k, v) in self.origin.extra.into_iter() { | ||
map.insert(k, v); | ||
} | ||
Value::Object(map) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::objects::json::json_user::JsonUser; | ||
use crate::objects::user::User; | ||
use anyhow::Result; | ||
use hamcrest::{equal_to, is, HamcrestMatcher}; | ||
use serde_json::Value; | ||
|
||
#[test] | ||
fn prints_json() -> Result<()> { | ||
let jeff = "jeff"; | ||
let mut base = User::new(String::from(jeff)); | ||
let url = "testing"; | ||
base.extra | ||
.insert(String::from("url"), Value::String(String::from(url))); | ||
let user = JsonUser::new(base); | ||
let value = user.as_json(); | ||
assert_that!(value["login"].as_str(), is(equal_to(Some(jeff)))); | ||
assert_that!(value["url"].as_str(), is(equal_to(Some(url)))); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2024 Aliaksei Bialiauski | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included | ||
// in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
/// JSON User. | ||
pub mod json_user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
5551f71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
137-e669be66
discovered inserver/src/objects/user.rs
) and submitted as #141. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.5551f71
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puzzle
137-66b3c00b
discovered inserver/src/objects/user.rs
) and submitted as #142. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.