get locale functions

This commit is contained in:
Ruidy 2021-02-19 13:12:07 +01:00
parent 88b033425c
commit 68b73c29e4
4 changed files with 18 additions and 3 deletions

10
src/data.test.ts Normal file
View file

@ -0,0 +1,10 @@
import { assertStrictEquals } from "https://deno.land/std@0.87.0/testing/asserts.ts";
import { getLocaleById } from "./data.ts";
Deno.test("Get locale by id", () => {
const id = 25;
const actual = getLocaleById(id);
const expected = "Salut le Monde!";
assertStrictEquals(actual, expected, `Expected ${expected}; got ${actual}`);
});

View file

@ -1,4 +1,4 @@
export const locales = {
const locales = {
Afrikaans: "Hallo, wêreld!",
Albanian: "Pershëndetje Botë",
Arabic: "أهلاً بالعالم (Ahlan bil 'Alam)",
@ -80,3 +80,7 @@ export const locales = {
};
export const localesSize = Object.keys(locales).length;
export const getLocaleById = (id: number) => {
return Object.values(locales)[id - 1];
};

View file

@ -13,9 +13,9 @@ Deno.test("Hello test", () => {
});
Deno.test("Specific Hello", () => {
const id = 5;
const id = 25;
const actual = sayHello(id);
const expected = "Bonjour le monde";
const expected = "Salut le Monde!";
assertStrictEquals(actual, expected);
});

View file

@ -8,6 +8,7 @@ export const sayHello = (id?: number) => {
if (id && idInValidRange(id)) {
throw new ValidationError(`Invalid index: ${id}`);
}
// const hello = getLocaleByNumber(id);
return (id === 5) ? "Bonjour le monde" : "Hello, World!";
};