@lokascript/framework 2.0.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.
- package/LICENSE +20 -0
- package/README.md +142 -0
- package/dist/aot/aot-orchestrator.d.ts +75 -0
- package/dist/aot/aot-orchestrator.d.ts.map +1 -0
- package/dist/aot/domain-scanner.d.ts +27 -0
- package/dist/aot/domain-scanner.d.ts.map +1 -0
- package/dist/aot/index.d.ts +8 -0
- package/dist/aot/index.d.ts.map +1 -0
- package/dist/aot/types.d.ts +103 -0
- package/dist/aot/types.d.ts.map +1 -0
- package/dist/api/create-dsl.d.ts +91 -0
- package/dist/api/create-dsl.d.ts.map +1 -0
- package/dist/api/dispatcher.d.ts +108 -0
- package/dist/api/dispatcher.d.ts.map +1 -0
- package/dist/api/domain-registry.d.ts +152 -0
- package/dist/api/domain-registry.d.ts.map +1 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +2082 -0
- package/dist/api/index.js.map +1 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +2674 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/logger.d.ts +32 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/pattern-matching/index.d.ts +6 -0
- package/dist/core/pattern-matching/index.d.ts.map +1 -0
- package/dist/core/pattern-matching/index.js +1239 -0
- package/dist/core/pattern-matching/index.js.map +1 -0
- package/dist/core/pattern-matching/pattern-matcher.d.ts +239 -0
- package/dist/core/pattern-matching/pattern-matcher.d.ts.map +1 -0
- package/dist/core/pattern-matching/utils/index.d.ts +6 -0
- package/dist/core/pattern-matching/utils/index.d.ts.map +1 -0
- package/dist/core/pattern-matching/utils/possessive-keywords.d.ts +38 -0
- package/dist/core/pattern-matching/utils/possessive-keywords.d.ts.map +1 -0
- package/dist/core/pattern-matching/utils/type-validation.d.ts +63 -0
- package/dist/core/pattern-matching/utils/type-validation.d.ts.map +1 -0
- package/dist/core/tokenization/base-tokenizer.d.ts +344 -0
- package/dist/core/tokenization/base-tokenizer.d.ts.map +1 -0
- package/dist/core/tokenization/char-classifiers.d.ts +56 -0
- package/dist/core/tokenization/char-classifiers.d.ts.map +1 -0
- package/dist/core/tokenization/default-extractors.d.ts +48 -0
- package/dist/core/tokenization/default-extractors.d.ts.map +1 -0
- package/dist/core/tokenization/extractors/index.d.ts +9 -0
- package/dist/core/tokenization/extractors/index.d.ts.map +1 -0
- package/dist/core/tokenization/extractors/operator.d.ts +23 -0
- package/dist/core/tokenization/extractors/operator.d.ts.map +1 -0
- package/dist/core/tokenization/extractors/punctuation.d.ts +22 -0
- package/dist/core/tokenization/extractors/punctuation.d.ts.map +1 -0
- package/dist/core/tokenization/extractors.d.ts +61 -0
- package/dist/core/tokenization/extractors.d.ts.map +1 -0
- package/dist/core/tokenization/index.d.ts +11 -0
- package/dist/core/tokenization/index.d.ts.map +1 -0
- package/dist/core/tokenization/index.js +1345 -0
- package/dist/core/tokenization/index.js.map +1 -0
- package/dist/core/tokenization/morphology/index.d.ts +5 -0
- package/dist/core/tokenization/morphology/index.d.ts.map +1 -0
- package/dist/core/tokenization/morphology/types.d.ts +110 -0
- package/dist/core/tokenization/morphology/types.d.ts.map +1 -0
- package/dist/core/tokenization/token-utils.d.ts +111 -0
- package/dist/core/tokenization/token-utils.d.ts.map +1 -0
- package/dist/core/types.d.ts +382 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +108 -0
- package/dist/core/types.js.map +1 -0
- package/dist/generation/diagnostics.d.ts +120 -0
- package/dist/generation/diagnostics.d.ts.map +1 -0
- package/dist/generation/index.d.ts +7 -0
- package/dist/generation/index.d.ts.map +1 -0
- package/dist/generation/index.js +339 -0
- package/dist/generation/index.js.map +1 -0
- package/dist/generation/pattern-generator.d.ts +48 -0
- package/dist/generation/pattern-generator.d.ts.map +1 -0
- package/dist/generation/renderer.d.ts +115 -0
- package/dist/generation/renderer.d.ts.map +1 -0
- package/dist/grammar/index.d.ts +10 -0
- package/dist/grammar/index.d.ts.map +1 -0
- package/dist/grammar/index.js +391 -0
- package/dist/grammar/index.js.map +1 -0
- package/dist/grammar/transformer.d.ts +56 -0
- package/dist/grammar/transformer.d.ts.map +1 -0
- package/dist/grammar/types.d.ts +236 -0
- package/dist/grammar/types.d.ts.map +1 -0
- package/dist/index.cjs +4454 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4336 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/dictionary.d.ts +82 -0
- package/dist/interfaces/dictionary.d.ts.map +1 -0
- package/dist/interfaces/index.d.ts +10 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/profile-provider.d.ts +67 -0
- package/dist/interfaces/profile-provider.d.ts.map +1 -0
- package/dist/interfaces/value-extractor.d.ts +168 -0
- package/dist/interfaces/value-extractor.d.ts.map +1 -0
- package/dist/multilingual/index.d.ts +8 -0
- package/dist/multilingual/index.d.ts.map +1 -0
- package/dist/multilingual/index.js +1 -0
- package/dist/multilingual/index.js.map +1 -0
- package/dist/parsing/index.d.ts +8 -0
- package/dist/parsing/index.d.ts.map +1 -0
- package/dist/parsing/index.js +1415 -0
- package/dist/parsing/index.js.map +1 -0
- package/dist/parsing/multi-statement.d.ts +265 -0
- package/dist/parsing/multi-statement.d.ts.map +1 -0
- package/dist/schema/command-schema.d.ts +78 -0
- package/dist/schema/command-schema.d.ts.map +1 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +25 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/test-setup.d.ts +9 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/dist/testing/index.d.ts +50 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +16969 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +122 -0
- package/src/__test__/fixtures/sql-dsl.ts +232 -0
- package/src/__test__/sql-integration.test.ts +189 -0
- package/src/__test__/test-utils.ts +260 -0
- package/src/aot/aot-orchestrator.test.ts +413 -0
- package/src/aot/aot-orchestrator.ts +238 -0
- package/src/aot/domain-scanner.ts +178 -0
- package/src/aot/index.ts +8 -0
- package/src/aot/types.ts +124 -0
- package/src/api/create-dsl.ts +367 -0
- package/src/api/dispatcher.test.ts +336 -0
- package/src/api/dispatcher.ts +222 -0
- package/src/api/domain-registry.test.ts +336 -0
- package/src/api/domain-registry.ts +500 -0
- package/src/api/index.ts +7 -0
- package/src/core/index.ts +7 -0
- package/src/core/logger.ts +130 -0
- package/src/core/pattern-matching/index.ts +6 -0
- package/src/core/pattern-matching/pattern-matcher.test.ts +900 -0
- package/src/core/pattern-matching/pattern-matcher.ts +1548 -0
- package/src/core/pattern-matching/pattern-matcher.ts.backup +1267 -0
- package/src/core/pattern-matching/utils/index.ts +6 -0
- package/src/core/pattern-matching/utils/possessive-keywords.ts +55 -0
- package/src/core/pattern-matching/utils/type-validation.test.ts +316 -0
- package/src/core/pattern-matching/utils/type-validation.ts +134 -0
- package/src/core/tokenization/base-tokenizer.ts +916 -0
- package/src/core/tokenization/char-classifiers.ts +79 -0
- package/src/core/tokenization/create-simple-tokenizer.test.ts +260 -0
- package/src/core/tokenization/default-extractors.ts +69 -0
- package/src/core/tokenization/extractors/index.ts +9 -0
- package/src/core/tokenization/extractors/operator.ts +75 -0
- package/src/core/tokenization/extractors/punctuation.ts +39 -0
- package/src/core/tokenization/extractors.ts +452 -0
- package/src/core/tokenization/index.ts +11 -0
- package/src/core/tokenization/morphology/index.ts +5 -0
- package/src/core/tokenization/morphology/types.ts +211 -0
- package/src/core/tokenization/token-utils.ts +252 -0
- package/src/core/types.ts +589 -0
- package/src/generation/diagnostics.test.ts +171 -0
- package/src/generation/diagnostics.ts +239 -0
- package/src/generation/index.ts +7 -0
- package/src/generation/pattern-generator.test.ts +430 -0
- package/src/generation/pattern-generator.ts +315 -0
- package/src/generation/renderer.test.ts +266 -0
- package/src/generation/renderer.ts +244 -0
- package/src/grammar/index.ts +12 -0
- package/src/grammar/transformer.ts +159 -0
- package/src/grammar/types.ts +630 -0
- package/src/index.ts +157 -0
- package/src/interfaces/dictionary.ts +123 -0
- package/src/interfaces/index.ts +10 -0
- package/src/interfaces/profile-provider.ts +88 -0
- package/src/interfaces/value-extractor.ts +435 -0
- package/src/multilingual/index.ts +9 -0
- package/src/parsing/index.ts +27 -0
- package/src/parsing/multi-statement.test.ts +480 -0
- package/src/parsing/multi-statement.ts +648 -0
- package/src/schema/command-schema.ts +118 -0
- package/src/schema/index.ts +5 -0
- package/src/test-setup.ts +45 -0
- package/src/testing/index.ts +137 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pattern Generator Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests the pattern generation system that creates LanguagePattern objects
|
|
5
|
+
* from CommandSchema + LanguageProfile combinations.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, it, expect } from 'vitest';
|
|
9
|
+
import { generatePattern, type PatternGenLanguageProfile } from './pattern-generator';
|
|
10
|
+
import { defineCommand, defineRole } from '../schema';
|
|
11
|
+
|
|
12
|
+
describe('PatternGenerator', () => {
|
|
13
|
+
describe('generatePattern', () => {
|
|
14
|
+
it('should generate a basic SVO pattern', () => {
|
|
15
|
+
const schema = defineCommand({
|
|
16
|
+
action: 'toggle',
|
|
17
|
+
roles: [
|
|
18
|
+
defineRole({
|
|
19
|
+
role: 'patient',
|
|
20
|
+
required: true,
|
|
21
|
+
expectedTypes: ['selector'],
|
|
22
|
+
}),
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const profile: PatternGenLanguageProfile = {
|
|
27
|
+
code: 'en',
|
|
28
|
+
wordOrder: 'SVO',
|
|
29
|
+
keywords: {
|
|
30
|
+
toggle: { primary: 'toggle' },
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const pattern = generatePattern(schema, profile);
|
|
35
|
+
|
|
36
|
+
expect(pattern.id).toBe('toggle-en-generated');
|
|
37
|
+
expect(pattern.language).toBe('en');
|
|
38
|
+
expect(pattern.command).toBe('toggle');
|
|
39
|
+
expect(pattern.priority).toBe(100);
|
|
40
|
+
expect(pattern.template.tokens).toHaveLength(2);
|
|
41
|
+
expect(pattern.template.tokens[0]).toEqual({ type: 'literal', value: 'toggle' });
|
|
42
|
+
expect(pattern.template.tokens[1]).toMatchObject({ type: 'role', role: 'patient' });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should generate an SOV pattern with verb last', () => {
|
|
46
|
+
const schema = defineCommand({
|
|
47
|
+
action: 'toggle',
|
|
48
|
+
roles: [
|
|
49
|
+
defineRole({
|
|
50
|
+
role: 'patient',
|
|
51
|
+
required: true,
|
|
52
|
+
expectedTypes: ['selector'],
|
|
53
|
+
sovPosition: 1,
|
|
54
|
+
}),
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const profile: PatternGenLanguageProfile = {
|
|
59
|
+
code: 'ja',
|
|
60
|
+
wordOrder: 'SOV',
|
|
61
|
+
keywords: {
|
|
62
|
+
toggle: { primary: 'トグル' },
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const pattern = generatePattern(schema, profile);
|
|
67
|
+
|
|
68
|
+
expect(pattern.template.tokens).toHaveLength(2);
|
|
69
|
+
// In SOV, role comes first, then verb
|
|
70
|
+
expect(pattern.template.tokens[0]).toMatchObject({ type: 'role', role: 'patient' });
|
|
71
|
+
expect(pattern.template.tokens[1]).toEqual({ type: 'literal', value: 'トグル' });
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should generate a VSO pattern with verb first', () => {
|
|
75
|
+
const schema = defineCommand({
|
|
76
|
+
action: 'toggle',
|
|
77
|
+
roles: [
|
|
78
|
+
defineRole({
|
|
79
|
+
role: 'patient',
|
|
80
|
+
required: true,
|
|
81
|
+
expectedTypes: ['selector'],
|
|
82
|
+
}),
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const profile: PatternGenLanguageProfile = {
|
|
87
|
+
code: 'ar',
|
|
88
|
+
wordOrder: 'VSO',
|
|
89
|
+
keywords: {
|
|
90
|
+
toggle: { primary: 'بدّل' },
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const pattern = generatePattern(schema, profile);
|
|
95
|
+
|
|
96
|
+
expect(pattern.template.tokens).toHaveLength(2);
|
|
97
|
+
// VSO is like SVO - verb first
|
|
98
|
+
expect(pattern.template.tokens[0]).toEqual({ type: 'literal', value: 'بدّل' });
|
|
99
|
+
expect(pattern.template.tokens[1]).toMatchObject({ type: 'role', role: 'patient' });
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should include role markers when specified', () => {
|
|
103
|
+
const schema = defineCommand({
|
|
104
|
+
action: 'get',
|
|
105
|
+
roles: [
|
|
106
|
+
defineRole({
|
|
107
|
+
role: 'target',
|
|
108
|
+
required: true,
|
|
109
|
+
expectedTypes: ['expression'],
|
|
110
|
+
markerOverride: { en: 'from' },
|
|
111
|
+
}),
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const profile: PatternGenLanguageProfile = {
|
|
116
|
+
code: 'en',
|
|
117
|
+
wordOrder: 'SVO',
|
|
118
|
+
keywords: {
|
|
119
|
+
get: { primary: 'get' },
|
|
120
|
+
},
|
|
121
|
+
roleMarkers: {
|
|
122
|
+
target: { primary: 'from', position: 'before' },
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const pattern = generatePattern(schema, profile);
|
|
127
|
+
|
|
128
|
+
// Should have: get, from (marker), target (role)
|
|
129
|
+
expect(pattern.template.tokens).toHaveLength(3);
|
|
130
|
+
expect(pattern.template.tokens[0]).toEqual({ type: 'literal', value: 'get' });
|
|
131
|
+
expect(pattern.template.tokens[1]).toEqual({ type: 'literal', value: 'from' });
|
|
132
|
+
expect(pattern.template.tokens[2]).toMatchObject({ type: 'role', role: 'target' });
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should handle optional roles with groups', () => {
|
|
136
|
+
const schema = defineCommand({
|
|
137
|
+
action: 'select',
|
|
138
|
+
roles: [
|
|
139
|
+
defineRole({
|
|
140
|
+
role: 'columns',
|
|
141
|
+
required: true,
|
|
142
|
+
expectedTypes: ['expression'],
|
|
143
|
+
}),
|
|
144
|
+
defineRole({
|
|
145
|
+
role: 'source',
|
|
146
|
+
required: false,
|
|
147
|
+
expectedTypes: ['expression'],
|
|
148
|
+
markerOverride: { en: 'from' },
|
|
149
|
+
}),
|
|
150
|
+
],
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const profile: PatternGenLanguageProfile = {
|
|
154
|
+
code: 'en',
|
|
155
|
+
wordOrder: 'SVO',
|
|
156
|
+
keywords: {
|
|
157
|
+
select: { primary: 'select' },
|
|
158
|
+
},
|
|
159
|
+
roleMarkers: {
|
|
160
|
+
source: { primary: 'from', position: 'before' },
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const pattern = generatePattern(schema, profile);
|
|
165
|
+
|
|
166
|
+
// Should have optional group for source
|
|
167
|
+
expect(
|
|
168
|
+
pattern.template.tokens.some(t => t.type === 'group' && 'optional' in t && t.optional)
|
|
169
|
+
).toBe(true);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('should build extraction rules for all roles', () => {
|
|
173
|
+
const schema = defineCommand({
|
|
174
|
+
action: 'select',
|
|
175
|
+
roles: [
|
|
176
|
+
defineRole({
|
|
177
|
+
role: 'columns',
|
|
178
|
+
required: true,
|
|
179
|
+
expectedTypes: ['expression'],
|
|
180
|
+
}),
|
|
181
|
+
defineRole({
|
|
182
|
+
role: 'source',
|
|
183
|
+
required: true,
|
|
184
|
+
expectedTypes: ['expression'],
|
|
185
|
+
markerOverride: { en: 'from' },
|
|
186
|
+
}),
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
const profile: PatternGenLanguageProfile = {
|
|
191
|
+
code: 'en',
|
|
192
|
+
wordOrder: 'SVO',
|
|
193
|
+
keywords: {
|
|
194
|
+
select: { primary: 'select' },
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const pattern = generatePattern(schema, profile);
|
|
199
|
+
|
|
200
|
+
expect(pattern.extraction).toHaveProperty('columns');
|
|
201
|
+
expect(pattern.extraction).toHaveProperty('source');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('should use marker-based extraction when marker exists', () => {
|
|
205
|
+
const schema = defineCommand({
|
|
206
|
+
action: 'get',
|
|
207
|
+
roles: [
|
|
208
|
+
defineRole({
|
|
209
|
+
role: 'target',
|
|
210
|
+
required: true,
|
|
211
|
+
expectedTypes: ['expression'],
|
|
212
|
+
markerOverride: { en: 'from' },
|
|
213
|
+
}),
|
|
214
|
+
],
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const profile: PatternGenLanguageProfile = {
|
|
218
|
+
code: 'en',
|
|
219
|
+
wordOrder: 'SVO',
|
|
220
|
+
keywords: {
|
|
221
|
+
get: { primary: 'get' },
|
|
222
|
+
},
|
|
223
|
+
roleMarkers: {
|
|
224
|
+
target: { primary: 'from', position: 'before' },
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const pattern = generatePattern(schema, profile);
|
|
229
|
+
|
|
230
|
+
expect(pattern.extraction.target).toHaveProperty('marker', 'from');
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('should throw error for missing keyword translation', () => {
|
|
234
|
+
const schema = defineCommand({
|
|
235
|
+
action: 'unknown',
|
|
236
|
+
roles: [],
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
const profile: PatternGenLanguageProfile = {
|
|
240
|
+
code: 'en',
|
|
241
|
+
wordOrder: 'SVO',
|
|
242
|
+
keywords: {
|
|
243
|
+
toggle: { primary: 'toggle' },
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
expect(() => generatePattern(schema, profile)).toThrow(
|
|
248
|
+
"No keyword translation for 'unknown' in en"
|
|
249
|
+
);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('should respect custom priority configuration', () => {
|
|
253
|
+
const schema = defineCommand({
|
|
254
|
+
action: 'toggle',
|
|
255
|
+
roles: [],
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const profile: PatternGenLanguageProfile = {
|
|
259
|
+
code: 'en',
|
|
260
|
+
wordOrder: 'SVO',
|
|
261
|
+
keywords: {
|
|
262
|
+
toggle: { primary: 'toggle' },
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const pattern = generatePattern(schema, profile, { basePriority: 50 });
|
|
267
|
+
|
|
268
|
+
expect(pattern.priority).toBe(50);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('should handle multiple roles with correct ordering', () => {
|
|
272
|
+
const schema = defineCommand({
|
|
273
|
+
action: 'put',
|
|
274
|
+
roles: [
|
|
275
|
+
defineRole({
|
|
276
|
+
role: 'value',
|
|
277
|
+
required: true,
|
|
278
|
+
expectedTypes: ['expression'],
|
|
279
|
+
svoPosition: 2,
|
|
280
|
+
}),
|
|
281
|
+
defineRole({
|
|
282
|
+
role: 'destination',
|
|
283
|
+
required: true,
|
|
284
|
+
expectedTypes: ['selector'],
|
|
285
|
+
svoPosition: 1,
|
|
286
|
+
markerOverride: { en: 'into' },
|
|
287
|
+
}),
|
|
288
|
+
],
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
const profile: PatternGenLanguageProfile = {
|
|
292
|
+
code: 'en',
|
|
293
|
+
wordOrder: 'SVO',
|
|
294
|
+
keywords: {
|
|
295
|
+
put: { primary: 'put' },
|
|
296
|
+
},
|
|
297
|
+
roleMarkers: {
|
|
298
|
+
destination: { primary: 'into', position: 'before' },
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const pattern = generatePattern(schema, profile);
|
|
303
|
+
|
|
304
|
+
// Should be: put, value (higher svoPosition = first), into, destination
|
|
305
|
+
expect(pattern.template.tokens[0]).toEqual({ type: 'literal', value: 'put' });
|
|
306
|
+
expect(pattern.template.tokens[1]).toMatchObject({ type: 'role', role: 'value' });
|
|
307
|
+
expect(pattern.template.tokens[2]).toEqual({ type: 'literal', value: 'into' });
|
|
308
|
+
expect(pattern.template.tokens[3]).toMatchObject({ type: 'role', role: 'destination' });
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('should generate format string for documentation', () => {
|
|
312
|
+
const schema = defineCommand({
|
|
313
|
+
action: 'toggle',
|
|
314
|
+
roles: [
|
|
315
|
+
defineRole({
|
|
316
|
+
role: 'patient',
|
|
317
|
+
required: true,
|
|
318
|
+
expectedTypes: ['selector'],
|
|
319
|
+
}),
|
|
320
|
+
],
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
const profile: PatternGenLanguageProfile = {
|
|
324
|
+
code: 'en',
|
|
325
|
+
wordOrder: 'SVO',
|
|
326
|
+
keywords: {
|
|
327
|
+
toggle: { primary: 'toggle' },
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const pattern = generatePattern(schema, profile);
|
|
332
|
+
|
|
333
|
+
expect(pattern.template.format).toBeTruthy();
|
|
334
|
+
expect(typeof pattern.template.format).toBe('string');
|
|
335
|
+
expect(pattern.template.format).toContain('toggle');
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it('should handle empty roles array', () => {
|
|
339
|
+
const schema = defineCommand({
|
|
340
|
+
action: 'reload',
|
|
341
|
+
roles: [],
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const profile: PatternGenLanguageProfile = {
|
|
345
|
+
code: 'en',
|
|
346
|
+
wordOrder: 'SVO',
|
|
347
|
+
keywords: {
|
|
348
|
+
reload: { primary: 'reload' },
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
const pattern = generatePattern(schema, profile);
|
|
353
|
+
|
|
354
|
+
expect(pattern.template.tokens).toHaveLength(1);
|
|
355
|
+
expect(pattern.template.tokens[0]).toEqual({ type: 'literal', value: 'reload' });
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it('should handle alternative keywords', () => {
|
|
359
|
+
const schema = defineCommand({
|
|
360
|
+
action: 'toggle',
|
|
361
|
+
roles: [
|
|
362
|
+
defineRole({
|
|
363
|
+
role: 'patient',
|
|
364
|
+
required: true,
|
|
365
|
+
expectedTypes: ['selector'],
|
|
366
|
+
}),
|
|
367
|
+
],
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
const profile: PatternGenLanguageProfile = {
|
|
371
|
+
code: 'en',
|
|
372
|
+
wordOrder: 'SVO',
|
|
373
|
+
keywords: {
|
|
374
|
+
toggle: { primary: 'toggle', alternatives: ['switch'] },
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
const pattern = generatePattern(schema, profile);
|
|
379
|
+
|
|
380
|
+
// Primary keyword should be used in tokens, alternatives passed through
|
|
381
|
+
expect(pattern.template.tokens[0]).toEqual({
|
|
382
|
+
type: 'literal',
|
|
383
|
+
value: 'toggle',
|
|
384
|
+
alternatives: ['switch'],
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('should use markerOverride from role spec', () => {
|
|
389
|
+
const schema = defineCommand({
|
|
390
|
+
action: 'get',
|
|
391
|
+
roles: [
|
|
392
|
+
defineRole({
|
|
393
|
+
role: 'source',
|
|
394
|
+
required: true,
|
|
395
|
+
expectedTypes: ['expression'],
|
|
396
|
+
markerOverride: { en: 'from', es: 'de' },
|
|
397
|
+
}),
|
|
398
|
+
],
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
const englishProfile: PatternGenLanguageProfile = {
|
|
402
|
+
code: 'en',
|
|
403
|
+
wordOrder: 'SVO',
|
|
404
|
+
keywords: {
|
|
405
|
+
get: { primary: 'get' },
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
const spanishProfile: PatternGenLanguageProfile = {
|
|
410
|
+
code: 'es',
|
|
411
|
+
wordOrder: 'SVO',
|
|
412
|
+
keywords: {
|
|
413
|
+
get: { primary: 'obtener' },
|
|
414
|
+
},
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
const enPattern = generatePattern(schema, englishProfile);
|
|
418
|
+
const esPattern = generatePattern(schema, spanishProfile);
|
|
419
|
+
|
|
420
|
+
// English should have 'from' marker
|
|
421
|
+
expect(enPattern.template.tokens.some(t => t.type === 'literal' && t.value === 'from')).toBe(
|
|
422
|
+
true
|
|
423
|
+
);
|
|
424
|
+
// Spanish should have 'de' marker
|
|
425
|
+
expect(esPattern.template.tokens.some(t => t.type === 'literal' && t.value === 'de')).toBe(
|
|
426
|
+
true
|
|
427
|
+
);
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
});
|