Fixing cut to allow cutting one thing multiple times

This commit is contained in:
Jean Viscogliosi-Pate 2025-08-18 06:54:22 -07:00
parent 366cf11034
commit 2204fb141d
3 changed files with 3 additions and 9 deletions

View File

@ -57,9 +57,6 @@ const options = {
} }
} }
/* Invalid input */
metamorpov.translate({}, options.firstPerson);
/* vrb, vrn */ /* vrb, vrn */
assert.equal(metamorpov.translate("vrb/be/", options.firstPerson), "was"); // I was assert.equal(metamorpov.translate("vrb/be/", options.firstPerson), "was"); // I was
assert.equal(metamorpov.translate("vrb/be/", options.secondPerson), "were"); // You were assert.equal(metamorpov.translate("vrb/be/", options.secondPerson), "were"); // You were
@ -188,6 +185,7 @@ assert.equal(metamorpov.translate("cut/only last 1/word/", options.firstPerson),
assert.equal(metamorpov.translate("cut/only last 2/word/", options.firstPerson), "rd"); assert.equal(metamorpov.translate("cut/only last 2/word/", options.firstPerson), "rd");
assert.equal(metamorpov.translate("cut/only last 3/word/", options.firstPerson), "ord"); assert.equal(metamorpov.translate("cut/only last 3/word/", options.firstPerson), "ord");
assert.equal(metamorpov.translate("cut/only last 4/word/", options.firstPerson), "ord"); // Cut at least one letter assert.equal(metamorpov.translate("cut/only last 4/word/", options.firstPerson), "ord"); // Cut at least one letter
assert.equal(metamorpov.translate("cut/off first 1/cut/off last 1/word//", options.firstPerson), "or"); // Cut twice
assert.equal(metamorpov.translate("cut/only first 1/word/oah", options.firstPerson), "woah"); // Should continue after replacing assert.equal(metamorpov.translate("cut/only first 1/word/oah", options.firstPerson), "woah"); // Should continue after replacing
assert.equal(metamorpov.translate("cut/off last 1/ab/ cut/only last 2/abc/", options.firstPerson), "a bc"); // Should replace both assert.equal(metamorpov.translate("cut/off last 1/ab/ cut/only last 2/abc/", options.firstPerson), "a bc"); // Should replace both

View File

@ -434,7 +434,7 @@ function cut(request) {
/cut\/(?<offonly>off|only) /, /cut\/(?<offonly>off|only) /,
/(?<firstlast>first|last) /, /(?<firstlast>first|last) /,
/(?<index>[1-9][0-9]*)\//, /(?<index>[1-9][0-9]*)\//,
/(?<target>[^\/]+)\// /(?<target>(?!cut\/)[^\/]+)\//
].map(r => r.source).join(''), 'i'); ].map(r => r.source).join(''), 'i');
request.loop(request, { request.loop(request, {
regexp: regexp regexp: regexp

6
package-lock.json generated
View File

@ -8,7 +8,7 @@
"name": "metamorpov", "name": "metamorpov",
"version": "1.0.0", "version": "1.0.0",
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"devDependencies": { "dependencies": {
"english-verbs-gerunds": "^3.4.0", "english-verbs-gerunds": "^3.4.0",
"english-verbs-helper": "^3.4.0", "english-verbs-helper": "^3.4.0",
"english-verbs-irregular": "^3.4.0", "english-verbs-irregular": "^3.4.0",
@ -19,14 +19,12 @@
"version": "3.4.0", "version": "3.4.0",
"resolved": "https://registry.npmjs.org/english-verbs-gerunds/-/english-verbs-gerunds-3.4.0.tgz", "resolved": "https://registry.npmjs.org/english-verbs-gerunds/-/english-verbs-gerunds-3.4.0.tgz",
"integrity": "sha512-sc6Zgm7Du+KKIloln0GzcT/fZxIqJBXlfU9B8DLi1bPmKK/hVK3HsRWywNaAGwHU4+SpZ7ADvLvoXlMI2PkwUw==", "integrity": "sha512-sc6Zgm7Du+KKIloln0GzcT/fZxIqJBXlfU9B8DLi1bPmKK/hVK3HsRWywNaAGwHU4+SpZ7ADvLvoXlMI2PkwUw==",
"dev": true,
"license": "Apache-2.0" "license": "Apache-2.0"
}, },
"node_modules/english-verbs-helper": { "node_modules/english-verbs-helper": {
"version": "3.4.0", "version": "3.4.0",
"resolved": "https://registry.npmjs.org/english-verbs-helper/-/english-verbs-helper-3.4.0.tgz", "resolved": "https://registry.npmjs.org/english-verbs-helper/-/english-verbs-helper-3.4.0.tgz",
"integrity": "sha512-yP1msoIysGuUolx1s3K7dHj5ASqitjHN3PAe3rrF7/mbcHqg1VaLyGVII7Onkv3AHnrPqMT6ITiPtd2rccE7eg==", "integrity": "sha512-yP1msoIysGuUolx1s3K7dHj5ASqitjHN3PAe3rrF7/mbcHqg1VaLyGVII7Onkv3AHnrPqMT6ITiPtd2rccE7eg==",
"dev": true,
"license": "Apache-2.0", "license": "Apache-2.0",
"funding": { "funding": {
"type": "patreon", "type": "patreon",
@ -37,14 +35,12 @@
"version": "3.4.0", "version": "3.4.0",
"resolved": "https://registry.npmjs.org/english-verbs-irregular/-/english-verbs-irregular-3.4.0.tgz", "resolved": "https://registry.npmjs.org/english-verbs-irregular/-/english-verbs-irregular-3.4.0.tgz",
"integrity": "sha512-Rk0fgdzJ0oqpERPHr6QV2Dp8nnNKO3Si92RWYCe7fgxks8+yEOtUDu0ZBm3AJ6Ccqaa5ZtVh/pndUYdbKkr7xg==", "integrity": "sha512-Rk0fgdzJ0oqpERPHr6QV2Dp8nnNKO3Si92RWYCe7fgxks8+yEOtUDu0ZBm3AJ6Ccqaa5ZtVh/pndUYdbKkr7xg==",
"dev": true,
"license": "Apache-2.0" "license": "Apache-2.0"
}, },
"node_modules/indefinite": { "node_modules/indefinite": {
"version": "2.5.1", "version": "2.5.1",
"resolved": "https://registry.npmjs.org/indefinite/-/indefinite-2.5.1.tgz", "resolved": "https://registry.npmjs.org/indefinite/-/indefinite-2.5.1.tgz",
"integrity": "sha512-Ul0hCdnSjuFDEloYWeozTaEfljbz+0q+u4HsHns2dOk2DlhGlbRMGFtNcIL+Ve7sZYeIOTOAKA0usAXBGHpNDg==", "integrity": "sha512-Ul0hCdnSjuFDEloYWeozTaEfljbz+0q+u4HsHns2dOk2DlhGlbRMGFtNcIL+Ve7sZYeIOTOAKA0usAXBGHpNDg==",
"dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">=6.0.0" "node": ">=6.0.0"