Commit 9afad9f5 authored by Ludan Stoecklé's avatar Ludan Stoecklé

ing stuff

parent 9838a3ac
......@@ -13,6 +13,8 @@ export interface ExtraParams {
WILL?: boolean;
}
// helpers
function getIrregularPreterit(verbsInfo: VerbsInfo, verb: string): string {
if (verbsInfo && verbsInfo[verb] && verbsInfo[verb].length != 0) {
const verbInfo = verbsInfo[verb];
......@@ -26,6 +28,27 @@ function getIrregularPreterit(verbsInfo: VerbsInfo, verb: string): string {
}
}
const consonants = 'bcdfghjklmnpqrstvxzw';
export function getIng(verb: string): string {
if (verb.match(new RegExp(`[${consonants}]e$`, 'g'))) {
// If the infinitive ends with a consonant followed by an –e,
// you have to take off the –e to form your present participle.
return verb.substring(0, verb.length - 1) + 'ing';
} else if (verb.match(new RegExp(`[aeiou][${consonants}]$`, 'g'))) {
// If the infinitive ends with one vowel followed by one consonant(except of –y),
// you have to double this consonant to form your present participle.
return verb + verb.charAt(verb.length - 1) + 'ing';
} else if (verb.endsWith('ie')) {
// If the infinitive ends with –ie,
// the letters are replaced by –y followed by –ing in the past participle form.
return verb.substring(0, verb.length - 2) + 'y' + 'ing';
} else {
return verb + 'ing';
}
}
// 1 per tense
function getSimplePast(verbsInfo: VerbsInfo, verb: string, number: Numbers): string {
let irregular: string;
if (verb === 'be') {
......
......@@ -51,6 +51,26 @@ const testCases = {
FUTURE: [['rest', 'S', 'will rest']],
};
// https://www.usingenglish.com/reference/irregular-verbs/shoe.html
const testCasesIng = [
['find', 'finding'],
['laugh', 'laughing'],
['wash', 'washing'],
['arise', 'arising'],
['become', 'becoming'],
['have', 'having'],
['get', 'getting'],
['let', 'letting'],
['plan', 'planning'],
['die', 'dying'],
['lie', 'lying'],
['dare', 'daring'],
['ban', 'banning'],
['fit', 'fitting'],
['shoe', 'shoeing'],
['pay', 'paying'],
];
describe('english-verbs', function() {
describe('#getConjugation()', function() {
describe('nominal cases', function() {
......@@ -86,6 +106,16 @@ describe('english-verbs', function() {
});
}
});
describe('ing form', function() {
for (let i = 0; i < testCasesIng.length; i++) {
const testCase = testCasesIng[i];
const verb = testCase[0];
const expected = testCase[1];
it(`${verb} => ${expected}`, function() {
assert.equal(EnglishVerbs.getIng(verb), expected);
});
}
});
describe('edge cases', function() {
it(`null verb`, function() {
assert.throws(() => EnglishVerbs.getConjugation(null, null, 'PRESENT', 'S'), /verb/);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment