Exemplo n.º 1
0
        public static TextElement ParserLoadWord(WordBase word, string code, string value, string name, int from, int to, int end)
        {
            string     n          = string.Empty;
            TextBuffer textBuffer = Util.NewBufferWs(code);

            word.TextBuffer = textBuffer;

            var outNo = new List <TextElement>();

            //var idn = new WordIdent("kurt") { TextBuffer = textBuffer };
            Assert.AreEqual(true, word.Load(outNo, 0), n + "Identifier: Can't read");

            textBuffer.FindNextWord(null, false);
            TextElement text = null;

            if (outNo.Count > 0 || to > 0)
            {
                text = outNo[0];
            }

            if (text != null && text is CodeElement)
            {
                var codeElem = text as CodeElement;
                Assert.IsNotNull(codeElem, n + "Identifier: Can't find node after reading");
                Assert.AreEqual(value, codeElem.Value, n + "Identifier: The value is not correct");
                Assert.AreEqual(name, codeElem.Name, n + "Identifier: The name is not correct");
                Assert.AreEqual(from, codeElem.SubString.From, n + "Identifier: The start is not correct");
                Assert.AreEqual(to, codeElem.SubString.To, n + "Identifier: The end is not correct");
            }
            if (text != null && text is CommentElement)
            {
                var comm = outNo[0] as CommentElement;
                Assert.IsNotNull(comm, n + "Identifier: Can't find node after reading");
                Assert.AreEqual(value, comm.Value, n + "Identifier: The value is not correct");
                Assert.AreEqual(name, comm.Name, n + "Identifier: The name is not correct");
                Assert.AreEqual(from, comm.SubString.From, n + "Identifier: The start is not correct");
                Assert.AreEqual(to, comm.SubString.To, n + "Identifier: The end is not correct");
            }
            Assert.AreEqual(end, textBuffer.PointerNextChar, n + "Identifier: The buffer pointer is of after reading");

            return(text);
        }
Exemplo n.º 2
0
        public static void WordLoadError(string buf, WordBase word, string testName, string expected)
        {
            TextBuffer textBuffer = Util.NewBufferWs(buf);

            word.TextBuffer = textBuffer;
            Rule rule = new Rule("testRule", word);

            //rule.add
            var outNo = new List <TextElement>();

            //var idn = new WordIdent("kurt") { TextBuffer = textBuffer };
            Assert.AreEqual(false, word.Load(outNo, 0), "No read error");
            Assert.AreEqual(false, word.ResolveErrorsForward(0), "No read error");
            Assert.IsNotNull(textBuffer.Status.Error, testName + " No error object");

            string actual = textBuffer.Status.Error.Message;
            string s      = string.Join("\r\n", textBuffer.Status.AllErrors.Select(err => err.Message).ToArray());

            //ParseErrorResPos(testName, line, col, errMsg1, resourceExpression, parm);
            //string expected =
            Assert.AreEqual(expected, actual, testName);
        }