Skip to content

Commit

Permalink
refactor: naming 통일
Browse files Browse the repository at this point in the history
  • Loading branch information
sa02045 committed Jun 25, 2024
1 parent 58bab4f commit 2d3974e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
40 changes: 20 additions & 20 deletions src/_internal/hangul.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
binaryAssembleHangul,
isHangulAlphabet,
isHangulCharacter,
isHangulString,
assertHangulString,
isHangul,
assertHangul,
parseHangul,
safeParseHangul,
} from './hangul';
Expand All @@ -26,15 +26,15 @@ describe('isHangul*', () => {
expect(isHangulAlphabet('a')).toBe(false);
});

it('isHangulString은 한글 문자열을 받으면 true를 반환한다.', () => {
expect(isHangulString('값')).toBe(true);
expect(isHangulString('ㄱ')).toBe(true);
expect(isHangulString('ㅏ')).toBe(true);
expect(isHangulString('저는 고양이를 좋아합니다')).toBe(true);
expect(isHangulString('a')).toBe(false);
expect(isHangulString(111)).toBe(false);
expect(isHangulString([111, 111])).toBe(false);
expect(isHangulString({ a: 111 })).toBe(false);
it('isHangul은 한글 문자열을 받으면 true를 반환한다.', () => {
expect(isHangul('값')).toBe(true);
expect(isHangul('ㄱ')).toBe(true);
expect(isHangul('ㅏ')).toBe(true);
expect(isHangul('저는 고양이를 좋아합니다')).toBe(true);
expect(isHangul('a')).toBe(false);
expect(isHangul(111)).toBe(false);
expect(isHangul([111, 111])).toBe(false);
expect(isHangul({ a: 111 })).toBe(false);
});
});

Expand Down Expand Up @@ -162,19 +162,19 @@ describe('binaryAssembleHangul', () => {
expect(binaryAssembleHangul('저는 고양이를 좋아합니다', 'ㅜ')).toEqual('저는 고양이를 좋아합니다ㅜ');
});

describe('assertHangulString', () => {
describe('assertHangul', () => {
it('한글 문자열을 받으면 에러를 발생시키지 않는다.', () => {
expect(() => assertHangulString('ㄱ')).not.toThrow();
expect(() => assertHangulString('고양이')).not.toThrow();
expect(() => assertHangulString('저는 고양이를 좋아합니다')).not.toThrow();
expect(() => assertHangulString('저는 고양이를 좋아합니ㄷ')).not.toThrow();
expect(() => assertHangul('ㄱ')).not.toThrow();
expect(() => assertHangul('고양이')).not.toThrow();
expect(() => assertHangul('저는 고양이를 좋아합니다')).not.toThrow();
expect(() => assertHangul('저는 고양이를 좋아합니ㄷ')).not.toThrow();
});

it("한글 문자열이 아닌 값을 받으면 '___ is not a valid hangul string' 에러를 발생시킨다.", () => {
expect(() => assertHangulString('aaaaaa')).toThrowError('"aaaaaa" is not a valid hangul string');
expect(() => assertHangulString(111)).toThrowError('111 is not a valid hangul string');
expect(() => assertHangulString([111, 111])).toThrowError('[111,111] is not a valid hangul string');
expect(() => assertHangulString({ a: 111 })).toThrowError('{"a":111} is not a valid hangul string');
expect(() => assertHangul('aaaaaa')).toThrowError('"aaaaaa" is not a valid hangul string');
expect(() => assertHangul(111)).toThrowError('111 is not a valid hangul string');
expect(() => assertHangul([111, 111])).toThrowError('[111,111] is not a valid hangul string');
expect(() => assertHangul({ a: 111 })).toThrowError('{"a":111} is not a valid hangul string');
});
});
});
8 changes: 4 additions & 4 deletions src/_internal/hangul.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ export function isHangulAlphabet(character: string) {
return /^[ㄱ-ㅣ]$/.test(character);
}

export function isHangulString(actual: unknown): actual is string {
export function isHangul(actual: unknown): actual is string {
return typeof actual === 'string' && /^[가-힣ㄱ-ㅣ\s]+$/.test(actual);
}

export function assertHangulString(actual: unknown, message?: string): asserts actual is string {
assert(isHangulString(actual), message || `${JSON.stringify(actual)} is not a valid hangul string`);
export function assertHangul(actual: unknown, message?: string): asserts actual is string {
assert(isHangul(actual), message || `${JSON.stringify(actual)} is not a valid hangul string`);
}

export function parseHangul(actual: unknown): string {
assertHangulString(actual);
assertHangul(actual);
return actual;
}

Expand Down

0 comments on commit 2d3974e

Please sign in to comment.