rust/tests/consts.rs

44 lines
955 B
Rust
Raw Normal View History

2015-08-16 15:56:09 +02:00
#![allow(plugin_as_library)]
#![feature(rustc_private)]
extern crate clippy;
2015-08-16 15:56:09 +02:00
extern crate syntax;
extern crate rustc;
use clippy::consts::{constant, ConstantVariant};
2015-08-16 15:56:09 +02:00
use clippy::consts::ConstantVariant::*;
use syntax::ast::*;
2015-08-16 15:56:09 +02:00
use syntax::ptr::P;
use syntax::codemap::{Spanned, COMMAND_LINE_SP};
use std::mem;
use rustc::lint::Context;
fn ctx() -> &'static Context<'static, 'static> {
unsafe {
let x : *const Context<'static, 'static> = std::ptr::null();
mem::transmute(x)
}
}
fn lit(l: Lit_) -> Expr {
Expr{
id: 1,
node: ExprLit(P(Spanned{
node: l,
span: COMMAND_LINE_SP,
})),
span: COMMAND_LINE_SP,
}
}
fn check(expect: ConstantVariant, expr: &Expr) {
assert_eq!(Some(expect), constant(ctx(), expr).map(|x| x.constant))
2015-08-16 15:56:09 +02:00
}
#[test]
fn test_lit() {
check(ConstantBool(true), &lit(LitBool(true)));
check(ConstantBool(false), &lit(LitBool(false)));
}