Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ fn fun_to_str(decl: ast::fn_decl, name: ast::ident,

#[test]
fn test_fun_to_str() {
let decl: ast::fn_decl = {
let decl: ast::fn_decl = ast::fn_decl {
inputs: ~[],
output: @{id: 0,
output: @ast::Ty {id: 0,
node: ast::ty_nil,
span: ast_util::dummy_sp()},
purity: ast::impure_fn,
//purity: ast::impure_fn,
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 {
Expand Down Expand Up @@ -214,7 +214,7 @@ fn test_variant_to_str() {
attrs: ~[],
args: ~[],
id: 0,
disr_expr: none
disr_expr: None
});

let varstr = variant_to_str(var);
Expand Down
44 changes: 43 additions & 1 deletion src/libsyntax/util/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn mk<T:Eq IterBytes Hash Const Copy>() -> 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();
for init.each() |v| { rv.intern(*v); }
return rv;
Expand Down Expand Up @@ -70,3 +70,45 @@ impl <T:Eq IterBytes Hash Const Copy> hash_interner<T>: Interner<T> {

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;
}