mirror of
https://github.com/rjNemo/deno_hello
synced 2026-06-06 01:56:40 +00:00
get locale functions
This commit is contained in:
parent
88b033425c
commit
68b73c29e4
4 changed files with 18 additions and 3 deletions
10
src/data.test.ts
Normal file
10
src/data.test.ts
Normal 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}`);
|
||||
});
|
||||
|
|
@ -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];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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!";
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue