public bool TestFunction(Function f) { bool bRet = true; testCount += 1; CatMetaDataBlock md = f.GetMetaData(); if (md != null) { List <CatMetaData> tests = md.FindAll("test"); foreach (CatMetaData test in tests) { CatMetaData input = test.Find("in"); CatMetaData output = test.Find("out"); if (input == null || output == null) { Output.WriteLine("ill-formed test in " + f.GetName()); return(false); } try { Executor aux = new Executor(this); aux.Execute(input.GetContent()); CatList listInput = aux.GetStackAsList(); aux.Clear(); aux.Execute(output.GetContent()); CatList listOutput = aux.GetStackAsList(); aux.Clear(); if (!listInput.Equals(listOutput)) { Output.WriteLine("failed test for instruction " + f.GetName()); Output.WriteLine("test input program = " + input.GetContent()); Output.WriteLine("test output program = " + output.GetContent()); Output.WriteLine("input program result = " + listInput.ToString()); Output.WriteLine("output program result = " + listOutput.ToString()); bRet = false; } } catch (Exception e) { Output.WriteLine("failed test for instruction " + f.GetName()); Output.WriteLine("exception occured: " + e.Message); bRet = false; } } } return(bRet); }
public void SetMetaData(CatMetaDataBlock meta) { mpMetaData = meta; CatMetaData desc = meta.Find("desc"); if (desc != null) { msDesc = desc.msContent; } CatMetaData tags = meta.Find("tags"); if (tags != null) { msTags = tags.msContent; } }
public CatMetaDataBlock(AstMetaDataBlock node) : base("root", null) { CatMetaData cur = this; int nCurIndent = -1; for (int i = 0; i < node.children.Count; ++i) { AstMetaData tmp = node.children[i]; if (tmp is AstMetaDataLabel) { int nIndent; string sName; SplitLabel(tmp.ToString(), out nIndent, out sName); if (nIndent > nCurIndent) { cur = cur.NewChild(sName); } else if (nIndent == nCurIndent) { cur = cur.GetParent(); Trace.Assert(cur != null); cur = cur.NewChild(sName); } else { cur = cur.GetParent(); Trace.Assert(cur != null); cur = cur.GetParent(); Trace.Assert(cur != null); cur = cur.NewChild(sName); } nCurIndent = nIndent; } else if (tmp is AstMetaDataContent) { cur.AddContent(tmp.ToString()); } else { throw new Exception("invalid AstMetaDataBlock"); } } }