Skip to content

Commit

Permalink
test: function-based table generator
Browse files Browse the repository at this point in the history
  • Loading branch information
igordejanovic committed Dec 25, 2023
1 parent 416dd64 commit a0ad0c8
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
3 changes: 3 additions & 0 deletions check-update-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ for i in {1..5}; do
done

cd -
# Deafult test
cargo test
# Test with function based table generator
cargo test --features functions
cargo clippy --all --all-targets -- -D warnings
cargo fmt --all
5 changes: 5 additions & 0 deletions examples/calculator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ rustemo-compiler = { path = "../../rustemo-compiler" }

[build-dependencies]
rustemo-compiler = { path = "../../rustemo-compiler" }

[features]

# Used for testing different table generator approaches
functions = []
9 changes: 8 additions & 1 deletion examples/calculator/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
use std::process::exit;

fn main() {
if let Err(e) = rustemo_compiler::process_crate_dir() {
let mut settings = rustemo_compiler::Settings::new();
if std::env::var("CARGO_FEATURE_FUNCTIONS").is_ok() {
settings = settings.generator_table_type(
rustemo_compiler::GeneratorTableType::Functions,
);
}

if let Err(e) = settings.process_dir() {
eprintln!("{}", e);
exit(1);
}
Expand Down
5 changes: 5 additions & 0 deletions examples/json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ rustemo-compiler = { path = "../../rustemo-compiler" }

[build-dependencies]
rustemo-compiler = { path = "../../rustemo-compiler" }

[features]

# Used for testing different table generator approaches
functions = []
9 changes: 8 additions & 1 deletion examples/json/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
use std::process::exit;

fn main() {
if let Err(e) = rustemo_compiler::process_crate_dir() {
let mut settings = rustemo_compiler::Settings::new();
if std::env::var("CARGO_FEATURE_FUNCTIONS").is_ok() {
settings = settings.generator_table_type(
rustemo_compiler::GeneratorTableType::Functions,
);
}

if let Err(e) = settings.process_dir() {
eprintln!("{}", e);
exit(1);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ rustemo-compiler = { path = "../rustemo-compiler" }

[build-dependencies]
rustemo-compiler = { path = "../rustemo-compiler" }

[features]

# Used for testing different table generator approaches
functions = []
20 changes: 12 additions & 8 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ use std::{env, path::PathBuf, process::exit};
use rustemo_compiler::{BuilderType, LexerType, ParserAlgo, Settings};

fn main() {
fn default_settings() -> Settings {
let mut settings = rustemo_compiler::Settings::new().force(true);
if std::env::var("CARGO_FEATURE_FUNCTIONS").is_ok() {
settings = settings.generator_table_type(
rustemo_compiler::GeneratorTableType::Functions,
);
}
settings
}
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));

let out_dir =
PathBuf::from(env::var("OUT_DIR").expect("Cargo didn't set OUT_DIR"));

let settings = rustemo_compiler::Settings::new().force(true);

#[allow(clippy::type_complexity)]
let tests: &[(&str, Box<dyn Fn(Settings) -> Settings>)] = &[
("rule_patterns", Box::new(|s| s)),
Expand Down Expand Up @@ -128,8 +135,7 @@ fn main() {
let p = format!("src/{test}");
let dir = out_dir.join(&p);
if let Err(e) = config(
settings
.clone()
default_settings()
.out_dir_root(dir.clone())
.out_dir_actions_root(dir),
)
Expand All @@ -142,16 +148,14 @@ fn main() {
}

// Testing code generation in the source tree
let settings = rustemo_compiler::Settings::new().force(true);
if let Err(e) = settings
if let Err(e) = default_settings()
.in_source_tree()
.process_grammar(&root_dir.join("src/output_dir/output_dir.rustemo"))
{
eprintln!("{}", e);
exit(1);
}
let settings = rustemo_compiler::Settings::new().force(true);
if let Err(e) = settings.actions_in_source_tree().process_grammar(
if let Err(e) = default_settings().actions_in_source_tree().process_grammar(
&root_dir.join("src/output_dir/output_dir_act.rustemo"),
) {
eprintln!("{}", e);
Expand Down

0 comments on commit a0ad0c8

Please sign in to comment.