From fedc4c53385b054968275b9bb18bac2ab395b645 Mon Sep 17 00:00:00 2001 From: J Henry Waugh Date: Thu, 27 Aug 2020 22:59:25 -0500 Subject: [PATCH] Add exported_fn tests for rhai_fn in module --- codegen/ui_tests/export_mod_bad_attr.rs | 27 ++++++++++++++++++ codegen/ui_tests/export_mod_bad_attr.stderr | 11 ++++++++ codegen/ui_tests/export_mod_bad_value.rs | 27 ++++++++++++++++++ codegen/ui_tests/export_mod_bad_value.stderr | 11 ++++++++ codegen/ui_tests/export_mod_cfg.rs | 28 +++++++++++++++++++ codegen/ui_tests/export_mod_cfg.stderr | 11 ++++++++ codegen/ui_tests/export_mod_extra_value.rs | 27 ++++++++++++++++++ .../ui_tests/export_mod_extra_value.stderr | 11 ++++++++ codegen/ui_tests/export_mod_junk_arg.rs | 27 ++++++++++++++++++ codegen/ui_tests/export_mod_junk_arg.stderr | 11 ++++++++ codegen/ui_tests/export_mod_missing_value.rs | 27 ++++++++++++++++++ .../ui_tests/export_mod_missing_value.stderr | 11 ++++++++ codegen/ui_tests/export_mod_path_attr.rs | 27 ++++++++++++++++++ codegen/ui_tests/export_mod_path_attr.stderr | 11 ++++++++ .../rhai_mod_non_clonable_return.stderr | 10 +++++++ 15 files changed, 277 insertions(+) create mode 100644 codegen/ui_tests/export_mod_bad_attr.rs create mode 100644 codegen/ui_tests/export_mod_bad_attr.stderr create mode 100644 codegen/ui_tests/export_mod_bad_value.rs create mode 100644 codegen/ui_tests/export_mod_bad_value.stderr create mode 100644 codegen/ui_tests/export_mod_cfg.rs create mode 100644 codegen/ui_tests/export_mod_cfg.stderr create mode 100644 codegen/ui_tests/export_mod_extra_value.rs create mode 100644 codegen/ui_tests/export_mod_extra_value.stderr create mode 100644 codegen/ui_tests/export_mod_junk_arg.rs create mode 100644 codegen/ui_tests/export_mod_junk_arg.stderr create mode 100644 codegen/ui_tests/export_mod_missing_value.rs create mode 100644 codegen/ui_tests/export_mod_missing_value.stderr create mode 100644 codegen/ui_tests/export_mod_path_attr.rs create mode 100644 codegen/ui_tests/export_mod_path_attr.stderr create mode 100644 codegen/ui_tests/rhai_mod_non_clonable_return.stderr diff --git a/codegen/ui_tests/export_mod_bad_attr.rs b/codegen/ui_tests/export_mod_bad_attr.rs new file mode 100644 index 00000000..8f8f7c2b --- /dev/null +++ b/codegen/ui_tests/export_mod_bad_attr.rs @@ -0,0 +1,27 @@ +use rhai::plugin::*; + +#[derive(Clone)] +struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_mod { +#[rhai_fn(unknown = "thing")] +pub fn test_fn(input: Point) -> bool { + input.x > input.y +} +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_mod::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/export_mod_bad_attr.stderr b/codegen/ui_tests/export_mod_bad_attr.stderr new file mode 100644 index 00000000..9704d74d --- /dev/null +++ b/codegen/ui_tests/export_mod_bad_attr.stderr @@ -0,0 +1,11 @@ +error: unknown attribute 'unknown' + --> $DIR/export_mod_bad_attr.rs:11:11 + | +11 | #[rhai_fn(unknown = "thing")] + | ^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_mod` + --> $DIR/export_mod_bad_attr.rs:22:8 + | +22 | if test_mod::test_fn(n) { + | ^^^^^^^^ use of undeclared type or module `test_mod` diff --git a/codegen/ui_tests/export_mod_bad_value.rs b/codegen/ui_tests/export_mod_bad_value.rs new file mode 100644 index 00000000..c513dd35 --- /dev/null +++ b/codegen/ui_tests/export_mod_bad_value.rs @@ -0,0 +1,27 @@ +use rhai::plugin::*; + +#[derive(Clone)] +struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_mod { +#[rhai_fn(name = true)] +pub fn test_fn(input: Point) -> bool { + input.x > input.y +} +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_mod::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/export_mod_bad_value.stderr b/codegen/ui_tests/export_mod_bad_value.stderr new file mode 100644 index 00000000..63b22e4e --- /dev/null +++ b/codegen/ui_tests/export_mod_bad_value.stderr @@ -0,0 +1,11 @@ +error: expecting string literal + --> $DIR/export_mod_bad_value.rs:11:18 + | +11 | #[rhai_fn(name = true)] + | ^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_mod` + --> $DIR/export_mod_bad_value.rs:22:8 + | +22 | if test_mod::test_fn(n) { + | ^^^^^^^^ use of undeclared type or module `test_mod` diff --git a/codegen/ui_tests/export_mod_cfg.rs b/codegen/ui_tests/export_mod_cfg.rs new file mode 100644 index 00000000..49838a73 --- /dev/null +++ b/codegen/ui_tests/export_mod_cfg.rs @@ -0,0 +1,28 @@ +use rhai::plugin::*; + +#[derive(Clone)] +pub struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_mod { +#[cfg(not(feature = "foo"))] +#[rhai_fn] +pub fn test_fn(input: Point) -> bool { + input.x > input.y +} +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_mod::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/export_mod_cfg.stderr b/codegen/ui_tests/export_mod_cfg.stderr new file mode 100644 index 00000000..b932ec86 --- /dev/null +++ b/codegen/ui_tests/export_mod_cfg.stderr @@ -0,0 +1,11 @@ +error: cfg attributes not allowed on this item + --> $DIR/export_mod_cfg.rs:11:1 + | +11 | #[cfg(not(feature = "foo"))] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_mod` + --> $DIR/export_mod_cfg.rs:23:8 + | +23 | if test_mod::test_fn(n) { + | ^^^^^^^^ use of undeclared type or module `test_mod` diff --git a/codegen/ui_tests/export_mod_extra_value.rs b/codegen/ui_tests/export_mod_extra_value.rs new file mode 100644 index 00000000..6636f108 --- /dev/null +++ b/codegen/ui_tests/export_mod_extra_value.rs @@ -0,0 +1,27 @@ +use rhai::plugin::*; + +#[derive(Clone)] +struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_mod { +#[rhai_fn(return_raw = "yes")] +pub fn test_fn(input: Point) -> bool { + input.x > input.y +} +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_mod::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/export_mod_extra_value.stderr b/codegen/ui_tests/export_mod_extra_value.stderr new file mode 100644 index 00000000..0e3c65d6 --- /dev/null +++ b/codegen/ui_tests/export_mod_extra_value.stderr @@ -0,0 +1,11 @@ +error: extraneous value + --> $DIR/export_mod_extra_value.rs:11:24 + | +11 | #[rhai_fn(return_raw = "yes")] + | ^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_mod` + --> $DIR/export_mod_extra_value.rs:22:8 + | +22 | if test_mod::test_fn(n) { + | ^^^^^^^^ use of undeclared type or module `test_mod` diff --git a/codegen/ui_tests/export_mod_junk_arg.rs b/codegen/ui_tests/export_mod_junk_arg.rs new file mode 100644 index 00000000..12190cf2 --- /dev/null +++ b/codegen/ui_tests/export_mod_junk_arg.rs @@ -0,0 +1,27 @@ +use rhai::plugin::*; + +#[derive(Clone)] +struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_mod { +#[rhai_fn("wheeeee")] +pub fn test_fn(input: Point) -> bool { + input.x > input.y +} +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_mod::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/export_mod_junk_arg.stderr b/codegen/ui_tests/export_mod_junk_arg.stderr new file mode 100644 index 00000000..f4505bae --- /dev/null +++ b/codegen/ui_tests/export_mod_junk_arg.stderr @@ -0,0 +1,11 @@ +error: expecting identifier + --> $DIR/export_mod_junk_arg.rs:11:11 + | +11 | #[rhai_fn("wheeeee")] + | ^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_mod` + --> $DIR/export_mod_junk_arg.rs:22:8 + | +22 | if test_mod::test_fn(n) { + | ^^^^^^^^ use of undeclared type or module `test_mod` diff --git a/codegen/ui_tests/export_mod_missing_value.rs b/codegen/ui_tests/export_mod_missing_value.rs new file mode 100644 index 00000000..f57c247b --- /dev/null +++ b/codegen/ui_tests/export_mod_missing_value.rs @@ -0,0 +1,27 @@ +use rhai::plugin::*; + +#[derive(Clone)] +struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_mod { +#[rhai_fn(name)] +pub fn test_fn(input: Point) -> bool { + input.x > input.y +} +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_mod::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/export_mod_missing_value.stderr b/codegen/ui_tests/export_mod_missing_value.stderr new file mode 100644 index 00000000..f479f5fa --- /dev/null +++ b/codegen/ui_tests/export_mod_missing_value.stderr @@ -0,0 +1,11 @@ +error: requires value + --> $DIR/export_mod_missing_value.rs:11:11 + | +11 | #[rhai_fn(name)] + | ^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_mod` + --> $DIR/export_mod_missing_value.rs:22:8 + | +22 | if test_mod::test_fn(n) { + | ^^^^^^^^ use of undeclared type or module `test_mod` diff --git a/codegen/ui_tests/export_mod_path_attr.rs b/codegen/ui_tests/export_mod_path_attr.rs new file mode 100644 index 00000000..a489f042 --- /dev/null +++ b/codegen/ui_tests/export_mod_path_attr.rs @@ -0,0 +1,27 @@ +use rhai::plugin::*; + +#[derive(Clone)] +struct Point { + x: f32, + y: f32, +} + +#[export_module] +pub mod test_mod { +#[rhai_fn(rhai::name = "thing")] +pub fn test_fn(input: Point) -> bool { + input.x > input.y +} +} + +fn main() { + let n = Point { + x: 0.0, + y: 10.0, + }; + if test_mod::test_fn(n) { + println!("yes"); + } else { + println!("no"); + } +} diff --git a/codegen/ui_tests/export_mod_path_attr.stderr b/codegen/ui_tests/export_mod_path_attr.stderr new file mode 100644 index 00000000..d96d7c8c --- /dev/null +++ b/codegen/ui_tests/export_mod_path_attr.stderr @@ -0,0 +1,11 @@ +error: expecting attribute name + --> $DIR/export_mod_path_attr.rs:11:11 + | +11 | #[rhai_fn(rhai::name = "thing")] + | ^^^^^^^^^^ + +error[E0433]: failed to resolve: use of undeclared type or module `test_mod` + --> $DIR/export_mod_path_attr.rs:22:8 + | +22 | if test_mod::test_fn(n) { + | ^^^^^^^^ use of undeclared type or module `test_mod` diff --git a/codegen/ui_tests/rhai_mod_non_clonable_return.stderr b/codegen/ui_tests/rhai_mod_non_clonable_return.stderr new file mode 100644 index 00000000..db880026 --- /dev/null +++ b/codegen/ui_tests/rhai_mod_non_clonable_return.stderr @@ -0,0 +1,10 @@ +error[E0277]: the trait bound `NonClonable: std::clone::Clone` is not satisfied + --> $DIR/rhai_mod_non_clonable_return.rs:12:12 + | +12 | pub fn test_fn(input: f32) -> NonClonable { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `NonClonable` + | + ::: /home/cryptkeeper/Desktop/Software/ytdl-replacement/rhai/src/any.rs:537:30 + | +537 | pub fn from(value: T) -> Self { + | ----- required by this bound in `rhai::Dynamic::from`