|
| 1 | +import { getNextWord } from './getNextWord'; |
| 2 | + |
| 3 | +describe('getNextWord', () => { |
| 4 | + describe('English text', () => { |
| 5 | + it('should get first word with no spaces', () => { |
| 6 | + expect(getNextWord({ text: 'hello world' })).toEqual({ |
| 7 | + firstWord: 'hello', |
| 8 | + remainingText: ' world', |
| 9 | + }); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should handle leading spaces', () => { |
| 13 | + expect(getNextWord({ text: ' hello world' })).toEqual({ |
| 14 | + firstWord: ' hello', |
| 15 | + remainingText: ' world', |
| 16 | + }); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should handle single word', () => { |
| 20 | + expect(getNextWord({ text: 'hello' })).toEqual({ |
| 21 | + firstWord: 'hello', |
| 22 | + remainingText: '', |
| 23 | + }); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe('CJK characters', () => { |
| 28 | + it('should handle Chinese characters', () => { |
| 29 | + expect(getNextWord({ text: '你好 世界' })).toEqual({ |
| 30 | + firstWord: '你', |
| 31 | + remainingText: '好 世界', |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should handle Chinese character followed by punctuation', () => { |
| 36 | + expect(getNextWord({ text: '你。好 世界' })).toEqual({ |
| 37 | + firstWord: '你。', |
| 38 | + remainingText: '好 世界', |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should handle various CJK punctuation marks', () => { |
| 43 | + expect(getNextWord({ text: '你、好 世界' })).toEqual({ |
| 44 | + firstWord: '你、', |
| 45 | + remainingText: '好 世界', |
| 46 | + }); |
| 47 | + |
| 48 | + expect(getNextWord({ text: '你!世界' })).toEqual({ |
| 49 | + firstWord: '你!', |
| 50 | + remainingText: '世界', |
| 51 | + }); |
| 52 | + |
| 53 | + expect(getNextWord({ text: '你?好' })).toEqual({ |
| 54 | + firstWord: '你?', |
| 55 | + remainingText: '好', |
| 56 | + }); |
| 57 | + |
| 58 | + expect(getNextWord({ text: 'hello? world' })).toEqual({ |
| 59 | + firstWord: 'hello?', |
| 60 | + remainingText: ' world', |
| 61 | + }); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should handle Japanese Hiragana', () => { |
| 65 | + expect(getNextWord({ text: 'こんにちは 世界' })).toEqual({ |
| 66 | + firstWord: 'こ', |
| 67 | + remainingText: 'んにちは 世界', |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should handle Korean characters', () => { |
| 72 | + expect(getNextWord({ text: '안녕하세요 세계' })).toEqual({ |
| 73 | + firstWord: '안', |
| 74 | + remainingText: '녕하세요 세계', |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + it('should handle CJK with leading spaces', () => { |
| 79 | + expect(getNextWord({ text: ' 你好 世界' })).toEqual({ |
| 80 | + firstWord: ' 你', |
| 81 | + remainingText: '好 世界', |
| 82 | + }); |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + describe('mixed content', () => { |
| 87 | + it('should handle mix of English and CJK', () => { |
| 88 | + expect(getNextWord({ text: 'hello 你好' })).toEqual({ |
| 89 | + firstWord: 'hello', |
| 90 | + remainingText: ' 你好', |
| 91 | + }); |
| 92 | + }); |
| 93 | + |
| 94 | + it('should handle English words directly adjacent to Chinese characters', () => { |
| 95 | + expect(getNextWord({ text: 'React是nice框架' })).toEqual({ |
| 96 | + firstWord: 'React', |
| 97 | + remainingText: '是nice框架', |
| 98 | + }); |
| 99 | + }); |
| 100 | + |
| 101 | + it('should handle CJK followed by English', () => { |
| 102 | + expect(getNextWord({ text: '你 hello' })).toEqual({ |
| 103 | + firstWord: '你', |
| 104 | + remainingText: ' hello', |
| 105 | + }); |
| 106 | + }); |
| 107 | + }); |
| 108 | +}); |
0 commit comments