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.

57 lines
2.0 KiB

import java.time.LocalDate;
import java.util.Scanner;
public class MainTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
HistoryCommand history = new HistoryCommand();
// 实验案例1:创建Article对象测试
System.out.println("----- 实验案例1:创建并打印文章对象 -----");
Article art = new Article(
"Java入门教程",
"面向对象、集合、作业讲解",
"https://test.com/java",
"张老师",
LocalDate.of(2025,5,7)
);
art.showInfo();
System.out.println();
// 实验案例2:命令别名 + 历史记录 + URL校验 交互测试
System.out.println("----- 实验案例2:命令行交互测试 -----");
System.out.println("指令示例:c 网址、h、exit");
while(true){
System.out.print("请输入命令:");
String input = sc.nextLine().trim();
// 记录原始命令到历史
history.addCommand(input);
// 解析别名
String realCmd = CommandUtil.parseAlias(input);
System.out.println("解析后命令:" + realCmd);
// 简单指令分发
if(realCmd.startsWith("crawl")){
String[] parts = realCmd.split(" ",2);
if(parts.length >= 2){
String url = parts[1];
if(CommandUtil.checkUrl(url)){
System.out.println("URL合法,开始爬取:" + url);
}else{
System.out.println("URL格式不合法!");
}
}
}else if(realCmd.equals("history")){
// 查看历史
history.showHistory();
}else if(realCmd.equals("exit")){
System.out.println("退出程序");
break;
}
System.out.println("------------------------");
}
sc.close();
}
}