cleaning up, adding tests
This commit is contained in:
parent
721c174b6c
commit
8716005581
2 changed files with 48 additions and 6 deletions
|
@ -172,15 +172,15 @@ fn fun_to_str(decl: ast::fn_decl, name: ast::ident,
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fun_to_str() {
|
fn test_fun_to_str() {
|
||||||
let decl: ast::fn_decl = {
|
let decl: ast::fn_decl = ast::fn_decl {
|
||||||
inputs: ~[],
|
inputs: ~[],
|
||||||
output: @{id: 0,
|
output: @ast::Ty {id: 0,
|
||||||
node: ast::ty_nil,
|
node: ast::ty_nil,
|
||||||
span: ast_util::dummy_sp()},
|
span: ast_util::dummy_sp()},
|
||||||
purity: ast::impure_fn,
|
//purity: ast::impure_fn,
|
||||||
cf: ast::return_val
|
cf: ast::return_val
|
||||||
};
|
};
|
||||||
assert fun_to_str(decl, "a", ~[]) == "fn a()";
|
assert fun_to_str(decl, "abba", ~[]) == "fn abba()";
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_to_str(blk: ast::blk, intr: @ident_interner) -> ~str {
|
fn block_to_str(blk: ast::blk, intr: @ident_interner) -> ~str {
|
||||||
|
@ -214,7 +214,7 @@ fn test_variant_to_str() {
|
||||||
attrs: ~[],
|
attrs: ~[],
|
||||||
args: ~[],
|
args: ~[],
|
||||||
id: 0,
|
id: 0,
|
||||||
disr_expr: none
|
disr_expr: None
|
||||||
});
|
});
|
||||||
|
|
||||||
let varstr = variant_to_str(var);
|
let varstr = variant_to_str(var);
|
||||||
|
|
|
@ -29,7 +29,7 @@ fn mk<T:Eq IterBytes Hash Const Copy>() -> Interner<T> {
|
||||||
move ((move hi) as Interner::<T>)
|
move ((move hi) as Interner::<T>)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mk_prefill<T:Eq IterBytes Hash Const Copy>(init: ~[T]) -> Interner<T> {
|
fn mk_prefill<T:Eq IterBytes Hash Const Copy>(init: &[T]) -> Interner<T> {
|
||||||
let rv = mk();
|
let rv = mk();
|
||||||
for init.each() |v| { rv.intern(*v); }
|
for init.each() |v| { rv.intern(*v); }
|
||||||
return rv;
|
return rv;
|
||||||
|
@ -70,3 +70,45 @@ impl <T:Eq IterBytes Hash Const Copy> hash_interner<T>: Interner<T> {
|
||||||
|
|
||||||
fn len() -> uint { return self.vect.len(); }
|
fn len() -> uint { return self.vect.len(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_fail]
|
||||||
|
fn i1 () {
|
||||||
|
let i : Interner<@~str> = mk();
|
||||||
|
i.get(13);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn i2 () {
|
||||||
|
let i : Interner<@~str> = mk();
|
||||||
|
// first one is zero:
|
||||||
|
assert i.intern (@~"dog") == 0;
|
||||||
|
// re-use gets the same entry:
|
||||||
|
assert i.intern (@~"dog") == 0;
|
||||||
|
// different string gets a different #:
|
||||||
|
assert i.intern (@~"cat") == 1;
|
||||||
|
assert i.intern (@~"cat") == 1;
|
||||||
|
// dog is still at zero
|
||||||
|
assert i.intern (@~"dog") == 0;
|
||||||
|
// gensym gets 3
|
||||||
|
assert i.gensym (@~"zebra" ) == 2;
|
||||||
|
// gensym of same string gets new number :
|
||||||
|
assert i.gensym (@~"zebra" ) == 3;
|
||||||
|
// gensym of *existing* string gets new number:
|
||||||
|
assert i.gensym (@~"dog") == 4;
|
||||||
|
assert i.get(0) == @~"dog";
|
||||||
|
assert i.get(1) == @~"cat";
|
||||||
|
assert i.get(2) == @~"zebra";
|
||||||
|
assert i.get(3) == @~"zebra";
|
||||||
|
assert i.get(4) == @~"dog";
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn i3 () {
|
||||||
|
let i : Interner<@~str> = mk_prefill([@~"Alan",@~"Bob",@~"Carol"]);
|
||||||
|
assert i.get(0) == @~"Alan";
|
||||||
|
assert i.get(1) == @~"Bob";
|
||||||
|
assert i.get(2) == @~"Carol";
|
||||||
|
assert i.intern(@~"Bob") == 1;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue