Skip to content

Commit 25184da

Browse files
committed
Merge pull request #4600 from jbclements/cleanup-and-test-cases
cleaning up, adding tests
2 parents 721c174 + 8716005 commit 25184da

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

src/libsyntax/print/pprust.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ fn fun_to_str(decl: ast::fn_decl, name: ast::ident,
172172

173173
#[test]
174174
fn test_fun_to_str() {
175-
let decl: ast::fn_decl = {
175+
let decl: ast::fn_decl = ast::fn_decl {
176176
inputs: ~[],
177-
output: @{id: 0,
177+
output: @ast::Ty {id: 0,
178178
node: ast::ty_nil,
179179
span: ast_util::dummy_sp()},
180-
purity: ast::impure_fn,
180+
//purity: ast::impure_fn,
181181
cf: ast::return_val
182182
};
183-
assert fun_to_str(decl, "a", ~[]) == "fn a()";
183+
assert fun_to_str(decl, "abba", ~[]) == "fn abba()";
184184
}
185185

186186
fn block_to_str(blk: ast::blk, intr: @ident_interner) -> ~str {
@@ -214,7 +214,7 @@ fn test_variant_to_str() {
214214
attrs: ~[],
215215
args: ~[],
216216
id: 0,
217-
disr_expr: none
217+
disr_expr: None
218218
});
219219

220220
let varstr = variant_to_str(var);

src/libsyntax/util/interner.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn mk<T:Eq IterBytes Hash Const Copy>() -> Interner<T> {
2929
move ((move hi) as Interner::<T>)
3030
}
3131

32-
fn mk_prefill<T:Eq IterBytes Hash Const Copy>(init: ~[T]) -> Interner<T> {
32+
fn mk_prefill<T:Eq IterBytes Hash Const Copy>(init: &[T]) -> Interner<T> {
3333
let rv = mk();
3434
for init.each() |v| { rv.intern(*v); }
3535
return rv;
@@ -70,3 +70,45 @@ impl <T:Eq IterBytes Hash Const Copy> hash_interner<T>: Interner<T> {
7070

7171
fn len() -> uint { return self.vect.len(); }
7272
}
73+
74+
75+
#[test]
76+
#[should_fail]
77+
fn i1 () {
78+
let i : Interner<@~str> = mk();
79+
i.get(13);
80+
}
81+
82+
#[test]
83+
fn i2 () {
84+
let i : Interner<@~str> = mk();
85+
// first one is zero:
86+
assert i.intern (@~"dog") == 0;
87+
// re-use gets the same entry:
88+
assert i.intern (@~"dog") == 0;
89+
// different string gets a different #:
90+
assert i.intern (@~"cat") == 1;
91+
assert i.intern (@~"cat") == 1;
92+
// dog is still at zero
93+
assert i.intern (@~"dog") == 0;
94+
// gensym gets 3
95+
assert i.gensym (@~"zebra" ) == 2;
96+
// gensym of same string gets new number :
97+
assert i.gensym (@~"zebra" ) == 3;
98+
// gensym of *existing* string gets new number:
99+
assert i.gensym (@~"dog") == 4;
100+
assert i.get(0) == @~"dog";
101+
assert i.get(1) == @~"cat";
102+
assert i.get(2) == @~"zebra";
103+
assert i.get(3) == @~"zebra";
104+
assert i.get(4) == @~"dog";
105+
}
106+
107+
#[test]
108+
fn i3 () {
109+
let i : Interner<@~str> = mk_prefill([@~"Alan",@~"Bob",@~"Carol"]);
110+
assert i.get(0) == @~"Alan";
111+
assert i.get(1) == @~"Bob";
112+
assert i.get(2) == @~"Carol";
113+
assert i.intern(@~"Bob") == 1;
114+
}

0 commit comments

Comments
 (0)