Skip to content

Commit

Permalink
test: add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenira committed Oct 28, 2023
1 parent 828c8e7 commit 032bee3
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

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

20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,23 @@ prost = "0.12.1"
serde = { version = "1.0.190", features = ["derive"] }
tokio = { version = "1.33.0", features = ["macros", "rt-multi-thread"] }
tonic = "0.10.2"

[dev-dependencies]
pretty_assertions = "1.4.0"

[profile.dev]
opt-level = 0
debug = true
panic = "abort"

[profile.test]
opt-level = 0
debug = true

[profile.release]
opt-level = 3
debug = false
panic = "unwind"
lto = true
codegen-units = 1
strip = true
12 changes: 12 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,15 @@ impl lua::Poppable for Config {
Self::from_object(obj).map_err(lua::Error::pop_error_from_err::<Self, _>)
}
}

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

#[test]
fn test_config_default() {
let config = Config::default();
assert_eq!(config.rpc_port, 50051);
}
}
50 changes: 50 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! Neovim plugin for daktilo

#![warn(missing_docs)]
#![warn(clippy::missing_docs_in_private_items)]

use config::Config;
use daktilo_server::client_proto::{daktilo_client::DaktiloClient, ReportCursorMovementRequest};
use nvim_oxi as oxi;
Expand Down Expand Up @@ -143,3 +148,48 @@ fn daktilo_nvim() -> oxi::Result<Dictionary> {
Function::from_fn(start),
)]))
}

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

#[test]
fn test_buff_info_constructor() {
let buf_info = BufInfo::new(Some("test".to_string()), (1, 2));
assert_eq!(buf_info.col, 2);
assert_eq!(buf_info.line, 0);
assert_eq!(buf_info.name, Some("test".to_string()));
}

#[test]
fn test_buff_info_into_report_cursor_movement_request() {
let buf_info = BufInfo::new(Some("test".to_string()), (1, 2));
let request: ReportCursorMovementRequest = buf_info.into();
assert_eq!(request.column_number, 2);
assert_eq!(request.line_number, Some(0));
assert_eq!(request.file_path, Some("test".to_string()));
}

#[test]
fn test_message_event_from_anyhow_error() {
let err = anyhow::anyhow!("test");
let message_event = MessageEvent::from(err);
assert_eq!(message_event.err, true);
assert_eq!(message_event.message, "test".to_string());
}

#[test]
fn test_message_event_from_str() {
let message_event = MessageEvent::from("test");
assert_eq!(message_event.err, false);
assert_eq!(message_event.message, "test".to_string());
}

#[test]
fn test_message_event_new() {
let message_event = MessageEvent::new(true, "test".to_string());
assert_eq!(message_event.err, true);
assert_eq!(message_event.message, "test".to_string());
}
}

0 comments on commit 032bee3

Please sign in to comment.