mirror of https://github.com/rwf2/Rocket.git
Add more codegen tests.
This commit is contained in:
parent
6498c26473
commit
3ddc133a0e
|
@ -46,6 +46,7 @@ fn get_struct_lifetime(ecx: &mut ExtCtxt, item: &Annotatable, span: Span)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Use proper logging to emit the error messages.
|
||||||
pub fn from_form_derive(ecx: &mut ExtCtxt, span: Span, meta_item: &MetaItem,
|
pub fn from_form_derive(ecx: &mut ExtCtxt, span: Span, meta_item: &MetaItem,
|
||||||
annotated: &Annotatable, push: &mut FnMut(Annotatable)) {
|
annotated: &Annotatable, push: &mut FnMut(Annotatable)) {
|
||||||
let struct_lifetime = get_struct_lifetime(ecx, annotated, span);
|
let struct_lifetime = get_struct_lifetime(ecx, annotated, span);
|
||||||
|
|
|
@ -164,7 +164,7 @@ fn parse_method(ecx: &ExtCtxt, meta_item: &NestedMetaItem) -> Spanned<Method> {
|
||||||
return span(method, word.span());
|
return span(method, word.span());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let msg = format!("{} is not a valid method.", word.name());
|
let msg = format!("{} is not a valid HTTP method.", word.name());
|
||||||
ecx.span_err(word.span(), &msg);
|
ecx.span_err(word.span(), &msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,7 +224,8 @@ fn parse_form(ecx: &ExtCtxt, kv: &KVSpanned<LitKind>) -> Ident {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ecx.struct_span_err(kv.span, r#"expected `form = "<name>"`"#)
|
let err_string = r#"`form` value must be a parameter, e.g: "<name>"`"#;
|
||||||
|
ecx.struct_span_fatal(kv.span, err_string)
|
||||||
.help(r#"form, if specified, must be a key-value pair where
|
.help(r#"form, if specified, must be a key-value pair where
|
||||||
the key is `form` and the value is a string with a single
|
the key is `form` and the value is a string with a single
|
||||||
parameter inside '<' '>'. e.g: form = "<login>""#)
|
parameter inside '<' '>'. e.g: form = "<login>""#)
|
||||||
|
@ -243,7 +244,7 @@ fn parse_rank(ecx: &ExtCtxt, kv: &KVSpanned<LitKind>) -> isize {
|
||||||
ecx.span_err(kv.value.span, msg.as_str());
|
ecx.span_err(kv.value.span, msg.as_str());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ecx.struct_span_err(kv.span, r#"expected `rank = int`"#)
|
ecx.struct_span_err(kv.span, r#"`rank` value must be an int"#)
|
||||||
.help(r#"the rank, if specified, must be a key-value pair where
|
.help(r#"the rank, if specified, must be a key-value pair where
|
||||||
the key is `rank` and the value is an integer.
|
the key is `rank` and the value is an integer.
|
||||||
e.g: rank = 1, or e.g: rank = 10"#)
|
e.g: rank = 1, or e.g: rank = 10"#)
|
||||||
|
@ -267,7 +268,7 @@ fn parse_format(ecx: &ExtCtxt, kv: &KVSpanned<LitKind>) -> ContentType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ecx.struct_span_err(kv.span, r#"expected `format = "content/type"`"#)
|
ecx.struct_span_err(kv.span, r#"`format` must be a "content/type"`"#)
|
||||||
.help(r#"format, if specified, must be a key-value pair where
|
.help(r#"format, if specified, must be a key-value pair where
|
||||||
the key is `format` and the value is a string representing the
|
the key is `format` and the value is a string representing the
|
||||||
content-type accepted. e.g: format = "application/json""#)
|
content-type accepted. e.g: format = "application/json""#)
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[get] //~ ERROR incorrect use of attribute
|
||||||
|
//~^ ERROR malformed attribute
|
||||||
|
fn get() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = routes![get];
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[get(path = "hello", 123)] //~ ERROR expected
|
||||||
|
fn get() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = routes![get];
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[get(1)] //~ ERROR expected `path = string`
|
||||||
|
fn get0() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
#[get(path = 1)] //~ ERROR must be a string
|
||||||
|
fn get1() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
#[get(path = "h", rank = "2")] //~ ERROR must be an int
|
||||||
|
fn get2() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
#[get(path = "h", format = 100)] //~ ERROR must be a "content/type"
|
||||||
|
fn get3() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[get("")] //~ ERROR can only be used on functions
|
||||||
|
enum B { } //~ ERROR but was applied
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = routes![get];
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[get("")] //~ ERROR can only be used on functions
|
||||||
|
impl C for A { } //~ ERROR but was applied
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = routes![get];
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[get("")] //~ ERROR can only be used on functions
|
||||||
|
struct A; //~ ERROR but was applied
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = routes![get];
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[get("")] //~ ERROR can only be used on functions
|
||||||
|
trait C { } //~ ERROR but was applied
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = routes![get];
|
||||||
|
}
|
|
@ -4,4 +4,10 @@
|
||||||
#[get("/<name>")] //~ ERROR 'name' is declared
|
#[get("/<name>")] //~ ERROR 'name' is declared
|
||||||
fn get(other: &str) -> &'static str { "hi" } //~ ERROR isn't in the function
|
fn get(other: &str) -> &'static str { "hi" } //~ ERROR isn't in the function
|
||||||
|
|
||||||
|
#[get("/a?<r>")] //~ ERROR 'r' is declared
|
||||||
|
fn get1() -> &'static str { "hi" } //~ ERROR isn't in the function
|
||||||
|
|
||||||
|
#[get("/a", form = "<test>")] //~ ERROR 'test' is declared
|
||||||
|
fn get2() -> &'static str { "hi" } //~ ERROR isn't in the function
|
||||||
|
|
||||||
fn main() { }
|
fn main() { }
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[route(FIX, "hello")] //~ ERROR FIX is not a valid HTTP method
|
||||||
|
//~^ ERROR valid HTTP method
|
||||||
|
fn get() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = routes![get];
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[route(CONNECT, "hello")] //~ ERROR valid HTTP method
|
||||||
|
fn get() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = routes![get];
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[get(path = "hello", unknown = 123)] //~ ERROR 'unknown' is not a known param
|
||||||
|
fn get() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = routes![get];
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[get("/test/<one>/<two>/<three>")]
|
||||||
|
fn get(one: &str, two: usize, three: isize) -> &'static str { "hi" }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = routes![get];
|
||||||
|
}
|
Loading…
Reference in New Issue