You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 lines
1.9 KiB

import 'package:eaimar/data/services/emai_iflytek_turn.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('时间带星期和时区,提示里不出现经纬度', () {
final now = DateTime(2026, 10, 18, 0, 59);
final prompt = EmaiTurn.systemPrompt(
now: now,
spokenPlace: '上海市浦东新区世纪大道1号',
answerLanguage: '中文',
history: [EmaiMemory(true, '你好')],
);
expect(prompt, contains('2026年10月18日'));
expect(prompt, contains('星期日'));
expect(prompt, contains('00:59'));
expect(prompt, contains('UTC'));
expect(prompt, contains('当前位置:上海市浦东新区世纪大道1号'));
expect(prompt, isNot(contains('31.2')));
});
test('没有地址时写当前没有位置', () {
final prompt = EmaiTurn.systemPrompt(
now: DateTime(2026, 10, 18),
spokenPlace: '未知',
answerLanguage: '中文',
history: const [],
);
expect(prompt, contains('当前没有位置'));
expect(prompt, isNot(contains('当前位置:未知')));
});
test('搜索词补上当天日期', () {
final day = DateTime(2026, 10, 18);
expect(EmaiTurn.searchQuery('今天新闻', day), '今天新闻 2026-10-18');
expect(EmaiTurn.searchQuery('新闻 2026-10-18', day), '新闻 2026-10-18');
});
test('解析工具调用并丢掉令牌字段', () {
final calls = EmaiTurn.parseCalls(
'{"name":"hefeng_weather","arguments":"{\\"city\\":\\"上海\\",\\"auth_token\\":\\"secret\\"}"}',
);
expect(calls, hasLength(1));
expect(calls.single.name, 'hefeng_weather');
expect(calls.single.args['city'], '上海');
expect(calls.single.args.containsKey('auth_token'), isFalse);
});
test('问我在哪才等待定位', () {
expect(EmaiTurn.asksWhere('我现在在哪里'), isTrue);
expect(EmaiTurn.asksWhere('where am I'), isTrue);
expect(EmaiTurn.asksWhere('今天天气怎么样'), isFalse);
});
}