Exercism exercises in ReScript.
Track exercises target ReScript 12.2.0 using the ReScript Test testing framework on Node.js 22+. If you're contributing to the track, you will also need make.
Run the following commands from inside the project root directory to install the required tools:
npm install
git submodule update --init --recursive # add/update a local copy of the problem-specification submoduleTo automate the creation of practice exercise tests, our track tooling consumes data from the the problem specifications submodule. Because these specifications serve as the canonical source for all Exercism tracks, any upstream updates ensure our test cases remain consistent with the global exercise standard.
If you have format on save enabled for JSON files, it is recommended to disable this feature. Alternatively save JSON files with Ctrl+K s to save without applying formatting rules.
Open up two terminals. By running the commands below, files will compile on save and re-run the test suite.
# Terminal 1
npm run res:start
# Terminal 2
npm run testDocumentation on contributing to Exercism can be found here.
New practice exercises can be added via:
bin/add-practice-exercise <exercise-slug>
# Optionally, you can also specify the exercise's difficulty (via `-d`) and/or author's GitHub username (via `-a`):
bin/add-practice-exercise -a foobar -d 3 <exercise-slug>Now complete the following steps:
- Ensure that the new exercise data is correctly placed in order of difficulty and then alphabetically within that difficulty rating -
config.json - Implement exercise test cases, detailed in the testing section below -
templates/Test_template.res - Write an example of code here that will pass all test cases. This does not need to be the finest example of how to complete this exercise, but it must pass all the test cases -
exercises/practice/<exercise-slug>/.meta/<exercise-name>.res - Update the example solution's interface file with the function signatures -
exercises/practice/<exercise-slug>/.meta/<exercise-name>.reso - Create an exercise stub which returns
panic("'<function-name>' has not been implemented")-exercises/practice/<exercise-slug>/src/<exercise-name>.res - Update the exercise stub's interface file with the exposed function signatures so that the student has a reference to what names and types are used -
exercises/practice/<exercise-slug>/src/<exercise-name>.resi
Tests are written using rescript-test. There is a test templating system in place to reduce the amount of work needed by a developer. Follow these steps when writing tests:
exercises/practice/<exercise-slug>/.meta/tests.toml- if any of these test cases are not relevant to the language, addignore = trueon a newline below the descriptiontest_templates/<Exercise>_template.res- edit this file to allow the test generator to automatically create test files. If this file does not exist, copytemplates/Test_template.resand rename to match the aforementioned filename.- you must write your comparator functions - https://bloodyowl.github.io/rescript-test/assertions.
- common assertions with comparator functions are located at
test_generator/Assertions.res. Add the ones you'd like to use to thegenerateTestsfunction's last argument, egTestGenerator.generateTests(slug, template, [DictEqual]). - edit the
templatefunction so that it will generate the test cases. Thecaseparameter refers to a test case inproblem-specifications/exercises/<exercise-slug>/canonical-data.json. Refer to other exercise test templates for inspiration.
Run all exercise tests:
make testThis command will iterate over all exercises and check to see if their example implementation passes all the tests.
To test that all exercises will pass in the CI/CD environment, run:
./bin/verify-exercises
# test a single exercise:
./bin/verify-exercises <exercise-slug>Use PascalCase.res for ReScript implementation file names.
A ReScript interface file (.resi) should be included with every exercise to help the user get started.
Run make format on your code before pushing.
If you are using VS Code, install the official ReScript VS Code extension for syntax highlighting and code formatting.
configlet is an Exercism-wide tool for working with tracks. You can download it by running:
./bin/fetch-configletRun the lint command to verify if exercises have the required files and if config files are correct. Address any issues before pushing your changes:
./bin/configlet lintRun the fmt command to verify if the configuration files are formatted correctly. Address any issues before pushing your changes:
./bin/configlet fmt
# check a single exercise
./bin/configlet fmt -e <exercise-slug>
# auto format files
./bin/configlet fmt -uyIf you are auto formatting files, only commit the files relevant to your pull request.
If you find this documentation is inaccurate or incomplete, or can be improved in any way, please don't hesitate to create a new topic on the Exercism Forum