Skip to content

Commit cbdc300

Browse files
committed
test: improve testing
1 parent 80fa2ef commit cbdc300

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const parse = (content: string) => {
6161
const arr = (new Engine({})).parseCode(content, 'lang').children
6262
.filter(child => child.kind === 'return')[0] as any;
6363

64-
return parseItem(arr.expr);
64+
return convertToDotsSyntax(parseItem(arr.expr));
6565
}
6666

6767
const parseItem = (expr) => {

test/fixtures/lang/en/auth.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@
33
return [
44
'failed' => 'These credentials do not match our records.',
55
'password' => 'The provided password is incorrect.',
6+
'foo' => [
7+
'level1' => [
8+
'level2' => 'baren'
9+
]
10+
]
611
];

test/fixtures/lang/pt/auth.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@
33
return [
44
'failed' => 'As credenciais indicadas não coincidem com as registadas no sistema.',
55
'password' => 'A palavra-passe indicada está incorreta.',
6+
'foo' => [
7+
'level1' => [
8+
'level2' => 'barpt'
9+
]
10+
],
611
];

test/loader.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import fs from 'fs';
2-
import path from 'path';
32
import { parseAll, parse, hasPhpTranslations } from '../src/loader';
43

54
beforeEach(() => {
@@ -20,9 +19,11 @@ it('creates a file for each lang', () => {
2019

2120
const langEn = JSON.parse(fs.readFileSync(files[0].path).toString());
2221
expect(langEn['auth.failed']).toBe('These credentials do not match our records.');
22+
expect(langEn['auth.foo.level1.level2']).toBe('baren');
2323

2424
const langPt = JSON.parse(fs.readFileSync(files[1].path).toString());
2525
expect(langPt['auth.failed']).toBe('As credenciais indicadas não coincidem com as registadas no sistema.');
26+
expect(langPt['auth.foo.level1.level2']).toBe('barpt');
2627
});
2728

2829
it('transforms .php lang to .json', () => {
@@ -31,6 +32,14 @@ it('transforms .php lang to .json', () => {
3132
expect(lang['failed']).toBe('These credentials do not match our records.');
3233
});
3334

35+
it('transform nested .php lang files to .json', () => {
36+
const langPt = parse(fs.readFileSync(__dirname + '/fixtures/lang/pt/auth.php').toString());
37+
expect(langPt['foo.level1.level2']).toBe('barpt');
38+
39+
const langEn = parse(fs.readFileSync(__dirname + '/fixtures/lang/en/auth.php').toString());
40+
expect(langEn['foo.level1.level2']).toBe('baren');
41+
});
42+
3443
it('checks if there is .php translations', () => {
3544
const hasTranslations = hasPhpTranslations(__dirname + '/fixtures/lang/');
3645

0 commit comments

Comments
 (0)