# Build
# -----

# Verifies that everything builds.
build_all:
	cargo build --examples


# Unit tests
# ~~~~~~~~~~

# Runs all unit tests in the crate.
unit_tests:
	cargo nextest run --no-fail-fast --status-level=fail

# Generates a simple coverage report and writes it to disk as an HTML file.
coverage:
	cargo llvm-cov --html


# Integration tests
# ~~~~~~~~~~~~~~~~~

# Generates all tinantas, krdantas, and dhatus supported by the program and writes them to disk.
create_test_files:
	cargo run --release --example snapshot_tests create --output-dir test-files

# Runs a full evaluation over all forms generated by vidyut-prakriya. `hash` is
# the SHA-256 hash of the test file. We use `hash` to verify test file
# integrity and ensure that our test cases are stable.
#
# NOTE: test files might contain invalid forms. Our goal with this test is
# simply to confirm that the system hasn't changed in unexpected ways.
test_all: test_tinantas test_krdantas test_dhatus

test_tinantas:
	cargo run --release --example snapshot_tests validate \
		--test-type tinantas \
		-f test-files/tinantas-basic.msgpack \
		-h "1ca53f0f7612728943699d20b5e42d80ca340ed330102cdede1e2e3b8af9e973" \
		-f test-files/tinantas-nic.msgpack \
		-h "a8b186ff62fe20a08e147537614bbb3220fbfd8d2fce356514e5e595d1e579fb" \
		-f test-files/tinantas-san.msgpack \
		-h "6a5180111ba24c8a6cbdb9257990438c816515b5102193449857ab20bd07164e" \
		-f test-files/tinantas-yan.msgpack \
		-h "0ba293917913f2aed9423ea3125071c56426ca2fc9e06a2632f27297de4b0139" \
		-f test-files/tinantas-yan-luk.msgpack \
		-h "871c631461aa2ab1ded884de5bdf12464879f5da46c660c3076c333a3a90fd7f" \
		-f test-files/tinantas-san-nic.msgpack \
		-h "66b82321c244f4369422b06c2db9254d61a680eceeb6e9c0e8b8ac24a274b3c8" \
		-f test-files/tinantas-nic-san.msgpack \
		-h "c84fc7a9cfce47561b5075f974f5fae4a2820549336c344a97978f719c01e409"

test_krdantas:
	cargo run --release --example snapshot_tests validate \
		--test-type krdantas \
		-f test-files/krdantas-basic.msgpack \
		-h "abe607447082b6ca6758018a7457e27f0bf9f5b271ac918d79ad8248e6f5f742" \
		-f test-files/krdantas-nic.msgpack \
		-h "4eedde749a5849b36136e304af9273e03993667d486f02d3bf8323419fe59495" \
		-f test-files/krdantas-san.msgpack \
		-h "7e08b483201ae98d3c16c130e2c696a5a7ad8c16f7cafce1c2f3910d1d17ef38" \
		-f test-files/krdantas-yan.msgpack \
		-h "ec01fd40625cb40ad75195c713aad8c52ab4d8bb8bfc87e6818637211699efe2" \
		-f test-files/krdantas-yan-luk.msgpack \
		-h "9b6f271c9ae57bf9ae05472fb4652489b0d8d6fee4d8c499fc63fc7edd1064ae" \
		-f test-files/krdantas-san-nic.msgpack \
		-h "ec38109021286d0ffb6ed5343f472ab8a6ffe8179aa6f76cb11449b3fb650c4c" \
		-f test-files/krdantas-nic-san.msgpack \
		-h "de4a2869943599d21ce8a760bf2861b116aeee4bf6c78e3ac416b7bbbdcf1011"

test_dhatus:
	cargo run --release --example snapshot_tests validate \
		--test-type dhatus \
		-f test-files/dhatus.msgpack \
		-h "b76f6643625ca659b4fb7e7dd8534d9204237ec20c512943a4d87441ec938dae"


test_subantas:
	cargo run --bin test_subantas -- \
		--test-cases test-files/subantas.csv

check_rule_coverage:
	./scripts/check_rule_coverage.py > report.log 


# Performance
# ~~~~~~~~~~~

# Profiles the program's execution time on OSX. This command will probably not
# work on other operating systems.
profile-time-osx:
	cargo instruments -t time --release --example bench


# Other
# ~~~~~

# Generates project docs and opens them in your default browser.
docs:
	cargo doc --no-deps --open


# Web builds
# ----------

# Builds WASM module and JS wrapper (pkg/vidyut_prakriya.js).
#
# This is a release build. Creating it will be slower but smaller and (perhaps)
# more performant.
wasm_release:
	wasm-pack build --target web --release -- --features serde

# Builds WASM module and JS wrapper (pkg/vidyut_prakriya.js).
#
# This is a dev build. Creating it will be faster, but size and performance
# will not be optimized.
wasm_dev:
	wasm-pack build --target web -- --features serde

# Builds a simple web debugger.
debugger:
	./scripts/run-debugger.sh
