-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract keys out to helper files and use js style code for assertion
afterwards run formatter for standardized formatting
- Loading branch information
Showing
5 changed files
with
182 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,81 @@ | ||
export const testKeys = ["+", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "<", "=", ">", "?", "A", "B", "C", | ||
"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", | ||
"X", "Y", "Z", "[", "\\", "]", "^", "_", "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", | ||
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~"]; | ||
export const testKeys = [ | ||
"+", | ||
".", | ||
"/", | ||
"0", | ||
"1", | ||
"2", | ||
"3", | ||
"4", | ||
"5", | ||
"6", | ||
"7", | ||
"8", | ||
"9", | ||
"<", | ||
"=", | ||
">", | ||
"?", | ||
"A", | ||
"B", | ||
"C", | ||
"D", | ||
"E", | ||
"F", | ||
"G", | ||
"H", | ||
"I", | ||
"J", | ||
"K", | ||
"L", | ||
"M", | ||
"N", | ||
"O", | ||
"P", | ||
"Q", | ||
"R", | ||
"S", | ||
"T", | ||
"U", | ||
"V", | ||
"W", | ||
"X", | ||
"Y", | ||
"Z", | ||
"[", | ||
"\\", | ||
"]", | ||
"^", | ||
"_", | ||
"`", | ||
"a", | ||
"b", | ||
"c", | ||
"d", | ||
"e", | ||
"f", | ||
"g", | ||
"h", | ||
"i", | ||
"j", | ||
"k", | ||
"l", | ||
"m", | ||
"n", | ||
"o", | ||
"p", | ||
"q", | ||
"r", | ||
"s", | ||
"t", | ||
"u", | ||
"v", | ||
"w", | ||
"x", | ||
"y", | ||
"z", | ||
"{", | ||
"|", | ||
"}", | ||
"~", | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
export const expectedKeys = [ | ||
"\u200C", | ||
"।", | ||
"्", | ||
"०", | ||
"१", | ||
"२", | ||
"३", | ||
"४", | ||
"५", | ||
"६", | ||
"७", | ||
"८", | ||
"९", | ||
"ङ", | ||
"\u200D", | ||
"॥", | ||
"?", | ||
"आ", | ||
"भ", | ||
"च", | ||
"ध", | ||
"ै", | ||
"ऊ", | ||
"घ", | ||
"अ", | ||
"ी", | ||
"झ", | ||
"ख", | ||
"ळ", | ||
"ं", | ||
"ण", | ||
"ओ", | ||
"फ", | ||
"ठ", | ||
"ृ", | ||
"श", | ||
"थ", | ||
"ू", | ||
"ँ", | ||
"औ", | ||
"ढ", | ||
"ञ", | ||
"ऋ", | ||
"इ", | ||
"ॐ", | ||
"ए", | ||
"^", | ||
"॒", | ||
"ऽ", | ||
"ा", | ||
"ब", | ||
"छ", | ||
"द", | ||
"े", | ||
"उ", | ||
"ग", | ||
"ह", | ||
"ि", | ||
"ज", | ||
"क", | ||
"ल", | ||
"म", | ||
"न", | ||
"ो", | ||
"प", | ||
"ट", | ||
"र", | ||
"स", | ||
"त", | ||
"ु", | ||
"व", | ||
"ौ", | ||
"ड", | ||
"य", | ||
"ष", | ||
"ई", | ||
"ः", | ||
"ऐ", | ||
"़", | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,24 @@ | ||
import assert from 'assert'; | ||
import romanized from '../../src/layouts/romanized'; | ||
import { testKeys } from '../helper.js'; | ||
import assert from "assert"; | ||
import romanized from "../../src/layouts/romanized"; | ||
import { testKeys } from "../helper.js"; | ||
import { expectedKeys } from "./romanized.helper.js"; | ||
|
||
describe('romanized', () => { | ||
describe('formatKey()', () => { | ||
it('should return corresponding Nepali character.', () => { | ||
const expected = ["\u200C", "।", "्", "०", "१", "२", "३", "४", "५", "६", "७", "८", "९", "ङ", "\u200D", | ||
"॥", "?", "आ", "भ", "च", "ध", "ै", "ऊ", "घ", "अ", "ी", "झ", "ख", "ळ", "ं", "ण", "ओ", "फ", "ठ", "ृ", | ||
"श", "थ", "ू", "ँ", "औ", "ढ", "ञ", "ऋ", "इ", "ॐ", "ए", "^", " ", "ऽ", "ा", "ब", "छ", "द", "े", "उ", | ||
"ग", "ह", "ि", "ज", "क", "ल", "म", "न", "ो", "प", "ट", "र", "स", "त", "ु", "व", "ौ", "ड", | ||
"य", "ष", "ई", "ः", "ऐ", "़"]; | ||
|
||
testKeys.every((element, index, array) => { | ||
assert.strictEqual(romanized.formatKey(element), expected[index]); | ||
}); | ||
describe("romanized", () => { | ||
describe("formatKey()", () => { | ||
it("should return corresponding romanized Nepali character.", () => { | ||
const receivedKeys = testKeys.map((key) => romanized.formatKey(key)); | ||
assert.deepEqual(expectedKeys, receivedKeys); | ||
}); | ||
|
||
it('should return undefined if it fails to map', () => { | ||
|
||
for (var i = 0; i < 127; i++) { | ||
let inputStr = String.fromCharCode(i); | ||
let found = testKeys.find(element => element == inputStr); | ||
it("should return undefined if no mapping exists", () => { | ||
const asciiCodes = [...Array(255 + 1).keys()]; | ||
const asciiKeys = asciiCodes.map((key) => String.fromCharCode(key)); | ||
const filteredKeys = asciiKeys.filter((key) => testKeys.indexOf(key) < 0); | ||
|
||
if (!found) { | ||
assert.strictEqual(romanized.formatKey(inputStr), undefined); | ||
} | ||
} | ||
const receivedKeys = filteredKeys.map((key) => romanized.formatKey(key)); | ||
const expectedKeys = [...Array(receivedKeys.length)]; | ||
|
||
assert.deepEqual(expectedKeys, receivedKeys); | ||
}); | ||
}); | ||
}); |