summaryrefslogtreecommitdiff
path: root/templates
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2020-12-05 09:39:05 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2020-12-21 08:29:23 +0000
commitbf748ff006c6a4c3f6853b1da7d090cebd825bd5 (patch)
treeebb026dd90a253ec22628c1ee5a86eb8983508ec /templates
parent9127938b0a382cd62e5c12fc97fe5212993ef0b4 (diff)
downloadsubplot-bf748ff006c6a4c3f6853b1da7d090cebd825bd5.tar.gz
feat: Initial rust templates
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'templates')
-rw-r--r--templates/rust/template.rs.tera66
-rw-r--r--templates/rust/template.yaml2
2 files changed, 68 insertions, 0 deletions
diff --git a/templates/rust/template.rs.tera b/templates/rust/template.rs.tera
new file mode 100644
index 0000000..845cbc7
--- /dev/null
+++ b/templates/rust/template.rs.tera
@@ -0,0 +1,66 @@
+use subplotlib::prelude::*;
+
+{% for func in functions %}
+
+// --------------------------------
+// This came from {{ func.source }}
+
+{{ func.code }}
+
+{% endfor %}
+
+// --------------------------------
+
+lazy_static! {
+ static ref SUBPLOT_EMBEDDED_FILES: Vec<SubplotDataFile> = vec![
+{% for file in files %}
+ SubplotDataFile::new("{{ file.filename | base64 }}",
+ "{{ file.contents | base64 }}"),
+{% endfor %}
+ ];
+}
+
+{% for scenario in scenarios %}
+
+// ---------------------------------
+
+// {{ scenario.title }}
+#[test]
+fn scenario_{{ loop.index }}() {
+ let mut scenario = Scenario::new(&base64_decode("{{scenario.title | base64}}"));
+ {% for step in scenario.steps %}
+ let step = BUILDER_{{step.function}}::default()
+ {% for part in step.parts %}{% if part.CapturedText is defined -%}
+ {%- set name = part.CapturedText.name -%}
+ {%- set text = part.CapturedText.text -%}
+ {%- set type = step.types[name] | default(value='string') -%}
+ .{{name}}(
+ {% if type in ['number', 'raw', 'literal'] %}{{text}}
+ {% elif type in ['string']%}&base64_decode("{{text | base64}}")
+ {% elif type in ['file'] %}
+ {
+ use std::path::PathBuf;
+ let target_name: PathBuf = base64_decode("{{ text | base64 }}").into();
+ SUBPLOT_EMBEDDED_FILES
+ .iter()
+ .find(|df| df.name() == target_name)
+ .expect("Unable to find file at runtime")
+ .clone()
+ }
+ {% else %} /* WOAH */ {{text}}
+ {%- endif %}
+ )
+ {% endif -%}
+ {% endfor -%}
+ .build();
+ {%- if step.cleanup %}
+ let cleanup = BUILDER_{{step.cleanup}}::default().build();
+ scenario.add_step(step, Some(cleanup));
+ {%- else %}
+ scenario.add_step(step, None);
+ {%- endif %}
+ {% endfor %}
+
+ scenario.run().unwrap();
+}
+{% endfor %} \ No newline at end of file
diff --git a/templates/rust/template.yaml b/templates/rust/template.yaml
new file mode 100644
index 0000000..110f5df
--- /dev/null
+++ b/templates/rust/template.yaml
@@ -0,0 +1,2 @@
+template: template.rs.tera
+run: cargo test