完成 vhdl 的 UT
This commit is contained in:
parent
1308a35546
commit
0a1eb5e080
@ -89,7 +89,7 @@ fn make_textdocumenitem_from_path(path_buf: &PathBuf) -> Option<TextDocumentItem
|
|||||||
|
|
||||||
/// 前端交互接口: do_fast,输入文件路径,计算出对应的 fast 结构
|
/// 前端交互接口: do_fast,输入文件路径,计算出对应的 fast 结构
|
||||||
pub fn do_fast<'a>(path: String, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
pub fn do_fast<'a>(path: String, backend: &Arc<Backend>) -> Result<FastHdlparam> {
|
||||||
info!("parse fast {}", path);
|
info!("parse fast \"{}\"", path);
|
||||||
|
|
||||||
let language_id = get_language_id_by_path_str(&path);
|
let language_id = get_language_id_by_path_str(&path);
|
||||||
match language_id.as_str() {
|
match language_id.as_str() {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
mod vhdl;
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
const TESTFILES_DIR: &str = "testfiles";
|
const TESTFILES_DIR: &str = "testfiles";
|
||||||
|
|
||||||
@ -10,6 +12,8 @@ const TEST_FILE: &str = "/home/dide/project/Digital-Test/MipsDesign/src/MyCpu.v"
|
|||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
const INCOMPLETE_EXAMPLE: &str = "/home/dide/project/Digital-Test/Digital-IDE-test/user/src/incomplete-example";
|
const INCOMPLETE_EXAMPLE: &str = "/home/dide/project/Digital-Test/Digital-IDE-test/user/src/incomplete-example";
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
|
const TESTFILES_TEMP_DIR: &str = "/home/dide/project/Digital-Test/Digital-IDE-temp";
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
macro_rules! unwrap_result {
|
macro_rules! unwrap_result {
|
||||||
|
26
src/test/vhdl.rs
Normal file
26
src/test/vhdl.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test_vhdl_fast {
|
||||||
|
use crate::{core::vhdl_parser::{make_fast_from_design_file, vhdl_parse}, test::TESTFILES_TEMP_DIR, utils::*};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_temp() {
|
||||||
|
let file_iter = RecursiveFileIterator::new(TESTFILES_TEMP_DIR);
|
||||||
|
for file in file_iter {
|
||||||
|
let language_id = get_language_id_by_pathbuf(&file);
|
||||||
|
if language_id == "vhdl" {
|
||||||
|
println!("test file: {:?}", file);
|
||||||
|
if let Some(design_file) = vhdl_parse(&file) {
|
||||||
|
if let Some(_) = make_fast_from_design_file(&design_file) {
|
||||||
|
println!("<(^-^)>");
|
||||||
|
} else {
|
||||||
|
eprintln!("error happen when make fast {:?}", file);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
eprintln!("error happen when parse {:?}", file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
use std::{fs, path::PathBuf};
|
use std::{fs, path::PathBuf, str::FromStr};
|
||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use ropey::Rope;
|
use ropey::Rope;
|
||||||
@ -29,3 +29,35 @@ pub fn open_doc_as_rope(path: &PathBuf) -> Option<Rope> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct RecursiveFileIterator {
|
||||||
|
stack: Vec<PathBuf>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RecursiveFileIterator {
|
||||||
|
pub fn new(start_dir: &str) -> Self {
|
||||||
|
let start_dir = PathBuf::from_str(start_dir).unwrap();
|
||||||
|
RecursiveFileIterator {
|
||||||
|
stack: vec![start_dir],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Iterator for RecursiveFileIterator {
|
||||||
|
type Item = PathBuf;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
while let Some(path) = self.stack.pop() {
|
||||||
|
if path.is_dir() {
|
||||||
|
if let Ok(entries) = fs::read_dir(path) {
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
self.stack.push(entry.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Some(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ use vhdl_lang::{ast::ObjectClass, AnyEntKind, Concurrent, Object, Overloaded, Sr
|
|||||||
|
|
||||||
pub mod fast;
|
pub mod fast;
|
||||||
pub mod file;
|
pub mod file;
|
||||||
|
pub use file::*;
|
||||||
|
|
||||||
/// 根据 pos 获取到当前光标所在的字符串,相当于 getWordRangeAtPosition
|
/// 根据 pos 获取到当前光标所在的字符串,相当于 getWordRangeAtPosition
|
||||||
pub fn get_definition_token(line: &RopeSlice, pos: Position) -> String {
|
pub fn get_definition_token(line: &RopeSlice, pos: Position) -> String {
|
||||||
@ -91,6 +92,17 @@ pub fn get_language_id_by_uri(uri: &Url) -> String {
|
|||||||
get_language_id_by_extname(ext_name)
|
get_language_id_by_extname(ext_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 根据路径字符串获取 hdl 的 language id
|
||||||
|
/// 返回值为 "vhdl" | "verilog" | "systemverilog" | "plaintext"
|
||||||
|
/// 不采用枚举是因为需要在 lsp 中使用到它们的字符串值
|
||||||
|
pub fn get_language_id_by_pathbuf(pathbuf: &PathBuf) -> String {
|
||||||
|
let ext_name = pathbuf.as_path()
|
||||||
|
.extension()
|
||||||
|
.and_then(std::ffi::OsStr::to_str)
|
||||||
|
.unwrap_or("");
|
||||||
|
get_language_id_by_extname(ext_name)
|
||||||
|
}
|
||||||
|
|
||||||
/// 根据路径字符串获取 hdl 的 language id
|
/// 根据路径字符串获取 hdl 的 language id
|
||||||
/// 返回值为 "vhdl" | "verilog" | "systemverilog" | "plaintext"
|
/// 返回值为 "vhdl" | "verilog" | "systemverilog" | "plaintext"
|
||||||
/// 不采用枚举是因为需要在 lsp 中使用到它们的字符串值
|
/// 不采用枚举是因为需要在 lsp 中使用到它们的字符串值
|
||||||
|
Loading…
x
Reference in New Issue
Block a user