Skip to content

Commit

Permalink
Merge pull request #135 from myyrakle/test/#132
Browse files Browse the repository at this point in the history
[#132] error 모듈 테스트코드 작성
  • Loading branch information
myyrakle authored Jul 24, 2024
2 parents 6c4dbe1 + bbac772 commit 9c0df8c
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/errors/execute_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,22 @@ impl std::fmt::Display for ExecuteError {
write!(formatter, "{}", self.message)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_execute_error_eq() {
let error1 = ExecuteError::wrap("test");
let error2 = ExecuteError::wrap("test");
assert_eq!(error1, error2);
}

#[test]
fn test_execute_error_display() {
let error = ExecuteError::wrap("test");

assert!(error.to_string().contains("test"));
}
}
21 changes: 21 additions & 0 deletions src/errors/into_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,24 @@ impl std::fmt::Display for IntoError {
write!(formatter, "parsing error(into error): {}", self.message)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_into_error_eq() {
let error1 = IntoError::wrap("test");
let error2 = IntoError::wrap("test");
assert_eq!(error1, error2);
}

#[test]
fn test_into_error_display() {
let error = IntoError::wrap("test");

assert!(error
.to_string()
.contains("parsing error(into error): test"));
}
}
19 changes: 19 additions & 0 deletions src/errors/lexing_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,22 @@ impl std::fmt::Display for LexingError {
write!(formatter, "lexing error: {}", self.message)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_lexing_error_eq() {
let error1 = LexingError::wrap("test");
let error2 = LexingError::wrap("test");
assert_eq!(error1, error2);
}

#[test]
fn test_lexing_error_display() {
let error = LexingError::wrap("test");

assert!(error.to_string().contains("lexing error: test"));
}
}
28 changes: 28 additions & 0 deletions src/errors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,31 @@ impl ToString for RRDBError {
}
}
}

#[cfg(test)]
mod tests {
use predule::{ExecuteError, IntoError, LexingError, ParsingError, ServerError, TypeError};

use super::*;

#[test]
fn test_rrdb_error_to_string() {
let error = ExecuteError::wrap("test");
assert!(error.to_string().contains("test"));

let error = IntoError::wrap("test");
assert!(error.to_string().contains("test"));

let error = LexingError::wrap("test");
assert!(error.to_string().contains("test"));

let error = ParsingError::wrap("test");
assert!(error.to_string().contains("test"));

let error = ServerError::wrap("test");
assert!(error.to_string().contains("test"));

let error = TypeError::wrap("test");
assert!(error.to_string().contains("test"));
}
}
19 changes: 19 additions & 0 deletions src/errors/parsing_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,22 @@ impl std::fmt::Display for ParsingError {
write!(formatter, "parsing error: {}", self.message)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_parsing_error_eq() {
let error1 = ParsingError::wrap("test");
let error2 = ParsingError::wrap("test");
assert_eq!(error1, error2);
}

#[test]
fn test_parsing_error_display() {
let error = ParsingError::wrap("test");

assert!(error.to_string().contains("parsing error: test"));
}
}
44 changes: 44 additions & 0 deletions src/errors/server_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use super::RRDBError;

#[derive(Debug)]
pub struct ServerError {
pub message: String,
Expand All @@ -23,10 +25,52 @@ impl ServerError {
}
}

impl ServerError {
pub fn wrap<T: ToString>(message: T) -> RRDBError {
RRDBError::ServerError(Self {
message: message.to_string(),
backtrace: std::backtrace::Backtrace::capture(),
})
}
}

impl std::error::Error for ServerError {}

impl std::fmt::Display for ServerError {
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(formatter, "server error: {}", self.message)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_server_error_eq() {
let error1 = ServerError::wrap("test");
let error2 = ServerError::wrap("test");
assert_eq!(error1, error2);
}

#[test]
fn test_server_error_display() {
let error = ServerError::wrap("test");

assert!(error.to_string().contains("server error: test"));
}

#[test]
fn test_server_error_new() {
let error = ServerError::new("test");

assert_eq!(error.message, "test");
}

#[test]
fn test_server_error_boxed() {
let error = ServerError::boxed("test");

assert_eq!(error.message, "test");
}
}
19 changes: 19 additions & 0 deletions src/errors/type_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,22 @@ impl std::fmt::Display for TypeError {
write!(formatter, "parsing error: {}", self.message)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_type_error_eq() {
let error1 = TypeError::wrap("test");
let error2 = TypeError::wrap("test");
assert_eq!(error1, error2);
}

#[test]
fn test_type_error_display() {
let error = TypeError::wrap("test");

assert!(error.to_string().contains("parsing error: test"));
}
}

0 comments on commit 9c0df8c

Please sign in to comment.