-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into remove-cargo-component
- Loading branch information
Showing
22 changed files
with
672 additions
and
1,025 deletions.
There are no files selected for viewing
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
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
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,21 @@ | ||
use crate::code_generation::rust_generation::generate_code; | ||
use crate::code_generation::yaml::model::yaml_to_model; | ||
use crate::code_generation::yaml::yaml_model::YamlFile; | ||
use anyhow::anyhow; | ||
use anyhow::Context; | ||
use std::panic; | ||
pub(crate) mod rust_generation; | ||
mod tests; | ||
pub(crate) mod yaml; | ||
|
||
pub fn generate_code_from_string( | ||
yaml: String, | ||
package: &crate::model::Package, | ||
) -> anyhow::Result<String> { | ||
let yaml_file = | ||
YamlFile::from_yaml(yaml.as_str()).context(format!("Failed to parse YAML: {}", yaml))?; | ||
let example = panic::catch_unwind(|| yaml_to_model(yaml_file, package.name.clone(), package)) | ||
.map_err(|_| anyhow!("Failed to convert YAML to model")) | ||
.context(format!("Failed to convert YAML {} to model", yaml))?; | ||
generate_code(example) | ||
} |
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,67 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use crate::code_generation::yaml::model::yaml_to_model; | ||
use crate::code_generation::yaml::tests::*; | ||
use crate::code_generation::YamlFile; | ||
use crate::{extract_schema_from_file, schema}; | ||
|
||
use crate::code_generation::rust_generation::generate_code; | ||
use crate::code_generation::yaml::tests::{ | ||
example_array, example_empty_properties, example_escape_string, example_numbers, | ||
}; | ||
|
||
macro_rules! yaml_deserialization_test { | ||
($test_name:ident, $test_module:ident) => { | ||
#[test] | ||
fn $test_name() { | ||
let yaml_file = YamlFile::from_yaml($test_module::YAML).unwrap(); | ||
let expected_yaml_file = $test_module::get_yaml_file(); | ||
assert_eq!(yaml_file, expected_yaml_file); | ||
} | ||
}; | ||
} | ||
|
||
yaml_deserialization_test!(generate_yaml_complex_yaml, complex_yaml); | ||
|
||
macro_rules! full_pipeline_test { | ||
($test_name:ident, $package_name:expr, $test_module:ident) => { | ||
#[test] | ||
fn $test_name() { | ||
let yaml_file = YamlFile::from_yaml($test_module::YAML).unwrap(); | ||
let expected_yaml_file = $test_module::get_yaml_file(); | ||
assert_eq!(yaml_file, expected_yaml_file); | ||
|
||
let schema_package: schema::Package = extract_schema_from_file( | ||
concat!("test_cases/", $package_name, ".json").as_ref(), | ||
) | ||
.unwrap(); | ||
let package = schema::to_model(&schema_package).unwrap(); | ||
let yaml_file = $test_module::get_yaml_file(); | ||
let result = yaml_to_model(yaml_file, $package_name.to_string(), &package); | ||
assert_eq!(result, $test_module::get_model()); | ||
|
||
let model = $test_module::get_model(); | ||
let code = generate_code(model).unwrap(); | ||
assert_eq!($test_module::get_rust_code(), code); | ||
} | ||
}; | ||
} | ||
|
||
full_pipeline_test!(full_pipeline_example_array, "cloudflare", example_array); | ||
full_pipeline_test!( | ||
full_pipeline_example_empty_properties, | ||
"cloudflare", | ||
example_empty_properties | ||
); | ||
full_pipeline_test!( | ||
full_pipeline_example_escape_string, | ||
"cloudflare", | ||
example_escape_string | ||
); | ||
full_pipeline_test!(full_pipeline_example_numbers, "cloudflare", example_numbers); | ||
full_pipeline_test!( | ||
full_pipeline_example_variable, | ||
"cloudflare", | ||
example_variable | ||
); | ||
} |
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,4 @@ | ||
pub(crate) mod model; | ||
#[cfg(test)] | ||
pub(crate) mod tests; | ||
pub(crate) mod yaml_model; |
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
Oops, something went wrong.