-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
6,427 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
/target | ||
/src/main.rs | ||
|
||
makefile | ||
log.txt | ||
makefile |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0" | |
repository = "https://github.com/apskhem/dbml-rs" | ||
readme = "README.md" | ||
authors = ["Apisit Ritreungroj <[email protected]>"] | ||
keywords = ["compiler", "dbml"] | ||
keywords = ["parser", "parse", "dbml"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
Table sal_emp { | ||
name text | ||
pay_by_quarter int[] [not null] | ||
schedule text[][] [null] | ||
pay_by_quarter "int[]" [not null] | ||
schedule "text[][]" [null] | ||
} | ||
|
||
Table tictactoe { | ||
squares integer[3][3] | ||
squares "integer[3][3]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use std::{path::{Path, PathBuf}, fs, io::Result}; | ||
|
||
const DBML_DIR: &str = "tests/dbml"; | ||
const OUT_DIR: &str = "tests/out"; | ||
|
||
fn read_dbml_dir<P: AsRef<Path>>(dir_path: P) -> Result<Vec<PathBuf>> { | ||
let mut out = vec![]; | ||
let entries = fs::read_dir(dir_path)?; | ||
|
||
for entry in entries { | ||
let file_path = entry?.path(); | ||
|
||
if file_path.is_file() { | ||
out.push(file_path); | ||
} | ||
} | ||
|
||
Ok(out) | ||
} | ||
|
||
fn create_out_dir() -> Result<()> { | ||
if !fs::metadata(OUT_DIR).is_ok() { | ||
fs::create_dir(OUT_DIR)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn parse_dbml() -> Result<()> { | ||
create_out_dir()?; | ||
|
||
let testing_dbml_files = read_dbml_dir(DBML_DIR)?; | ||
|
||
for path in testing_dbml_files { | ||
let content = fs::read_to_string(&path)?; | ||
let parsed = dbml_rs::parser::parse(&content) | ||
.unwrap_or_else(|err| panic!("{:?} {}", path, err)); | ||
|
||
let out_content = format!("{:#?}", parsed); | ||
|
||
let mut out_file_path = path.clone(); | ||
out_file_path.set_extension("ron"); | ||
let out_file_name = out_file_path.file_name().unwrap().to_str().unwrap(); | ||
let out_file_path = format!("{}/{}", OUT_DIR, out_file_name); | ||
|
||
fs::write(out_file_path, out_content)?; | ||
} | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.