import { InfioBlockAction, ParsedMsgBlock, parseMsgBlocks } from './parse-infio-block' describe('parseinfioBlocks', () => { it('should parse a string with infio_block elements', () => { const input = `Some text before # Example Markdown This is a sample markdown content for testing purposes. ## Features - Lists - **Bold text** - *Italic text* - [Links](https://example.com) ### Code Block \`\`\`python print("Hello, world!") \`\`\` Some text after` const expected: ParsedMsgBlock[] = [ { type: 'string', content: 'Some text before\n' }, { type: 'infio_block', content: ` # Example Markdown This is a sample markdown content for testing purposes. ## Features - Lists - **Bold text** - *Italic text* - [Links](https://example.com) ### Code Block \`\`\`python print("Hello, world!") \`\`\` `, language: 'markdown', filename: 'example.md', }, { type: 'string', content: '\nSome text after' }, ] const result = parseMsgBlocks(input) expect(result).toEqual(expected) }) it('should handle empty infio_block elements', () => { const input = ` ` const expected: ParsedMsgBlock[] = [ { type: 'string', content: '\n ' }, { type: 'infio_block', content: '', language: 'python', filename: undefined, }, { type: 'string', content: '\n ' }, ] const result = parseMsgBlocks(input) expect(result).toEqual(expected) }) it('should handle input without infio_block elements', () => { const input = 'Just a regular string without any infio_block elements.' const expected: ParsedMsgBlock[] = [{ type: 'string', content: input }] const result = parseMsgBlocks(input) expect(result).toEqual(expected) }) it('should handle multiple infio_block elements', () => { const input = `Start def greet(name): print(f"Hello, {name}!") Middle # Using tildes for code blocks Did you know that you can use tildes for code blocks? ~~~python print("Hello, world!") ~~~ End` const expected: ParsedMsgBlock[] = [ { type: 'string', content: 'Start\n' }, { type: 'infio_block', content: ` def greet(name): print(f"Hello, {name}!") `, language: 'python', filename: 'script.py', }, { type: 'string', content: '\nMiddle\n' }, { type: 'infio_block', content: ` # Using tildes for code blocks Did you know that you can use tildes for code blocks? ~~~python print("Hello, world!") ~~~ `, language: 'markdown', filename: 'example.md', }, { type: 'string', content: '\nEnd' }, ] const result = parseMsgBlocks(input) expect(result).toEqual(expected) }) it('should handle unfinished infio_block with only opening tag', () => { const input = `Start # Unfinished infio_block Some text after without closing tag` const expected: ParsedMsgBlock[] = [ { type: 'string', content: 'Start\n' }, { type: 'infio_block', content: ` # Unfinished infio_block Some text after without closing tag`, language: 'markdown', filename: undefined, }, ] const result = parseMsgBlocks(input) expect(result).toEqual(expected) }) it('should handle infio_block with startline and endline attributes', () => { const input = `` const expected: ParsedMsgBlock[] = [ { type: 'infio_block', content: '', language: 'markdown', startLine: 2, endLine: 5, }, ] const result = parseMsgBlocks(input) expect(result).toEqual(expected) }) it('should parse infio_block with action attribute', () => { const input = `` const expected: ParsedMsgBlock[] = [ { type: 'infio_block', content: '', action: InfioBlockAction.Edit, }, ] const result = parseMsgBlocks(input) expect(result).toEqual(expected) }) it('should handle invalid action attribute', () => { const input = `` const expected: ParsedMsgBlock[] = [ { type: 'infio_block', content: '', action: undefined, }, ] const result = parseMsgBlocks(input) expect(result).toEqual(expected) }) it('should parse a string with think elements', () => { const input = `Some text before This is a thought that should be parsed separately. It might contain multiple lines of text. Some text after` const expected: ParsedMsgBlock[] = [ { type: 'string', content: 'Some text before\n' }, { type: 'think', content: ` This is a thought that should be parsed separately. It might contain multiple lines of text. ` }, { type: 'string', content: '\nSome text after' }, ] const result = parseMsgBlocks(input) expect(result).toEqual(expected) }) it('should handle empty think elements', () => { const input = ` ` const expected: ParsedMsgBlock[] = [ { type: 'string', content: '\n ' }, { type: 'think', content: '', }, { type: 'string', content: '\n ' }, ] const result = parseMsgBlocks(input) expect(result).toEqual(expected) }) it('should handle mixed infio_block and think elements', () => { const input = `Start def greet(name): print(f"Hello, {name}!") Middle Let me think about this problem... I need to consider several approaches. End` const expected: ParsedMsgBlock[] = [ { type: 'string', content: 'Start\n' }, { type: 'infio_block', content: ` def greet(name): print(f"Hello, {name}!") `, language: 'python', filename: 'script.py', }, { type: 'string', content: '\nMiddle\n' }, { type: 'think', content: ` Let me think about this problem... I need to consider several approaches. ` }, { type: 'string', content: '\nEnd' }, ] const result = parseMsgBlocks(input) expect(result).toEqual(expected) }) it('should handle unfinished think with only opening tag', () => { const input = `Start Some unfinished thought without closing tag` const expected: ParsedMsgBlock[] = [ { type: 'string', content: 'Start\n' }, { type: 'think', content: ` Some unfinished thought without closing tag`, }, ] const result = parseMsgBlocks(input) expect(result).toEqual(expected) }) })