mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-14 19:55:03 +01:00
Merge remote-tracking branch 'origin/main' into main
# Conflicts: # xtask/src/test_js.rs
This commit is contained in:
commit
fc131327b2
38 changed files with 2037 additions and 1242 deletions
|
|
@ -211,11 +211,31 @@ impl Codegen {
|
|||
|
||||
for class in &amqp.classes {
|
||||
let enum_name = class.name.to_upper_camel_case();
|
||||
for method in &class.methods {
|
||||
let method_name = method.name.to_upper_camel_case();
|
||||
write!(
|
||||
self.output,
|
||||
" {enum_name}{method_name}({enum_name}{method_name}),"
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(self.output, "}}\n").ok();
|
||||
|
||||
// now codegen the individual structs
|
||||
for class in &amqp.classes {
|
||||
let class_name = class.name.to_upper_camel_case();
|
||||
for method in &class.methods {
|
||||
let method_name = method.name.to_upper_camel_case();
|
||||
self.doc_comment(&class.doc, 4);
|
||||
self.doc_comment(&method.doc, 4);
|
||||
write!(self.output, " {enum_name}{method_name}").ok();
|
||||
writeln!(
|
||||
self.output,
|
||||
"#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct {class_name}{method_name}"
|
||||
)
|
||||
.ok();
|
||||
if !method.fields.is_empty() {
|
||||
writeln!(self.output, " {{").ok();
|
||||
for field in &method.fields {
|
||||
|
|
@ -225,24 +245,22 @@ impl Codegen {
|
|||
field.asserts.as_ref(),
|
||||
);
|
||||
if !field_docs.is_empty() {
|
||||
writeln!(self.output, " /// {field_docs}").ok();
|
||||
writeln!(self.output, " /// {field_docs}").ok();
|
||||
if !field.doc.is_empty() {
|
||||
writeln!(self.output, " ///").ok();
|
||||
self.doc_comment(&field.doc, 8);
|
||||
writeln!(self.output, " ///").ok();
|
||||
self.doc_comment(&field.doc, 4);
|
||||
}
|
||||
} else {
|
||||
self.doc_comment(&field.doc, 8);
|
||||
self.doc_comment(&field.doc, 4);
|
||||
}
|
||||
writeln!(self.output, " {field_name}: {field_type},").ok();
|
||||
writeln!(self.output, " pub {field_name}: {field_type},").ok();
|
||||
}
|
||||
writeln!(self.output, " }},").ok();
|
||||
writeln!(self.output, " }}\n").ok();
|
||||
} else {
|
||||
writeln!(self.output, ",").ok();
|
||||
writeln!(self.output, ";\n").ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(self.output, "}}\n").ok();
|
||||
}
|
||||
|
||||
fn amqp_type_to_rust_type(&self, amqp_type: &str) -> &'static str {
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ impl Codegen {
|
|||
self.output,
|
||||
"pub mod parse {{
|
||||
use amqp_core::methods::*;
|
||||
use crate::methods::parse_helper::*;
|
||||
use crate::error::TransError;
|
||||
use crate::methods::parse_helper::*;
|
||||
use nom::{{branch::alt, bytes::complete::tag}};
|
||||
use regex::Regex;
|
||||
use once_cell::sync::Lazy;
|
||||
|
|
@ -154,14 +154,14 @@ pub type IResult<'a, T> = nom::IResult<&'a [u8], T, TransError>;
|
|||
let method_name = method.name.to_upper_camel_case();
|
||||
writeln!(
|
||||
self.output,
|
||||
" Ok((input, Method::{class_name}{method_name} {{"
|
||||
" Ok((input, Method::{class_name}{method_name}({class_name}{method_name} {{"
|
||||
)
|
||||
.ok();
|
||||
for field in &method.fields {
|
||||
let field_name = self.snake_case(&field.name);
|
||||
writeln!(self.output, " {field_name},").ok();
|
||||
}
|
||||
writeln!(self.output, " }}))").ok();
|
||||
writeln!(self.output, " }})))").ok();
|
||||
|
||||
writeln!(self.output, "}}").ok();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ use crate::methods::RandomMethod;
|
|||
let method_name = method.name.to_upper_camel_case();
|
||||
writeln!(
|
||||
self.output,
|
||||
" {i} => Method::{class_name}{method_name} {{"
|
||||
" {i} => Method::{class_name}{method_name}( {class_name}{method_name}{{"
|
||||
)
|
||||
.ok();
|
||||
for field in &method.fields {
|
||||
|
|
@ -54,7 +54,7 @@ use crate::methods::RandomMethod;
|
|||
)
|
||||
.ok();
|
||||
}
|
||||
writeln!(self.output, " }},").ok();
|
||||
writeln!(self.output, " }}),").ok();
|
||||
}
|
||||
writeln!(
|
||||
self.output,
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ impl Codegen {
|
|||
self.output,
|
||||
"pub mod write {{
|
||||
use amqp_core::methods::*;
|
||||
use crate::methods::write_helper::*;
|
||||
use crate::error::TransError;
|
||||
use crate::methods::write_helper::*;
|
||||
use std::io::Write;
|
||||
|
||||
pub fn write_method<W: Write>(method: Method, mut writer: W) -> Result<(), TransError> {{
|
||||
|
|
@ -22,12 +22,16 @@ pub fn write_method<W: Write>(method: Method, mut writer: W) -> Result<(), Trans
|
|||
for method in &class.methods {
|
||||
let method_name = method.name.to_upper_camel_case();
|
||||
let method_index = method.index;
|
||||
writeln!(self.output, " Method::{class_name}{method_name} {{").ok();
|
||||
writeln!(
|
||||
self.output,
|
||||
" Method::{class_name}{method_name}({class_name}{method_name} {{"
|
||||
)
|
||||
.ok();
|
||||
for field in &method.fields {
|
||||
let field_name = self.snake_case(&field.name);
|
||||
writeln!(self.output, " {field_name},").ok();
|
||||
}
|
||||
writeln!(self.output, " }} => {{").ok();
|
||||
writeln!(self.output, " }}) => {{").ok();
|
||||
let [ci0, ci1] = class_index.to_be_bytes();
|
||||
let [mi0, mi1] = method_index.to_be_bytes();
|
||||
writeln!(
|
||||
|
|
|
|||
|
|
@ -1,10 +1,26 @@
|
|||
use crate::project_root;
|
||||
use anyhow::{ensure, Context, Result};
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn main() -> Result<()> {
|
||||
let test_js_root = project_root().join("test-js");
|
||||
println!("$ yarn");
|
||||
let project_root = project_root();
|
||||
let test_js_root = project_root.join("test-js");
|
||||
|
||||
let mut amqp_server = Command::new("cargo")
|
||||
.arg("run")
|
||||
.env("RUST_LOG", "trace")
|
||||
.spawn()
|
||||
.context("`cargo run` amqp")?;
|
||||
|
||||
let test_result = run_js(&test_js_root);
|
||||
|
||||
amqp_server.kill()?;
|
||||
|
||||
test_result
|
||||
}
|
||||
|
||||
fn run_js(test_js_root: &Path) -> Result<()> {
|
||||
let status = Command::new("yarn")
|
||||
.current_dir(&test_js_root)
|
||||
.status()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue