Skip to content

Commit

Permalink
Fix Clippy on 0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
noib3 committed Dec 22, 2024
1 parent f85ae87 commit 833dc5a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 57 deletions.
10 changes: 9 additions & 1 deletion crates/api/src/types/cmd_infos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub(crate) struct ParseCmdOutput {
#[cfg(feature = "neovim-nightly")]
addr: NvimString,

// Only on Nightly.
// Only on 0.10.
#[cfg(all(feature = "neovim-0-10", not(feature = "neovim-nightly")))]
nextcmd: Object,

Expand Down Expand Up @@ -331,6 +331,9 @@ impl TryFrom<ParseCmdOutput> for CmdInfos {
}

Ok(Self {
#[cfg(all(feature = "neovim-0-10", not(feature = "neovim-nightly")))] // Only on 0.10.
addr: utils::none_literal_is_none(Deserializer::new(addr))?,
#[cfg(feature = "neovim-nightly")] // Only on Nightly.
addr: utils::none_literal_is_none(Deserializer::new(addr.into()))?,
args: deserialize(args)?,
bang: deserialize(bang)?,
Expand All @@ -339,6 +342,11 @@ impl TryFrom<ParseCmdOutput> for CmdInfos {
magic: deserialize(magic)?,
mods: deserialize(mods)?,
nargs: deserialize(nargs)?,
#[cfg(all(feature = "neovim-0-10", not(feature = "neovim-nightly")))] // Only on 0.10.
nextcmd: utils::empty_string_is_none(Deserializer::new(
nextcmd,
))?,
#[cfg(feature = "neovim-nightly")] // Only on Nightly.
nextcmd: utils::empty_string_is_none(Deserializer::new(
nextcmd.into(),
))?,
Expand Down
27 changes: 12 additions & 15 deletions tests/src/api/extmark.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
use nvim_oxi as nvim;
use nvim_oxi::api::{self, opts::*, types::*, Buffer};

#[nvim::test]
#[nvim_oxi::test]
fn add_highlight() {
let mut buf = Buffer::current();
let id = api::create_namespace("Foo");
let res = buf.add_highlight(id, "Normal", 0, ..);
assert!(res.is_ok(), "{res:?}");
}

#[nvim::test]
#[nvim_oxi::test]
fn clear_namespace() {
let mut buf = Buffer::current();
let id = api::create_namespace("Foo");
let res = buf.clear_namespace(id, ..);
assert_eq!(Ok(()), res);
}

#[nvim::test]
#[nvim_oxi::test]
fn get_extmarks() {
let mut buf = Buffer::current();
let ns_id = api::create_namespace("Foo");
Expand Down Expand Up @@ -85,7 +84,7 @@ fn get_extmarks() {
assert_eq!(Some(ExtmarkVirtTextPosition::Overlay), infos.virt_text_pos);
}

#[nvim::test]
#[nvim_oxi::test]
fn get_namespaces() {
let id = api::create_namespace("Foo");

Expand All @@ -96,29 +95,27 @@ fn get_namespaces() {
assert_eq!(id, out);
}

#[nvim::test]
#[nvim_oxi::test]
fn set_decoration_provider() {
use nvim::print;

let id = api::create_namespace("Foo");

let opts = DecorationProviderOpts::builder()
.on_start(|args| {
print!("{args:?}");
nvim_oxi::print!("{args:?}");
true
})
.on_buf(|args| {
print!("{args:?}");
nvim_oxi::print!("{args:?}");
})
.on_win(|args| {
print!("{args:?}");
nvim_oxi::print!("{args:?}");
true
})
.on_line(|args| {
print!("{args:?}");
nvim_oxi::print!("{args:?}");
})
.on_end(|args| {
print!("{args:?}");
nvim_oxi::print!("{args:?}");
})
.build();

Expand All @@ -133,7 +130,7 @@ fn set_decoration_provider() {
assert!(bytes_written.is_ok(), "{bytes_written:?}");
}

#[nvim::test]
#[nvim_oxi::test]
fn set_get_del_extmark() {
let mut buf = Buffer::current();
let ns_id = api::create_namespace("Foo");
Expand Down Expand Up @@ -207,7 +204,7 @@ fn set_get_del_extmark() {
}

#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
#[nvim::test]
#[nvim_oxi::test]
fn virt_text_pos_inline() {
let mut buf = Buffer::current();

Expand Down
25 changes: 14 additions & 11 deletions tests/src/api/tabpage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use nvim_oxi::{self as nvim, api::TabPage};
use nvim_oxi::api::TabPage;

#[nvim::test]
#[nvim_oxi::test]
fn get_list_wins() {
let tab = TabPage::current();

Expand All @@ -16,38 +16,41 @@ fn get_list_wins() {
assert_eq!(win, all_wins.into_iter().next().unwrap());
}

#[nvim::test]
#[nvim_oxi::test]
fn tabpage_get_number() {
assert_eq!(Ok(1), TabPage::current().get_number())
}

#[nvim::test]
#[nvim_oxi::test]
fn is_valid() {
assert!(TabPage::current().is_valid());
}

#[nvim::test]
#[nvim_oxi::test]
fn tabpage_set_get_del_var() {
let mut tab = TabPage::current();
tab.set_var("foo", 42).unwrap();
assert_eq!(Ok(42), tab.get_var("foo"));
assert_eq!(Ok(()), tab.del_var("foo"));
}

#[nvim::test]
#[nvim_oxi::test]
#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
fn tabpage_set_get_win() {
let config = nvim::api::types::WindowConfig::builder()
.relative(nvim::api::types::WindowRelativeTo::Editor)
let config = nvim_oxi::api::types::WindowConfig::builder()
.relative(nvim_oxi::api::types::WindowRelativeTo::Editor)
.height(10)
.width(5)
.row(1.5)
.col(1.5)
.build();

let window =
nvim::api::open_win(&nvim::api::Buffer::current(), true, &config)
.unwrap();
let window = nvim_oxi::api::open_win(
&nvim_oxi::api::Buffer::current(),
true,
&config,
)
.unwrap();

let mut tab = TabPage::current();

Expand Down
48 changes: 23 additions & 25 deletions tests/src/api/vimscript.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
use nvim_oxi as oxi;
#[allow(unused_imports)]
use nvim_oxi::api::{self, opts::*, types::*};

#[oxi::test]
#[nvim_oxi::test]
fn call_function() {
let res = api::call_function::<_, usize>("strwidth", ("foo bar",));
assert_eq!(Ok(7), res);
}

#[oxi::test(cmd = "set autoread")] // getting `W13` warnings otherwise
#[nvim_oxi::test(cmd = "set autoread")] // getting `W13` warnings otherwise
fn cmd_basic() {
let cmd = "checktime";
let infos = CmdInfos::builder().cmd(cmd).build();
let opts = CmdOpts::builder().output(true).build();
assert_eq!(Ok(None), api::cmd(&infos, &opts));
}

#[oxi::test]
#[nvim_oxi::test]
fn cmd_no_output() {
let cmd = "checktime";
let infos = CmdInfos::builder().cmd(cmd).build();
let opts = CmdOpts::builder().output(false).build();
assert_eq!(Ok(None), api::cmd(&infos, &opts));
}

#[oxi::test]
#[nvim_oxi::test]
fn command() {
let res = api::command(":lua vim.api.nvim_buf_set_var(0, 'foo', 'bar')");
assert_eq!(Ok(()), res);
Expand All @@ -35,7 +33,7 @@ fn command() {
);
}

#[oxi::test]
#[nvim_oxi::test]
fn eval() {
let res = api::eval::<u8>("41 + 1");
assert_eq!(Ok(42), res);
Expand All @@ -44,7 +42,7 @@ fn eval() {
assert_eq!(Ok(69), res); // nice
}

#[oxi::test]
#[nvim_oxi::test]
fn exec() {
let no_op = api::exec(":", true);
assert_eq!(Ok(None), no_op);
Expand All @@ -53,7 +51,7 @@ fn exec() {
assert_eq!(Ok(Some("2".into())), add);
}

#[oxi::test]
#[nvim_oxi::test]
fn parse_cmd_basic() {
let res = api::parse_cmd("echo 'foo'", &Default::default());
assert!(res.is_ok(), "{res:?}");
Expand All @@ -71,25 +69,25 @@ fn parse_cmd_basic() {
assert_eq!(Some(0), infos.count);

let magic = infos.magic.unwrap();
assert_eq!(false, magic.file);
assert_eq!(false, magic.bar);
assert!(!magic.file);
assert!(!magic.bar);

let mods = infos.mods.unwrap();
assert_eq!(false, mods.browse);
assert_eq!(false, mods.confirm);
assert_eq!(false, mods.emsg_silent);
assert_eq!(false, mods.hide);
assert_eq!(false, mods.keepalt);
assert_eq!(false, mods.keepjumps);
assert_eq!(false, mods.keepmarks);
assert_eq!(false, mods.keeppatterns);
assert_eq!(false, mods.lockmarks);
assert_eq!(false, mods.noautocmd);
assert_eq!(false, mods.sandbox);
assert_eq!(false, mods.silent);
assert!(!mods.browse);
assert!(!mods.confirm);
assert!(!mods.emsg_silent);
assert!(!mods.hide);
assert!(!mods.keepalt);
assert!(!mods.keepjumps);
assert!(!mods.keepmarks);
assert!(!mods.keeppatterns);
assert!(!mods.lockmarks);
assert!(!mods.noautocmd);
assert!(!mods.sandbox);
assert!(!mods.silent);
assert_eq!(None, mods.split);
assert_eq!(-1, mods.tab);
assert_eq!(false, mods.vertical);
assert!(!mods.vertical);

assert_eq!(Some(CommandNArgs::Any), infos.nargs);
assert_eq!(None, infos.nextcmd);
Expand All @@ -101,7 +99,7 @@ fn parse_cmd_basic() {
assert_eq!(Some(CmdRange::None), infos.range);
}

#[oxi::test]
#[nvim_oxi::test]
fn parse_expression_basic() {
let res = api::parse_expression("lua print('a')", "", true);
assert!(res.is_ok(), "{res:?}");
Expand Down
6 changes: 3 additions & 3 deletions tests/src/libuv/async_handle.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::cell::RefCell;
use std::rc::Rc;

use nvim_oxi::{self as nvim, libuv::*};
use nvim_oxi::libuv::*;

#[nvim::test]
#[nvim_oxi::test]
#[ignore = "the callback is never called"]
fn async_handle_0() {
let num_called = Rc::new(RefCell::new(0));
Expand All @@ -24,7 +24,7 @@ fn async_handle_0() {

// TODO: how do we wait for the callback to be executed without
// blocking the main thread?
nvim::schedule(move |_| {
nvim_oxi::schedule(move |_| {
assert_eq!(*also_num_called.borrow(), i);
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/libuv/timer_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::sync::mpsc;
use std::thread::sleep;
use std::time::Duration;

use nvim_oxi::{self as nvim, libuv::*};
use nvim_oxi::libuv::*;

#[nvim::test]
#[nvim_oxi::test]
fn timer_handle_0() {
let (tx, rx) = mpsc::channel();

Expand Down

0 comments on commit 833dc5a

Please sign in to comment.