diff --git a/codegen/tests/compile-fail/typed-uri-bad-type.rs b/codegen/tests/compile-fail/typed-uri-bad-type.rs new file mode 100644 index 00000000..98c3f139 --- /dev/null +++ b/codegen/tests/compile-fail/typed-uri-bad-type.rs @@ -0,0 +1,35 @@ +#![feature(plugin, decl_macro)] +#![plugin(rocket_codegen)] +#![allow(dead_code, unused_variables)] + +extern crate rocket; + +use rocket::http::RawStr; +use rocket::request::FromParam; + +struct S; + +impl<'a> FromParam<'a> for S { + type Error = (); + fn from_param(param: &'a RawStr) -> Result { Ok(S) } +} + +#[post("/")] +fn simple(id: i32) -> &'static str { "" } + +#[post("//")] + //~^ ERROR the trait bound `S: std::fmt::Display` is not satisfied +fn not_uri_display(id: i32, name: S) -> &'static str { "" } + +#[post("//")] +fn not_uri_display_but_unused(id: i32, name: S) -> &'static str { "" } + +fn main() { + uri!(simple: id = "hi"); + //~^ ERROR the trait bound `i32: std::convert::From<&str>` is not satisfied + uri!(simple: "hello"); + //~^ ERROR the trait bound `i32: std::convert::From<&str>` is not satisfied + uri!(simple: id = 239239i64); + //~^ ERROR the trait bound `i32: std::convert::From` is not satisfied + uri!(not_uri_display: 10, S); +} diff --git a/codegen/tests/compile-fail/typed-uris-bad-params.rs b/codegen/tests/compile-fail/typed-uris-bad-params.rs new file mode 100644 index 00000000..fd040e18 --- /dev/null +++ b/codegen/tests/compile-fail/typed-uris-bad-params.rs @@ -0,0 +1,30 @@ +#![feature(plugin, decl_macro, custom_derive)] +#![plugin(rocket_codegen)] +#![allow(dead_code, unused_variables)] + +extern crate rocket; + +use std::fmt; + +use rocket::http::Cookies; + +#[post("/")] +fn simple(id: i32) -> &'static str { "" } + +#[post("/")] +fn guard_1(cookies: Cookies, id: i32) -> &'static str { "" } + +fn main() { + uri!(simple); //~ ERROR expects 1 parameter but 0 were supplied + uri!(simple: 1, 23); //~ ERROR expects 1 parameter but 2 were supplied + uri!(simple: "Hello", 23, ); //~ ERROR expects 1 parameter but 2 were supplied + uri!(guard_1: "hi", 100); //~ ERROR expects 1 parameter but 2 were supplied + + uri!(simple: id = 100, name = "hi"); //~ ERROR invalid parameters + uri!(simple: id = 100, id = 100); //~ ERROR invalid parameters + uri!(simple: name = 100, id = 100); //~ ERROR invalid parameters + uri!(simple: id = 100, id = 100, ); //~ ERROR invalid parameters + uri!(simple: name = "hi"); //~ ERROR invalid parameters + uri!(guard_1: cookies = "hi", id = 100); //~ ERROR invalid parameters + uri!(guard_1: id = 100, cookies = "hi"); //~ ERROR invalid parameters +} diff --git a/codegen/tests/compile-fail/typed-uris-invalid-syntax.rs b/codegen/tests/compile-fail/typed-uris-invalid-syntax.rs new file mode 100644 index 00000000..124c3b45 --- /dev/null +++ b/codegen/tests/compile-fail/typed-uris-invalid-syntax.rs @@ -0,0 +1,20 @@ +#![feature(plugin, decl_macro, custom_derive)] +#![plugin(rocket_codegen)] +#![allow(dead_code, unused_variables)] + +extern crate rocket; + +#[post("//")] +fn simple(id: i32, name: String) -> &'static str { "" } + +fn main() { + uri!(simple: id = 100, "Hello"); //~ ERROR cannot be mixed + uri!(simple: "Hello", id = 100); //~ ERROR cannot be mixed + uri!(simple,); //~ ERROR expected one of `::`, `:`, or `` + uri!(simple:); //~ ERROR expected argument list + uri!("mount"); //~ ERROR expected `,`, found `` + uri!("mount",); //~ ERROR expected identifier + uri!(); //~ ERROR cannot be empty + uri!(simple: id = ); //~ ERROR expected argument list + //~^ ERROR expected expression +}