|
1 | 1 | import { promisify } from 'node:util'; |
2 | 2 | import path from 'node:path'; |
3 | | -import { mo } from '../src/index.js'; |
| 3 | +import { mo } from '../lib/index.mjs'; |
4 | 4 | import { readFile as fsReadFile } from 'node:fs'; |
5 | 5 | import { fileURLToPath } from 'node:url'; |
6 | | -import * as chai from 'chai'; |
| 6 | +import { describe, test } from 'node:test'; |
| 7 | +import assert from 'node:assert'; |
7 | 8 |
|
8 | 9 | const __filename = fileURLToPath(import.meta.url); |
9 | 10 | const __dirname = path.dirname(__filename); |
10 | 11 |
|
11 | 12 | const readFile = promisify(fsReadFile); |
12 | 13 |
|
13 | | -const expect = chai.expect; |
14 | | - |
15 | | -const littleEndianMagic = [0xde, 0x12, 0x04, 0x95]; |
16 | | -const bigEndianMagic = [0x95, 0x04, 0x12, 0xde]; |
17 | | - |
18 | | -chai.config.includeStack = true; |
19 | | - |
20 | 14 | describe('MO Compiler', () => { |
21 | | - describe('UTF-8 LE', async () => { |
22 | | - it('should compile', async () => { |
| 15 | + describe('UTF-8', () => { |
| 16 | + test('should compile', async () => { |
23 | 17 | const [json, moData] = await Promise.all([ |
24 | 18 | readFile(path.join(__dirname, 'fixtures/utf8-po.json'), 'utf8'), |
25 | | - readFile(path.join(__dirname, 'fixtures/utf8-le.mo')) |
| 19 | + readFile(path.join(__dirname, 'fixtures/utf8.mo')) |
26 | 20 | ]); |
27 | 21 |
|
28 | 22 | const compiled = mo.compile(JSON.parse(json)); |
29 | 23 |
|
30 | | - expect(compiled.toString('utf8')).to.deep.equal(moData.toString('utf8')); |
31 | | - }); |
32 | | - |
33 | | - it('should have the correct magic number', async () => { |
34 | | - const json = await readFile(path.join(__dirname, 'fixtures/utf8-po.json'), 'utf8'); |
35 | | - |
36 | | - const compiled = mo.compile(JSON.parse(json)); |
37 | | - |
38 | | - expect(Array.from(compiled.subarray(0, 4))).to.eql(littleEndianMagic); |
39 | | - }); |
40 | | - }); |
41 | | - |
42 | | - describe('UTF-8 BE', () => { |
43 | | - it('should compile', async () => { |
44 | | - const [json, moData] = await Promise.all([ |
45 | | - readFile(path.join(__dirname, 'fixtures/utf8-po.json'), 'utf8'), |
46 | | - readFile(path.join(__dirname, 'fixtures/utf8-be.mo')) |
47 | | - ]); |
48 | | - |
49 | | - const compiled = mo.compile(JSON.parse(json), { endian: 'be' }); |
50 | | - |
51 | | - expect(compiled.toString('utf8')).to.deep.equal(moData.toString('utf8')); |
52 | | - }); |
53 | | - |
54 | | - it('should have the correct magic number', async () => { |
55 | | - const json = await readFile(path.join(__dirname, 'fixtures/utf8-po.json'), 'utf8'); |
56 | | - |
57 | | - const compiled = mo.compile(JSON.parse(json), { endian: 'be' }); |
58 | | - |
59 | | - expect(Array.from(compiled.subarray(0, 4))).to.eql(bigEndianMagic); |
| 24 | + assert.deepStrictEqual(compiled.toString('utf8'), moData.toString('utf8')); |
60 | 25 | }); |
61 | 26 | }); |
62 | 27 |
|
63 | | - describe('Latin-13 LE', () => { |
64 | | - it('should compile', async () => { |
65 | | - const [json, moData] = await Promise.all([ |
66 | | - readFile(path.join(__dirname, 'fixtures/latin13-po.json'), 'utf8'), |
67 | | - readFile(path.join(__dirname, 'fixtures/latin13-le.mo')) |
68 | | - ]); |
69 | | - |
70 | | - const compiled = mo.compile(JSON.parse(json)); |
71 | | - |
72 | | - expect(compiled.toString('utf8')).to.equal(moData.toString('utf8')); |
73 | | - }); |
74 | | - |
75 | | - it('should have the correct magic number', async () => { |
76 | | - const json = await readFile(path.join(__dirname, 'fixtures/latin13-po.json'), 'utf8'); |
77 | | - |
78 | | - const compiled = mo.compile(JSON.parse(json)); |
79 | | - |
80 | | - expect(Array.from(compiled.subarray(0, 4))).to.eql(littleEndianMagic); |
81 | | - }); |
82 | | - }); |
83 | | - |
84 | | - describe('Latin-13 BE', () => { |
85 | | - it('should compile', async () => { |
86 | | - const [json, moData] = await Promise.all([ |
87 | | - readFile(path.join(__dirname, 'fixtures/latin13-po.json'), 'utf8'), |
88 | | - readFile(path.join(__dirname, 'fixtures/latin13-be.mo')) |
89 | | - ]); |
90 | | - |
91 | | - const compiled = mo.compile(JSON.parse(json), { endian: 'be' }); |
92 | | - |
93 | | - expect(compiled.toString('utf8')).to.equal(moData.toString('utf8')); |
94 | | - }); |
95 | | - |
96 | | - it('should have the correct magic number', async () => { |
97 | | - const json = await readFile(path.join(__dirname, 'fixtures/latin13-po.json'), 'utf8'); |
98 | | - |
99 | | - const compiled = mo.compile(JSON.parse(json), { endian: 'be' }); |
100 | | - |
101 | | - expect(Array.from(compiled.subarray(0, 4))).to.eql(bigEndianMagic); |
102 | | - }); |
103 | | - }); |
104 | 28 | }); |
0 commit comments