Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
Separated tests and added integration testing for compiled code
Browse files Browse the repository at this point in the history
  • Loading branch information
falfiya committed Oct 21, 2018
1 parent 2ccff4a commit 26bb7c8
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 138 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
verbose: true,
testMatch: [
'**/__tests__/**/*.?(m)js',
// '**/__tests__/**/*.?(m)js',
'**/?(*.)(test|t).?(m)js',
],
moduleFileExtensions: [
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "0.0.2",
"description": " A library to process and standardize hangul characters across unicode blocks",
"main": "dist/Hangul.cjs.min.js",
"files": [
"/dist"
],
"scripts": {
"start": "rollup -c -w",
"build": "rollup -c",
Expand Down
133 changes: 0 additions & 133 deletions src/main.t.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CombinedRange, UnicodeRange } from './UnicodeRange';
import { CombinedRange, UnicodeRange } from '../src/unicode/UnicodeRange';

const uRange0 = new UnicodeRange(0, 50);
const uRange1 = new UnicodeRange(80, 100);
Expand Down
2 changes: 1 addition & 1 deletion src/unicode/characters.t.js → tests/characters.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
consonants, vowels, hangulToKey, keyToHangul,
} from './characters';
} from '../src/unicode/characters';

const characterEntries = Object.entries(Object.assign({}, consonants, vowels));
const keyToHangulEntries = Object.entries(keyToHangul);
Expand Down
5 changes: 5 additions & 0 deletions tests/cjs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import integrationTests from './integrationTests';

const Hangul = require('../dist/Hangul.cjs.min.js');

integrationTests(Hangul);
2 changes: 1 addition & 1 deletion src/deepTest.t.js → tests/deepTest.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { contains, isAll } from './deepTest';
import { contains, isAll } from '../src/deepTest';

const string = 'Hello, world!';
const stringGroup = ['hell', ['o'], ['w', 'o', ['rl', 'd']], '!', [[['5']]]];
Expand Down
133 changes: 133 additions & 0 deletions tests/integrationTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
export default function integrationTests(Hangul) {
const a = Symbol('oneArgument');
const typeDecorator = datum => ((typeof datum === 'object' || typeof datum === 'string')
? JSON.stringify(datum)
: datum);
const tests = {
assemble: [
['ㄱㅗㅇㅑㅇㅇㅣ', '고양이'],
[a, ['ㄱ', 'ㅗ', 'ㅇ', 'ㅑ', 'ㅇ', 'ㅇ', 'ㅣ'], '고양이'],
[a, ['ㅇㅣㄱㅓㅅㄷㅗ ㅈㅏㄱㄷㅗㅇㅎㅏㅂㄴㅣㄷㅏ'], '이것도 작동합니다'],
['Hello ㅇㅏㄴㄴㅕㅇ World ㅅㅔㅅㅏㅇ', 'Hello 안녕 World 세상'],
],
composeComplex: [
[['ㄷ', 'ㄷ'], 'ㄸ'],
[['ㅅㅅ', 'ㅅ'], 'ㅅㅅㅅ'],
[['', 'ㅅ'], 'ㅅ'],
[['ㄹ', 'ㄱ', ''], 'ㄺ'],
[['ㄹ', 'ㄱ', true], 'ㄺtrue'],
[['ㄹ', 'ㄱ', 1], 'ㄺ1'],
// composition with different options
[
['ㅅㅅ', 'ㅅ', '', { hardFail: true }],
Error('is not a Character!'),
],
[
['', 'ㅅ', '', { hardFail: true }],
Error('The first input to Hangul.composeComplex'),
],
[
['ㄷ', 'ㄷ', 'ㅁ', { hardFail: true }],
Error('but cannot combine'),
],
[
['ㅂ', 'ㅅ', 'ㄷ', {
complex3: true,
complexArchaic: true,
}],
'ㅵ',
],
// [['ㅗ', 'ㅏ', '', { complexJung: false }], 'ㅗㅏ'],
// [['ㄱ', 'ㄱ', '', { composeComplexDouble: false }], 'ㄱㄱ'],
],
composeSyllable: [
[['ㅈ', 'ㅣ', 'ㅂ'], '집'],
[['ㅁ', 'ㅗ', 'ㅣ'], '모ㅣ'],
[['ㅁ', 'ㅗ', 'ㅣ', { hardFail: true }], Error('')],
[['ㅁ', 'a'], 'ㅁa'],
[['ㅁ', 'a', '', { hardFail: true }], Error('is not a valid jung Character!')],
[['ㅁㅏ', 'ㄷ'], 'ㅁㅏㄷ'],
[['ㅃ', 'ㅏ'], '빠'],
],
decomposeComplex: [
['ㄸ', 'ㄸ'],
[['ㄸ', { grouped: true }], 'ㄸ'],
[['ㄸ', { decomposeDouble: true }], 'ㄷㄷ'],
[['ㄸ', { grouped: true, decomposeDouble: true }], 'ㄷㄷ'],
[['', { grouped: true }], ''],
],
decomposeSyllable: [
['빠', 'ㅃㅏ'],
['양', 'ㅇㅑㅇ'],
['ㅂ', 'ㅂ'],
[['ㅂ', { hardFail: true }], Error('is not a syllable!')],
],
disassemble: [
['고양이', 'ㄱㅗㅇㅑㅇㅇㅣ'],
[['빠른', { grouped: true }], [['ㅃ', 'ㅏ'], ['ㄹ', 'ㅡ', 'ㄴ']]],
[['없다', { grouped: true }], [['ㅇ', 'ㅓ', ['ㅂ', 'ㅅ']], ['ㄷ', 'ㅏ']]],
['', ''],
[['', { grouped: true }], []],
],
disassembleCharacter: [
['없', 'ㅇㅓㅂㅅ'],
[['없', { grouped: true }], ['ㅇ', 'ㅓ', ['ㅂ', 'ㅅ']]],
],
stronger: [
['ㄱ', 'ㄲ'],
['ㅂ', 'ㅃ'],
['ㅋ', 'ㄲ'],
['ㅅ', 'ㅆ'],
],
hangulToKeys: [
['고양이', 'rhdiddl'],
[['빠른', { grouped: true }], [['Q', 'k'], ['f', 'm', 's']]],
[['없다', { grouped: true }], [['d', 'j', ['q', 't']], ['e', 'k']]],
['', ''],
[['', { grouped: true }], []],
],
keysToHangul: [
['qwerty', 'ㅂㅈㄷㄳㅛ'],
[a, ['qwer', 'ty'], 'ㅂㅈㄷㄱ쇼'],
],
};

Object.keys(tests).forEach((functionName) => {
const pairs = tests[functionName];
describe(`Hangul.${functionName}`, () => {
const fn = Hangul[functionName];
if (!fn) {
throw Hangul;
}
pairs.forEach((en) => {
let args;
let res;
if (en[0] === a) {
args = [en[1]];
[, , res] = en;
} else if (Array.isArray(en[0])) {
[args, res] = en;
} else {
args = [en[0]];
[, res] = en;
}
const stargs = args.map(typeDecorator).join(', ');
if (res instanceof Error) {
const { message } = res;
test(`${stargs} throws "${message}"`, () => {
expect(() => fn(...args)).toThrow(message);
});
} else if (res instanceof Object) {
test(`${(stargs)} => ${typeDecorator(res)}`, () => {
expect(fn(...args)).toEqual(res);
});
} else if (Array.isArray(en)) {
test(`${(stargs)} => ${typeDecorator(res)}`, () => {
expect(fn(...args)).toBe(res);
});
}
});
});
});
// I'm not gonna test the hangul block things because I'm lazy
}
4 changes: 4 additions & 0 deletions tests/main.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as Hangul from '../src/main';
import integrationTests from './integrationTests';

integrationTests(Hangul);
2 changes: 1 addition & 1 deletion src/types.t.js → tests/types.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as types from './types';
import * as types from '../src/types';

describe('types.character Values', () => {
test('types.character("a") returns a', () => {
Expand Down

0 comments on commit 26bb7c8

Please sign in to comment.