55 lines
1.8 KiB
Rust
55 lines
1.8 KiB
Rust
// 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_ast, root = "fixtures/ast/" }
|
|
}
|
|
|
|
fn test_ast(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 and parse top-level items
|
|
ast::items(&db, ed.get_file()).into_iter().for_each(|meta| {
|
|
ast::item(&db, meta);
|
|
});
|
|
|
|
// all good
|
|
Ok(())
|
|
}
|