cleanup tests and whitespace

This commit is contained in:
faldor20 2024-03-11 16:25:46 +10:00
parent 64c25cf4d5
commit 899dbdd7ec
No known key found for this signature in database
GPG Key ID: F2216079B890CD57
4 changed files with 38 additions and 17 deletions

View File

@ -1,6 +1,6 @@
## An interface for docs tests
interface Docs
exposes [makeUser, getName]
exposes [makeUser, getNameExposed]
imports []
## This is a user
@ -11,6 +11,8 @@ makeUser : Str -> User
makeUser = \name ->
{ name }
## gets the user's name
## Gets the user's name
getName = \a -> a.name
getNameExposed = getName

View File

@ -17,12 +17,13 @@ mod helpers;
use crate::helpers::fixtures_dir;
use bumpalo::Bump;
use roc_can::module::ExposedByModule;
use roc_load_internal::docs::DocDef;
use roc_load_internal::file::{
ExecutionMode, LoadConfig, LoadResult, LoadStart, LoadingProblem, Threading,
};
use roc_load_internal::module::LoadedModule;
use roc_module::ident::ModuleName;
use roc_module::symbol::{Interns, ModuleId};
use roc_module::symbol::{Interns, ModuleId, Symbol};
use roc_packaging::cache::RocCacheDir;
use roc_problem::can::Problem;
use roc_region::all::LineInfo;
@ -427,18 +428,36 @@ fn load_docs() {
let subs_by_module = Default::default();
let loaded_module = load_fixture("no_deps", "Docs", subs_by_module);
let prob = format!("{:#?}", loaded_module.can_problems);
let prob_type = format!("{:#?}", loaded_module.type_problems);
// assert_str_eq!("", prob, "can problems");
// assert_str_eq!("", prob_type, "type problems");
let docs = format!(
"{:#?}",
loaded_module
.docs_by_module
.get(&loaded_module.module_id)
.unwrap()
);
assert_str_eq!("", docs);
let docs = loaded_module
.docs_by_module
.get(&loaded_module.module_id)
.expect("module should have docs");
let docs = docs
.entries
.iter()
.map(|a| match a {
roc_load_internal::docs::DocEntry::DocDef(DocDef { name, docs, .. }) => {
(Some(name.clone()), docs.clone().map(|a| a.to_string()))
}
roc_load_internal::docs::DocEntry::ModuleDoc(docs)
| roc_load_internal::docs::DocEntry::DetachedDoc(docs) => (None, Some(docs.clone())),
})
.collect::<Vec<_>>();
let expected = vec![
(None, Some("An interface for docs tests\n")),
(Some("User"), Some("This is a user\n")),
(Some("makeUser"), Some("Makes a user\n")),
(Some("getName"), Some("Gets the user's name\n")),
(Some("getNameExposed"), None),
]
.into_iter()
.map(|(a, b)| (a.map(|a| a.to_string()), b.map(|b| b.to_string())))
.collect::<Vec<_>>();
// let has_all_docs = expected.map(|a| docs.contains(&a)).all(|a| a);
// assert!(has_all_docs, "Some of the expected docs were not created")
assert_eq!(expected, docs);
}
#[test]

View File

@ -139,7 +139,7 @@ fn get_completion_docs(
.iter()
.filter_map(|doc| match doc {
roc_load::docs::DocEntry::DocDef(DocDef { docs, symbol, .. }) => {
let docs = docs.clone()?;
let docs = docs.as_ref().map(|a| a.trim().to_string())?;
let (idx, _s) = symbols.iter().enumerate().find(|(_i, s)| s == &&symbol)?;
symbols.swap_remove(idx);
Some((*symbol, docs))

View File

@ -47,7 +47,7 @@ pub(super) fn module_documentation(
let module_doc = module_docs
.and_then(|docs| {
docs.entries.first().and_then(|first_doc| match first_doc {
roc_load::docs::DocEntry::ModuleDoc(str) => Some(str.clone()),
roc_load::docs::DocEntry::ModuleDoc(str) => Some(str.clone().trim().to_string()),
_ => None,
})
})