using NUnit.Framework; using System.IO; using System; using System.Text; using System.Text.RegularExpressions; namespace NewLanguage { [TestFixture] public class TestFromWorkbook { static Regex tiddlerRE = new Regex(@"^
[^""]*)"".*(tags=""(?[^""]*)"")?"); [Test] public void Test1() { const string workbook = "../../../workbook.html"; using (TextReader rdr = new StreamReader(workbook)) { string currentTiddler = null; while (true) { string line = rdr.ReadLine(); if (line == null) return; Match m = tiddlerRE.Match(line); if (m.Success) { currentTiddler = m.Groups["title"].Value; } // beginning of TiddlyWiki extended // code section, either within a // tiddler or as the first line. else if (line.Equals("{{{") || line.Equals("
{{{"))
                    {
                        testCode(currentTiddler, rdr);
                    }
                }
            }
        }

        private void testCode(string tiddler, TextReader from)
        {
            StringBuilder code = new StringBuilder();
            while (true)
            {
                string line = from.ReadLine();
                if (line.Equals("}}}") || line.Equals("}}}
")) { // end of code section if (code.ToString().StartsWith("#BNF")) { // not our language return; } Console.WriteLine("Code from {0}: {1}", tiddler, code.ToString()); //Lexer lex = new Lexer(new StringReader(code.ToString())); //for (Token tok = lex.GetNext(); tok.cls != TokenClass.EOF; tok = lex.GetNext()) //{ //Console.WriteLine(" {0}", tok); //} Console.WriteLine("NOT Lexed OK"); return; } else if (line.Equals("{{{") || tiddlerRE.Match(line).Success) { Assert.Fail("Unterminated code sequence in {0}", tiddler); } else { code.AppendLine(line); } } } } }