void TestNullArray() { var dc=new DeepCmp(); List<PathEntry> path; Is(dc.Compare(null,new[]{1,2},out path),DeepCmp.Result.ValNe); IsDeeply(path,new[]{new PathEntry(0,new[]{0,2})}); Is(dc.Compare(new[]{null,"b"},new[]{"a","b"},out path),DeepCmp.Result.ValNe); IsDeeply(path,new[]{new PathEntry(0,new[]{2,2}),new PathEntry(1)}); }
void TestDic() { var dc=new DeepCmp(); List<PathEntry> path; Is(dc.Compare(new Dictionary<int,int>{{1,2}},new SortedDictionary<int,int>{{1,2}},out path),DeepCmp.Result.Eq); Is(path,null); Is(dc.Compare(new Dictionary<int,int>{{1,2}},new SortedDictionary<int,int>{{1,3}},out path),DeepCmp.Result.ValNe); IsDeeply(path,new[]{new PathEntry(0,new int[]{1,1}),new PathEntry(1)}); Is(dc.Compare(new Dictionary<int,int>{{1,2},{0,1}},new SortedDictionary<int,int>{{0,1},{2,3}},out path),DeepCmp.Result.KeyNe); IsDeeply(path,new[]{new PathEntry(0,new int[]{2,2}),new PathEntry(2)}); }
void TestArray() { var dc=new DeepCmp(); List<PathEntry> path; Is(dc.Compare(new[]{1,2},new[]{1,2},out path),DeepCmp.Result.Eq); Is(path,null); Is(dc.Compare(new[]{1,2},new[]{1,3},out path),DeepCmp.Result.ValNe); IsDeeply(path,new[]{new PathEntry(0,new[]{2,2}),new PathEntry(2)}); Is(dc.Compare(new[]{1,2},new[]{2,2},out path),DeepCmp.Result.ValNe); IsDeeply(path,new[]{new PathEntry(0,new[]{2,2}),new PathEntry(1)}); }
void TestNullScalar() { var dc=new DeepCmp(); List<PathEntry> path; Is(dc.Compare("a",null,out path),DeepCmp.Result.ValNe); IsDeeply(path,new PathEntry[]{new PathEntry{Idx=0}}); Is(dc.Compare(null,"b",out path),DeepCmp.Result.ValNe); IsDeeply(path,new PathEntry[]{new PathEntry{Idx=0}}); Is(dc.Compare(null,null,out path),DeepCmp.Result.Eq); IsDeeply(path,null); }
string Helper(object l,object r) { var dc=new DeepCmp(); List<PathEntry> path; dc.Compare(l,r,out path); // Dump("path",path); var sw=new StringWriter(); sw.NewLine="\r\n"; var cw=new YAMLCommentWriter(sw,null); var dic=new OrderedDictionary{{"a","blah"},{"actual",l},{"expected",r}}; cw.WriteComment(0,dic,path,null); return sw.ToString(); }
void TestFields() { var dc=new DeepCmp(); List<PathEntry> path; Is(dc.Compare(new A(1,null),new A(1,null),out path),DeepCmp.Result.Eq); Is(path,null); Is(dc.Compare(new A(1,null),new A(2,null),out path),DeepCmp.Result.ValNe); IsDeeply(path,new[]{new PathEntry(0,new[]{2,2}),new PathEntry(1)}); Is(dc.Compare(new A(1,new A(2,null)),new A(1,new A(2,null)),out path),DeepCmp.Result.Eq); Is(path,null); Is(dc.Compare(new A(1,new A(2,null)),new A(1,new A(3,null)),out path),DeepCmp.Result.ValNe); IsDeeply(path,new[]{new PathEntry(0,new[]{2,2}),new PathEntry(2,new[]{2,2}),new PathEntry(3)}); }
void TestNest() { var dc=new DeepCmp(); List<PathEntry> path; var a=new A(1,null); a.Aref=a; var b=new A(1,null); b.Aref=b; Is(dc.Compare(a,b,out path),DeepCmp.Result.Eq); Is(path,null); // 'got' and 'expected' referring to each other a.Aref=b; b.Aref=a; Is(dc.Compare(a,b,out path),DeepCmp.Result.Eq); Is(path,null); a.B=2; Is(dc.Compare(a,b,out path),DeepCmp.Result.ValNe); IsDeeply(path,new[]{new PathEntry(0,new[]{2,2}),new PathEntry(1)}); }
static bool IsDeeplyCommon(object got, object expected, string name) { List <PathEntry> path; DeepCmp.Result res = new DeepCmp(BlackBoxTypes).Compare(got, expected, out path); bool bres = res == DeepCmp.Result.Eq; using (new WithInvariantCulture()) { lock (WriteLock) { ReportOkness(name, bres); if (!bres || Verbose >= 4) { var comdic = MkCommentDic(bres, name, null, GetStackFrame()); comdic.Add("actual", got); comdic.Add("expected", expected); WriteComment(comdic, path, name); } } } TimerReset(); return(bres); }
void TestNullDic() { var dc=new DeepCmp(); List<PathEntry> path; Is(dc.Compare(null,new Dictionary<string,string>{{"a","b"}},out path),DeepCmp.Result.ValNe); IsDeeply(path,new[]{new PathEntry(0,new[]{0,1})}); Is(dc.Compare(new Dictionary<string,string>{{"a",null}},new Dictionary<string,string>{{"a","b"}},out path),DeepCmp.Result.ValNe); IsDeeply(path,new[]{new PathEntry(0,new[]{1,1}),new PathEntry(1)}); }