about summary refs log tree commit diff
path: root/users/tazjin/rlox/src/bytecode/interner/tests.rs
blob: b34bf68353892449ebe46385204a0ffe2d8e4e1e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use super::*;

#[test]
fn interns_strings() {
    let mut interner = Interner::with_capacity(128);
    let id = interner.intern("hello world");
    assert_eq!("hello world", interner.lookup(id));
}

#[test]
fn deduplicates_strings() {
    let mut interner = Interner::with_capacity(128);
    let id_1 = interner.intern("hello world");
    let id_2 = interner.intern("hello world");
    assert_eq!(id_1, id_2);
}

#[test]
fn ids_survive_growing() {
    let mut interner = Interner::with_capacity(16);
    let id = interner.intern("hello");
    interner.intern("excessively large string that will cause eallocation");
    assert_eq!("hello", interner.lookup(id));
}