示例#1
0
        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);
        }
示例#2
0
        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;
            }
        }
示例#3
0
        public static CatMetaDataBlock Create(string s)
        {
            s = "{{\n" + s + "\n}}\n";
            Peg.Parser parser  = new Peg.Parser(s);
            bool       bResult = parser.Parse(CatGrammar.MetaDataBlock());

            if (!bResult)
            {
                throw new Exception("failed to parse meta-data block");
            }
            Peg.PegAstNode tree = parser.GetAst();
            if (tree.GetNumChildren() == 0)
            {
                return(null);
            }
            if (tree.GetNumChildren() != 1)
            {
                throw new Exception("invalid number of child nodes in meta-data block node");
            }
            AstMetaDataBlock node = new AstMetaDataBlock(tree.GetChild(0));
            CatMetaDataBlock ret  = new CatMetaDataBlock(node);

            return(ret);
        }