mol_regexp 0.0.328 → 0.0.331

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/node.test.js CHANGED
@@ -540,6 +540,9 @@ var $;
540
540
  //mol/type/assert/assert.ts
541
541
  ;
542
542
  "use strict";
543
+ //mol/type/equals/equals.test.ts
544
+ ;
545
+ "use strict";
543
546
  //mol/type/partial/deep/deep.test.ts
544
547
  ;
545
548
  "use strict";
@@ -1051,9 +1054,6 @@ var $;
1051
1054
  //mol/assert/assert.ts
1052
1055
  ;
1053
1056
  "use strict";
1054
- //mol/type/equals/equals.test.ts
1055
- ;
1056
- "use strict";
1057
1057
  //mol/type/merge/merge.test.ts
1058
1058
  ;
1059
1059
  "use strict";
@@ -1061,561 +1061,236 @@ var $;
1061
1061
  ;
1062
1062
  "use strict";
1063
1063
  var $;
1064
+ (function ($) {
1065
+ function $mol_log3_area_lazy(event) {
1066
+ const self = this;
1067
+ const stack = self.$mol_log3_stack;
1068
+ const deep = stack.length;
1069
+ let logged = false;
1070
+ stack.push(() => {
1071
+ logged = true;
1072
+ self.$mol_log3_area.call(self, event);
1073
+ });
1074
+ return () => {
1075
+ if (logged)
1076
+ self.console.groupEnd();
1077
+ if (stack.length > deep)
1078
+ stack.length = deep;
1079
+ };
1080
+ }
1081
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1082
+ $.$mol_log3_stack = [];
1083
+ })($ || ($ = {}));
1084
+ //mol/log3/log3.ts
1085
+ ;
1086
+ "use strict";
1087
+ var $;
1088
+ (function ($) {
1089
+ function $mol_log3_node_make(level, output, type, color) {
1090
+ return function $mol_log3_logger(event) {
1091
+ if (!event.time)
1092
+ event = { time: new Date().toISOString(), ...event };
1093
+ const tree = this.$mol_tree.fromJSON(event).clone({ type });
1094
+ let str = tree.toString();
1095
+ if (process[output].isTTY) {
1096
+ str = $node.colorette[color + 'Bright'](str);
1097
+ }
1098
+ ;
1099
+ this.console[level](str);
1100
+ const self = this;
1101
+ return () => self.console.groupEnd();
1102
+ };
1103
+ }
1104
+ $.$mol_log3_node_make = $mol_log3_node_make;
1105
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
1106
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
1107
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
1108
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
1109
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
1110
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
1111
+ })($ || ($ = {}));
1112
+ //mol/log3/log3.node.ts
1113
+ ;
1114
+ "use strict";
1115
+ var $;
1116
+ (function ($_1) {
1117
+ $mol_test_mocks.push($ => {
1118
+ $.$mol_log3_come = () => { };
1119
+ $.$mol_log3_done = () => { };
1120
+ $.$mol_log3_fail = () => { };
1121
+ $.$mol_log3_warn = () => { };
1122
+ $.$mol_log3_rise = () => { };
1123
+ $.$mol_log3_area = () => () => { };
1124
+ });
1125
+ })($ || ($ = {}));
1126
+ //mol/log3/log3.test.ts
1127
+ ;
1128
+ "use strict";
1129
+ var $;
1130
+ (function ($) {
1131
+ $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
1132
+ function $mol_ambient(overrides) {
1133
+ return Object.setPrototypeOf(overrides, this || $);
1134
+ }
1135
+ $.$mol_ambient = $mol_ambient;
1136
+ })($ || ($ = {}));
1137
+ //mol/ambient/ambient.ts
1138
+ ;
1139
+ "use strict";
1140
+ var $;
1064
1141
  (function ($) {
1065
1142
  $mol_test({
1066
- 'escape'() {
1067
- const specials = $mol_regexp.from('.*+?^${}()|[]\\');
1068
- $mol_assert_equal(specials.source, '\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\\\');
1069
- },
1070
- 'char code'() {
1071
- const space = $mol_regexp.from(32);
1072
- $mol_assert_like(' '.match(space), [' ']);
1073
- },
1074
- 'repeat fixed'() {
1075
- const { repeat, decimal_only: digit } = $mol_regexp;
1076
- const year = repeat(digit, 4, 4);
1077
- $mol_assert_like('#2020#'.match(year), ['2020']);
1078
- },
1079
- 'greedy repeat'() {
1080
- const { repeat, repeat_greedy, latin_only: letter } = $mol_regexp;
1081
- $mol_assert_like('abc'.match(repeat(letter, 1, 2)), ['a', 'b', 'c']);
1082
- $mol_assert_like('abc'.match(repeat_greedy(letter, 1, 2)), ['ab', 'c']);
1083
- },
1084
- 'repeat range'() {
1085
- const { repeat_greedy, decimal_only: digit } = $mol_regexp;
1086
- const year = repeat_greedy(digit, 2, 4);
1087
- $mol_assert_like('#2#'.match(year), null);
1088
- $mol_assert_like('#20#'.match(year), ['20']);
1089
- $mol_assert_like('#2020#'.match(year), ['2020']);
1090
- $mol_assert_like('#20201#'.match(year), ['2020']);
1091
- },
1092
- 'repeat from'() {
1093
- const { repeat_greedy, latin_only: letter } = $mol_regexp;
1094
- const name = repeat_greedy(letter, 2);
1095
- $mol_assert_like('##'.match(name), null);
1096
- $mol_assert_like('#a#'.match(name), null);
1097
- $mol_assert_like('#ab#'.match(name), ['ab']);
1098
- $mol_assert_like('#abc#'.match(name), ['abc']);
1099
- },
1100
- 'from string'() {
1101
- const regexp = $mol_regexp.from('[\\d]');
1102
- $mol_assert_equal(regexp.source, '\\[\\\\d\\]');
1103
- $mol_assert_equal(regexp.flags, 'gsu');
1104
- },
1105
- 'from regexp'() {
1106
- const regexp = $mol_regexp.from(/[\d]/i);
1107
- $mol_assert_equal(regexp.source, '[\\d]');
1108
- $mol_assert_equal(regexp.flags, 'i');
1109
- },
1110
- 'split'() {
1111
- const regexp = $mol_regexp.from(';');
1112
- $mol_assert_like('aaa;bbb;ccc'.split(regexp), ['aaa', ';', 'bbb', ';', 'ccc']);
1113
- $mol_assert_like('aaa;;ccc'.split(regexp), ['aaa', ';', '', ';', 'ccc']);
1114
- $mol_assert_like('aaa'.split(regexp), ['aaa']);
1115
- $mol_assert_like(''.split(regexp), ['']);
1116
- },
1117
- 'test for matching'() {
1118
- const regexp = $mol_regexp.from('foo');
1119
- $mol_assert_like(regexp.test(''), false);
1120
- $mol_assert_like(regexp.test('fo'), false);
1121
- $mol_assert_like(regexp.test('foo'), true);
1122
- $mol_assert_like(regexp.test('foobar'), true);
1123
- $mol_assert_like(regexp.test('barfoo'), true);
1124
- },
1125
- 'case ignoring'() {
1126
- const xxx = $mol_regexp.from('x', { ignoreCase: true });
1127
- $mol_assert_like(xxx.flags, 'gisu');
1128
- $mol_assert_like(xxx.exec('xx')[0], 'x');
1129
- $mol_assert_like(xxx.exec('XX')[0], 'X');
1143
+ 'get'() {
1144
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1145
+ $mol_assert_equal(proxy.foo, 777);
1130
1146
  },
1131
- 'multiline mode'() {
1132
- const { end, from } = $mol_regexp;
1133
- const xxx = from(['x', end], { multiline: true });
1134
- $mol_assert_like(xxx.exec('x\ny')[0], 'x');
1135
- $mol_assert_like(xxx.flags, 'gmsu');
1147
+ 'has'() {
1148
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1149
+ $mol_assert_equal('foo' in proxy, true);
1136
1150
  },
1137
- 'flags override'() {
1138
- const triplet = $mol_regexp.from($mol_regexp.from(/.../, { ignoreCase: true }), { multiline: true });
1139
- $mol_assert_like(triplet.toString(), '/.../gmsu');
1151
+ 'set'() {
1152
+ const target = { foo: 777 };
1153
+ const proxy = $mol_delegate({}, () => target);
1154
+ proxy.foo = 123;
1155
+ $mol_assert_equal(target.foo, 123);
1140
1156
  },
1141
- 'sequence'() {
1142
- const { begin, end, decimal_only: digit, repeat, from } = $mol_regexp;
1143
- const year = repeat(digit, 4, 4);
1144
- const dash = '-';
1145
- const month = repeat(digit, 2, 2);
1146
- const day = repeat(digit, 2, 2);
1147
- const date = from([begin, year, dash, month, dash, day, end]);
1148
- $mol_assert_like(date.exec('2020-01-02')[0], '2020-01-02');
1157
+ 'getOwnPropertyDescriptor'() {
1158
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1159
+ $mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
1160
+ value: 777,
1161
+ writable: true,
1162
+ enumerable: true,
1163
+ configurable: true,
1164
+ });
1149
1165
  },
1150
- 'optional'() {
1151
- const name = $mol_regexp.from(['A', ['4']]);
1152
- $mol_assert_equal('AB'.match(name)[0], 'A');
1153
- $mol_assert_equal('A4'.match(name)[0], 'A4');
1166
+ 'ownKeys'() {
1167
+ const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
1168
+ $mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
1154
1169
  },
1155
- 'only groups'() {
1156
- const regexp = $mol_regexp.from({ dog: '@' });
1157
- $mol_assert_like([...'#'.matchAll(regexp)][0].groups, undefined);
1158
- $mol_assert_like([...'@'.matchAll(regexp)][0].groups, { dog: '@' });
1170
+ 'getPrototypeOf'() {
1171
+ class Foo {
1172
+ }
1173
+ const proxy = $mol_delegate({}, () => new Foo);
1174
+ $mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
1159
1175
  },
1160
- 'catch skipped'() {
1161
- const regexp = $mol_regexp.from(/(@)(\d?)/g);
1162
- $mol_assert_like([...'[[@]]'.matchAll(regexp)].map(f => [...f]), [
1163
- ['[['],
1164
- ['@', '@', ''],
1165
- [']]'],
1166
- ]);
1176
+ 'setPrototypeOf'() {
1177
+ class Foo {
1178
+ }
1179
+ const target = {};
1180
+ const proxy = $mol_delegate({}, () => target);
1181
+ Object.setPrototypeOf(proxy, Foo.prototype);
1182
+ $mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
1167
1183
  },
1168
- 'enum variants'() {
1169
- let Sex;
1170
- (function (Sex) {
1171
- Sex["male"] = "male";
1172
- Sex["female"] = "female";
1173
- })(Sex || (Sex = {}));
1174
- const sexism = $mol_regexp.from(Sex);
1175
- $mol_assert_like([...''.matchAll(sexism)].length, 0);
1176
- $mol_assert_like([...'trans'.matchAll(sexism)][0].groups, undefined);
1177
- $mol_assert_like([...'male'.matchAll(sexism)][0].groups, { male: 'male', female: '' });
1178
- $mol_assert_like([...'female'.matchAll(sexism)][0].groups, { male: '', female: 'female' });
1184
+ 'instanceof'() {
1185
+ class Foo {
1186
+ }
1187
+ const proxy = $mol_delegate({}, () => new Foo);
1188
+ $mol_assert_ok(proxy instanceof Foo);
1189
+ $mol_assert_ok(proxy instanceof $mol_delegate);
1179
1190
  },
1180
- 'recursive only groups'() {
1181
- let Sex;
1182
- (function (Sex) {
1183
- Sex["male"] = "male";
1184
- Sex["female"] = "female";
1185
- })(Sex || (Sex = {}));
1186
- const sexism = $mol_regexp.from({ Sex });
1187
- $mol_assert_like([...''.matchAll(sexism)].length, 0);
1188
- $mol_assert_like([...'male'.matchAll(sexism)][0].groups, { Sex: 'male', male: 'male', female: '' });
1189
- $mol_assert_like([...'female'.matchAll(sexism)][0].groups, { Sex: 'female', male: '', female: 'female' });
1190
- },
1191
- 'sequence with groups'() {
1192
- const { begin, end, decimal_only: digit, repeat, from } = $mol_regexp;
1193
- const year = repeat(digit, 4, 4);
1194
- const dash = '-';
1195
- const month = repeat(digit, 2, 2);
1196
- const day = repeat(digit, 2, 2);
1197
- const regexp = from([begin, { year }, dash, { month }, dash, { day }, end]);
1198
- const found = [...'2020-01-02'.matchAll(regexp)];
1199
- $mol_assert_like(found[0].groups, {
1200
- year: '2020',
1201
- month: '01',
1202
- day: '02',
1203
- });
1204
- },
1205
- 'sequence with groups of mixed type'() {
1206
- const prefix = '/';
1207
- const postfix = '/';
1208
- const regexp = $mol_regexp.from([{ prefix }, /(\w+)/, { postfix }, /([gumi]*)/]);
1209
- $mol_assert_like([...'/foo/mi'.matchAll(regexp)], [
1210
- Object.assign(["/foo/mi", "/", "foo", "/", "mi"], {
1211
- groups: {
1212
- prefix: '/',
1213
- postfix: '/',
1214
- },
1215
- index: 0,
1216
- input: "/",
1217
- }),
1218
- ]);
1219
- },
1220
- 'recursive sequence with groups'() {
1221
- const { begin, end, decimal_only: digit, repeat, from } = $mol_regexp;
1222
- const year = repeat(digit, 4, 4);
1223
- const dash = '-';
1224
- const month = repeat(digit, 2, 2);
1225
- const day = repeat(digit, 2, 2);
1226
- const regexp = from([
1227
- begin, { date: [{ year }, dash, { month }] }, dash, { day }, end
1228
- ]);
1229
- const found = [...'2020-01-02'.matchAll(regexp)];
1230
- $mol_assert_like(found[0].groups, {
1231
- date: '2020-01',
1232
- year: '2020',
1233
- month: '01',
1234
- day: '02',
1235
- });
1236
- },
1237
- 'parse multiple'() {
1238
- const { decimal_only: digit, from } = $mol_regexp;
1239
- const regexp = from({ digit });
1240
- $mol_assert_like([...'123'.matchAll(regexp)].map(f => f.groups), [
1241
- { digit: '1' },
1242
- { digit: '2' },
1243
- { digit: '3' },
1244
- ]);
1245
- },
1246
- 'variants'() {
1247
- const { begin, or, end, from } = $mol_regexp;
1248
- const sexism = from([
1249
- begin, 'sex = ', { sex: ['male', or, 'female'] }, end
1250
- ]);
1251
- $mol_assert_like([...'sex = male'.matchAll(sexism)][0].groups, { sex: 'male' });
1252
- $mol_assert_like([...'sex = female'.matchAll(sexism)][0].groups, { sex: 'female' });
1253
- $mol_assert_like([...'sex = malefemale'.matchAll(sexism)][0].groups, undefined);
1254
- },
1255
- 'force after'() {
1256
- const { latin_only: letter, force_after, from } = $mol_regexp;
1257
- const regexp = from([letter, force_after('.')]);
1258
- $mol_assert_like('x.'.match(regexp), ['x']);
1259
- $mol_assert_like('x,'.match(regexp), null);
1260
- },
1261
- 'forbid after'() {
1262
- const { latin_only: letter, forbid_after, from } = $mol_regexp;
1263
- const regexp = from([letter, forbid_after('.')]);
1264
- $mol_assert_like('x.'.match(regexp), null);
1265
- $mol_assert_like('x,'.match(regexp), ['x']);
1266
- },
1267
- 'char except'() {
1268
- const { char_except, latin_only, tab } = $mol_regexp;
1269
- const name = char_except(latin_only, tab);
1270
- $mol_assert_like('a'.match(name), null);
1271
- $mol_assert_like('\t'.match(name), null);
1272
- $mol_assert_like('('.match(name), ['(']);
1273
- },
1274
- 'unicode only'() {
1275
- const { unicode_only, from } = $mol_regexp;
1276
- const name = from([
1277
- unicode_only('Script', 'Cyrillic'),
1278
- unicode_only('Hex_Digit'),
1279
- ]);
1280
- $mol_assert_like('FF'.match(name), null);
1281
- $mol_assert_like('ФG'.match(name), null);
1282
- $mol_assert_like('ФF'.match(name), ['ФF']);
1283
- },
1284
- 'generate by optional with inner group'() {
1285
- const { begin, end, from } = $mol_regexp;
1286
- const animals = from([begin, '#', ['^', { dog: '@' }], end]);
1287
- $mol_assert_equal(animals.generate({}), '#');
1288
- $mol_assert_equal(animals.generate({ dog: false }), '#');
1289
- $mol_assert_equal(animals.generate({ dog: true }), '#^@');
1290
- $mol_assert_fail(() => animals.generate({ dog: '$' }), 'Wrong param: dog=$');
1291
- },
1292
- 'generate by optional with inner group with variants'() {
1293
- const { begin, end, from } = $mol_regexp;
1294
- const animals = from([begin, '#', ['^', { animal: { dog: '@', fox: '&' } }], end]);
1295
- $mol_assert_equal(animals.generate({}), '#');
1296
- $mol_assert_equal(animals.generate({ dog: true }), '#^@');
1297
- $mol_assert_equal(animals.generate({ fox: true }), '#^&');
1298
- $mol_assert_fail(() => animals.generate({ dog: '$' }), 'Wrong param: dog=$');
1299
- },
1300
- 'complex example'() {
1301
- const { begin, end, char_only, char_range, latin_only, slash_back, repeat_greedy, from, } = $mol_regexp;
1302
- const atom_char = char_only(latin_only, "!#$%&'*+/=?^`{|}~-");
1303
- const atom = repeat_greedy(atom_char, 1);
1304
- const dot_atom = from([atom, repeat_greedy(['.', atom])]);
1305
- const name_letter = char_only(char_range(0x01, 0x08), 0x0b, 0x0c, char_range(0x0e, 0x1f), 0x21, char_range(0x23, 0x5b), char_range(0x5d, 0x7f));
1306
- const quoted_pair = from([
1307
- slash_back,
1308
- char_only(char_range(0x01, 0x09), 0x0b, 0x0c, char_range(0x0e, 0x7f))
1309
- ]);
1310
- const name = repeat_greedy({ name_letter, quoted_pair });
1311
- const quoted_name = from(['"', { name }, '"']);
1312
- const local_part = from({ dot_atom, quoted_name });
1313
- const domain = dot_atom;
1314
- const mail = from([begin, local_part, '@', { domain }, end]);
1315
- $mol_assert_equal('foo..bar@example.org'.match(mail), null);
1316
- $mol_assert_equal('foo..bar"@example.org'.match(mail), null);
1317
- $mol_assert_like([...'foo.bar@example.org'.matchAll(mail)][0].groups, {
1318
- domain: "example.org",
1319
- dot_atom: "foo.bar",
1320
- name: "",
1321
- name_letter: "",
1322
- quoted_name: "",
1323
- quoted_pair: "",
1324
- });
1325
- $mol_assert_like([...'"foo..bar"@example.org'.matchAll(mail)][0].groups, {
1326
- dot_atom: "",
1327
- quoted_name: '"foo..bar"',
1328
- name: "foo..bar",
1329
- name_letter: "r",
1330
- quoted_pair: "",
1331
- domain: "example.org",
1332
- });
1333
- $mol_assert_equal(mail.generate({ dot_atom: 'foo.bar', domain: 'example.org' }), 'foo.bar@example.org');
1334
- $mol_assert_equal(mail.generate({ name: 'foo..bar', domain: 'example.org' }), '"foo..bar"@example.org');
1335
- $mol_assert_fail(() => mail.generate({ dot_atom: 'foo..bar', domain: 'example.org' }), 'Wrong param: dot_atom=foo..bar');
1191
+ 'autobind'() {
1192
+ class Foo {
1193
+ }
1194
+ const proxy = $mol_delegate({}, () => new Foo);
1195
+ $mol_assert_ok(proxy instanceof Foo);
1196
+ $mol_assert_ok(proxy instanceof $mol_delegate);
1336
1197
  },
1337
1198
  });
1338
1199
  })($ || ($ = {}));
1339
- //mol/regexp/regexp.test.ts
1200
+ //mol/delegate/delegate.test.ts
1340
1201
  ;
1341
1202
  "use strict";
1342
1203
  var $;
1343
1204
  (function ($) {
1344
- function $mol_log3_area_lazy(event) {
1345
- const self = this;
1346
- const stack = self.$mol_log3_stack;
1347
- const deep = stack.length;
1348
- let logged = false;
1349
- stack.push(() => {
1350
- logged = true;
1351
- self.$mol_log3_area.call(self, event);
1205
+ const instances = new WeakSet();
1206
+ function $mol_delegate(proto, target) {
1207
+ const proxy = new Proxy(proto, {
1208
+ get: (_, field) => {
1209
+ const obj = target();
1210
+ let val = Reflect.get(obj, field);
1211
+ if (typeof val === 'function') {
1212
+ val = val.bind(obj);
1213
+ }
1214
+ return val;
1215
+ },
1216
+ has: (_, field) => Reflect.has(target(), field),
1217
+ set: (_, field, value) => Reflect.set(target(), field, value),
1218
+ getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
1219
+ ownKeys: () => Reflect.ownKeys(target()),
1220
+ getPrototypeOf: () => Reflect.getPrototypeOf(target()),
1221
+ setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
1222
+ isExtensible: () => Reflect.isExtensible(target()),
1223
+ preventExtensions: () => Reflect.preventExtensions(target()),
1224
+ apply: (_, self, args) => Reflect.apply(target(), self, args),
1225
+ construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
1226
+ defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
1227
+ deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
1352
1228
  });
1353
- return () => {
1354
- if (logged)
1355
- self.console.groupEnd();
1356
- if (stack.length > deep)
1357
- stack.length = deep;
1358
- };
1229
+ instances.add(proxy);
1230
+ return proxy;
1359
1231
  }
1360
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1361
- $.$mol_log3_stack = [];
1232
+ $.$mol_delegate = $mol_delegate;
1233
+ Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
1234
+ value: (obj) => instances.has(obj),
1235
+ });
1362
1236
  })($ || ($ = {}));
1363
- //mol/log3/log3.ts
1237
+ //mol/delegate/delegate.ts
1364
1238
  ;
1365
1239
  "use strict";
1366
1240
  var $;
1367
1241
  (function ($) {
1368
- function $mol_log3_node_make(level, output, type, color) {
1369
- return function $mol_log3_logger(event) {
1370
- if (!event.time)
1371
- event = { time: new Date().toISOString(), ...event };
1372
- const tree = this.$mol_tree.fromJSON(event).clone({ type });
1373
- let str = tree.toString();
1374
- if (process[output].isTTY) {
1375
- str = $node.colorette[color + 'Bright'](str);
1376
- }
1377
- ;
1378
- this.console[level](str);
1379
- const self = this;
1380
- return () => self.console.groupEnd();
1381
- };
1242
+ $.$mol_owning_map = new WeakMap();
1243
+ function $mol_owning_allow(having) {
1244
+ try {
1245
+ if (!having)
1246
+ return false;
1247
+ if (typeof having !== 'object')
1248
+ return false;
1249
+ if (having instanceof $mol_delegate)
1250
+ return false;
1251
+ if (typeof having['destructor'] !== 'function')
1252
+ return false;
1253
+ return true;
1254
+ }
1255
+ catch {
1256
+ return false;
1257
+ }
1382
1258
  }
1383
- $.$mol_log3_node_make = $mol_log3_node_make;
1384
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
1385
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
1386
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
1387
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
1388
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
1389
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
1259
+ $.$mol_owning_allow = $mol_owning_allow;
1260
+ function $mol_owning_get(having, Owner) {
1261
+ if (!$mol_owning_allow(having))
1262
+ return null;
1263
+ while (true) {
1264
+ const owner = $.$mol_owning_map.get(having);
1265
+ if (!owner)
1266
+ return owner;
1267
+ if (!Owner)
1268
+ return owner;
1269
+ if (owner instanceof Owner)
1270
+ return owner;
1271
+ having = owner;
1272
+ }
1273
+ }
1274
+ $.$mol_owning_get = $mol_owning_get;
1275
+ function $mol_owning_check(owner, having) {
1276
+ if (!$mol_owning_allow(having))
1277
+ return false;
1278
+ if ($.$mol_owning_map.get(having) !== owner)
1279
+ return false;
1280
+ return true;
1281
+ }
1282
+ $.$mol_owning_check = $mol_owning_check;
1283
+ function $mol_owning_catch(owner, having) {
1284
+ if (!$mol_owning_allow(having))
1285
+ return false;
1286
+ if ($.$mol_owning_map.get(having))
1287
+ return false;
1288
+ $.$mol_owning_map.set(having, owner);
1289
+ return true;
1290
+ }
1291
+ $.$mol_owning_catch = $mol_owning_catch;
1390
1292
  })($ || ($ = {}));
1391
- //mol/log3/log3.node.ts
1392
- ;
1393
- "use strict";
1394
- var $;
1395
- (function ($_1) {
1396
- $mol_test_mocks.push($ => {
1397
- $.$mol_log3_come = () => { };
1398
- $.$mol_log3_done = () => { };
1399
- $.$mol_log3_fail = () => { };
1400
- $.$mol_log3_warn = () => { };
1401
- $.$mol_log3_rise = () => { };
1402
- $.$mol_log3_area = () => () => { };
1403
- });
1404
- })($ || ($ = {}));
1405
- //mol/log3/log3.test.ts
1406
- ;
1407
- "use strict";
1408
- var $;
1409
- (function ($) {
1410
- function $mol_env() {
1411
- return {};
1412
- }
1413
- $.$mol_env = $mol_env;
1414
- })($ || ($ = {}));
1415
- //mol/env/env.ts
1416
- ;
1417
- "use strict";
1418
- var $;
1419
- (function ($) {
1420
- $.$mol_env = function $mol_env() {
1421
- return this.process.env;
1422
- };
1423
- })($ || ($ = {}));
1424
- //mol/env/env.node.ts
1425
- ;
1426
- "use strict";
1427
- var $;
1428
- (function ($) {
1429
- function $mol_exec(dir, command, ...args) {
1430
- let [app, ...args0] = command.split(' ');
1431
- args = [...args0, ...args];
1432
- this.$mol_log3_come({
1433
- place: '$mol_exec',
1434
- dir: $node.path.relative('', dir),
1435
- message: 'Run',
1436
- command: `${app} ${args.join(' ')}`,
1437
- });
1438
- var res = $node['child_process'].spawnSync(app, args, {
1439
- cwd: $node.path.resolve(dir),
1440
- shell: true,
1441
- env: this.$mol_env(),
1442
- });
1443
- if (res.status || res.error)
1444
- return $mol_fail(res.error || new Error(res.stderr.toString()));
1445
- if (!res.stdout)
1446
- res.stdout = Buffer.from([]);
1447
- return res;
1448
- }
1449
- $.$mol_exec = $mol_exec;
1450
- })($ || ($ = {}));
1451
- //mol/exec/exec.node.ts
1452
- ;
1453
- "use strict";
1454
- var $;
1455
- (function ($) {
1456
- $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
1457
- function $mol_ambient(overrides) {
1458
- return Object.setPrototypeOf(overrides, this || $);
1459
- }
1460
- $.$mol_ambient = $mol_ambient;
1461
- })($ || ($ = {}));
1462
- //mol/ambient/ambient.ts
1463
- ;
1464
- "use strict";
1465
- var $;
1466
- (function ($) {
1467
- $mol_test({
1468
- 'get'() {
1469
- const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1470
- $mol_assert_equal(proxy.foo, 777);
1471
- },
1472
- 'has'() {
1473
- const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1474
- $mol_assert_equal('foo' in proxy, true);
1475
- },
1476
- 'set'() {
1477
- const target = { foo: 777 };
1478
- const proxy = $mol_delegate({}, () => target);
1479
- proxy.foo = 123;
1480
- $mol_assert_equal(target.foo, 123);
1481
- },
1482
- 'getOwnPropertyDescriptor'() {
1483
- const proxy = $mol_delegate({}, () => ({ foo: 777 }));
1484
- $mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
1485
- value: 777,
1486
- writable: true,
1487
- enumerable: true,
1488
- configurable: true,
1489
- });
1490
- },
1491
- 'ownKeys'() {
1492
- const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
1493
- $mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
1494
- },
1495
- 'getPrototypeOf'() {
1496
- class Foo {
1497
- }
1498
- const proxy = $mol_delegate({}, () => new Foo);
1499
- $mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
1500
- },
1501
- 'setPrototypeOf'() {
1502
- class Foo {
1503
- }
1504
- const target = {};
1505
- const proxy = $mol_delegate({}, () => target);
1506
- Object.setPrototypeOf(proxy, Foo.prototype);
1507
- $mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
1508
- },
1509
- 'instanceof'() {
1510
- class Foo {
1511
- }
1512
- const proxy = $mol_delegate({}, () => new Foo);
1513
- $mol_assert_ok(proxy instanceof Foo);
1514
- $mol_assert_ok(proxy instanceof $mol_delegate);
1515
- },
1516
- 'autobind'() {
1517
- class Foo {
1518
- }
1519
- const proxy = $mol_delegate({}, () => new Foo);
1520
- $mol_assert_ok(proxy instanceof Foo);
1521
- $mol_assert_ok(proxy instanceof $mol_delegate);
1522
- },
1523
- });
1524
- })($ || ($ = {}));
1525
- //mol/delegate/delegate.test.ts
1526
- ;
1527
- "use strict";
1528
- var $;
1529
- (function ($) {
1530
- const instances = new WeakSet();
1531
- function $mol_delegate(proto, target) {
1532
- const proxy = new Proxy(proto, {
1533
- get: (_, field) => {
1534
- const obj = target();
1535
- let val = Reflect.get(obj, field);
1536
- if (typeof val === 'function') {
1537
- val = val.bind(obj);
1538
- }
1539
- return val;
1540
- },
1541
- has: (_, field) => Reflect.has(target(), field),
1542
- set: (_, field, value) => Reflect.set(target(), field, value),
1543
- getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
1544
- ownKeys: () => Reflect.ownKeys(target()),
1545
- getPrototypeOf: () => Reflect.getPrototypeOf(target()),
1546
- setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
1547
- isExtensible: () => Reflect.isExtensible(target()),
1548
- preventExtensions: () => Reflect.preventExtensions(target()),
1549
- apply: (_, self, args) => Reflect.apply(target(), self, args),
1550
- construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
1551
- defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
1552
- deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
1553
- });
1554
- instances.add(proxy);
1555
- return proxy;
1556
- }
1557
- $.$mol_delegate = $mol_delegate;
1558
- Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
1559
- value: (obj) => instances.has(obj),
1560
- });
1561
- })($ || ($ = {}));
1562
- //mol/delegate/delegate.ts
1563
- ;
1564
- "use strict";
1565
- var $;
1566
- (function ($) {
1567
- $.$mol_owning_map = new WeakMap();
1568
- function $mol_owning_allow(having) {
1569
- try {
1570
- if (!having)
1571
- return false;
1572
- if (typeof having !== 'object')
1573
- return false;
1574
- if (having instanceof $mol_delegate)
1575
- return false;
1576
- if (typeof having['destructor'] !== 'function')
1577
- return false;
1578
- return true;
1579
- }
1580
- catch {
1581
- return false;
1582
- }
1583
- }
1584
- $.$mol_owning_allow = $mol_owning_allow;
1585
- function $mol_owning_get(having, Owner) {
1586
- if (!$mol_owning_allow(having))
1587
- return null;
1588
- while (true) {
1589
- const owner = $.$mol_owning_map.get(having);
1590
- if (!owner)
1591
- return owner;
1592
- if (!Owner)
1593
- return owner;
1594
- if (owner instanceof Owner)
1595
- return owner;
1596
- having = owner;
1597
- }
1598
- }
1599
- $.$mol_owning_get = $mol_owning_get;
1600
- function $mol_owning_check(owner, having) {
1601
- if (!$mol_owning_allow(having))
1602
- return false;
1603
- if ($.$mol_owning_map.get(having) !== owner)
1604
- return false;
1605
- return true;
1606
- }
1607
- $.$mol_owning_check = $mol_owning_check;
1608
- function $mol_owning_catch(owner, having) {
1609
- if (!$mol_owning_allow(having))
1610
- return false;
1611
- if ($.$mol_owning_map.get(having))
1612
- return false;
1613
- $.$mol_owning_map.set(having, owner);
1614
- return true;
1615
- }
1616
- $.$mol_owning_catch = $mol_owning_catch;
1617
- })($ || ($ = {}));
1618
- //mol/owning/owning.ts
1293
+ //mol/owning/owning.ts
1619
1294
  ;
1620
1295
  "use strict";
1621
1296
  //mol/type/writable/writable.test.ts
@@ -2082,5 +1757,330 @@ var $;
2082
1757
  $.$mol_tree = $mol_tree;
2083
1758
  })($ || ($ = {}));
2084
1759
  //mol/tree/tree.ts
1760
+ ;
1761
+ "use strict";
1762
+ var $;
1763
+ (function ($) {
1764
+ function $mol_env() {
1765
+ return {};
1766
+ }
1767
+ $.$mol_env = $mol_env;
1768
+ })($ || ($ = {}));
1769
+ //mol/env/env.ts
1770
+ ;
1771
+ "use strict";
1772
+ var $;
1773
+ (function ($) {
1774
+ $.$mol_env = function $mol_env() {
1775
+ return this.process.env;
1776
+ };
1777
+ })($ || ($ = {}));
1778
+ //mol/env/env.node.ts
1779
+ ;
1780
+ "use strict";
1781
+ var $;
1782
+ (function ($) {
1783
+ function $mol_exec(dir, command, ...args) {
1784
+ let [app, ...args0] = command.split(' ');
1785
+ args = [...args0, ...args];
1786
+ this.$mol_log3_come({
1787
+ place: '$mol_exec',
1788
+ dir: $node.path.relative('', dir),
1789
+ message: 'Run',
1790
+ command: `${app} ${args.join(' ')}`,
1791
+ });
1792
+ var res = $node['child_process'].spawnSync(app, args, {
1793
+ cwd: $node.path.resolve(dir),
1794
+ shell: true,
1795
+ env: this.$mol_env(),
1796
+ });
1797
+ if (res.status || res.error)
1798
+ return $mol_fail(res.error || new Error(res.stderr.toString()));
1799
+ if (!res.stdout)
1800
+ res.stdout = Buffer.from([]);
1801
+ return res;
1802
+ }
1803
+ $.$mol_exec = $mol_exec;
1804
+ })($ || ($ = {}));
1805
+ //mol/exec/exec.node.ts
1806
+ ;
1807
+ "use strict";
1808
+ var $;
1809
+ (function ($) {
1810
+ $mol_test({
1811
+ 'escape'() {
1812
+ const specials = $mol_regexp.from('.*+?^${}()|[]\\');
1813
+ $mol_assert_equal(specials.source, '\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\\\');
1814
+ },
1815
+ 'char code'() {
1816
+ const space = $mol_regexp.from(32);
1817
+ $mol_assert_like(' '.match(space), [' ']);
1818
+ },
1819
+ 'repeat fixed'() {
1820
+ const { repeat, decimal_only: digit } = $mol_regexp;
1821
+ const year = repeat(digit, 4, 4);
1822
+ $mol_assert_like('#2020#'.match(year), ['2020']);
1823
+ },
1824
+ 'greedy repeat'() {
1825
+ const { repeat, repeat_greedy, latin_only: letter } = $mol_regexp;
1826
+ $mol_assert_like('abc'.match(repeat(letter, 1, 2)), ['a', 'b', 'c']);
1827
+ $mol_assert_like('abc'.match(repeat_greedy(letter, 1, 2)), ['ab', 'c']);
1828
+ },
1829
+ 'repeat range'() {
1830
+ const { repeat_greedy, decimal_only: digit } = $mol_regexp;
1831
+ const year = repeat_greedy(digit, 2, 4);
1832
+ $mol_assert_like('#2#'.match(year), null);
1833
+ $mol_assert_like('#20#'.match(year), ['20']);
1834
+ $mol_assert_like('#2020#'.match(year), ['2020']);
1835
+ $mol_assert_like('#20201#'.match(year), ['2020']);
1836
+ },
1837
+ 'repeat from'() {
1838
+ const { repeat_greedy, latin_only: letter } = $mol_regexp;
1839
+ const name = repeat_greedy(letter, 2);
1840
+ $mol_assert_like('##'.match(name), null);
1841
+ $mol_assert_like('#a#'.match(name), null);
1842
+ $mol_assert_like('#ab#'.match(name), ['ab']);
1843
+ $mol_assert_like('#abc#'.match(name), ['abc']);
1844
+ },
1845
+ 'from string'() {
1846
+ const regexp = $mol_regexp.from('[\\d]');
1847
+ $mol_assert_equal(regexp.source, '\\[\\\\d\\]');
1848
+ $mol_assert_equal(regexp.flags, 'gsu');
1849
+ },
1850
+ 'from regexp'() {
1851
+ const regexp = $mol_regexp.from(/[\d]/i);
1852
+ $mol_assert_equal(regexp.source, '[\\d]');
1853
+ $mol_assert_equal(regexp.flags, 'i');
1854
+ },
1855
+ 'split'() {
1856
+ const regexp = $mol_regexp.from(';');
1857
+ $mol_assert_like('aaa;bbb;ccc'.split(regexp), ['aaa', ';', 'bbb', ';', 'ccc']);
1858
+ $mol_assert_like('aaa;;ccc'.split(regexp), ['aaa', ';', '', ';', 'ccc']);
1859
+ $mol_assert_like('aaa'.split(regexp), ['aaa']);
1860
+ $mol_assert_like(''.split(regexp), ['']);
1861
+ },
1862
+ 'test for matching'() {
1863
+ const regexp = $mol_regexp.from('foo');
1864
+ $mol_assert_like(regexp.test(''), false);
1865
+ $mol_assert_like(regexp.test('fo'), false);
1866
+ $mol_assert_like(regexp.test('foo'), true);
1867
+ $mol_assert_like(regexp.test('foobar'), true);
1868
+ $mol_assert_like(regexp.test('barfoo'), true);
1869
+ },
1870
+ 'case ignoring'() {
1871
+ const xxx = $mol_regexp.from('x', { ignoreCase: true });
1872
+ $mol_assert_like(xxx.flags, 'gisu');
1873
+ $mol_assert_like(xxx.exec('xx')[0], 'x');
1874
+ $mol_assert_like(xxx.exec('XX')[0], 'X');
1875
+ },
1876
+ 'multiline mode'() {
1877
+ const { end, from } = $mol_regexp;
1878
+ const xxx = from(['x', end], { multiline: true });
1879
+ $mol_assert_like(xxx.exec('x\ny')[0], 'x');
1880
+ $mol_assert_like(xxx.flags, 'gmsu');
1881
+ },
1882
+ 'flags override'() {
1883
+ const triplet = $mol_regexp.from($mol_regexp.from(/.../, { ignoreCase: true }), { multiline: true });
1884
+ $mol_assert_like(triplet.toString(), '/.../gmsu');
1885
+ },
1886
+ 'sequence'() {
1887
+ const { begin, end, decimal_only: digit, repeat, from } = $mol_regexp;
1888
+ const year = repeat(digit, 4, 4);
1889
+ const dash = '-';
1890
+ const month = repeat(digit, 2, 2);
1891
+ const day = repeat(digit, 2, 2);
1892
+ const date = from([begin, year, dash, month, dash, day, end]);
1893
+ $mol_assert_like(date.exec('2020-01-02')[0], '2020-01-02');
1894
+ },
1895
+ 'optional'() {
1896
+ const name = $mol_regexp.from(['A', ['4']]);
1897
+ $mol_assert_equal('AB'.match(name)[0], 'A');
1898
+ $mol_assert_equal('A4'.match(name)[0], 'A4');
1899
+ },
1900
+ 'only groups'() {
1901
+ const regexp = $mol_regexp.from({ dog: '@' });
1902
+ $mol_assert_like([...'#'.matchAll(regexp)][0].groups, undefined);
1903
+ $mol_assert_like([...'@'.matchAll(regexp)][0].groups, { dog: '@' });
1904
+ },
1905
+ 'catch skipped'() {
1906
+ const regexp = $mol_regexp.from(/(@)(\d?)/g);
1907
+ $mol_assert_like([...'[[@]]'.matchAll(regexp)].map(f => [...f]), [
1908
+ ['[['],
1909
+ ['@', '@', ''],
1910
+ [']]'],
1911
+ ]);
1912
+ },
1913
+ 'enum variants'() {
1914
+ let Sex;
1915
+ (function (Sex) {
1916
+ Sex["male"] = "male";
1917
+ Sex["female"] = "female";
1918
+ })(Sex || (Sex = {}));
1919
+ const sexism = $mol_regexp.from(Sex);
1920
+ $mol_assert_like([...''.matchAll(sexism)].length, 0);
1921
+ $mol_assert_like([...'trans'.matchAll(sexism)][0].groups, undefined);
1922
+ $mol_assert_like([...'male'.matchAll(sexism)][0].groups, { male: 'male', female: '' });
1923
+ $mol_assert_like([...'female'.matchAll(sexism)][0].groups, { male: '', female: 'female' });
1924
+ },
1925
+ 'recursive only groups'() {
1926
+ let Sex;
1927
+ (function (Sex) {
1928
+ Sex["male"] = "male";
1929
+ Sex["female"] = "female";
1930
+ })(Sex || (Sex = {}));
1931
+ const sexism = $mol_regexp.from({ Sex });
1932
+ $mol_assert_like([...''.matchAll(sexism)].length, 0);
1933
+ $mol_assert_like([...'male'.matchAll(sexism)][0].groups, { Sex: 'male', male: 'male', female: '' });
1934
+ $mol_assert_like([...'female'.matchAll(sexism)][0].groups, { Sex: 'female', male: '', female: 'female' });
1935
+ },
1936
+ 'sequence with groups'() {
1937
+ const { begin, end, decimal_only: digit, repeat, from } = $mol_regexp;
1938
+ const year = repeat(digit, 4, 4);
1939
+ const dash = '-';
1940
+ const month = repeat(digit, 2, 2);
1941
+ const day = repeat(digit, 2, 2);
1942
+ const regexp = from([begin, { year }, dash, { month }, dash, { day }, end]);
1943
+ const found = [...'2020-01-02'.matchAll(regexp)];
1944
+ $mol_assert_like(found[0].groups, {
1945
+ year: '2020',
1946
+ month: '01',
1947
+ day: '02',
1948
+ });
1949
+ },
1950
+ 'sequence with groups of mixed type'() {
1951
+ const prefix = '/';
1952
+ const postfix = '/';
1953
+ const regexp = $mol_regexp.from([{ prefix }, /(\w+)/, { postfix }, /([gumi]*)/]);
1954
+ $mol_assert_like([...'/foo/mi'.matchAll(regexp)], [
1955
+ Object.assign(["/foo/mi", "/", "foo", "/", "mi"], {
1956
+ groups: {
1957
+ prefix: '/',
1958
+ postfix: '/',
1959
+ },
1960
+ index: 0,
1961
+ input: "/",
1962
+ }),
1963
+ ]);
1964
+ },
1965
+ 'recursive sequence with groups'() {
1966
+ const { begin, end, decimal_only: digit, repeat, from } = $mol_regexp;
1967
+ const year = repeat(digit, 4, 4);
1968
+ const dash = '-';
1969
+ const month = repeat(digit, 2, 2);
1970
+ const day = repeat(digit, 2, 2);
1971
+ const regexp = from([
1972
+ begin, { date: [{ year }, dash, { month }] }, dash, { day }, end
1973
+ ]);
1974
+ const found = [...'2020-01-02'.matchAll(regexp)];
1975
+ $mol_assert_like(found[0].groups, {
1976
+ date: '2020-01',
1977
+ year: '2020',
1978
+ month: '01',
1979
+ day: '02',
1980
+ });
1981
+ },
1982
+ 'parse multiple'() {
1983
+ const { decimal_only: digit, from } = $mol_regexp;
1984
+ const regexp = from({ digit });
1985
+ $mol_assert_like([...'123'.matchAll(regexp)].map(f => f.groups), [
1986
+ { digit: '1' },
1987
+ { digit: '2' },
1988
+ { digit: '3' },
1989
+ ]);
1990
+ },
1991
+ 'variants'() {
1992
+ const { begin, or, end, from } = $mol_regexp;
1993
+ const sexism = from([
1994
+ begin, 'sex = ', { sex: ['male', or, 'female'] }, end
1995
+ ]);
1996
+ $mol_assert_like([...'sex = male'.matchAll(sexism)][0].groups, { sex: 'male' });
1997
+ $mol_assert_like([...'sex = female'.matchAll(sexism)][0].groups, { sex: 'female' });
1998
+ $mol_assert_like([...'sex = malefemale'.matchAll(sexism)][0].groups, undefined);
1999
+ },
2000
+ 'force after'() {
2001
+ const { latin_only: letter, force_after, from } = $mol_regexp;
2002
+ const regexp = from([letter, force_after('.')]);
2003
+ $mol_assert_like('x.'.match(regexp), ['x']);
2004
+ $mol_assert_like('x,'.match(regexp), null);
2005
+ },
2006
+ 'forbid after'() {
2007
+ const { latin_only: letter, forbid_after, from } = $mol_regexp;
2008
+ const regexp = from([letter, forbid_after('.')]);
2009
+ $mol_assert_like('x.'.match(regexp), null);
2010
+ $mol_assert_like('x,'.match(regexp), ['x']);
2011
+ },
2012
+ 'char except'() {
2013
+ const { char_except, latin_only, tab } = $mol_regexp;
2014
+ const name = char_except(latin_only, tab);
2015
+ $mol_assert_like('a'.match(name), null);
2016
+ $mol_assert_like('\t'.match(name), null);
2017
+ $mol_assert_like('('.match(name), ['(']);
2018
+ },
2019
+ 'unicode only'() {
2020
+ const { unicode_only, from } = $mol_regexp;
2021
+ const name = from([
2022
+ unicode_only('Script', 'Cyrillic'),
2023
+ unicode_only('Hex_Digit'),
2024
+ ]);
2025
+ $mol_assert_like('FF'.match(name), null);
2026
+ $mol_assert_like('ФG'.match(name), null);
2027
+ $mol_assert_like('ФF'.match(name), ['ФF']);
2028
+ },
2029
+ 'generate by optional with inner group'() {
2030
+ const { begin, end, from } = $mol_regexp;
2031
+ const animals = from([begin, '#', ['^', { dog: '@' }], end]);
2032
+ $mol_assert_equal(animals.generate({}), '#');
2033
+ $mol_assert_equal(animals.generate({ dog: false }), '#');
2034
+ $mol_assert_equal(animals.generate({ dog: true }), '#^@');
2035
+ $mol_assert_fail(() => animals.generate({ dog: '$' }), 'Wrong param: dog=$');
2036
+ },
2037
+ 'generate by optional with inner group with variants'() {
2038
+ const { begin, end, from } = $mol_regexp;
2039
+ const animals = from([begin, '#', ['^', { animal: { dog: '@', fox: '&' } }], end]);
2040
+ $mol_assert_equal(animals.generate({}), '#');
2041
+ $mol_assert_equal(animals.generate({ dog: true }), '#^@');
2042
+ $mol_assert_equal(animals.generate({ fox: true }), '#^&');
2043
+ $mol_assert_fail(() => animals.generate({ dog: '$' }), 'Wrong param: dog=$');
2044
+ },
2045
+ 'complex example'() {
2046
+ const { begin, end, char_only, char_range, latin_only, slash_back, repeat_greedy, from, } = $mol_regexp;
2047
+ const atom_char = char_only(latin_only, "!#$%&'*+/=?^`{|}~-");
2048
+ const atom = repeat_greedy(atom_char, 1);
2049
+ const dot_atom = from([atom, repeat_greedy(['.', atom])]);
2050
+ const name_letter = char_only(char_range(0x01, 0x08), 0x0b, 0x0c, char_range(0x0e, 0x1f), 0x21, char_range(0x23, 0x5b), char_range(0x5d, 0x7f));
2051
+ const quoted_pair = from([
2052
+ slash_back,
2053
+ char_only(char_range(0x01, 0x09), 0x0b, 0x0c, char_range(0x0e, 0x7f))
2054
+ ]);
2055
+ const name = repeat_greedy({ name_letter, quoted_pair });
2056
+ const quoted_name = from(['"', { name }, '"']);
2057
+ const local_part = from({ dot_atom, quoted_name });
2058
+ const domain = dot_atom;
2059
+ const mail = from([begin, local_part, '@', { domain }, end]);
2060
+ $mol_assert_equal('foo..bar@example.org'.match(mail), null);
2061
+ $mol_assert_equal('foo..bar"@example.org'.match(mail), null);
2062
+ $mol_assert_like([...'foo.bar@example.org'.matchAll(mail)][0].groups, {
2063
+ domain: "example.org",
2064
+ dot_atom: "foo.bar",
2065
+ name: "",
2066
+ name_letter: "",
2067
+ quoted_name: "",
2068
+ quoted_pair: "",
2069
+ });
2070
+ $mol_assert_like([...'"foo..bar"@example.org'.matchAll(mail)][0].groups, {
2071
+ dot_atom: "",
2072
+ quoted_name: '"foo..bar"',
2073
+ name: "foo..bar",
2074
+ name_letter: "r",
2075
+ quoted_pair: "",
2076
+ domain: "example.org",
2077
+ });
2078
+ $mol_assert_equal(mail.generate({ dot_atom: 'foo.bar', domain: 'example.org' }), 'foo.bar@example.org');
2079
+ $mol_assert_equal(mail.generate({ name: 'foo..bar', domain: 'example.org' }), '"foo..bar"@example.org');
2080
+ $mol_assert_fail(() => mail.generate({ dot_atom: 'foo..bar', domain: 'example.org' }), 'Wrong param: dot_atom=foo..bar');
2081
+ },
2082
+ });
2083
+ })($ || ($ = {}));
2084
+ //mol/regexp/regexp.test.ts
2085
2085
 
2086
2086
  //# sourceMappingURL=node.test.js.map