Add unit test for plugin

This commit is contained in:
Manish Goregaokar 2015-06-02 16:38:46 +05:30
parent 2551cce51e
commit 7bc88d541f
4 changed files with 41 additions and 0 deletions

View file

@ -1280,6 +1280,7 @@ name = "util_tests"
version = "0.0.1"
dependencies = [
"geom 0.1.0 (git+https://github.com/servo/rust-geom)",
"plugins 0.0.1",
"util 0.0.1",
]

View file

@ -11,5 +11,9 @@ doctest = false
[dependencies.util]
path = "../../../components/util"
[dependencies.plugins]
path = "../../../components/plugins"
[dependencies.geom]
git = "https://github.com/servo/rust-geom"

View file

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![feature(plugin, custom_derive, custom_attributes)]
#![plugin(plugins)]
extern crate util;
extern crate geom;
@ -9,3 +11,4 @@ extern crate geom;
#[cfg(test)] mod logical_geometry;
#[cfg(test)] mod task;
#[cfg(test)] mod vec;
#[cfg(test)] mod mem;

33
tests/unit/util/mem.rs Normal file
View file

@ -0,0 +1,33 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use util::mem::HeapSizeOf;
struct Four;
impl HeapSizeOf for Four {
fn heap_size_of_children(&self) -> usize {
4
}
}
#[derive(HeapSizeOf)]
struct Eight(Four, Four, bool, bool, bool);
#[derive(HeapSizeOf)]
enum EightOrFour {
Eight(Eight),
Four(Four),
Zero(u8)
}
#[test]
fn test_heap_size() {
assert_eq!(Four.heap_size_of_children(), 4);
let eight = Eight(Four, Four, true, true, true);
assert_eq!(eight.heap_size_of_children(), 8);
assert_eq!(EightOrFour::Eight(eight).heap_size_of_children(), 8);
assert_eq!(EightOrFour::Four(Four).heap_size_of_children(), 4);
assert_eq!(EightOrFour::Zero(1).heap_size_of_children(), 0);
}