Skip to content

Commit

Permalink
�fix: prevent runtime error in josaPicker when word is empty string (#39
Browse files Browse the repository at this point in the history
)

* fix: remove unnecessary not null assertions

* fix: 빈 문자열에 대한 런타임 오류 개선

* test: 엣지케이스에 대한 테스트 추가
  • Loading branch information
jw-r authored Apr 19, 2024
1 parent b420276 commit 200ecd9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/josa.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ describe('Hangul', () => {
});

describe('josa.pick', () => {
it('첫 번째 매개변수가 빈 문자열이라면 옵션중 첫 번째 값을 반환한다', () => {
expect(josa.pick('', '이/가')).toBe('이');
});
it('주격조사', () => {
expect(josa.pick('샴푸', '이/가')).toBe('가');
expect(josa.pick('칫솔', '이/가')).toBe('이');
Expand Down
8 changes: 6 additions & 2 deletions src/josa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ export function josa(word: string, josa: JosaOption): string {
josa.pick = josaPicker;

function josaPicker(word: string, josa: JosaOption): string {
if (word.length === 0) {
return josa.split('/')[0];
}

const has받침 = hasBatchim(word);
let index = has받침 ? 0 : 1;

const is종성ㄹ = disassembleCompleteHangulCharacter(word[word.length - 1]!)?.last === 'ㄹ';
const is종성ㄹ = disassembleCompleteHangulCharacter(word[word.length - 1])?.last === 'ㄹ';

const isCaseOf로 = has받침 && is종성ㄹ && 로_조사.includes(josa);

Expand All @@ -46,5 +50,5 @@ function josaPicker(word: string, josa: JosaOption): string {
index = 1;
}

return josa.split('/')[index]!;
return josa.split('/')[index];
}

0 comments on commit 200ecd9

Please sign in to comment.