Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,28 @@
],
"internalConsoleOptions": "openOnSessionStart",
"cwd": "${workspaceFolder}/../botbuilder-dotnet/tests/Microsoft.Bot.Builder.Dialogs.Adaptive.Tests/tests/LUISRecognizerTests"
},
{
"type": "node",
"request": "launch",
"name": "LG Expand Test",
"preLaunchTask": "${defaultBuildTask}",
"program": "${workspaceFolder}/packages/lg/bin/run",
"outputCapture": "std",
"outFiles": [
"./packages/lg/lib/**"
],
"args": [
"lg:expand",
"--in",
"accessScope.lg",
"--testInput",
"data.json",
"--template",
"GetIndex"
],
"internalConsoleOptions": "openOnSessionStart",
"cwd": "${workspaceFolder}/packages/lg/test/fixtures/testcase"
}
]
}
8 changes: 5 additions & 3 deletions packages/lg/src/commands/lg/expand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as txtfile from 'read-text-file'
import * as path from 'path'
import * as fs from 'fs-extra'
import * as readlineSync from 'readline-sync'
import * as lodash from 'lodash'

export default class ExpandCommand extends Command {
static description = 'Expand one or all templates in .lg file(s). Expand an inline expression.'
Expand Down Expand Up @@ -230,8 +231,9 @@ export default class ExpandCommand extends Command {

if (expectedVariables !== undefined) {
for (const variable of expectedVariables) {
if (variablesObj !== undefined && variablesObj[variable] !== undefined) {
result.set(variable, variablesObj[variable])
const evalPathResult = lodash.get(variablesObj, variable)
if (variablesObj !== undefined && evalPathResult !== undefined) {
result.set(variable, evalPathResult)
} else if (userInputValues !== undefined && userInputValues.has(variable)) {
result.set(variable, userInputValues.get(variable))
} else {
Expand All @@ -247,7 +249,7 @@ export default class ExpandCommand extends Command {
const result: any = {}
if (variablesValue !== undefined) {
for (const variable of variablesValue) {
result[variable[0]] = variable[1]
lodash.set(result, variable[0], variable[1])
}
}

Expand Down
68 changes: 68 additions & 0 deletions packages/lg/test/commands/lg/expand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,71 @@ describe('lg:expand lg template', async () => {
await TestUtil.compareFiles(path.join(generatedFolderPath, outputFileName), path.join(verifiedFolderPath, '4.testinput.expand.lg'))
})
})

describe('lg:expand lg template with scope', async () => {
after(async function () {
await fs.remove(generatedFolder)
})

before(async function () {
await fs.remove(generatedFolder)
await fs.mkdirp(generatedFolder)
})

const inputFileName = 'accessScope.lg'
let outputFileName = 'accessScope.expand.lg'

let testInputTemplate = 'welcomeUser'
// test access nested path
test
.command(['lg:expand',
'--in',
path.join(__dirname, testcaseFolderPath, inputFileName),
'--out',
generatedFolder,
'--template',
testInputTemplate,
'--testInput',
path.join(__dirname, testcaseFolderPath, 'data.json'),
'-r',
'-f'])
.it('', async () => {
await TestUtil.compareFiles(path.join(generatedFolderPath, outputFileName), path.join(verifiedFolderPath, 'accessScope.testinput.expand.lg'))
})

testInputTemplate = 'AddItemReadBack'
// test multiple nested path access
test
.command(['lg:expand',
'--in',
path.join(__dirname, testcaseFolderPath, inputFileName),
'--out',
generatedFolder,
'--template',
testInputTemplate,
'--testInput',
path.join(__dirname, testcaseFolderPath, 'data.json'),
'-r',
'-f'])
.it('', async () => {
await TestUtil.compareFiles(path.join(generatedFolderPath, outputFileName), path.join(verifiedFolderPath, 'accessScope2.testinput.expand.lg'))
})

testInputTemplate = 'GetIndex'
// test multiple nested path access
test
.command(['lg:expand',
'--in',
path.join(__dirname, testcaseFolderPath, inputFileName),
'--out',
generatedFolder,
'--template',
testInputTemplate,
'--testInput',
path.join(__dirname, testcaseFolderPath, 'data.json'),
'-r',
'-f'])
.it('', async () => {
await TestUtil.compareFiles(path.join(generatedFolderPath, outputFileName), path.join(verifiedFolderPath, 'accessScope3.testinput.expand.lg'))
})
})
22 changes: 22 additions & 0 deletions packages/lg/test/fixtures/testcase/accessScope.lg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#welcomeUser(age)
- hi ${user.name} at ${age}
- hello ${user.name} at ${age}

# AddItemReadBack
[Activity
Text = ${HelpPrefix()}, I have added "**${dialog.itemTitle}**" to your **${dialog.listType}** list. You have **${count(user.lists[dialog.listType])}** items in your ${dialog.listType} list.
${WelcomeActions()}
]

# HelpPrefix
- Sure
- You bet
- Absolutely

# WelcomeActions
[Activity
SuggestedActions = Add item | View lists | Remove item | Profile | Cancel | Help
]

#GetIndex
- ${user.lists.reminder[1]}
13 changes: 12 additions & 1 deletion packages/lg/test/fixtures/testcase/data.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
{
"time":"morning"
"time":"morning",
"user": {
"name": "cosmic",
"lists": {
"reminder": ["car washing", "laundry", "cooking"]
}
},
"age": 18,
"dialog": {
"itemTitle": "Sunday ToDo",
"listType": "reminder"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# welcomeUser
- hi cosmic at 18
- hello cosmic at 18

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# AddItemReadBack
- {"lgType":"Activity","text":"Sure, I have added "**Sunday ToDo**" to your **reminder** list. You have **3** items in your reminder list.","suggestedactions":["Add item ","View lists ","Remove item ","Profile ","Cancel ","Help"]}
- {"lgType":"Activity","text":"You bet, I have added "**Sunday ToDo**" to your **reminder** list. You have **3** items in your reminder list.","suggestedactions":["Add item ","View lists ","Remove item ","Profile ","Cancel ","Help"]}
- {"lgType":"Activity","text":"Absolutely, I have added "**Sunday ToDo**" to your **reminder** list. You have **3** items in your reminder list.","suggestedactions":["Add item ","View lists ","Remove item ","Profile ","Cancel ","Help"]}

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# GetIndex
- laundry