Skip to content

Commit 5b682ac

Browse files
authored
🤖 Merge PR DefinitelyTyped#73068 [russian-nouns-js] restore deleted test file and add author by @RusAnonym
1 parent 2420166 commit 5b682ac

File tree

3 files changed

+217
-2
lines changed

3 files changed

+217
-2
lines changed

types/russian-nouns-js/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
{
1313
"name": "RusAnonym",
1414
"githubUsername": "RusAnonym"
15+
},
16+
{
17+
"name": "georgy7",
18+
"githubUsername": "georgy7"
1519
}
1620
]
1721
}
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
// <editor-fold defaultstate="collapsed" desc="Assertion functions">
2+
let anAssertionFailed: boolean = false;
3+
4+
function assertEquals(a: any, b: any, msg?: string) {
5+
if (anAssertionFailed) {
6+
return;
7+
}
8+
9+
if (a !== b) {
10+
console.log(`Assertion error: ${a} !== ${b}`);
11+
12+
if (msg) {
13+
console.log(msg);
14+
}
15+
16+
console.log("Runtime check failed!");
17+
anAssertionFailed = true;
18+
}
19+
}
20+
21+
function assertEqualsSingleValue(array: string[], value: string) {
22+
if (anAssertionFailed) {
23+
return;
24+
}
25+
26+
assertEquals(array.length, 1, `len([${array}]) !== 1`);
27+
assertEquals(array[0], value);
28+
}
29+
30+
function assertAllCases(
31+
results: Array<string[]>,
32+
values: Array<string[] | string>,
33+
) {
34+
if (anAssertionFailed) {
35+
return;
36+
}
37+
38+
assertEquals(results.length, 7);
39+
assertEquals(values.length, 7);
40+
41+
for (let i = 0; i < 7; i++) {
42+
const result = results[i];
43+
const value = values[i];
44+
45+
if (typeof value === "string") {
46+
assertEqualsSingleValue(result, value);
47+
} else if (value instanceof Array) {
48+
assertEquals(result.length, value.length, "Incorrect length.");
49+
for (let j = 0; j < value.length; j++) {
50+
assertEquals(result[j], value[j]);
51+
}
52+
} else {
53+
console.log(`${value} is neither an array nor a string.`);
54+
console.log("Runtime check failed!");
55+
anAssertionFailed = true;
56+
}
57+
}
58+
}
59+
60+
function report(msg: string) {
61+
if (anAssertionFailed) {
62+
return;
63+
}
64+
65+
console.log(msg);
66+
}
67+
// </editor-fold>
68+
69+
import {
70+
Case,
71+
CASES,
72+
createLemma,
73+
createLemmaOrNull,
74+
Engine,
75+
Gender,
76+
Lemma,
77+
LocativeForm,
78+
LocativeFormAttribute,
79+
} from "russian-nouns-js";
80+
81+
const rne = new Engine();
82+
83+
let result: string[];
84+
85+
result = rne.decline({ text: "имя", gender: Gender.NEUTER }, Case.GENITIVE);
86+
assertEqualsSingleValue(result, "имени");
87+
88+
result = rne.decline({ text: "имя", gender: Gender.NEUTER }, Case.INSTRUMENTAL);
89+
assertEqualsSingleValue(result, "именем");
90+
91+
let coat: Lemma = createLemma({
92+
text: "пальто",
93+
gender: Gender.NEUTER,
94+
indeclinable: true,
95+
});
96+
97+
result = rne.decline(coat, Case.GENITIVE);
98+
assertEqualsSingleValue(result, "пальто");
99+
100+
assertEquals(coat.getDeclension(), -1);
101+
102+
let mountain: Lemma = createLemma({
103+
text: "гора",
104+
gender: Gender.FEMININE,
105+
});
106+
107+
let results: string[][] = CASES.map(function(c: Case) {
108+
return rne.decline(mountain, c);
109+
});
110+
111+
assertAllCases(results, ["гора", "горы", "горе", "гору", ["горой", "горою"], "горе", "горе"]);
112+
113+
result = rne.pluralize(mountain);
114+
assertEqualsSingleValue(result, "горы");
115+
const pluralMountain: string = result[0];
116+
117+
results = CASES.map(function(c: Case) {
118+
return rne.decline(mountain, c, pluralMountain);
119+
});
120+
121+
assertAllCases(results, ["горы", "гор", "горам", "горы", "горами", "горах", "горах"]);
122+
123+
assertEquals(mountain.getDeclension(), 2);
124+
assertEquals(mountain.getSchoolDeclension(), 1);
125+
126+
let mountainGender: Gender | undefined = mountain.getGender();
127+
assertEquals(mountainGender, Gender.FEMININE);
128+
129+
assertEquals(null, createLemmaOrNull({ text: "абвгд" }));
130+
131+
(() => {
132+
let x: Lemma | null = createLemmaOrNull({
133+
text: "гора",
134+
gender: Gender.FEMININE,
135+
});
136+
137+
assertEquals(x != null, true);
138+
139+
if (x != null) {
140+
assertEquals(x.text(), "гора");
141+
}
142+
})();
143+
144+
report(" Main functions (8) ............... OK");
145+
146+
let cringe: Lemma = createLemma({
147+
text: "кринж",
148+
gender: Gender.MASCULINE,
149+
});
150+
151+
result = rne.decline(cringe, Case.INSTRUMENTAL);
152+
assertEqualsSingleValue(result, "кринжем");
153+
154+
rne.sd.put(cringe, "SEESESE-EEEEEE");
155+
result = rne.decline(cringe, Case.INSTRUMENTAL);
156+
assertEqualsSingleValue(result, "кринжом");
157+
158+
assertEquals(rne.sd.hasStressedEndingSingular(cringe, Case.INSTRUMENTAL).length, 1);
159+
assertEquals(rne.sd.hasStressedEndingSingular(cringe, Case.INSTRUMENTAL)[0], true);
160+
161+
rne.sd.put(cringe, "SEESbSE-EEEEEE");
162+
result = rne.decline(cringe, Case.INSTRUMENTAL);
163+
assertEquals(result.length, 2);
164+
assertEquals(result[0], "кринжем");
165+
assertEquals(result[1], "кринжом");
166+
167+
rne.sd.put(cringe, "SEESsSE-EEEEEE");
168+
result = rne.decline(cringe, Case.INSTRUMENTAL);
169+
assertEquals(result.length, 2);
170+
assertEquals(result[0], "кринжем");
171+
assertEquals(result[1], "кринжом");
172+
173+
rne.sd.put(cringe, "SEESeSE-EEEEEE");
174+
result = rne.decline(cringe, Case.INSTRUMENTAL);
175+
assertEquals(result.length, 2);
176+
assertEquals(result[0], "кринжом");
177+
assertEquals(result[1], "кринжем");
178+
179+
assertEquals(rne.sd.hasStressedEndingSingular(cringe, Case.INSTRUMENTAL).length, 2);
180+
assertEquals(rne.sd.hasStressedEndingSingular(cringe, Case.INSTRUMENTAL)[0], true);
181+
assertEquals(rne.sd.hasStressedEndingSingular(cringe, Case.INSTRUMENTAL)[1], false);
182+
183+
report(" StressDictionary (9) ............. OK");
184+
185+
let row: Lemma = createLemma({
186+
text: "ряд",
187+
gender: Gender.MASCULINE,
188+
});
189+
190+
results = CASES.map(function(c: Case) {
191+
return rne.decline(row, c);
192+
});
193+
194+
assertAllCases(results, ["ряд", "ряда", "ряду", "ряд", "рядом", "ряде", "ряду"]);
195+
196+
let rowLocativeForms: LocativeForm[] = rne.getLocativeForms(row);
197+
198+
assertEquals(rowLocativeForms.length, 1, "locative forms count");
199+
assertEquals(rowLocativeForms[0].preposition, "в", "lf.preposition");
200+
assertEquals(rowLocativeForms[0].attributes > 0, true, "lf.semantics > 0");
201+
assertEquals(rowLocativeForms[0].word, "ряду", "lf.word");
202+
203+
assertEquals(
204+
rowLocativeForms[0].attributes,
205+
LocativeFormAttribute.STRUCTURE,
206+
"lf.semantics",
207+
);
208+
209+
report(" LocativeForm (10) ................ OK");

types/russian-nouns-js/tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"compilerOptions": {
33
"module": "node16",
44
"lib": [
5-
"es6"
5+
"es6",
6+
"dom"
67
],
78
"noImplicitAny": true,
89
"noImplicitThis": true,
@@ -13,6 +14,7 @@
1314
"forceConsistentCasingInFileNames": true
1415
},
1516
"files": [
16-
"index.d.ts"
17+
"index.d.ts",
18+
"russian-nouns-js-tests.ts"
1719
]
1820
}

0 commit comments

Comments
 (0)