papagaio 0.1.8 → 0.2.3
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/README.md +227 -206
- package/{cli.js → bin/cli.js} +2 -2
- package/index.html +1 -1
- package/package.json +8 -7
- package/src/papagaio.js +319 -0
- package/tests/test.js +98 -0
- package/tests/tests.json +406 -0
- package/papagaio.js +0 -659
package/tests/tests.json
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
{
|
|
2
|
+
"tests": [
|
|
3
|
+
{
|
|
4
|
+
"id": 1,
|
|
5
|
+
"name": "Basic pattern with 3 variables",
|
|
6
|
+
"code": "pattern {$x $y $z} {$z, $y, $x}\napple banana cherry",
|
|
7
|
+
"shouldContain": "cherry, banana, apple"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": 2,
|
|
11
|
+
"name": "Flexible whitespace ($)",
|
|
12
|
+
"code": "pattern {$x$$and$$$y} {$x & $y}\nhello and world",
|
|
13
|
+
"shouldContain": "hello & world"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"id": 3,
|
|
17
|
+
"name": "Block with delimiters ( )",
|
|
18
|
+
"code": "pattern {$block content {(}{)}} {[$content]}\ndata (hello world)",
|
|
19
|
+
"shouldContain": "[hello world]"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"id": 4,
|
|
23
|
+
"name": "Multiple patterns - reorder",
|
|
24
|
+
"code": "pattern {$a $b} {$b:$a}\nfoo bar",
|
|
25
|
+
"shouldContain": "bar:foo"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"id": 5,
|
|
29
|
+
"name": "Unique IDs incremental",
|
|
30
|
+
"code": "pattern {item} {item#$unique}\nitem\nitem\nitem",
|
|
31
|
+
"shouldContain": "item#u0"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": 6,
|
|
35
|
+
"name": "Block with brackets [ ]",
|
|
36
|
+
"code": "pattern {$block arr {[}{]}} {ARRAY($arr)}\n[1, 2, 3]",
|
|
37
|
+
"shouldContain": "ARRAY(1, 2, 3)"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": 7,
|
|
41
|
+
"name": "Pattern with special characters",
|
|
42
|
+
"code": "pattern {$a + $b} {$a PLUS $b}\n5 + 3",
|
|
43
|
+
"shouldContain": "5 PLUS 3"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"id": 8,
|
|
47
|
+
"name": "Match with prefix and suffix",
|
|
48
|
+
"code": "pattern {Hello $name} {>> $name <<}\nHello Alice",
|
|
49
|
+
"shouldContain": ">> Alice <<"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"id": 9,
|
|
53
|
+
"name": "Pattern repetition (global)",
|
|
54
|
+
"code": "pattern {x} {X}\nx y x z x",
|
|
55
|
+
"shouldContain": "X y X z X"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"id": 10,
|
|
59
|
+
"name": "Block with parentheses ( )",
|
|
60
|
+
"code": "pattern {$block params {(}{)}} {FUNC[$params]}\ncalcular(a, b, c)",
|
|
61
|
+
"shouldContain": "FUNC[a, b, c]"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"id": 11,
|
|
65
|
+
"name": "Pattern with $eval - arithmetic operation",
|
|
66
|
+
"code": "pattern {sum $a $b} {result: $eval{return $a + $b}}\nsum 10 20",
|
|
67
|
+
"shouldContain": "result: 30"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"id": 12,
|
|
71
|
+
"name": "Nested block with multiple levels",
|
|
72
|
+
"code": "pattern {$block inner {<}{>}} {INNER{$inner}}\nouter <inner content here>",
|
|
73
|
+
"shouldContain": "INNER{inner content here}"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"id": 13,
|
|
77
|
+
"name": "Pattern with flexible whitespace in middle",
|
|
78
|
+
"code": "pattern {from$$to} {path: from -> to}\nfrom to\nfrom to\nfrom to",
|
|
79
|
+
"shouldContain": "path: from -> to"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"id": 14,
|
|
83
|
+
"name": "Multiple $unique in one pattern",
|
|
84
|
+
"code": "pattern {log $msg} {[$unique] LOG: $msg [$unique]}\nlog error",
|
|
85
|
+
"shouldContain": "[u3] LOG: error"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"id": 15,
|
|
89
|
+
"name": "Block with quotes as delimiter",
|
|
90
|
+
"code": "pattern {$block str {\"}{\"}} {STRING: $str}\n\"hello world\"",
|
|
91
|
+
"shouldContain": "STRING: hello world"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"id": 16,
|
|
95
|
+
"name": "Pattern with 4+ variables",
|
|
96
|
+
"code": "pattern {$a $b $c $d $e} {$e-$d-$c-$b-$a}\n1 2 3 4 5",
|
|
97
|
+
"shouldContain": "5-4-3-2-1"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"id": 17,
|
|
101
|
+
"name": "Block with empty delimiter (special)",
|
|
102
|
+
"code": "pattern {start $a middle $b end} {($a|$b)}\nstart foo middle bar end",
|
|
103
|
+
"shouldContain": "(foo|bar)"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"id": 18,
|
|
107
|
+
"name": "Pattern generates HTML",
|
|
108
|
+
"code": "pattern {$tag $word} {<$tag>$word</$tag>}\ndiv Hello",
|
|
109
|
+
"shouldContain": "<div>Hello</div>"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"id": 19,
|
|
113
|
+
"name": "Block with numeric delimiters",
|
|
114
|
+
"code": "pattern {$block data {<<}{>>}} {DATA[$data]}\n<<json: {x: 1}>>",
|
|
115
|
+
"shouldContain": "DATA[json: {x: 1}]"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"id": 20,
|
|
119
|
+
"name": "Multiple sequential patterns complex",
|
|
120
|
+
"code": "pattern {Mr. $name} {Senhor $name}\npattern {Senhor $n} {Sir $n (formal)}\nMr. Smith",
|
|
121
|
+
"shouldContain": "Sir Smith"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"id": 21,
|
|
125
|
+
"name": "Block with operator symbol",
|
|
126
|
+
"code": "pattern {$block op {**}{**}} {OPERATION: $op}\n**a + b + c**",
|
|
127
|
+
"shouldContain": "OPERATION: a + b + c"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"id": 22,
|
|
131
|
+
"name": "Flexible whitespace with semicolon",
|
|
132
|
+
"code": "pattern {$$$a$$;$$$b$$} {$a AND $b}\nx ; y\nx; y\nx ; y",
|
|
133
|
+
"shouldContain": "x AND y"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"id": 23,
|
|
137
|
+
"name": "Context with nested pattern",
|
|
138
|
+
"code": "context {\npattern {$x} {<$x>}\napple\nbanana\ncherry\n}",
|
|
139
|
+
"shouldContain": "<apple>"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"id": 24,
|
|
143
|
+
"name": "Markdown bold to HTML",
|
|
144
|
+
"code": "pattern {**$text**} {<strong>$text</strong>}\nThis is **important** text",
|
|
145
|
+
"shouldContain": "<strong>important</strong>"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"id": 25,
|
|
149
|
+
"name": "Markdown italic to HTML",
|
|
150
|
+
"code": "pattern {*$text*} {<em>$text</em>}\nThis is *italic* text",
|
|
151
|
+
"shouldContain": "<em>italic</em>"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
"id": 26,
|
|
155
|
+
"name": "Configuration key=value",
|
|
156
|
+
"code": "pattern {$key = $value} {const $key = '$value';}\nserver_host = localhost\ndb_port = 3000",
|
|
157
|
+
"shouldContain": "const server_host = 'localhost';"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"id": 27,
|
|
161
|
+
"name": "Full name transformation",
|
|
162
|
+
"code": "pattern {$first $last} {{ name: '$last, $first' }}\nJohn Doe",
|
|
163
|
+
"shouldContain": "{ name: 'Doe, John' }"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"id": 28,
|
|
167
|
+
"name": "CSV to JSON simple",
|
|
168
|
+
"code": "pattern {$a,$b,$c} {{ field1: '$a', field2: '$b', field3: '$c' }}\nAlice,30,Engineer",
|
|
169
|
+
"shouldContain": "{ field1: 'Alice', field2: '30', field3: 'Engineer' }"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"id": 29,
|
|
173
|
+
"name": "Pattern with dictionary",
|
|
174
|
+
"code": "pattern {$a and $b} {$b and $a}\ncats and dogs",
|
|
175
|
+
"shouldContain": "dogs and cats"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"id": 30,
|
|
179
|
+
"name": "Multiple patterns in cascade",
|
|
180
|
+
"code": "pattern {a} {b}\npattern {b} {c}\npattern {c} {d}\na",
|
|
181
|
+
"shouldContain": "d"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"id": 31,
|
|
185
|
+
"name": "Block with empty delimiter (default)",
|
|
186
|
+
"code": "pattern {$block data {}{}} {DATA:$data}\ndata { hello world }",
|
|
187
|
+
"shouldContain": "DATA: hello world"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"id": 32,
|
|
191
|
+
"name": "Pattern with special character dot",
|
|
192
|
+
"code": "pattern {$x.txt} {file: $x}\ndocument.txt",
|
|
193
|
+
"shouldContain": "file: document"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"id": 33,
|
|
197
|
+
"name": "Block captures multiple nested levels",
|
|
198
|
+
"code": "pattern {$block inner {<}{>}} {INNER{$inner}}\nouter <middle <deep> more>",
|
|
199
|
+
"shouldContain": "INNER{middle <deep> more}"
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"id": 34,
|
|
203
|
+
"name": "Pattern with numbers and special chars",
|
|
204
|
+
"code": "pattern {$x + $y = $z} {$z is sum of $x and $y}\n5 + 3 = 8",
|
|
205
|
+
"shouldContain": "8 is sum of 5 and 3"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"id": 35,
|
|
209
|
+
"name": "Empty context is removed",
|
|
210
|
+
"code": "Start\ncontext {\n \n}\nEnd",
|
|
211
|
+
"shouldContain": "Start"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"id": 36,
|
|
215
|
+
"name": "Pattern HTML generator function",
|
|
216
|
+
"code": "pattern {$tag $content} {<$tag>$content</$tag>}\ndiv HelloWorld",
|
|
217
|
+
"shouldContain": "<div>HelloWorld</div>"
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"id": 37,
|
|
221
|
+
"name": "Block with multi-char delimiter",
|
|
222
|
+
"code": "pattern {$block code {<<}{>>}} {CODE[$code]}\n<<console.log('test')>>",
|
|
223
|
+
"shouldContain": "CODE[console.log('test')]"
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
"id": 38,
|
|
227
|
+
"name": "Markdown list to HTML",
|
|
228
|
+
"code": "pattern {- $item} {<li>$item</li>}\n- Apple\n- Banana",
|
|
229
|
+
"shouldContain": "<li>Apple</li>"
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
"id": 39,
|
|
233
|
+
"name": "Pattern with literal $ ($)",
|
|
234
|
+
"code": "pattern {price} {Price: $50}\nprice",
|
|
235
|
+
"shouldContain": "Price: $50"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
"id": 40,
|
|
239
|
+
"name": "Markdown heading h1",
|
|
240
|
+
"code": "pattern {# $title} {<h1>$title</h1>}\n# Welcome",
|
|
241
|
+
"shouldContain": "<h1>Welcome</h1>"
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
"id": 41,
|
|
245
|
+
"name": "Markdown heading h2",
|
|
246
|
+
"code": "pattern {## $title} {<h2>$title</h2>}\n## Section",
|
|
247
|
+
"shouldContain": "<h2>Section</h2>"
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"id": 42,
|
|
251
|
+
"name": "Variables with underscore names",
|
|
252
|
+
"code": "pattern {$var_name $other_var} {$other_var:$var_name}\nfirst second",
|
|
253
|
+
"shouldContain": "second:first"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
"id": 43,
|
|
257
|
+
"name": "Pattern with variable reuse",
|
|
258
|
+
"code": "pattern {$x} {$x-$x-$x}\ndata",
|
|
259
|
+
"shouldContain": "data-data-data"
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
"id": 44,
|
|
263
|
+
"name": "Block with double quotes",
|
|
264
|
+
"code": "pattern {$block str {\\\"}{\\\"}} {STR[$str]}\n\\\"hello\\\"",
|
|
265
|
+
"shouldContain": "STR[hello]"
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
"id": 45,
|
|
269
|
+
"name": "Pattern with flexible space before and after",
|
|
270
|
+
"code": "pattern {$$hello$$} {FOUND}\n hello ",
|
|
271
|
+
"shouldContain": "FOUND"
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
"id": 46,
|
|
275
|
+
"name": "Multiple blocks in one pattern",
|
|
276
|
+
"code": "pattern {$block a {(}{)}, $block b {[}{]}} {PAIR: $a and $b}\n(first), [second]",
|
|
277
|
+
"shouldContain": "PAIR: first and second"
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
"id": 47,
|
|
281
|
+
"name": "Pattern with math symbols",
|
|
282
|
+
"code": "pattern {$x * $y} {multiplication: $x * $y}\n5 * 3",
|
|
283
|
+
"shouldContain": "multiplication: 5 * 3"
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
"id": 48,
|
|
287
|
+
"name": "Eval with division and decimals",
|
|
288
|
+
"code": "pattern {div $a $b} {quotient: $eval{return $a / $b}}\ndiv 7 2",
|
|
289
|
+
"shouldContain": "quotient: 3.5"
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
"id": 49,
|
|
293
|
+
"name": "Negative numbers in $eval",
|
|
294
|
+
"code": "pattern {calc $a $b} {result: $eval{return $a - $b}}\ncalc -5 -10",
|
|
295
|
+
"shouldContain": "result: 5"
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
"id": 50,
|
|
299
|
+
"name": "Tabs as flexible whitespace",
|
|
300
|
+
"code": "pattern {from$$to} {path: from -> to}\nfrom\tto",
|
|
301
|
+
"shouldContain": "path: from -> to"
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
"id": 51,
|
|
305
|
+
"name": "Unicode characters in variables",
|
|
306
|
+
"code": "pattern {greet $name} {Olá $name}\ngreet 世界",
|
|
307
|
+
"shouldContain": "Olá 世界"
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
"id": 52,
|
|
311
|
+
"name": "Emoji support",
|
|
312
|
+
"code": "pattern {say $emoji} {You said: $emoji}\nsay 😊",
|
|
313
|
+
"shouldContain": "You said: 😊"
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
"id": 53,
|
|
317
|
+
"name": "Trim multiple surrounding spaces",
|
|
318
|
+
"code": "pattern {$$$word$$} {FOUND: $word}\n word ",
|
|
319
|
+
"shouldContain": "FOUND: word"
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
"id": 54,
|
|
323
|
+
"name": "No match leaves input intact",
|
|
324
|
+
"code": "pattern {nomatch $x} {X}\nnothing matches here",
|
|
325
|
+
"shouldContain": "nothing matches here"
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
"id": 55,
|
|
329
|
+
"name": "Block captures first simple angle block(known issue)",
|
|
330
|
+
"code": "pattern {$block txt {<}{>}} {CAP[$txt]}\nstart <one> middle <two> end",
|
|
331
|
+
"shouldContain": "CAP[one]"
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
"id": 56,
|
|
335
|
+
"name": "Overlapping patterns cascade",
|
|
336
|
+
"code": "pattern {a} {A}\npattern {A} {B}\na",
|
|
337
|
+
"shouldContain": "B"
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
"id": 57,
|
|
341
|
+
"name": "Literal dollar in replacement",
|
|
342
|
+
"code": "pattern {price} {Price: $50}\nprice",
|
|
343
|
+
"shouldContain": "Price: $50"
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
"id": 58,
|
|
347
|
+
"name": "Dot in variable suffix(known issue)",
|
|
348
|
+
"code": "pattern {$file.ext} {file: $file}\nphoto.png",
|
|
349
|
+
"shouldContain": "file: photo"
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
"id": 59,
|
|
353
|
+
"name": "Repeated global replacements",
|
|
354
|
+
"code": "pattern {x} {X}\nxxxxx",
|
|
355
|
+
"shouldContain": "XXXXX"
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
"id": 60,
|
|
359
|
+
"name": "Context preserves inner pattern output",
|
|
360
|
+
"code": "context {\npattern {$x} {<$x>}\ninner\n}\ninner\nouter",
|
|
361
|
+
"shouldContain": "<inner>"
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
"id": 61,
|
|
365
|
+
"name": "Block with pipe delimiters(known issue)",
|
|
366
|
+
"code": "pattern {$block mid {|}{|}} {PIPE[$mid]}\n|a| and |b|",
|
|
367
|
+
"shouldContain": "PIPE[a]"
|
|
368
|
+
},
|
|
369
|
+
{
|
|
370
|
+
"id": 62,
|
|
371
|
+
"name": "Trailing comma punctuation handling",
|
|
372
|
+
"code": "pattern {$w,} {$w!}\nhello,",
|
|
373
|
+
"shouldContain": "hello!"
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
"id": 63,
|
|
377
|
+
"name": "Comma-separated two variables",
|
|
378
|
+
"code": "pattern {$a,$b} {[$a][$b]}\none,two",
|
|
379
|
+
"shouldContain": "[one][two]"
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
"id": 64,
|
|
383
|
+
"name": "Apostrophe in pattern literal(known issue)",
|
|
384
|
+
"code": "pattern {It's $name} {Hello $name}\nIt's John",
|
|
385
|
+
"shouldContain": "Hello John"
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
"id": 65,
|
|
389
|
+
"name": "Arithmetic increment with large number",
|
|
390
|
+
"code": "pattern {num $a} {$eval{return parseInt($a) + 1}}\nnum 999",
|
|
391
|
+
"shouldContain": "1000"
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
"id": 66,
|
|
395
|
+
"name": "Parentheses block capture with nesting",
|
|
396
|
+
"code": "pattern {$block txt {(}{)}} {B[$txt]}\n(a(b)c)",
|
|
397
|
+
"shouldContain": "B[a(b)c]"
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
"id": 67,
|
|
401
|
+
"name": "Literal special regex characters in pattern",
|
|
402
|
+
"code": "pattern {a.*b} {PAT}\na.*b",
|
|
403
|
+
"shouldContain": "PAT"
|
|
404
|
+
}
|
|
405
|
+
]
|
|
406
|
+
}
|