Skip to content

Commit c4b4710

Browse files
author
Patrick Sachs
committed
Added tests for locale system
1 parent c5b3b08 commit c4b4710

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

test/logic/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import syntaxTest from "./syntax";
2+
import localeTest from "./locale";
23

34
function run() {
45
syntaxTest();
6+
localeTest();
57
// ... Add more logic specifc tests once we need them in different files ...
68
}
79

test/logic/locale.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as localeSystem from "../../src/locale";
2+
3+
function run() {
4+
test('Formatting with all arguments present and used', () => {
5+
const string = 'The {adjective} {color} {animal} jumps over the lazy dog.';
6+
const result = localeSystem.format(string, {
7+
adjective: 'smart',
8+
color: 'blue',
9+
animal: 'cat'
10+
});
11+
expect(result).toEqual("The smart blue cat jumps over the lazy dog.")
12+
});
13+
14+
test('Formatting with some arguments used twice', () => {
15+
const string = 'The {adjective} {color} {animal} jumps over the {adjective} dog.';
16+
const result = localeSystem.format(string, {
17+
adjective: 'smart',
18+
color: 'blue',
19+
animal: 'cat'
20+
});
21+
expect(result).toEqual("The smart blue cat jumps over the smart dog.")
22+
});
23+
24+
test('Formatting with some arguments not used', () => {
25+
const string = 'The {adjective} brown {animal} jumps over the lazy dog.';
26+
const result = localeSystem.format(string, {
27+
adjective: 'smart',
28+
color: 'blue',
29+
animal: 'cat'
30+
});
31+
expect(result).toEqual("The smart brown cat jumps over the lazy dog.")
32+
});
33+
34+
test('Formatting with some arguments missing', () => {
35+
const string = 'The {adjective} {color} {animal} jumps over the lazy dog.';
36+
const result = localeSystem.format(string, {
37+
adjective: 'smart',
38+
color: 'blue'
39+
});
40+
expect(result).toEqual("The smart blue {animal} jumps over the lazy dog.")
41+
});
42+
43+
test('Formatting with some arguments having different casing', () => {
44+
const string = 'The {aDjecTIVe} {Color} {animal} jumps over the lazy dog.';
45+
const result = localeSystem.format(string, {
46+
AdJECtivE: 'smart',
47+
color: 'blue',
48+
Animal: 'cat'
49+
});
50+
expect(result).toEqual("The smart blue cat jumps over the lazy dog.")
51+
});
52+
}
53+
54+
export default run;

0 commit comments

Comments
 (0)