Lines
100 %
Functions
Branches
use super::{load, lookups};
use crate::lookup_log::{Lookup, LookupKind};
const ORG: &str = "* Title\nprose (get-account \"Prose\")\n\
#+begin_src lisp :tangle \"x.nms\"\n(string= name \"Suica\")(get-account \"Metro\")\n#+end_src\n\
#+begin_src sh\necho \"Shell\"\n#+end_src\n";
fn keys(found: &[Lookup]) -> Vec<(LookupKind, &str)> {
found.iter().map(|l| (l.kind, l.key.as_str())).collect()
}
#[test]
fn only_the_lisp_blocks_of_an_org_file_are_code() -> Result<(), String> {
let code = super::lisp_blocks(ORG);
assert_eq!(keys(&lookups(&code)?), [(LookupKind::Account, "Metro")]);
Ok(())
fn lookup_keys_are_found_in_nested_forms_and_logical_rows() -> Result<(), String> {
let found = lookups(
"(defun f () (let ((a (get-commodity \"usd\"))) (g `(:from \"A\" :to-commodity \"EUR\" :note \"N\"))))",
)?;
let mut found = keys(&found);
found.sort_by_key(|(_, key)| *key);
assert_eq!(
found,
[
(LookupKind::Account, "A"),
(LookupKind::Commodity, "EUR"),
(LookupKind::Commodity, "usd")
]
);
fn other_string_literals_are_not_lookups() -> Result<(), String> {
lookups("(string= x \"Suica\")(get-account y)(list \"Cash\")")?,
[]
fn a_source_that_does_not_parse_is_reported() {
let err = lookups("(get-account").unwrap_err();
assert!(err.starts_with("does not parse"), "{err}");
fn a_directory_loads_the_declared_extensions_in_order() -> anyhow::Result<()> {
let dir = tempfile::tempdir()?;
std::fs::write(dir.path().join("b.org"), ORG)?;
std::fs::write(dir.path().join("b.nms"), "(get-account \"Mirror\")")?;
std::fs::write(dir.path().join("a.nms"), "(get-account \"A\")")?;
std::fs::write(dir.path().join("notes.txt"), "(")?;
std::fs::write(dir.path().join("broken.lisp"), "(")?;
let (sources, findings) = load(dir.path());
let names: Vec<_> = sources
.iter()
.filter_map(|s| s.name.rsplit('/').next())
.collect();
assert_eq!(names, ["a.nms", "b.org"]);
assert_eq!(findings.len(), 1);
assert!(findings[0].subject.to_string().ends_with("broken.lisp"));
fn a_missing_directory_is_reported() {
let (sources, findings) = load(std::path::Path::new("/nonexistent/sources"));
assert!(sources.is_empty());