diff options
Diffstat (limited to 'packages/core/src/code_assist/converter.test.ts')
| -rw-r--r-- | packages/core/src/code_assist/converter.test.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/packages/core/src/code_assist/converter.test.ts b/packages/core/src/code_assist/converter.test.ts index 3d3a8ef3..ab040fe6 100644 --- a/packages/core/src/code_assist/converter.test.ts +++ b/packages/core/src/code_assist/converter.test.ts @@ -9,8 +9,10 @@ import { toGenerateContentRequest, fromGenerateContentResponse, CaGenerateContentResponse, + toContents, } from './converter.js'; import { + ContentListUnion, GenerateContentParameters, GenerateContentResponse, FinishReason, @@ -295,4 +297,57 @@ describe('converter', () => { ); }); }); + + describe('toContents', () => { + it('should handle Content', () => { + const content: ContentListUnion = { + role: 'user', + parts: [{ text: 'hello' }], + }; + expect(toContents(content)).toEqual([ + { role: 'user', parts: [{ text: 'hello' }] }, + ]); + }); + + it('should handle array of Contents', () => { + const contents: ContentListUnion = [ + { role: 'user', parts: [{ text: 'hello' }] }, + { role: 'model', parts: [{ text: 'hi' }] }, + ]; + expect(toContents(contents)).toEqual([ + { role: 'user', parts: [{ text: 'hello' }] }, + { role: 'model', parts: [{ text: 'hi' }] }, + ]); + }); + + it('should handle Part', () => { + const part: ContentListUnion = { text: 'a part' }; + expect(toContents(part)).toEqual([ + { role: 'user', parts: [{ text: 'a part' }] }, + ]); + }); + + it('should handle array of Parts', () => { + const parts = [{ text: 'part 1' }, 'part 2']; + expect(toContents(parts)).toEqual([ + { role: 'user', parts: [{ text: 'part 1' }] }, + { role: 'user', parts: [{ text: 'part 2' }] }, + ]); + }); + + it('should handle string', () => { + const str: ContentListUnion = 'a string'; + expect(toContents(str)).toEqual([ + { role: 'user', parts: [{ text: 'a string' }] }, + ]); + }); + + it('should handle array of strings', () => { + const strings: ContentListUnion = ['string 1', 'string 2']; + expect(toContents(strings)).toEqual([ + { role: 'user', parts: [{ text: 'string 1' }] }, + { role: 'user', parts: [{ text: 'string 2' }] }, + ]); + }); + }); }); |
