You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a formatter for the TLA<sup>+</sup> language.
5
+
This is a formatter for the TLA<sup>+</sup> language.
5
6
6
-
It uses tlaplus tools' SANY library to parse your specification, and it applies some (at the moment) predefined format to it.
7
+
It uses tlaplus tools' SANY library to parse your specification, and it applies some (at the moment) predefined format
8
+
to it.
7
9
8
10
This is still _ALPHA_ software, feel free to try it out and leave feedback but be aware it might break your specs.
9
11
10
12
## Project Goals:
13
+
11
14
* A formatter for the TLA+ language. Pluscal is currently not a priority.
12
15
* It should be configurable but also provide sane defaults.
13
16
* It should never add useless chars (no extra spaces or extra newlines)
@@ -16,40 +19,71 @@ This is still _ALPHA_ software, feel free to try it out and leave feedback but b
16
19
* It should be fast.
17
20
18
21
## Configurations:
22
+
19
23
If you have specific requests for configuration options you would like to have, please consider opening an issue.
20
24
21
-
Currently, the idea is to follow the same ideas behind rustfmt. A user level formatter config and a project level formatter config.
25
+
Currently, the idea is to follow the same ideas behind rustfmt. A user level formatter config and a project level
26
+
formatter config.
22
27
23
28
## Example
29
+
24
30
To see some examples of current reformatting, compare:
25
-
* HourClock.tla: [before](https://github.com/FedericoPonzi/tlaplus-formatter/blob/main/src/test/resources/inputs/HourClock.tla) and [after](https://github.com/FedericoPonzi/tlaplus-formatter/blob/main/src/test/resources/outputs/HourClock.tla)
26
-
* TowerOfHanoi.tla: [before](https://github.com/FedericoPonzi/tlaplus-formatter/blob/main/src/test/resources/inputs/TowerOfHanoi.tla) and [after](https://github.com/FedericoPonzi/tlaplus-formatter/blob/main/src/test/resources/outputs/TowerOfHanoi.tla)
27
-
* Stones.tla: [before](https://github.com/FedericoPonzi/tlaplus-formatter/blob/main/src/test/resources/inputs/Stones.tla) and [after](https://github.com/FedericoPonzi/tlaplus-formatter/blob/main/src/test/resources/outputs/Stones.tla)
28
31
29
-
More examples are in the test/java/resources/{inputs|outputs} folders. These sources are taken from the TLA+ Examples repo.
and [after](https://github.com/FedericoPonzi/tlaplus-formatter/blob/main/src/test/resources/outputs/Stones.tla)
46
+
47
+
More examples are in the test/java/resources/{inputs|outputs} folders. These sources are taken from the TLA+ Examples
48
+
repo.
49
+
50
+
## Testing with TLA+-Smith
51
+
52
+
This project integrates [TLA+-Smith](https://github.com/fponzi/tlaplus-smith), a random TLA+ specification generator,
53
+
for comprehensive testing. TLA+-Smith helps ensure the formatter works correctly with a wide variety of TLA+ constructs
54
+
and edge cases.
30
55
31
56
## How to run
32
-
If you want to try it out, go to the build page of the latest commit, and download the "Package.zip" file from the artifact section at the bottom of the page ([Example](https://github.com/FedericoPonzi/tlaplus-formatter/actions/runs/10027954925)).
33
57
34
-
You will need at least java 11 (same requirement as tlatools).
58
+
If you want to try it out, go to the build page of the latest commit, and download the "Package.zip" file from the
It will print your reformatted spec in output. If the optional "OUTFILE" parameter is specified, it will write the output to that file.
42
-
You can use the input file as output file as well. Run with `-help` parameter for the help text.
70
+
It will print your reformatted spec in output. If the optional "OUTFILE" parameter is specified, it will write the
71
+
output to that file.
72
+
You can use the input file as the output file as well. Run with `-help` parameter for the help text.
43
73
44
74
## VSCode integration
75
+
45
76
It's a work in progress, see [PR-327](https://github.com/tlaplus/vscode-tlaplus/pull/327/files) on vscode-tlaplus repo.
46
77
47
78
## Limitations
48
-
Because it uses SANY underneath (TLC's parser), your spec needs to first succeed SANY's
49
-
parsing process, otherwise the formatter won't be able to reformat your file.
79
+
80
+
Because it uses SANY underneath (TLC's parser), your spec needs to first succeed SANY's
81
+
parsing process; otherwise the formatter won't be able to reformat your file.
50
82
51
83
---
52
84
53
85
## Development
54
-
Some of the `constants` used in the code are coming from SANY's codebase, specifically from this file: `src/tla2sany/st/SyntaxTreeConstants.java` (check [tlaplus repo](https://github.com/tlaplus/tlaplus/)).
86
+
87
+
Some of the `constants` used in the code are coming from SANY's codebase, specifically from this file:
This document describes the testing approach for the TLA+ formatter.
4
+
5
+
## Test Types
6
+
7
+
### Unit Tests
8
+
Individual component tests located in `src/test/java/me/fponzi/tlaplusformatter/` that test specific lexicon elements and formatting constructs.
9
+
10
+
### Integration Tests
11
+
End-to-end tests that format complete TLA+ specifications and compare against expected outputs in `src/test/resources/`.
12
+
13
+
### Property-Based Tests
14
+
Automated tests using [jqwik](https://jqwik.net/) that generate hundreds of random TLA+ specifications to verify formatter correctness.
15
+
16
+
## Property-Based Testing
17
+
18
+
The `PropertyBasedFormatterTest` class uses property-based testing to automatically verify formatter behavior across a wide range of inputs. Property-based testing generates random test data and verifies that certain properties always hold, making it excellent for finding edge cases that manual testing might miss.
19
+
20
+
The implementation generates syntactically valid TLA+ specifications with:
21
+
- Random module names
22
+
- 0-3 constant declarations
23
+
- Simple operator definitions using the declared constants
24
+
25
+
Two critical properties are tested:
26
+
27
+
**Semantic Preservation**: The formatter must preserve the meaning of the code. This is verified by parsing both the original and formatted specifications into Abstract Syntax Trees (ASTs) and ensuring they are structurally identical.
28
+
29
+
**Idempotence**: Running the formatter multiple times should produce the same result. This ensures the formatter reaches a stable state and doesn't continuously modify the code.
30
+
31
+
### Running Property-Based Tests
32
+
33
+
```bash
34
+
# Run all property-based tests (1000 examples each by default)
35
+
./gradlew test --tests PropertyBasedFormatterTest
36
+
37
+
# Run with specific seed for reproducible results
38
+
./gradlew test --tests PropertyBasedFormatterTest -Djqwik.seeds=123456789
39
+
40
+
# Run all tests
41
+
./gradlew test
42
+
```
43
+
44
+
The property-based tests automatically run 1000 random examples by default and include edge case testing, providing comprehensive coverage with minimal test code.
0 commit comments