this repo has no description
1import assert from 'node:assert'
2import { describe, test } from 'node:test'
3import { TaggedStringParser } from '../../src/TaggedStringParser.ts'
4
5describe('Malformed Input Handling', () => {
6 describe('malformed tags in delimited mode', () => {
7 test('should skip unclosed tag at end of string', () => {
8 const parser = new TaggedStringParser()
9 const result = parser.parse('[operation:OP-123] started [incomplete')
10
11 assert.strictEqual(result.entities.length, 1)
12 assert.strictEqual(result.entities[0].type, 'operation')
13 assert.strictEqual(result.entities[0].value, 'OP-123')
14 })
15
16 test('should handle tag without type separator', () => {
17 const parser = new TaggedStringParser()
18 const result = parser.parse('[justvalue]')
19
20 assert.strictEqual(result.entities.length, 1)
21 assert.strictEqual(result.entities[0].type, '')
22 assert.strictEqual(result.entities[0].value, 'justvalue')
23 })
24
25 test('should skip empty tags', () => {
26 const parser = new TaggedStringParser()
27 const result = parser.parse('[operation:OP-123] [] [stack:ST-456]')
28
29 assert.strictEqual(result.entities.length, 2)
30 assert.strictEqual(result.entities[0].type, 'operation')
31 assert.strictEqual(result.entities[1].type, 'stack')
32 })
33
34 test('should skip tags with only whitespace', () => {
35 const parser = new TaggedStringParser()
36 const result = parser.parse('[operation:OP-123] [ ] [stack:ST-456]')
37
38 assert.strictEqual(result.entities.length, 2)
39 assert.strictEqual(result.entities[0].type, 'operation')
40 assert.strictEqual(result.entities[1].type, 'stack')
41 })
42 })
43})