summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-06-12 06:39:50 +0000
committerLars Wirzenius <liw@liw.fi>2021-06-12 06:39:50 +0000
commit5e651a3bf5c965c8c922d96e1386ee2bb686bfbf (patch)
treea7f5d0d6e6157b0fa905b88685f0a11d620ecf24
parent8f729f785d324735bd451b5cb142f7b107386230 (diff)
parentf6eb1a692a3890b30558376f939a955fec1f4252 (diff)
downloadsubplot-5e651a3bf5c965c8c922d96e1386ee2bb686bfbf.tar.gz
Merge branch 'sorted-metadata' into 'main'
Sort output of metadata command Closes #200 See merge request subplot/subplot!178
-rw-r--r--reference.md6
-rw-r--r--share/python/template/asserts.py30
-rw-r--r--src/bin/cli/mod.rs18
-rw-r--r--subplot.md14
4 files changed, 48 insertions, 20 deletions
diff --git a/reference.md b/reference.md
index f2713b0..09ac659 100644
--- a/reference.md
+++ b/reference.md
@@ -10,7 +10,7 @@ documents.
~~~scenario
given an installed subplot
-given a clone of https://gitlab.com/subplot/subplot.git in src at bfbcaf9eedb9f2339494c3ee16d5761121631342
+given a clone of https://gitlab.com/subplot/subplot.git in src at 725775084f47cc2449d8d55687cf163f6b8f2d96
when I docgen subplot.md to test.pdf, in src
then file src/test.pdf exists
~~~
@@ -19,7 +19,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 bfbcaf9eedb9f2339494c3ee16d5761121631342
+given a clone of https://gitlab.com/subplot/subplot.git in src at 725775084f47cc2449d8d55687cf163f6b8f2d96
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
@@ -30,7 +30,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 bfbcaf9eedb9f2339494c3ee16d5761121631342
+given a clone of https://gitlab.com/subplot/subplot.git in src at 725775084f47cc2449d8d55687cf163f6b8f2d96
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/share/python/template/asserts.py b/share/python/template/asserts.py
index c898454..33609ce 100644
--- a/share/python/template/asserts.py
+++ b/share/python/template/asserts.py
@@ -9,15 +9,37 @@ def assert_ne(a, b):
# Check that two dict values are equal.
-def assert_dict_eq(a, b):
- assert isinstance(a, dict)
- assert isinstance(b, dict)
+def _assert_dict_eq(a, b):
for key in a:
assert key in b, f"exected {key} in both dicts"
av = a[key]
bv = b[key]
assert_eq(type(av), type(bv))
if isinstance(av, list):
- assert_eq(list(sorted(av)), list(sorted(bv)))
+ _assert_list_eq(av, bv)
+ elif isinstance(av, dict):
+ _assert_dict_eq(av, bv)
+ else:
+ assert_eq(av, bv)
for key in b:
assert key in a, f"exected {key} in both dicts"
+
+
+# Check that two list values are equal
+def _assert_list_eq(a, b):
+ assert_eq(len(a), len(b))
+ for (av, bv) in zip(a, b):
+ assert_eq(type(av), type(bv))
+ if isinstance(av, list):
+ _assert_list_eq(av, bv)
+ elif isinstance(av, dict):
+ _assert_dict_eq(av, bv)
+ else:
+ assert_eq(av, bv)
+
+
+# Recursively check two dictionaries are equal
+def assert_dict_eq(a, b):
+ assert isinstance(a, dict)
+ assert isinstance(b, dict)
+ _assert_dict_eq(a, b)
diff --git a/src/bin/cli/mod.rs b/src/bin/cli/mod.rs
index f3225db..6d643ba 100644
--- a/src/bin/cli/mod.rs
+++ b/src/bin/cli/mod.rs
@@ -41,40 +41,46 @@ pub struct Metadata {
impl TryFrom<&mut Document> for Metadata {
type Error = subplot::SubplotError;
fn try_from(doc: &mut Document) -> std::result::Result<Self, Self::Error> {
- let sources: Vec<_> = doc
+ let mut sources: Vec<_> = doc
.sources()
.into_iter()
.map(|p| filename(Some(&p)))
.collect();
+ sources.sort_unstable();
let title = doc.meta().title().to_owned();
- let binding_files = doc
+ let mut binding_files: Vec<_> = doc
.meta()
.bindings_filenames()
.into_iter()
.map(|p| filename(Some(&p)))
.collect();
- let function_files = doc
+ binding_files.sort_unstable();
+ let mut function_files: Vec<_> = doc
.meta()
.functions_filenames()
.into_iter()
.map(|p| filename(Some(&p)))
.collect();
- let bibliographies = doc
+ function_files.sort_unstable();
+ let mut bibliographies: Vec<_> = doc
.meta()
.bibliographies()
.into_iter()
.map(|p| filename(Some(&p)))
.collect();
- let scenarios = doc
+ bibliographies.sort_unstable();
+ let mut scenarios: Vec<_> = doc
.scenarios()?
.into_iter()
.map(|s| s.title().to_owned())
.collect();
- let files = doc
+ scenarios.sort_unstable();
+ let mut files: Vec<_> = doc
.files()
.iter()
.map(|f| f.filename().to_owned())
.collect();
+ files.sort_unstable();
Ok(Self {
sources,
title,
diff --git a/subplot.md b/subplot.md
index 230acb3..1ef6ad9 100644
--- a/subplot.md
+++ b/subplot.md
@@ -2261,14 +2261,14 @@ bibliography: [foo.bib, bar.bib]
{
"title": "Document refers to external images",
"sources": [
- "images.md",
"b.yaml",
- "other.yaml",
+ "bar.bib",
"f.py",
- "other.py",
"foo.bib",
- "bar.bib",
- "image.gif"
+ "image.gif",
+ "images.md",
+ "other.py",
+ "other.yaml"
],
"binding_files": [
"b.yaml",
@@ -2279,8 +2279,8 @@ bibliography: [foo.bib, bar.bib]
"other.py"
],
"bibliographies": [
- "foo.bib",
- "bar.bib"
+ "bar.bib",
+ "foo.bib"
],
"files": [],
"scenarios": []