harmonyc 0.8.0 → 0.8.1

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.
@@ -60,6 +60,7 @@ export class NodeTest {
60
60
  }
61
61
  errorStep(action, errorMessage) {
62
62
  var _a;
63
+ this.declareFeatureVariables([action]);
63
64
  this.tf.print(`expect(async () => {`);
64
65
  this.tf.indent(() => {
65
66
  action.toCode(this);
@@ -67,14 +68,7 @@ export class NodeTest {
67
68
  this.tf.print(`}).rejects.toThrow(${(_a = errorMessage === null || errorMessage === void 0 ? void 0 : errorMessage.toCode(this)) !== null && _a !== void 0 ? _a : ''});`);
68
69
  }
69
70
  step(action, responses) {
70
- for (const p of [action, ...responses]) {
71
- const feature = p.feature.name;
72
- let f = this.featureVars.get(feature);
73
- if (!f) {
74
- f = toId(feature, abbrev, this.featureVars);
75
- this.tf.print(`const ${f} = new ${pascalCase(feature)}Phrases();`);
76
- }
77
- }
71
+ this.declareFeatureVariables([action, ...responses]);
78
72
  if (responses.length === 0) {
79
73
  action.toCode(this);
80
74
  return;
@@ -94,6 +88,16 @@ export class NodeTest {
94
88
  }
95
89
  });
96
90
  }
91
+ declareFeatureVariables(phrases) {
92
+ for (const p of phrases) {
93
+ const feature = p.feature.name;
94
+ let f = this.featureVars.get(feature);
95
+ if (!f) {
96
+ f = toId(feature, abbrev, this.featureVars);
97
+ this.tf.print(`const ${f} = new ${pascalCase(feature)}Phrases();`);
98
+ }
99
+ }
100
+ }
97
101
  phrase(p) {
98
102
  const phrasefn = this.functionName(p);
99
103
  if (!this.phraseFns.has(phrasefn))
@@ -16,7 +16,7 @@ export async function compileFiles(pattern) {
16
16
  console.log(`Compiled ${fns.length} file${fns.length === 1 ? '' : 's'}.`);
17
17
  const generated = features.filter((f) => f.phrasesFileAction === 'generated');
18
18
  if (generated.length) {
19
- console.log(`Generated ${generated.length} steps file${generated.length === 1 ? '' : 's'}.`);
19
+ console.log(`Generated ${generated.length} phrases file${generated.length === 1 ? '' : 's'}.`);
20
20
  }
21
21
  return { fns, outFns: features.map((f) => f.outFile.name) };
22
22
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "harmonyc",
3
3
  "description": "Harmony Code - model-driven BDD for Vitest",
4
- "version": "0.8.0",
4
+ "version": "0.8.1",
5
5
  "author": "Bernát Kalló",
6
6
  "type": "module",
7
7
  "bin": {
@@ -0,0 +1,9 @@
1
+ export default class LexerSteps {
2
+ async When__(x) {
3
+ throw new Error("Pending: When__");
4
+ }
5
+ async Then__(x) {
6
+ throw new Error("Pending: Then__");
7
+ }
8
+ }
9
+ ;
@@ -34,7 +34,7 @@ const rules = [
34
34
  [true, /^:(?=\s*(?:\n|$))/g, T.Colon],
35
35
  [
36
36
  true,
37
- /^(?!\s|=>|!!|- |\+ |[\[\]"`|]).+?(?=[\[\]"`|]|\n|$|=>|!!|:\s*(?:\n|$)|$)/g,
37
+ /^(?!\s|=>|!!|- |\+ |[\[\]"`|]|:\s*(?:\n|$)).+?(?=[\[\]"`|]|\n|$|=>|!!|:\s*(?:\n|$)|$)/g,
38
38
  T.Words,
39
39
  ],
40
40
  [true, /^-/g, T.Minus],
package/parser/parser.js CHANGED
@@ -25,7 +25,7 @@ export const RESPONSE = apply(PHRASE, ([parts, docstring]) => {
25
25
  export const ARROW = kmid(seq(opt_sc(NEWLINES), SPACES), tok(T.ResponseArrow), SPACES);
26
26
  export const RESPONSE_ITEM = kright(ARROW, RESPONSE);
27
27
  export const STEP = apply(seq(ACTION, rep_sc(RESPONSE_ITEM)), ([action, responses]) => new Step(action, responses).setFork(true));
28
- export const LABEL = apply(kleft(list_sc(PART, SPACES), tok(T.Colon)), (words) => new Label(words.map((w) => w.toString()).join(' ')));
28
+ export const LABEL = apply(kleft(list_sc(PART, SPACES), seq(tok(T.Colon), SPACES)), (words) => new Label(words.map((w) => w.toString()).join(' ')));
29
29
  export const SECTION = apply(LABEL, (text) => new Section(text));
30
30
  export const BRANCH = alt_sc(SECTION, STEP); // section first, to make sure there is no colon after step
31
31
  export const DENTS = apply(opt_sc(seq(SPACES, alt_sc(tok(T.Plus), tok(T.Minus)), tok(T.Space))), (lineHead) => {
@@ -0,0 +1,12 @@
1
+ export default class ParserSteps {
2
+ async When_production__(x) {
3
+ throw new Error("Pending: When_production__");
4
+ }
5
+ async When__(x) {
6
+ throw new Error("Pending: When__");
7
+ }
8
+ async Then__(x) {
9
+ throw new Error("Pending: Then__");
10
+ }
11
+ }
12
+ ;