Skip to content

Commit

Permalink
Fix TTY playground
Browse files Browse the repository at this point in the history
* Correct mapping from language to default query
* Correct mapping from language to sample input
* Use the appropriate feature flag for the language
  • Loading branch information
Xophmeister committed Jul 9, 2024
1 parent 0548af6 commit 3ae1c01
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions bin/playground.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
#shellcheck shell=bash

# "Quick-and-Dirty" Topiary Playground

Expand Down Expand Up @@ -27,11 +26,30 @@ fail() {
exit 1
}

get_sample_input() {
get-default-query() {
local language="$1"
local query

case "${language}" in
"ocaml_interface")
query=ocaml
;;

*)
# NOTE Query files use dashes, instead of underscores
query="${language//_/-}"
;;
esac

printf "topiary-queries/queries/%s.scm" "${query}"
}

get-sample-input() {
local language="$1"

# Only return the first result, presuming there is one
find topiary-core/tests/samples/input -name "${language}.*" \
# NOTE Sample files use dashes, instead of underscores
find topiary-cli/tests/samples/input -name "${language//_/-}.*" \
| head -1
}

Expand All @@ -41,14 +59,20 @@ format() {
local input="$3"
local skip_idempotence="${4-1}"

local -a cargo_args=(
--quiet
--no-default-features
--features "${language}"
)

local -a topiary_args=(
--language "${language}"
--query "${query}"
)

(( skip_idempotence )) && topiary_args+=(--skip-idempotence)

cargo run --quiet -- fmt "${topiary_args[@]}" < "${input}"
cargo run "${cargo_args[@]}" -- fmt "${topiary_args[@]}" < "${input}"
}

idempotency() {
Expand All @@ -73,18 +97,18 @@ main() {
case $# in
1)
language="$1"
query="topiary-queries/queries/${language}.scm"
input="$(get_sample_input "${language}")"
query="$(get-default-query "${language}")"
input="$(get-sample-input "${language}")"
;;

2)
language="$1"

if [[ "$2" =~ \.scm$ ]]; then
query="$2"
input="$(get_sample_input "${language}")"
input="$(get-sample-input "${language}")"
else
query="topiary-queries/queries/${language}.scm"
query="$(get-default-query "${language}")"
input="$2"
fi
;;
Expand All @@ -100,8 +124,6 @@ main() {
;;
esac

local language="$1"

[[ -e "${query}" ]] || fail "Couldn't find language query file '${query}'"
[[ -e "${input}" ]] || fail "Couldn't find input source file '${input}'"

Expand Down

0 comments on commit 3ae1c01

Please sign in to comment.