forked from microsoft/BotFramework-Composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improve LG response editor parsing for text/speech variations (m…
…icrosoft#7434) * fix * added comments * minor * lint * lint Co-authored-by: Soroush <[email protected]> Co-authored-by: TJ Durnford <[email protected]> Co-authored-by: Dong Lei <[email protected]>
- Loading branch information
1 parent
0b9eebf
commit c114f64
Showing
7 changed files
with
275 additions
and
73 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
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
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
90 changes: 90 additions & 0 deletions
90
Composer/packages/lib/shared/__tests__/lgUtils/stringBuilders/lgStringUtils.test.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,90 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { parseTemplateBody } from '../../../src'; | ||
|
||
const normalTemplateBody = `- variation0 | ||
- variation1 | ||
- variation2 | ||
- variation3`; | ||
|
||
const parsedNormalTemplateBody = [ | ||
{ kind: 'variation', value: 'variation0' }, | ||
{ kind: 'variation', value: 'variation1' }, | ||
{ kind: 'variation', value: 'variation2' }, | ||
{ kind: 'variation', value: 'variation3' }, | ||
]; | ||
|
||
const templateBody = `> comment 0 | ||
- variation1 | ||
- variation2 | ||
> comment 1 | ||
- variation3 | ||
- \`\`\` multiline | ||
variation | ||
- with dash | ||
\\- and escaped dash | ||
and normal text | ||
> and this comment! | ||
\\> and escaped comment | ||
\`\`\` | ||
> comment 2`; | ||
|
||
const parsedTemplateBody = [ | ||
{ kind: 'comment', value: 'comment 0' }, | ||
{ kind: 'variation', value: 'variation1' }, | ||
{ kind: 'variation', value: 'variation2' }, | ||
{ kind: 'comment', value: 'comment 1' }, | ||
{ kind: 'variation', value: 'variation3' }, | ||
{ | ||
kind: 'variation', | ||
value: `\`\`\` multiline | ||
variation | ||
- with dash | ||
\\- and escaped dash | ||
and normal text | ||
> and this comment! | ||
\\> and escaped comment | ||
\`\`\``, | ||
}, | ||
{ kind: 'newline', value: '' }, | ||
{ kind: 'newline', value: '' }, | ||
{ kind: 'comment', value: 'comment 2' }, | ||
]; | ||
|
||
const oneMultilineVariation = `- \`\`\` multiline | ||
variation | ||
- with dash | ||
\\- and escaped dash | ||
and normal text | ||
> and this comment! | ||
\\> and escaped comment | ||
\`\`\``; | ||
|
||
describe('lgStringUtils', () => { | ||
it('Should parse template body with normal variations', () => { | ||
const items = parseTemplateBody(normalTemplateBody); | ||
expect(items.length).toBe(4); | ||
expect(items).toEqual(parsedNormalTemplateBody); | ||
}); | ||
|
||
it('Should parse template body with variations, multiline variations and comments', () => { | ||
const items = parseTemplateBody(templateBody); | ||
expect(items.length).toBe(9); | ||
expect(items).toEqual(parsedTemplateBody); | ||
}); | ||
|
||
it('Should parse template body with one multiline variation', () => { | ||
const items = parseTemplateBody(oneMultilineVariation); | ||
expect(items.length).toBe(1); | ||
expect(items).toEqual([parsedTemplateBody[5]]); | ||
}); | ||
|
||
it('Should return empty array for undefined template body', () => { | ||
const items = parseTemplateBody(undefined); | ||
expect(items.length).toBe(0); | ||
expect(items).toEqual([]); | ||
}); | ||
}); |
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
Oops, something went wrong.