Skip to content

Commit 3cb74f1

Browse files
committed
(third) Convert examples into test suites
1 parent 4e83e93 commit 3cb74f1

File tree

9 files changed

+8881
-152
lines changed

9 files changed

+8881
-152
lines changed

experiments/stasm/third/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2+
.nyc_output
23
*.js

experiments/stasm/third/README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,16 @@ Easy. Variable references are first-class citizens of the data model, making it
6161
- Restricting message references and introducing phrases
6262
- [#149 Restricting message references](https://github.com/unicode-org/message-format-wg/discussions/149)
6363

64-
## How to Run
64+
## Running the Test Suite
6565

6666
Run all examples:
6767

68-
npm start
68+
npm test
6969

70-
Run each example individually:
70+
Run an example individually:
7171

72-
npm run example glossary
73-
npm run example phrases
74-
npm run example list
75-
npm run example number
76-
npm run example opaque
72+
npx tsc
73+
node example/example_number.js
7774

7875
## References
7976

experiments/stasm/third/example/example_glossary.ts

Lines changed: 149 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {test} from "tap";
12
import {FormattingContext} from "../impl/context.js";
23
import {Argument, Message, Parameter} from "../impl/model.js";
34
import {REGISTRY} from "../impl/registry.js";
@@ -104,9 +105,7 @@ REGISTRY["ACTOR"] = function get_noun(
104105
}
105106
};
106107

107-
console.log("==== English ====");
108-
109-
{
108+
test("NOUN is ADJECTIVE (English)", (tap) => {
110109
let message: Message = {
111110
lang: "en",
112111
id: "accord",
@@ -135,159 +134,227 @@ console.log("==== English ====");
135134
},
136135
],
137136
};
138-
console.log(
137+
138+
tap.equal(
139139
formatMessage(message, {
140140
item: new StringValue("t-shirt"),
141141
color: new StringValue("red"),
142-
})
142+
}),
143+
"The T-shirt is red."
143144
);
144145

145-
console.log(
146-
Array.of(
147-
...formatToParts(message, {
148-
item: new StringValue("t-shirt"),
149-
color: new StringValue("red"),
150-
})
151-
)
146+
tap.same(
147+
formatToParts(message, {
148+
item: new StringValue("t-shirt"),
149+
color: new StringValue("red"),
150+
}),
151+
[
152+
{type: "literal", value: "The "},
153+
{type: "literal", value: "T-shirt"},
154+
{type: "literal", value: " is "},
155+
{type: "literal", value: "red"},
156+
{type: "literal", value: "."},
157+
]
152158
);
153-
}
154159

155-
{
160+
tap.end();
161+
});
162+
163+
test("NOUN is ADJECTIVE (Polish; requires according the gender of the adjective)", (tap) => {
156164
let message: Message = {
157-
lang: "en",
158-
id: "you-see",
165+
lang: "pl",
166+
id: "accord",
159167
phrases: {},
160168
selectors: [],
161169
variants: [
162170
{
163171
keys: [],
164172
value: [
165-
{type: "StringLiteral", value: "You see "},
166173
{
167174
type: "FunctionCall",
168-
name: "ACTOR",
169-
args: [{type: "VariableReference", name: "monster"}],
175+
name: "NOUN",
176+
args: [{type: "VariableReference", name: "item"}],
170177
opts: {
171-
INDEFINITE: {type: "BooleanLiteral", value: true},
178+
CAPITALIZED: {type: "BooleanLiteral", value: true},
172179
},
173180
},
174-
{type: "StringLiteral", value: "!"},
181+
{type: "StringLiteral", value: " jest "},
182+
{
183+
type: "FunctionCall",
184+
name: "ADJECTIVE",
185+
args: [{type: "VariableReference", name: "color"}],
186+
opts: {
187+
ACCORD_WITH: {type: "VariableReference", name: "item"},
188+
},
189+
},
190+
{type: "StringLiteral", value: "."},
175191
],
176192
},
177193
],
178194
};
179-
console.log(
195+
196+
tap.equal(
180197
formatMessage(message, {
181-
monster: new StringValue("dinosaur"),
182-
})
198+
item: new StringValue("t-shirt"),
199+
color: new StringValue("red"),
200+
}),
201+
"Tiszert jest czerwony."
183202
);
184-
}
185203

186-
{
204+
tap.same(
205+
formatToParts(message, {
206+
item: new StringValue("t-shirt"),
207+
color: new StringValue("red"),
208+
}),
209+
[
210+
{type: "literal", value: "Tiszert"},
211+
{type: "literal", value: " jest "},
212+
{type: "literal", value: "czerwony"},
213+
{type: "literal", value: "."},
214+
]
215+
);
216+
217+
tap.end();
218+
});
219+
220+
test("Subject verb OBJECT (English)", (tap) => {
187221
let message: Message = {
188222
lang: "en",
189-
id: "they-wave",
223+
id: "you-see",
190224
phrases: {},
191225
selectors: [],
192226
variants: [
193227
{
194228
keys: [],
195229
value: [
230+
{type: "StringLiteral", value: "You see "},
196231
{
197232
type: "FunctionCall",
198233
name: "ACTOR",
199234
args: [{type: "VariableReference", name: "monster"}],
200235
opts: {
201-
DEFINITE: {type: "BooleanLiteral", value: true},
202-
CAPITALIZED: {type: "BooleanLiteral", value: true},
236+
INDEFINITE: {type: "BooleanLiteral", value: true},
203237
},
204238
},
205-
{type: "StringLiteral", value: " waves at you!"},
239+
{type: "StringLiteral", value: "!"},
206240
],
207241
},
208242
],
209243
};
210-
console.log(
244+
245+
tap.equal(
211246
formatMessage(message, {
212-
monster: new StringValue("ogre"),
213-
})
247+
monster: new StringValue("dinosaur"),
248+
}),
249+
"You see a dinosaur!"
250+
);
251+
252+
tap.same(
253+
formatToParts(message, {
254+
monster: new StringValue("dinosaur"),
255+
}),
256+
[
257+
{type: "literal", value: "You see "},
258+
{type: "literal", value: "a dinosaur"},
259+
{type: "literal", value: "!"},
260+
]
214261
);
215-
}
216262

217-
console.log("==== polski ====");
263+
tap.end();
264+
});
218265

219-
{
266+
test("Subject verb OBJECT (Polish; requires the accusative case)", (tap) => {
220267
let message: Message = {
221268
lang: "pl",
222-
id: "accord",
269+
id: "you-see",
223270
phrases: {},
224271
selectors: [],
225272
variants: [
226273
{
227274
keys: [],
228275
value: [
276+
{type: "StringLiteral", value: "Widzisz "},
229277
{
230278
type: "FunctionCall",
231-
name: "NOUN",
232-
args: [{type: "VariableReference", name: "item"}],
233-
opts: {
234-
CAPITALIZED: {type: "BooleanLiteral", value: true},
235-
},
236-
},
237-
{type: "StringLiteral", value: " jest "},
238-
{
239-
type: "FunctionCall",
240-
name: "ADJECTIVE",
241-
args: [{type: "VariableReference", name: "color"}],
279+
name: "ACTOR",
280+
args: [{type: "VariableReference", name: "monster"}],
242281
opts: {
243-
ACCORD_WITH: {type: "VariableReference", name: "item"},
282+
CASE: {type: "StringLiteral", value: "accusative"},
244283
},
245284
},
246-
{type: "StringLiteral", value: "."},
285+
{type: "StringLiteral", value: "!"},
247286
],
248287
},
249288
],
250289
};
251-
console.log(
290+
291+
tap.equal(
252292
formatMessage(message, {
253-
item: new StringValue("t-shirt"),
254-
color: new StringValue("red"),
255-
})
293+
monster: new StringValue("dinosaur"),
294+
}),
295+
"Widzisz dinozaura!"
256296
);
257-
}
258297

259-
{
298+
tap.same(
299+
formatToParts(message, {
300+
monster: new StringValue("dinosaur"),
301+
}),
302+
[
303+
{type: "literal", value: "Widzisz "},
304+
{type: "literal", value: "dinozaura"},
305+
{type: "literal", value: "!"},
306+
]
307+
);
308+
309+
tap.end();
310+
});
311+
312+
test("SUBJECT verb (English)", (tap) => {
260313
let message: Message = {
261-
lang: "pl",
262-
id: "you-see",
314+
lang: "en",
315+
id: "they-wave",
263316
phrases: {},
264317
selectors: [],
265318
variants: [
266319
{
267320
keys: [],
268321
value: [
269-
{type: "StringLiteral", value: "Widzisz "},
270322
{
271323
type: "FunctionCall",
272324
name: "ACTOR",
273325
args: [{type: "VariableReference", name: "monster"}],
274326
opts: {
275-
CASE: {type: "StringLiteral", value: "accusative"},
327+
DEFINITE: {type: "BooleanLiteral", value: true},
328+
CAPITALIZED: {type: "BooleanLiteral", value: true},
276329
},
277330
},
278-
{type: "StringLiteral", value: "!"},
331+
{type: "StringLiteral", value: " waves at you!"},
279332
],
280333
},
281334
],
282335
};
283-
console.log(
336+
337+
tap.equal(
284338
formatMessage(message, {
285-
monster: new StringValue("dinosaur"),
286-
})
339+
monster: new StringValue("ogre"),
340+
}),
341+
"The ogre waves at you!"
342+
);
343+
344+
tap.same(
345+
formatToParts(message, {
346+
monster: new StringValue("ogre"),
347+
}),
348+
[
349+
{type: "literal", value: "The ogre"},
350+
{type: "literal", value: " waves at you!"},
351+
]
287352
);
288-
}
289353

290-
{
354+
tap.end();
355+
});
356+
357+
test("SUBJECT verb (Polish)", (tap) => {
291358
let message: Message = {
292359
lang: "pl",
293360
id: "they-wave",
@@ -312,9 +379,22 @@ console.log("==== polski ====");
312379
],
313380
};
314381

315-
console.log(
382+
tap.equal(
316383
formatMessage(message, {
317384
monster: new StringValue("ogre"),
318-
})
385+
}),
386+
"Ogr macha do ciebie!"
387+
);
388+
389+
tap.same(
390+
formatToParts(message, {
391+
monster: new StringValue("ogre"),
392+
}),
393+
[
394+
{type: "literal", value: "Ogr"},
395+
{type: "literal", value: " macha do ciebie!"},
396+
]
319397
);
320-
}
398+
399+
tap.end();
400+
});

0 commit comments

Comments
 (0)