add: 检测递归转移单元测试

This commit is contained in:
jackfiled 2023-11-26 11:27:05 +08:00
parent 86551f244f
commit 79962727ba
5 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,22 @@
robotName: 啊准
stages:
- name: start
answer: 我是啊准,一个可以查询天气的机器人。
transformers:
- pattern: .*?天气|气温.*?
nextStageName: weather
- pattern: .*?
nextStageName: running
- name: running
answer: 对不起,做不到。
transformers:
- pattern:
nextStageName: running
- name: weather
answer: 今天北京市的天气是@weather/text气温是@weather/temp 摄氏度。
transformers:
- pattern:
nextStageName: running
beginStageName: start

View File

@ -0,0 +1,2 @@
今天北京的天气怎么样?
你说的对,但是

View File

@ -0,0 +1,6 @@
我是啊准,一个可以查询天气的机器人。
今天北京市的天气是晴气温是20 摄氏度。
我是啊准,一个可以查询天气的机器人。
对不起,做不到。
我是啊准,一个可以查询天气的机器人。
再见。

View File

@ -1,6 +1,8 @@
using Katheryne.Abstractions;
using Katheryne.Exceptions;
using Katheryne.Modules;
using Katheryne.Services;
using Katheryne.Tests.Mocks;
using Microsoft.Extensions.Logging;
using Moq;
@ -57,6 +59,21 @@ public class KatheryneRobotTests
ValidateOutput(_katheryneChatRobotFactory.GetRobot(), file);
}
[Fact]
public void RecursivelyExceptionTest()
{
IParamsModule weatherModule = new MockWeatherModule();
_katheryneChatRobotFactory.Modules.Clear();
_katheryneChatRobotFactory.Modules.Add(weatherModule.ModuleName, weatherModule);
InputOutputFile file = new("Grammar3");
StreamReader reader = new(Path.Combine(file.PrefixPath, "grammar.yaml"));
_katheryneChatRobotFactory.SetGrammar(reader.ReadToEnd());
Assert.Throws<GrammarException>(
() => ValidateOutput(_katheryneChatRobotFactory.GetRobot(), file));
}
[Fact]
public void WeatherModuleTest()
{

View File

@ -0,0 +1,21 @@
using Katheryne.Abstractions;
namespace Katheryne.Tests.Mocks;
public class MockWeatherModule : IParamsModule
{
private readonly Dictionary<string, string> _param = new()
{
{ "temp", "20" },
{ "text", "晴" }
};
public string ModuleName => "weather";
public string this[string param] => _param[param];
public bool ContainsParam(string param)
{
return _param.ContainsKey(param);
}
}