Skip to content

Commit

Permalink
support variable $Titlecase
Browse files Browse the repository at this point in the history
  • Loading branch information
vunb committed Mar 26, 2021
1 parent 81582c3 commit 3c84794
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/engine/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ export class Context {
// matching & replacing: ${var}, $var, #{var}, #var
// syntax: $var /format:list
// shorthand: $var :list
.replace(/[#$]\{?([a-z][\w_-]*)\}?\s*([\/:][a-z:_-]+)?/g, (match, variable: string, format: string) => {
.replace(/[#$]\{?([a-zA-Z][\w_-]*)\}?(\s*[\/:][a-z:_-]+)?/g, (match, variable: string, format: string) => {
const value = req.variables[variable];
// allow multiple spaces repeat in front of a format => so we must trim() it!
format = (format || '').trim();
if (format && /[/:]/.test(format.charAt(0))) {
let vDirectiveName = format.substring(1);
if (!/^format/.test(vDirectiveName)) {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/delay.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mock
.onPut('/api/http/put').reply(200, {
error: 0,
message: 'Ok',
Capitalization: 'NewVar',
})
.onDelete('/api/http/delete').reply(200, {
error: 0,
Expand Down
23 changes: 23 additions & 0 deletions test/engine/population.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { assert } from 'chai';
import { BotScript, Request } from '../../src/engine';

describe('Population: Variable Capitalization', () => {

it('should distinguish uppercase or lowercase', async () => {
const bot = new BotScript();

bot.parse(`
@ service1 put /api/http/put
+ put me
* true @> service1
- Result $message $Capitalization
`);
await bot.init();

const req = new Request();
const res = await bot.handleAsync(req.enter('put me'));
assert.equal(res.speechResponse, 'Result Ok NewVar', 'bot response with command executed and distinguish common case');
});

});

0 comments on commit 3c84794

Please sign in to comment.