summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-09-18 10:04:11 +0000
committerLars Wirzenius <liw@liw.fi>2021-09-18 10:04:11 +0000
commit5d023ad5bc648c9ed91d6860f6f706331542bfe5 (patch)
treef8037ed19c5b68456582d77ae41f50be657122c2
parent85e1d8fe7e0b2a6e020ec1d1319b3759c5ae0c2d (diff)
parente31322b9099722cd2108e1ab9362d220519af9e8 (diff)
downloadsubplot-5d023ad5bc648c9ed91d6860f6f706331542bfe5.tar.gz
Merge branch 'fixup-codegen' into 'main'
ast: Codeblocks should not have extra trailing newlines See merge request subplot/subplot!214
-rw-r--r--reference.md6
-rw-r--r--src/ast.rs13
-rw-r--r--src/doc.rs6
-rw-r--r--subplot.md118
4 files changed, 79 insertions, 64 deletions
diff --git a/reference.md b/reference.md
index ce79e14..1488ce0 100644
--- a/reference.md
+++ b/reference.md
@@ -11,7 +11,7 @@ documents.
~~~scenario
given an installed subplot
-given a clone of https://gitlab.com/subplot/subplot.git in src at 5cd2c2a8e56bdac1bc435fbd378ba7b10023c361
+given a clone of https://gitlab.com/subplot/subplot.git in src at 8fe4a393ccbda6820b57ec873f37f08ce17d7c3d
when I docgen subplot.md to test.pdf, in src
then file src/test.pdf exists
~~~
@@ -20,7 +20,7 @@ then file src/test.pdf exists
~~~scenario
given an installed subplot
-given a clone of https://gitlab.com/subplot/subplot.git in src at 5cd2c2a8e56bdac1bc435fbd378ba7b10023c361
+given a clone of https://gitlab.com/subplot/subplot.git in src at 8fe4a393ccbda6820b57ec873f37f08ce17d7c3d
when I docgen subplot.md to test.html, in src
when I run, in src, subplot docgen subplot.md -o subplot.html
then file src/test.html exists
@@ -31,7 +31,7 @@ then file src/test.html exists
~~~scenario
given an installed subplot
given file run_test.sh
-given a clone of https://gitlab.com/subplot/subplot.git in src at 5cd2c2a8e56bdac1bc435fbd378ba7b10023c361
+given a clone of https://gitlab.com/subplot/subplot.git in src at 8fe4a393ccbda6820b57ec873f37f08ce17d7c3d
when I run, in src, subplot codegen subplot.md -o test-inner.py
when I run bash run_test.sh
then command is successful
diff --git a/src/ast.rs b/src/ast.rs
index 60d234d..9543efd 100644
--- a/src/ast.rs
+++ b/src/ast.rs
@@ -188,6 +188,12 @@ fn code_block(kind: &CodeBlockKind, inlines: &mut Vec<Inline>) -> Block {
let text = plain_text_inline(inline);
code.push_str(&text);
}
+ // pulldown_cmark and pandoc differ in their codeblock handling,
+ // pulldown_cmark has an extra newline which we trim for now to be
+ // compatible with pandoc's parsing
+ if !code.is_empty() {
+ assert_eq!(code.pop(), Some('\n'));
+ }
Block::CodeBlock(attr, code)
}
@@ -222,8 +228,8 @@ fn parse_code_block_attrs(attrs: &str) -> Attr {
keyvalues.push((k.to_string(), v.to_string()));
}
}
- } else {
- id = attrs.to_string();
+ } else if !attrs.is_empty() {
+ classes.push(attrs.to_string());
}
(id, classes, keyvalues)
}
@@ -349,9 +355,10 @@ mod test {
#[test]
fn code_block_attrs() {
+ assert_eq!(parse_code_block_attrs(""), ("".to_string(), vec![], vec![]));
assert_eq!(
parse_code_block_attrs("foo"),
- ("foo".to_string(), vec![], vec![])
+ ("".to_string(), vec!["foo".to_string()], vec![])
);
assert_eq!(
parse_code_block_attrs("{#foo}"),
diff --git a/src/doc.rs b/src/doc.rs
index 10ac20f..2272581 100644
--- a/src/doc.rs
+++ b/src/doc.rs
@@ -406,8 +406,14 @@ impl<'a> Document {
}
/// Return matched scenarios in a document.
+ #[instrument(skip(self))]
pub fn matched_scenarios(&mut self, template: &str) -> Result<Vec<MatchedScenario>> {
let scenarios = self.scenarios()?;
+ event!(
+ Level::TRACE,
+ "Found {} scenarios, checking their bindings",
+ scenarios.len()
+ );
let bindings = self.meta().bindings();
scenarios
.iter()
diff --git a/subplot.md b/subplot.md
index 824e44a..a718490 100644
--- a/subplot.md
+++ b/subplot.md
@@ -648,8 +648,10 @@ title: "Subplot"
author: The Subplot project
date: work in progress
template: python
-bindings: subplot.yaml
-functions: subplot.py
+bindings:
+- subplot.yaml
+functions:
+- subplot.py
...
~~~
@@ -815,8 +817,8 @@ then command fails
~~~{#badfilename.md .file .markdown .numberLines}
---
title: Bad filenames in matched steps do not permit codegen
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
template: python
...
@@ -973,8 +975,8 @@ duplicated for each scenario.
~~~~{#simple.md .file .markdown .numberLines}
---
title: Test scenario
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
template: python
...
@@ -1098,8 +1100,8 @@ and command is successful
~~~{#allkeywords.md .file .markdown .numberLines}
---
title: All the keywords scenario
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
template: python
...
@@ -1134,9 +1136,9 @@ and command is successful
~~~{#aliases.md .file .markdown .numberLines}
---
-title: Keyword aliasesG
-bindings: b.yaml
-functions: f.py
+title: Keyword aliases
+bindings: [b.yaml]
+functions: [f.py]
...
# Aliases
@@ -1171,8 +1173,8 @@ then command fails
~~~{#continuationmisuse.md .file .markdown .numberLines}
---
title: Continuation keyword misuse
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
template: python
...
@@ -1235,8 +1237,8 @@ and command is successful
~~~~{#emptylines.md .file .markdown .numberLines}
---
title: Test scenario
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
template: python
...
@@ -1343,8 +1345,8 @@ and command is successful
~~~~~{#cleanup-success-python.md .file .markdown .numberLines}
---
title: Cleanup
-bindings: cleanup.yaml
-functions: cleanup.py
+bindings: [cleanup.yaml]
+functions: [cleanup.py]
template: python
...
@@ -1375,8 +1377,8 @@ and command fails
~~~~~{#cleanup-fail-python.md .file .markdown .numberLines}
---
title: Cleanup
-bindings: cleanup.yaml
-functions: cleanup.py
+bindings: [cleanup.yaml]
+functions: [cleanup.py]
template: python
...
@@ -1407,8 +1409,8 @@ and command is successful
~~~~~{#cleanup-success-bash.md .file .markdown .numberLines}
---
title: Cleanup
-bindings: cleanup.yaml
-functions: cleanup.sh
+bindings: [cleanup.yaml]
+functions: [cleanup.sh]
template: bash
...
@@ -1442,8 +1444,8 @@ and command fails
~~~~~{#cleanup-fail-bash.md .file .markdown .numberLines}
---
title: Cleanup
-bindings: cleanup.yaml
-functions: cleanup.sh
+bindings: [cleanup.yaml]
+functions: [cleanup.sh]
template: bash
...
@@ -1482,8 +1484,8 @@ and step "then TMPDIR is set" was run
~~~~{#tmpdir.md .file .markdown .numberLines}
---
title: TMPDIR
-bindings: tmpdir.yaml
-functions: tmpdir.py
+bindings: [tmpdir.yaml]
+functions: [tmpdir.py]
template: python
...
@@ -1534,8 +1536,8 @@ and command is successful
~~~~{#simplepattern.md .file .markdown .numberLines}
---
title: Simple pattern capture
-bindings: simplepattern.yaml
-functions: capture.py
+bindings: [simplepattern.yaml]
+functions: [capture.py]
template: python
...
@@ -1578,8 +1580,8 @@ and stderr contains "simple pattern contains regex"
~~~~{#confusedpattern.md .file .markdown .numberLines}
---
title: Simple pattern capture
-bindings: confusedpattern.yaml
-functions: capture.py
+bindings: [confusedpattern.yaml]
+functions: [capture.py]
template: python
...
@@ -1611,8 +1613,8 @@ then command is successful
~~~~{#confusedbutok.md .file .markdown .numberLines}
---
title: Simple pattern capture
-bindings: confusedbutok.yaml
-functions: capture.py
+bindings: [confusedbutok.yaml]
+functions: [capture.py]
template: python
...
@@ -1648,8 +1650,8 @@ and command is successful
~~~~{#regex.md .file .markdown .numberLines}
---
title: Regex capture
-bindings: regex.yaml
-functions: capture.py
+bindings: [regex.yaml]
+functions: [capture.py]
template: python
...
@@ -1696,8 +1698,8 @@ then command is successful
~~~~~~{#values.md .file .markdown .numberLines}
---
title: Values
-bindings: values.yaml
-functions: values.py
+bindings: [values.yaml]
+functions: [values.py]
template: python
...
@@ -1770,8 +1772,8 @@ then command is successful
~~~~~~{#env.md .file .markdown .numberLines}
---
title: Environment variables
-bindings: env.yaml
-functions: env.py
+bindings: [env.yaml]
+functions: [env.py]
template: python
...
@@ -1893,8 +1895,8 @@ and command is successful
---
title: Test scenario
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
template: python
...
@@ -1923,8 +1925,8 @@ and command is successful
---
title: Test scenario
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
template: python
...
@@ -1957,8 +1959,8 @@ and command is successful
---
title: Test scenario
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
template: python
...
@@ -1994,8 +1996,8 @@ and command is successful
---
title: Test scenario
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
template: python
...
@@ -2033,8 +2035,8 @@ then command fails
~~~{#notitle.md .file .markdown .numberLines}
---
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
...
@@ -2078,8 +2080,8 @@ then command is successful
~~~{#fancytitle.md .file .markdown .numberLines}
---
title: Plain *emph* **strong** ~~strikeout~~ superscript^10^ subscript~10~
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
template: python
...
@@ -2126,8 +2128,8 @@ and command is successful
~~~{#twoscenarios-python.md .file .markdown .numberLines}
---
title: Test scenario
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
template: python
...
@@ -2169,8 +2171,8 @@ and command is successful
~~~{#twoscenarios-bash.md .file .markdown .numberLines}
---
title: Test scenario
-bindings: b.yaml
-functions: f.sh
+bindings: [b.yaml]
+functions: [f.sh]
template: bash
...
@@ -2329,7 +2331,7 @@ and stderr contains ": missing-binding.yaml:"
~~~{#missing-binding.md .file .markdown .numberLines}
---
title: Missing binding
-bindings: missing-binding.yaml
+bindings: [missing-binding.yaml]
...
~~~
@@ -2350,8 +2352,8 @@ and stderr contains ": missing-functions.py:"
~~~{#missing-functions.md .file .markdown .numberLines}
---
title: Missing functions
-bindings: b.yaml
-functions: missing-functions.py
+bindings: [b.yaml]
+functions: [missing-functions.py]
template: python
...
~~~
@@ -2366,8 +2368,8 @@ subplot metadata would extract this information from the **simple.md** example:
~~~
title: Test scenario
-bindings: b.yaml
-functions: f.py
+bindings: [b.yaml]
+functions: [f.py]
scenario Simple
~~~