harmonyc 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/AGENTS.md +105 -0
  2. package/{cli → dist/cli}/cli.js +0 -0
  3. package/package.json +38 -12
  4. package/LICENSE +0 -21
  5. /package/{cli → dist/cli}/cli.d.ts +0 -0
  6. /package/{cli → dist/cli}/run.d.ts +0 -0
  7. /package/{cli → dist/cli}/run.js +0 -0
  8. /package/{cli → dist/cli}/watch.d.ts +0 -0
  9. /package/{cli → dist/cli}/watch.js +0 -0
  10. /package/{code_generator → dist/code_generator}/VitestGenerator.d.ts +0 -0
  11. /package/{code_generator → dist/code_generator}/VitestGenerator.js +0 -0
  12. /package/{code_generator → dist/code_generator}/outFile.d.ts +0 -0
  13. /package/{code_generator → dist/code_generator}/outFile.js +0 -0
  14. /package/{code_generator → dist/code_generator}/test_phrases.d.ts +0 -0
  15. /package/{code_generator → dist/code_generator}/test_phrases.js +0 -0
  16. /package/{compiler → dist/compiler}/compile.d.ts +0 -0
  17. /package/{compiler → dist/compiler}/compile.js +0 -0
  18. /package/{compiler → dist/compiler}/compiler.d.ts +0 -0
  19. /package/{compiler → dist/compiler}/compiler.js +0 -0
  20. /package/{filenames → dist/filenames}/filenames.d.ts +0 -0
  21. /package/{filenames → dist/filenames}/filenames.js +0 -0
  22. /package/{model → dist/model}/Router.d.ts +0 -0
  23. /package/{model → dist/model}/Router.js +0 -0
  24. /package/{model → dist/model}/model.d.ts +0 -0
  25. /package/{model → dist/model}/model.js +0 -0
  26. /package/{optimizations → dist/optimizations}/autoLabel/autoLabel.d.ts +0 -0
  27. /package/{optimizations → dist/optimizations}/autoLabel/autoLabel.js +0 -0
  28. /package/{parser → dist/parser}/lexer.d.ts +0 -0
  29. /package/{parser → dist/parser}/lexer.js +0 -0
  30. /package/{parser → dist/parser}/lexer_rules.d.ts +0 -0
  31. /package/{parser → dist/parser}/lexer_rules.js +0 -0
  32. /package/{parser → dist/parser}/parser.d.ts +0 -0
  33. /package/{parser → dist/parser}/parser.js +0 -0
  34. /package/{phrases_assistant → dist/phrases_assistant}/phrases_assistant.d.ts +0 -0
  35. /package/{phrases_assistant → dist/phrases_assistant}/phrases_assistant.js +0 -0
  36. /package/{util → dist/util}/indent.d.ts +0 -0
  37. /package/{util → dist/util}/indent.js +0 -0
  38. /package/{util → dist/util}/iterators.d.ts +0 -0
  39. /package/{util → dist/util}/iterators.js +0 -0
  40. /package/{util → dist/util}/xmur3.d.ts +0 -0
  41. /package/{util → dist/util}/xmur3.js +0 -0
  42. /package/{vitest → dist/vitest}/index.d.ts +0 -0
  43. /package/{vitest → dist/vitest}/index.js +0 -0
package/AGENTS.md ADDED
@@ -0,0 +1,105 @@
1
+ # Writing unit tests in .harmony files
2
+
3
+ When writing unit tests, write them in `.harmony` files using a special structured format. This specification will be compiled to JS on-the-fly and imports the corresponding `.phrases.ts` files for step implementations.
4
+
5
+ ## File Structure
6
+
7
+ For tests belonging to a feature, you need:
8
+
9
+ - `example.harmony` - Test specifications (this file)
10
+ - `example.phrases.ts` - Step implementations (you create this)
11
+
12
+ ## .harmony File Format
13
+
14
+ ### Syntax Rules
15
+
16
+ #### Line start
17
+
18
+ 1. **Lines starting with `+ `** on the same level become forks, each creating a separate test case.
19
+ 2. **Lines starting with `- `** become consecutive test steps in the same test case
20
+ 3. Every other line is ignored
21
+
22
+ #### Line content
23
+
24
+ 1. **Sections** are any line ending in `:`. It is ignored but is used for naming test cases and groups.
25
+ 2. **Steps** consist of an _action_ and an _expected outcome_ separated by `=>`.
26
+ 3. **Error steps** consist of an _action_ followed by `=> !!` and an _expected error message_ in double quotes.
27
+
28
+ #### Action and Expected Outcome syntax
29
+
30
+ Use human-readable phrases for both actions and expected outcomes.
31
+ Both actions and expected outcomes can contain:
32
+
33
+ - **words**
34
+ - **punctuation** is ignored
35
+ - **string arguments** enclosed in double quotes`"like this"`
36
+ - **code arguments** enclosed in backticks `` `like this` ``
37
+
38
+ Use string arguments for string parameters and code arguments for numbers, booleans, objects, arrays etc.
39
+
40
+ If there is one obvious default action in the test case with one parameter, use an action that contains just that parameter.
41
+ If there is one obvious default expected outcome with one parameter, use an expected outcome that contains just that parameter.
42
+
43
+ ### Example
44
+
45
+ ```harmony
46
+ # Calculator Functions
47
+
48
+ This library provides basic calculator functions.
49
+
50
+ + multiply():
51
+ - multiply `2` and `3` => `6`
52
+ - multiply `-2` and `3` => `-6`
53
+
54
+ + divide():
55
+ - divide `6` by `2` => `3`
56
+
57
+ Division by zero is an error.
58
+
59
+ + by zero:
60
+ We need to test both non-zero and zero dividends.
61
+ + divide `5` by `0` => !! "Division by zero"
62
+ + divide `0` by `0` => !! "Division by zero"
63
+ ```
64
+
65
+ ## .phrases.ts File Implementation
66
+
67
+ Create a class that implements step methods corresponding to your test specifications. Use imports as needed, e.g. import the functions you are testing.
68
+
69
+ `When_*` methods implement actions, and `Then_*` methods implement expected outcomes. `Then_*` methods receive
70
+ an extra parameter, the return value of the preceding `When_*` method. Add the words and parameters from the action / expected outcome, separated by underscores, with parameters denoted by `X`,`Y`,`Z`,`A`,`B`,...
71
+
72
+ Use vitest.expect in assertions.
73
+
74
+ Error responses need no implementation.
75
+
76
+ ```typescript
77
+ import { expect } from 'vitest'
78
+ import { multiply, divide } from './calculator'
79
+
80
+ export default class CalculatorPhrases {
81
+ result: number | undefined
82
+
83
+ async When_multiply_X_and_Y(a: number, b: number) {
84
+ return multiply(a, b)
85
+ }
86
+
87
+ async When_divide_X_by_Y(a: number, b: number) {
88
+ return divide(a, b)
89
+ }
90
+
91
+ async Then_X(expected: number, actual: number) {
92
+ expect(actual).toBe(expected)
93
+ }
94
+ }
95
+ ```
96
+
97
+ ## Best Practices
98
+
99
+ 1. **Keep test descriptions clear and concise**
100
+ 2. **Group related tests using sections**
101
+ 3. **Use meaningful parameter names in method signatures, and add TypeScript types**
102
+ 4. **Store state in class properties for complex scenarios**
103
+ 5. **Handle edge cases explicitly (errors, null values, etc.)**
104
+ 6. **Use descriptive comments in-line to explain test groups**
105
+ 7. **Test both happy path and error conditions**
File without changes
package/package.json CHANGED
@@ -1,18 +1,8 @@
1
1
  {
2
2
  "name": "harmonyc",
3
3
  "description": "Harmony Code - model-driven BDD for Vitest",
4
- "version": "0.19.0",
4
+ "version": "0.21.0",
5
5
  "author": "Bernát Kalló",
6
- "type": "module",
7
- "bin": {
8
- "harmonyc": "./cli.js"
9
- },
10
- "exports": {
11
- "./vitest": {
12
- "types": "./vitest/index.d.ts",
13
- "default": "./vitest/index.js"
14
- }
15
- },
16
6
  "homepage": "https://github.com/harmony-ac/code#readme",
17
7
  "repository": {
18
8
  "type": "git",
@@ -21,14 +11,50 @@
21
11
  "bugs": {
22
12
  "url": "https://github.com/harmony-ac/code/issues"
23
13
  },
14
+ "type": "module",
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "build:watch": "tsc --watch",
18
+ "harmonyc": "tsx ./src/cli/cli",
19
+ "test": "vitest --run",
20
+ "test:compile": "tsx ./src/cli/cli 'src/**/*.harmony'",
21
+ "dev": "vitest --watch",
22
+ "publish": "cp ../../README.md . && npm publish",
23
+ "release": "npm run test && npm run build && release publish"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "AGENTS.md",
28
+ "README.md"
29
+ ],
30
+ "exports": {
31
+ "./vitest": {
32
+ "types": "./dist/vitest/index.d.ts",
33
+ "default": "./dist/vitest/index.js"
34
+ }
35
+ },
36
+ "bin": {
37
+ "harmonyc": "./dist/cli/cli.js"
38
+ },
24
39
  "dependencies": {
25
40
  "fast-glob": "^3.3.2",
26
41
  "tinyrainbow": "1",
42
+ "ts-morph": "^27.0.2",
27
43
  "typescript-parsec": "0.3.4"
28
44
  },
29
45
  "optionalDependencies": {
30
46
  "watcher": "^2.3.1"
31
47
  },
48
+ "devDependencies": {
49
+ "@ossjs/release": "^0.10.0",
50
+ "@types/debug": "^4.1.12",
51
+ "@types/node": "^22.10.6",
52
+ "expect": "^29.7.0",
53
+ "tsx": "^4.7.1",
54
+ "typescript": "^5.3.3",
55
+ "vite": "^7.1.10",
56
+ "vitest": "^3.2.4"
57
+ },
32
58
  "license": "MIT",
33
59
  "keywords": [
34
60
  "unit test",
@@ -46,4 +72,4 @@
46
72
  "test modelling",
47
73
  "vitest"
48
74
  ]
49
- }
75
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024-2025 Bernát Kalló
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes