Add WIP resolve datatest harness

This commit is contained in:
2026-05-08 14:47:53 -06:00
parent 6d69bb4336
commit c0cd87522e
3 changed files with 68 additions and 1 deletions

View File

@@ -0,0 +1 @@
:-.

View File

@@ -45,7 +45,7 @@ pub mod prelude {
pub use crate::{
ast,
diagnostic::{self, AccumulateDiagnostic},
editor,
editor, resolve,
workspace::{self, AstNode, WithAst},
};
}

View File

@@ -0,0 +1,66 @@
// Copyright (C) 2025-2026 Marceline Cramer
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// This file is part of Kerolox.
//
// Kerolox is free software: you can redistribute it and/or modify it under
// the terms of the GNU Affero General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option) any
// later version.
//
// Kerolox is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
// more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Kerolox. If not, see <https://www.gnu.org/licenses/>.
use std::path::Path;
use kerolox_frontend::{editor::Editor, prelude::*, workspace::Workspace};
use salsa::DatabaseImpl as Db;
datatest_stable::harness! {
{ test = test_resolve, root = "fixtures/resolve/" },
{ test = test_resolve, root = "../../examples/" },
}
fn test_resolve(path: &Path) -> datatest_stable::Result<()> {
// read test file to string
let src = std::fs::read_to_string(path).unwrap();
// create editor
let mut db = Db::new();
let files = Default::default();
let stdlib = Default::default();
let workspace = Workspace::new(&db, files, stdlib);
let path = std::path::absolute(path).unwrap();
let uri = lsp_types::Url::from_file_path(&path).unwrap();
let ed = Editor::new(&mut db, workspace, uri, &src);
// ensure tree-sitter has fully parsed
assert!(
!workspace::file_has_syntax_error(&db, ed.get_file()),
"test has syntax error"
);
// list, parse, and resolve top-level items
ast::items(&db, ed.get_file()).into_iter().for_each(|meta| {
use ast::Item::*;
match ast::item(&db, meta) {
Relation(item) => todo!(),
TypeAlias(item) => todo!(),
Import(item) => todo!(),
Rule(item) => {
resolve::rule(&db, item);
}
Assumption(item) => {
resolve::assumption(&db, item);
}
}
});
// all good
Ok(())
}