public void Should_Highlight_Keywords_In_Input() { List <Keyword> keywords = new List <Keyword> { new Keyword("as", "blue", "capital", "normal"), new Keyword("if", "red", "lower", "bold"), new Keyword("and", "red", "capital", "bold"), new Keyword("then", "green", "lower", "normal"), new Keyword("when", "blue", "lower", "normal"), }; //string input = "If we write a program and compile it, then we can run the program to get output"; string input = "If we write a program and compile it, then as we run the program, we will get output"; var keywordFinder = new KeywordFinder(keywords); var highLigher = new HighLighter( keywordFinder, new IDecorater[] { new WordCasing(), new WordStyle(), new Colorization(), }); var result = highLigher.HighLight(input); //var expected = "[red]If[red] we write a program [red]and[red] compile it, [blue]then[blue] we can run the program to get output"; //var expected = "[red]If[red] we write a program [red]and[red] compile it, [green]then[green] [blue]as[blue] we run the program, we will get output"; //var expected = "[red]if[red] we write a program [red]AND[red] compile it, [green]then[green] [blue]AS[blue] we run the program, we will get output"; var expected = "[red][bold]if[bold][red] we write a program [red][bold]AND[bold][red] compile it, [green]then[green] [blue]AS[blue] we run the program, we will get output"; Assert.Equal(expected, result); }
public static List <Resp_Oc_Abs> To_Resp_Oc_Abs(this IEnumerable <OrgCompanyCombine> set, Company company, bool flag = true) { var list = new List <Resp_Oc_Abs>(company.pg_size); var end_list = new List <Resp_Oc_Abs>(); var oc_name_input = company.oc_name?.Replace("公司", ""); foreach (var c in set) { var r = new Resp_Oc_Abs(); if (c != null) { r.flag = c.od_CreateTime.Year != 1900; r.oc_addr = c.oc_address ?? ""; r.oc_area = c.oc_area; r.oc_code = c.oc_code; r.oc_art_person = c.od_faRen ?? string.Empty; r.oc_issue_time = c.oc_issuetime.ToString("yyyy-MM-dd") ?? ""; r.oc_name_hl = flag ? HighLighter.HighLight(c.oc_name, company.oc_name) : c.oc_name; r.oc_name = c.oc_name; r.oc_reg_capital = c.od_regMoney ?? ""; r.oe_status = c.oc_issuetime < DateTime.Now; r.oc_type = c.oc_companytype ?? ""; r.oc_status = r.flag ? Util.To_OpStatus(c.od_ext) : "未知"; } if (string.IsNullOrEmpty(oc_name_input)) { list.Add(r); } else { bool b_existed = false; for (int i = 0; i < oc_name_input.Length; i++) { if (c.oc_name.Contains(oc_name_input[i])) { list.Add(r); b_existed = true; break; } } if (!b_existed) { end_list.Add(r); } } } list.AddRange(end_list); return(list); }