|
40 | 40 | message "info" "This exercise doesn't have canonical data."
|
41 | 41 | message "success" "Stub file for tests has been created!"
|
42 | 42 | else
|
43 |
| - canonical_json=$(cat canonical_data.json) |
44 | 43 | local canonical_json
|
| 44 | + canonical_json=$(cat canonical_data.json) |
45 | 45 |
|
46 | 46 | # sometimes canonical data has multiple levels with multiple `cases` arrays.
|
47 | 47 | #(see kindergarten-garden https://github.com/exercism/problem-specifications/blob/main/exercises/kindergarten-garden/canonical-data.json)
|
48 | 48 | # so let's flatten it
|
49 |
| - cases=$(echo "$canonical_json" | jq '[ .. | objects | with_entries(select(.key | IN("uuid", "description", "input", "expected"))) | select(. != {}) | select(has("uuid")) ]') |
50 | 49 | local cases
|
51 |
| - fn_name=$(echo "$canonical_json" | jq -r 'first(.. | .property? // empty)') |
| 50 | + cases=$(echo "$canonical_json" | jq '[ .. | objects | with_entries(select(.key | IN("uuid", "description", "input", "expected"))) | select(. != {}) | select(has("uuid")) ]') |
52 | 51 | local fn_name
|
| 52 | + fn_name=$(echo "$canonical_json" | jq -r 'first(.. | .property? // empty)') |
53 | 53 |
|
54 | 54 | first_iteration=true
|
55 | 55 | # loop through each object
|
@@ -82,6 +82,7 @@ function create_lib_rs_template() {
|
82 | 82 | local exercise_dir=$1
|
83 | 83 | local slug=$2
|
84 | 84 | local has_canonical_data=$3
|
| 85 | + local fn_name |
85 | 86 | fn_name=$(create_fn_name "$slug" "$has_canonical_data")
|
86 | 87 | cat <<EOT >"${exercise_dir}/src/lib.rs"
|
87 | 88 | pub fn ${fn_name}() {
|
@@ -111,8 +112,8 @@ function create_example_rs_template() {
|
111 | 112 | local slug=$2
|
112 | 113 | local has_canonical_data=$3
|
113 | 114 |
|
114 |
| - fn_name=$(create_fn_name "$slug" "$has_canonical_data") |
115 | 115 | local fn_name
|
| 116 | + fn_name=$(create_fn_name "$slug" "$has_canonical_data") |
116 | 117 |
|
117 | 118 | mkdir "${exercise_dir}/.meta"
|
118 | 119 | cat <<EOT >"${exercise_dir}/.meta/example.rs"
|
|
0 commit comments