Skip to content

Commit b7ef2b9

Browse files
committed
test: add comparison tests against original gettext-parser
Introduce tests to ensure identical behavior between the forked gettext-parser and the original library, covering parsing and compilation for PO and MO files. Include a test-specific package with dependencies.
1 parent 41d12bb commit b7ef2b9

5 files changed

Lines changed: 151 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ jobs:
3030
with:
3131
node-version: ${{ matrix.node-version }}
3232
- run: npm install
33+
- run: npm run test:install
3334
- run: npm run build
3435
- run: npm run test:coverage

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gettext-parser-next",
33
"description": "Parse and compile gettext po and mo files to/from json, nothing more, nothing less",
44
"version": "1.0.0",
5-
"author": "",
5+
"author": ["Erik <erik@codekraft.it>", "john <john@codekraft.it>"],
66
"homepage": "http://github.com/smhg/gettext-parser",
77
"repository": {
88
"type": "git",
@@ -24,6 +24,14 @@
2424
}
2525
}
2626
},
27+
"files": [
28+
"lib/",
29+
"tests/*.ts",
30+
"*.json",
31+
"*.md",
32+
".gitignore",
33+
"LICENSE"
34+
],
2735
"engines": {
2836
"node": ">=18"
2937
},
@@ -32,6 +40,7 @@
3240
"build": "tsdown",
3341
"lint": "npx @biomejs/biome check --write ./src",
3442
"test": "node --test",
43+
"test:install": "cd test && npm install",
3544
"test:coverage": "node --test --experimental-test-coverage",
3645
"preversion": "npx publint && npm run lint && npm test",
3746
"postversion": "git push && git push --tags",

test/compare-test.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { promisify } from 'node:util';
2+
import path from 'node:path';
3+
import { readFile as fsReadFile } from 'node:fs';
4+
import { fileURLToPath } from 'node:url';
5+
import { describe, test } from 'node:test';
6+
import assert from 'node:assert';
7+
8+
import originalGettextParser from 'gettext-parser';
9+
import * as forkedGettextParser from '../lib/index.mjs';
10+
11+
const __filename = fileURLToPath(import.meta.url);
12+
const __dirname = path.dirname(__filename);
13+
14+
const readFile = promisify(fsReadFile);
15+
16+
describe('Compare with original gettext-parser', () => {
17+
describe('PO Parser', () => {
18+
test('should parse utf8.po identically', async () => {
19+
const poData = await readFile(path.join(__dirname, 'fixtures/utf8.po'));
20+
const originalParsed = originalGettextParser.po.parse(poData);
21+
const forkedParsed = forkedGettextParser.po.parse(poData);
22+
// We shouldn't assert on strict equality of Date objects or undefined vs non-existent keys,
23+
// but deepStrictEqual will cover basic deep comparison.
24+
assert.deepStrictEqual(forkedParsed, originalParsed);
25+
});
26+
27+
test('should parse latin13.po identically', async () => {
28+
const poData = await readFile(path.join(__dirname, 'fixtures/latin13.po'));
29+
const originalParsed = originalGettextParser.po.parse(poData);
30+
const forkedParsed = forkedGettextParser.po.parse(poData);
31+
assert.deepStrictEqual(forkedParsed, originalParsed);
32+
});
33+
});
34+
35+
describe('MO Parser', () => {
36+
test('should parse utf8.mo identically', async () => {
37+
const moData = await readFile(path.join(__dirname, 'fixtures/utf8.mo'));
38+
const originalParsed = originalGettextParser.mo.parse(moData);
39+
const forkedParsed = forkedGettextParser.mo.parse(moData);
40+
assert.deepStrictEqual(forkedParsed, originalParsed);
41+
});
42+
43+
test('should parse latin13.mo identically', async () => {
44+
const moData = await readFile(path.join(__dirname, 'fixtures/latin13.mo'));
45+
const originalParsed = originalGettextParser.mo.parse(moData);
46+
const forkedParsed = forkedGettextParser.mo.parse(moData);
47+
assert.deepStrictEqual(forkedParsed, originalParsed);
48+
});
49+
});
50+
51+
describe('PO Compiler', () => {
52+
test('should compile utf8-po.json identically', async () => {
53+
const json = await readFile(path.join(__dirname, 'fixtures/utf8-po.json'), 'utf8');
54+
const parsed = JSON.parse(json);
55+
const originalCompiled = originalGettextParser.po.compile(parsed);
56+
const forkedCompiled = forkedGettextParser.po.compile(parsed);
57+
assert.deepStrictEqual(forkedCompiled, originalCompiled);
58+
});
59+
});
60+
61+
describe('MO Compiler', () => {
62+
test('should compile utf8-mo.json identically', async () => {
63+
const json = await readFile(path.join(__dirname, 'fixtures/utf8-mo.json'), 'utf8');
64+
const parsed = JSON.parse(json);
65+
const originalCompiled = originalGettextParser.mo.compile(parsed);
66+
const forkedCompiled = forkedGettextParser.mo.compile(parsed);
67+
assert.deepStrictEqual(forkedCompiled, originalCompiled);
68+
});
69+
});
70+
});

test/package-lock.json

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "gettext-parser-tests",
3+
"private": true,
4+
"type": "module",
5+
"dependencies": {
6+
"gettext-parser": "^9.0.1"
7+
}
8+
}

0 commit comments

Comments
 (0)