1
1
#! /usr/bin/env bash
2
2
3
3
# shellcheck source=/dev/null
4
- source ./bin/generator-utils/utils
4
+ source ./bin/generator-utils/utils.sh
5
5
6
6
function digest_template() {
7
7
template=$( cat bin/generator-utils/test_template)
@@ -12,15 +12,18 @@ function digest_template() {
12
12
13
13
canonical_json=$( cat canonical_data.json)
14
14
SLUG=$( echo " $canonical_json " | jq ' .exercise' )
15
- EXERCISE_DIR=" exercises/practice/${SLUG} "
16
- EXERCISE_DIR=" exercises/practice/${SLUG} "
17
- TEST_FILE=" ${EXERCISE_DIR} /tests/${SLUG} .rs"
18
- cat << EOT >"$TEST_FILE "
15
+ # shellcheck disable=SC2001
16
+ # Remove double quotes
17
+ SLUG=$( echo " $SLUG " | sed ' s/"//g' )
18
+ EXERCISE_DIR=" exercises/practice/$SLUG "
19
+ TEST_FILE=" $EXERCISE_DIR /tests/$SLUG .rs"
20
+ rm " $TEST_FILE "
21
+
22
+ cat << EOT >"$TEST_FILE "
19
23
use $( dash_to_underscore " $SLUG " ) ::*;
20
24
// Add tests here
21
25
22
26
EOT
23
- rm " $TEST_FILE "
24
27
cases=$( echo " $canonical_json " | jq ' [ .. | objects | with_entries(select(.key | IN("uuid", "description", "input", "expected", "property"))) | select(. != {}) | select(has("uuid")) ]' )
25
28
26
29
# shellcheck disable=SC2034
@@ -33,6 +36,10 @@ jq -c '.[]' <<<"$cases" | while read -r case; do
33
36
# Turn function name unto snake_case
34
37
formatted_template=$( echo " $eval_template " | sed -e ' :loop' -e ' s/\(fn[^(]*\)[ -]/\1_/g' -e ' t loop' | sed ' s/fn_/fn /' )
35
38
# Push to file
36
- echo " $formatted_template " >> tests.rs
39
+
40
+ echo " $formatted_template " >> " $TEST_FILE "
41
+ printf " \\ n" >> " $TEST_FILE "
37
42
38
43
done
44
+
45
+ rustfmt " $TEST_FILE "
0 commit comments