Add compile-fail tests for 'uri!' macro.

This commit is contained in:
Sergio Benitez 2017-09-11 00:46:47 -07:00
parent 02cff01e17
commit bbeb95357b
3 changed files with 85 additions and 0 deletions

View File

@ -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<Self, Self::Error> { Ok(S) }
}
#[post("/<id>")]
fn simple(id: i32) -> &'static str { "" }
#[post("/<id>/<name>")]
//~^ ERROR the trait bound `S: std::fmt::Display` is not satisfied
fn not_uri_display(id: i32, name: S) -> &'static str { "" }
#[post("/<id>/<name>")]
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<i64>` is not satisfied
uri!(not_uri_display: 10, S);
}

View File

@ -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("/<id>")]
fn simple(id: i32) -> &'static str { "" }
#[post("/<id>")]
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
}

View File

@ -0,0 +1,20 @@
#![feature(plugin, decl_macro, custom_derive)]
#![plugin(rocket_codegen)]
#![allow(dead_code, unused_variables)]
extern crate rocket;
#[post("/<id>/<name>")]
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 `<eof>`
uri!(simple:); //~ ERROR expected argument list
uri!("mount"); //~ ERROR expected `,`, found `<eof>`
uri!("mount",); //~ ERROR expected identifier
uri!(); //~ ERROR cannot be empty
uri!(simple: id = ); //~ ERROR expected argument list
//~^ ERROR expected expression
}