From 5cb4cc0d1d92ff360e145e2d3eccf8ccc8ed8d79 Mon Sep 17 00:00:00 2001
From: Boegie19 <34578426+Boegie19@users.noreply.github.com>
Date: Sat, 30 Jul 2022 03:45:19 +0200
Subject: [PATCH] feature init csv (#594)
* init csv feature + test
* fmt fixes
---
..._tests__build__init_csv_with_children.snap | 19 ++++++++
.../default.project.json | 6 +++
.../init_csv_with_children/src/init.csv | 2 +
.../init_csv_with_children/src/other.csv | 2 +
src/snapshot_middleware/csv.rs | 43 ++++++++++++++++++-
src/snapshot_middleware/mod.rs | 19 ++++++--
tests/tests/build.rs | 1 +
7 files changed, 88 insertions(+), 4 deletions(-)
create mode 100644 rojo-test/build-test-snapshots/end_to_end__tests__build__init_csv_with_children.snap
create mode 100644 rojo-test/build-tests/init_csv_with_children/default.project.json
create mode 100644 rojo-test/build-tests/init_csv_with_children/src/init.csv
create mode 100644 rojo-test/build-tests/init_csv_with_children/src/other.csv
diff --git a/rojo-test/build-test-snapshots/end_to_end__tests__build__init_csv_with_children.snap b/rojo-test/build-test-snapshots/end_to_end__tests__build__init_csv_with_children.snap
new file mode 100644
index 000000000..c089ebb25
--- /dev/null
+++ b/rojo-test/build-test-snapshots/end_to_end__tests__build__init_csv_with_children.snap
@@ -0,0 +1,19 @@
+---
+source: tests/tests/build.rs
+assertion_line: 100
+expression: contents
+---
+
+ -
+
+ init_csv_with_children
+ [{"key":"init.csv","values":{}}]
+
+
-
+
+ other
+ [{"key":"other.csv","values":{}}]
+
+
+
+
diff --git a/rojo-test/build-tests/init_csv_with_children/default.project.json b/rojo-test/build-tests/init_csv_with_children/default.project.json
new file mode 100644
index 000000000..9b77db501
--- /dev/null
+++ b/rojo-test/build-tests/init_csv_with_children/default.project.json
@@ -0,0 +1,6 @@
+{
+ "name": "init_csv_with_children",
+ "tree": {
+ "$path": "src"
+ }
+}
\ No newline at end of file
diff --git a/rojo-test/build-tests/init_csv_with_children/src/init.csv b/rojo-test/build-tests/init_csv_with_children/src/init.csv
new file mode 100644
index 000000000..a6bc3e7c0
--- /dev/null
+++ b/rojo-test/build-tests/init_csv_with_children/src/init.csv
@@ -0,0 +1,2 @@
+Key
+init.csv
\ No newline at end of file
diff --git a/rojo-test/build-tests/init_csv_with_children/src/other.csv b/rojo-test/build-tests/init_csv_with_children/src/other.csv
new file mode 100644
index 000000000..0fc62b493
--- /dev/null
+++ b/rojo-test/build-tests/init_csv_with_children/src/other.csv
@@ -0,0 +1,2 @@
+Key
+other.csv
\ No newline at end of file
diff --git a/src/snapshot_middleware/csv.rs b/src/snapshot_middleware/csv.rs
index a8f271808..708f1bb8c 100644
--- a/src/snapshot_middleware/csv.rs
+++ b/src/snapshot_middleware/csv.rs
@@ -7,7 +7,11 @@ use serde::Serialize;
use crate::snapshot::{InstanceContext, InstanceMetadata, InstanceSnapshot};
-use super::{meta_file::AdjacentMetadata, util::PathExt};
+use super::{
+ dir::{dir_meta, snapshot_dir_no_meta},
+ meta_file::AdjacentMetadata,
+ util::PathExt,
+};
pub fn snapshot_csv(
_context: &InstanceContext,
@@ -46,6 +50,43 @@ pub fn snapshot_csv(
Ok(Some(snapshot))
}
+/// Attempts to snapshot an 'init' csv contained inside of a folder with
+/// the given name.
+///
+/// csv named `init.csv`
+/// their parents, which acts similarly to `__init__.py` from the Python world.
+pub fn snapshot_csv_init(
+ context: &InstanceContext,
+ vfs: &Vfs,
+ init_path: &Path,
+) -> anyhow::Result