Skip to content

Commit

Permalink
Fix test_pool
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftSpider committed Mar 31, 2024
1 parent cf95185 commit 88f0e86
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 43 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/engine_bibtex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ tectonic_io_base = { path = "../io_base", version = '0.0.0-dev.0' }
tectonic_bridge_core = { path = "../bridge_core", version = "0.0.0-dev.0" }
tectonic_errors = { path = "../errors", version = "0.0.0-dev.0" }

[dev-dependencies]
tectonic_status_base = { path = "../status_base", version = "0.0.0-dev.0" }

[package.metadata.internal_dep_versions]
tectonic_bridge_core = "thiscommit:2021-01-17:fohCh1sh"
tectonic_errors = "5c9ba661edf5ef669f24f9904f99cca369d999e7"
Expand Down
100 changes: 57 additions & 43 deletions crates/engine_bibtex/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,50 +553,64 @@ pub(crate) fn add_out_pool(

#[cfg(test)]
mod tests {
// use super::*;
// use crate::BibtexConfig;
// use tectonic_bridge_core::{CoreBridgeLauncher, CoreBridgeState, DriverHooks, MinimalDriver};
use super::*;
use crate::BibtexConfig;
use tectonic_bridge_core::{CoreBridgeLauncher, CoreBridgeState, MinimalDriver};
use tectonic_io_base::{stack::IoStack, IoProvider};
use tectonic_status_base::NoopStatusBackend;

fn with_cbs(f: impl FnOnce(&mut CoreBridgeState<'_>)) {
let io_list: Vec<&mut dyn IoProvider> = vec![];
let io = IoStack::new(io_list);
let mut hooks = MinimalDriver::new(io);
let mut status = NoopStatusBackend::default();
let mut cbl = CoreBridgeLauncher::new(&mut hooks, &mut status);
cbl.with_global_lock(|cbs| {
f(cbs);
Ok(())
})
.unwrap();
}

// TODO: Create context without backend? Use custom backend-like type?
// Implement the relevant interfaces ourself?
// #[test]
// fn test_pool() {
// with_cbs(|cbs| {
// let mut ctx = Bibtex::new(cbs, BibtexConfig::default());
// let mut hash = HashData::new();
// let mut new_pool = StringPool::new();
// let res = new_pool
// .lookup_str_insert(&mut ctx, &mut hash, b"a cool string", HashExtra::Text)
// .unwrap();
// assert!(!res.exists);
// assert_eq!(
// new_pool.try_get_str(hash.text(res.loc)),
// Ok(b"a cool string" as &[_])
// );
//
// let res2 = new_pool
// .lookup_str_insert(&mut ctx, &mut hash, b"a cool string", HashExtra::Text)
// .unwrap();
// assert!(res2.exists);
// assert_eq!(
// new_pool.try_get_str(hash.text(res2.loc)),
// Ok(b"a cool string" as &[_])
// );
//
// let res3 = new_pool.lookup_str(&hash, b"a cool string", StrIlk::Text);
// assert!(res3.exists);
// assert_eq!(
// new_pool.try_get_str(hash.text(res3.loc)),
// Ok(b"a cool string" as &[_])
// );
//
// let res4 = new_pool.lookup_str(&hash, b"a bad string", StrIlk::Text);
// assert!(!res4.exists);
// assert_eq!(
// new_pool.try_get_str(hash.text(res4.loc)),
// Err(LookupErr::DoesntExist)
// );
// })
// .unwrap()
// }
#[test]
fn test_pool() {
with_cbs(|cbs| {
let mut ctx = Bibtex::new(cbs, BibtexConfig::default());
let mut hash = HashData::new();
let mut new_pool = StringPool::new();
let res = new_pool
.lookup_str_insert(&mut ctx, &mut hash, b"a cool string", HashExtra::Text)
.unwrap();
assert!(!res.exists);
assert_eq!(
new_pool.try_get_str(hash.text(res.loc)),
Ok(b"a cool string" as &[_])
);

let res2 = new_pool
.lookup_str_insert(&mut ctx, &mut hash, b"a cool string", HashExtra::Text)
.unwrap();
assert!(res2.exists);
assert_eq!(
new_pool.try_get_str(hash.text(res2.loc)),
Ok(b"a cool string" as &[_])
);

let res3 = new_pool.lookup_str(&hash, b"a cool string", StrIlk::Text);
assert!(res3.exists);
assert_eq!(
new_pool.try_get_str(hash.text(res3.loc)),
Ok(b"a cool string" as &[_])
);

let res4 = new_pool.lookup_str(&hash, b"a bad string", StrIlk::Text);
assert!(!res4.exists);
assert_eq!(
new_pool.try_get_str(hash.text(res4.loc)),
Err(LookupErr::DoesntExist)
);
})
}
}

0 comments on commit 88f0e86

Please sign in to comment.