Skip to content

Commit

Permalink
Add test to check that the binding rules for Solidity parse correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ggiraldez committed Jul 11, 2024
1 parent 6981113 commit fe90489
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion crates/codegen/runtime/cargo/src/runtime/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ pub type Bindings = metaslang_bindings::Bindings<KindTypes>;
pub type Handle<'a> = metaslang_bindings::Handle<'a, KindTypes>;

pub fn create(version: Version) -> Bindings {
Bindings::create(version, binding_rules::BINDING_RULES_SOURCE)
Bindings::create(version, get_binding_rules())
}

pub fn get_binding_rules() -> &'static str {
binding_rules::BINDING_RULES_SOURCE
}
4 changes: 4 additions & 0 deletions crates/codegen/runtime/generator/src/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ pub struct BindingsModel {
impl BindingsModel {
pub fn from_language(language: &model::Language) -> Result<Self> {
let binding_rules_source = language.binding_rules_file.read_to_string()?;
println!(
"cargo:rerun-if-changed={}",
language.binding_rules_file.to_string_lossy()
);

Ok(Self {
binding_rules_source,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/solidity/outputs/cargo/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ anyhow = { workspace = true }
codegen_language_definition = { workspace = true }
Inflector = { workspace = true }
infra_utils = { workspace = true }
metaslang_graph_builder = { workspace = true }
once_cell = { workspace = true }
regex = { workspace = true }
semver = { workspace = true }
Expand Down
22 changes: 22 additions & 0 deletions crates/solidity/outputs/cargo/tests/src/binding_rules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use std::path::PathBuf;

use metaslang_graph_builder::ast::File;
use slang_solidity::bindings;
use slang_solidity::cst::KindTypes;

#[test]
fn test_binding_rules_parse_successfully() {
let binding_rules = bindings::get_binding_rules();
let graph_builder = File::<KindTypes>::from_str(binding_rules);

assert!(
graph_builder.is_ok(),
"Parsing binding rules failed:\n{}",
graph_builder
.err()
.map(|err| err
.display_pretty(&PathBuf::from("rules.msgb"), binding_rules)
.to_string())
.unwrap_or_default()
);
}
1 change: 1 addition & 0 deletions crates/solidity/outputs/cargo/tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg(test)]

mod binding_rules;
mod cst_output;
mod doc_examples;
mod trivia;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fe90489

Please sign in to comment.