-
-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e17e584
commit ac08f2e
Showing
3 changed files
with
139 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@udecode/plate-ai': patch | ||
--- | ||
|
||
Copilot: `getNextWord` when handle the case with mixed Chinese and English text. |
108 changes: 108 additions & 0 deletions
108
packages/ai/src/react/copilot/utils/getNextWord.spec.ts
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,108 @@ | ||
import { getNextWord } from './getNextWord'; | ||
|
||
describe('getNextWord', () => { | ||
describe('English text', () => { | ||
it('should get first word with no spaces', () => { | ||
expect(getNextWord({ text: 'hello world' })).toEqual({ | ||
firstWord: 'hello', | ||
remainingText: ' world', | ||
}); | ||
}); | ||
|
||
it('should handle leading spaces', () => { | ||
expect(getNextWord({ text: ' hello world' })).toEqual({ | ||
firstWord: ' hello', | ||
remainingText: ' world', | ||
}); | ||
}); | ||
|
||
it('should handle single word', () => { | ||
expect(getNextWord({ text: 'hello' })).toEqual({ | ||
firstWord: 'hello', | ||
remainingText: '', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('CJK characters', () => { | ||
it('should handle Chinese characters', () => { | ||
expect(getNextWord({ text: '你好 世界' })).toEqual({ | ||
firstWord: '你', | ||
remainingText: '好 世界', | ||
}); | ||
}); | ||
|
||
it('should handle Chinese character followed by punctuation', () => { | ||
expect(getNextWord({ text: '你。好 世界' })).toEqual({ | ||
firstWord: '你。', | ||
remainingText: '好 世界', | ||
}); | ||
}); | ||
|
||
it('should handle various CJK punctuation marks', () => { | ||
expect(getNextWord({ text: '你、好 世界' })).toEqual({ | ||
firstWord: '你、', | ||
remainingText: '好 世界', | ||
}); | ||
|
||
expect(getNextWord({ text: '你!世界' })).toEqual({ | ||
firstWord: '你!', | ||
remainingText: '世界', | ||
}); | ||
|
||
expect(getNextWord({ text: '你?好' })).toEqual({ | ||
firstWord: '你?', | ||
remainingText: '好', | ||
}); | ||
|
||
expect(getNextWord({ text: 'hello? world' })).toEqual({ | ||
firstWord: 'hello?', | ||
remainingText: ' world', | ||
}); | ||
}); | ||
|
||
it('should handle Japanese Hiragana', () => { | ||
expect(getNextWord({ text: 'こんにちは 世界' })).toEqual({ | ||
firstWord: 'こ', | ||
remainingText: 'んにちは 世界', | ||
}); | ||
}); | ||
|
||
it('should handle Korean characters', () => { | ||
expect(getNextWord({ text: '안녕하세요 세계' })).toEqual({ | ||
firstWord: '안', | ||
remainingText: '녕하세요 세계', | ||
}); | ||
}); | ||
|
||
it('should handle CJK with leading spaces', () => { | ||
expect(getNextWord({ text: ' 你好 世界' })).toEqual({ | ||
firstWord: ' 你', | ||
remainingText: '好 世界', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('mixed content', () => { | ||
it('should handle mix of English and CJK', () => { | ||
expect(getNextWord({ text: 'hello 你好' })).toEqual({ | ||
firstWord: 'hello', | ||
remainingText: ' 你好', | ||
}); | ||
}); | ||
|
||
it('should handle English words directly adjacent to Chinese characters', () => { | ||
expect(getNextWord({ text: 'React是nice框架' })).toEqual({ | ||
firstWord: 'React', | ||
remainingText: '是nice框架', | ||
}); | ||
}); | ||
|
||
it('should handle CJK followed by English', () => { | ||
expect(getNextWord({ text: '你 hello' })).toEqual({ | ||
firstWord: '你', | ||
remainingText: ' hello', | ||
}); | ||
}); | ||
}); | ||
}); |
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