-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support validate lg custom functions (#3273)
* fix: support validate lg custom functions and separate the dialog validation from parser * use file name as namespace * add unit test * fix lint
- Loading branch information
Showing
18 changed files
with
406 additions
and
195 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
2 changes: 1 addition & 1 deletion
2
Composer/packages/lib/indexers/__tests__/dialogUtils/dialogChecker.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
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
61 changes: 61 additions & 0 deletions
61
Composer/packages/lib/indexers/__tests__/validations/expressionValidation.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,61 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
import { LgFile } from '@bfc/shared'; | ||
|
||
import { validate } from '../../src/validations/expressionValidation/validation'; | ||
|
||
import { searchLgCustomFunction } from './../../src/validations/expressionValidation/index'; | ||
|
||
describe('search lg custom function', () => { | ||
it('should return custom functions with namespace', () => { | ||
const lgFiles = [{ options: ['@strict = false', '@Namespace = foo', '@Exports = bar, cool'], id: 'test.en-us' }]; | ||
const result = searchLgCustomFunction(lgFiles as LgFile[]); | ||
expect(result.length).toEqual(2); | ||
expect(result[0]).toEqual('foo.bar'); | ||
expect(result[1]).toEqual('foo.cool'); | ||
}); | ||
|
||
it('should return custom functions with namespace', () => { | ||
const lgFiles = [{ options: ['@strict = false', '@Exports = bar, cool'], id: 'test.en-us' }]; | ||
const result = searchLgCustomFunction(lgFiles as LgFile[]); | ||
expect(result.length).toEqual(2); | ||
expect(result[0]).toEqual('test.en-us.bar'); | ||
expect(result[1]).toEqual('test.en-us.cool'); | ||
}); | ||
}); | ||
|
||
describe('validate expression', () => { | ||
it('if string expression do nothing', () => { | ||
const expression = { value: 'hello', required: false, path: 'test', types: ['string'] }; | ||
const result = validate(expression, []); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it('if start with =, but type is not match', () => { | ||
const expression = { value: '=13', required: false, path: 'test', types: ['string'] }; | ||
const result = validate(expression, []); | ||
expect(result?.message).toBe('the expression type is not match'); | ||
}); | ||
|
||
it('if start with =, and type is match', () => { | ||
const expression = { value: '=13', required: false, path: 'test', types: ['integer'] }; | ||
const result = validate(expression, []); | ||
expect(result).toBeNull(); | ||
expression.value = '=true'; | ||
expression.types[0] = 'boolean'; | ||
const result1 = validate(expression, []); | ||
expect(result1).toBeNull(); | ||
}); | ||
|
||
it('use custom functions, but lg file does not export', () => { | ||
const expression = { value: '=foo.bar()', required: false, path: 'test', types: ['boolean'] }; | ||
const result = validate(expression, []); | ||
expect(result).not.toBeNull(); | ||
}); | ||
|
||
it('use custom functions, and lg file does export', () => { | ||
const expression = { value: '=foo.bar()', required: false, path: 'test', types: ['boolean'] }; | ||
const result = validate(expression, ['foo.bar']); | ||
expect(result).toBeNull(); | ||
}); | ||
}); |
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
103 changes: 0 additions & 103 deletions
103
Composer/packages/lib/indexers/src/dialogUtils/dialogChecker.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.