Ejemplo n.º 1
0
        public void TestSimpleFexLine()
        {
            //arrange
            var fileService    = new FileService();
            var lines          = fileService.ReadFile(TestHelper.GetInputFilePath("simple.fex"));
            var fexService     = new FexService(lines);
            var fexLines       = fexService.Process();
            var contentService = new ContentService(fexLines);

            //act
            var content = contentService.Process();

            //assert
            Assert.IsTrue(content.Children[0] is Section);
            var section1 = content.Children[0];

            Assert.AreEqual(section1.Header.Text, "H1");
            Assert.AreEqual(section1.Content.Count, 0);
            Assert.AreEqual(section1.Children.Count, 1);
            Assert.IsTrue(section1.Children[0] is Section);

            var section2 = section1.Children[0];

            Assert.AreEqual(section2.Header.Text, "H2");
            Assert.AreEqual(section2.Content[0].Text, "hallo");
            Assert.AreEqual(section2.Content[1].Text, "welt");
        }
Ejemplo n.º 2
0
        public void TestColon()
        {
            //arrange
            var fileService = new FileService();
            var lines       = fileService.ReadFile(TestHelper.GetInputFilePath("colon.fex"));
            var fexService  = new FexService(lines);

            //act
            var fexLines = fexService.Process();

            //assert
            Assert.AreEqual(9, fexLines.Count);

            var levelList = new List <int>()
            {
                0, 1, 1, 2, 2, 1, 2, 1, 1
            };

            for (int i = 0; i < fexLines.Count; i++)
            {
                Assert.AreEqual(levelList[i], fexLines[i].Level);
            }

            Assert.AreEqual(0, fexLines.Count(l => l.Text.EndsWith(":")));
        }
Ejemplo n.º 3
0
        protected override void TestFex(string fileName)
        {
            //arrange
            var fileService    = new FileService();
            var lines          = fileService.ReadFile(TestHelper.GetInputFilePath(fileName));
            var fexService     = new FexService(lines);
            var fexLines       = fexService.Process();
            var contentService = new ContentService(fexLines);

            //act
            var content = contentService.Process();

            //assert
            Assert.IsTrue(content.Children.Count > 0);
            Assert.IsTrue(content.Content.Count == 0);
            Assert.IsTrue(content.Header == null);

            var dic = new Dictionary <string, int>()
            {
                { "simple.fex", 1 },
                { "advanced.fex", 1 },
                { "long.fex", 2 },
                { "codeContent.fex", 1 }
            };

            Assert.AreEqual(content.Children.Count, dic[fileName]);
        }
Ejemplo n.º 4
0
        public void TestLongFexLine()
        {
            //arrange
            var fileService    = new FileService();
            var lines          = fileService.ReadFile(TestHelper.GetInputFilePath("long.fex"));
            var fexService     = new FexService(lines);
            var fexLines       = fexService.Process();
            var contentService = new ContentService(fexLines);

            //act
            var content = contentService.Process();

            //assert
            Assert.IsTrue(content.Children[0] != null);
            Assert.IsTrue(content.Children[1] != null);
            var section1 = content.Children[0];
            var section4 = content.Children[1];

            Assert.AreEqual(section1.Header.Text, "H1");
            Assert.AreEqual(section1.Content.Count, 0);
            Assert.AreEqual(section1.Children.Count, 2);
            Assert.IsTrue(section1.Children[0] != null);
            Assert.IsTrue(section1.Children[1] != null);

            var section2 = section1.Children[0];

            Assert.AreEqual(section2.Header.Text, "H2");
            Assert.AreEqual(section2.Content.Count, 0);
            Assert.AreEqual(section2.Children.Count, 1);
            Assert.IsTrue(section2.Children[0] != null);

            var section21 = section2.Children[0];

            Assert.AreEqual(section21.Header.Text, "H2.1");
            Assert.AreEqual(section21.Content.Count, 2); //skip textContent inspection
            Assert.AreEqual(section21.Children.Count, 0);

            var section3 = section1.Children[1];

            Assert.AreEqual(section3.Header.Text, "H3");
            Assert.AreEqual(section3.Content.Count, 2);
            Assert.AreEqual(section3.Children.Count, 0);

            Assert.AreEqual(section4.Header.Text, "H4");
            Assert.AreEqual(section4.Content.Count, 0);
            Assert.AreEqual(section4.Children.Count, 1);
            Assert.IsTrue(section4.Children[0] != null);

            var section5 = section4.Children[0];

            Assert.AreEqual(section5.Header.Text, "H5");
            Assert.AreEqual(section5.Content.Count, 2);
            Assert.AreEqual(section5.Children.Count, 0);
        }
Ejemplo n.º 5
0
        protected override void TestFex(string fileName)
        {
            //arrange
            var fileService = new FileService();
            var lines       = fileService.ReadFile(TestHelper.GetInputFilePath(fileName));
            var fexService  = new FexService(lines);

            //act
            var fexLines = fexService.Process();

            //assert
            Assert.IsTrue(fexLines.Count > 0);

            var dic = new Dictionary <string, int>()
            {
                { "simple.fex", 4 },
                { "advanced.fex", 11 },
                { "long.fex", 12 }
            };

            Assert.AreEqual(fexLines.Count, dic[fileName]);

            var dic2 = new Dictionary <string, List <int> >()
            {
                {
                    "simple.fex",
                    new List <int>()
                    {
                        0, 1, 2, 2
                    }
                },
                {
                    "advanced.fex",
                    new List <int>()
                    {
                        0, 1, 2, 3, 3, 2, 2, 3, 4, 4, 2
                    }
                },
                {
                    "long.fex",
                    new List <int>()
                    {
                        0, 1, 2, 3, 3, 1, 2, 2, 0, 1, 2, 2
                    }
                }
            };

            for (int i = 0; i < dic2[fileName].Count; i++)
            {
                Assert.AreEqual(fexLines[i].Level, dic2[fileName][i]);
            }
        }
Ejemplo n.º 6
0
        public void TestSimpleFexLine()
        {
            //arrange
            var fileService = new FileService();
            var lines       = fileService.ReadFile(TestHelper.GetInputFilePath("simple.fex"));
            var fexService  = new FexService(lines);

            //act
            var fexLines = fexService.Process();

            //assert
            Assert.IsTrue(fexLines.Count > 0);
        }
Ejemplo n.º 7
0
        public void TestSimpleFexExact()
        {
            //arrange
            var fileService      = new FileService();
            var lines            = fileService.ReadFile(TestHelper.GetInputFilePath("simple.fex"));
            var fexService       = new FexService(lines);
            var fexLines         = fexService.Process();
            var statisticService = new StatisticService(fexLines);

            //act
            var statistic = statisticService.Process();

            //assert
            Assert.IsTrue(statistic.CharacterCount == 2 + 2 + 5 + 4);
            Assert.IsTrue(statistic.WordCount == 4);
            Assert.IsTrue(statistic.LineCount == 4);
        }
Ejemplo n.º 8
0
        protected override void TestFex(string fileName)
        {
            //arrange
            var fileService      = new FileService();
            var lines            = fileService.ReadFile(TestHelper.GetInputFilePath(fileName));
            var fexService       = new FexService(lines);
            var fexLines         = fexService.Process();
            var statisticService = new StatisticService(fexLines);

            //act
            var statistic = statisticService.Process();

            //assert
            Assert.IsTrue(statistic.CharacterCount > 0);
            Assert.IsTrue(statistic.WordCount > 0);
            Assert.IsTrue(statistic.LineCount > 0);

            Assert.IsTrue(statistic.CharacterCount > statistic.WordCount);
        }
Ejemplo n.º 9
0
        public void TestCode()
        {
            //arrange
            var fileService    = new FileService();
            var lines          = fileService.ReadFile(TestHelper.GetInputFilePath("code.fex"));
            var fexService     = new FexService(lines);
            var fexLines       = fexService.Process();
            var contentService = new ContentService(fexLines);

            //act
            var content = contentService.Process();

            //assert
            Assert.IsTrue(content.Children[0] != null);
            var section1 = content.Children[0];

            Assert.AreEqual(section1.Header.ContentType, ContentType.Text);
            Assert.AreEqual(section1.Header.Text, "H1");
            Assert.AreEqual(section1.Content.Count, 0);
            Assert.AreEqual(section1.Children.Count, 1);
            Assert.IsTrue(section1.Children[0] != null);

            var section2 = section1.Children[0];

            Assert.AreEqual(section2.Header.ContentType, ContentType.Text);
            Assert.AreEqual(section2.Header.Text, "H2");
            Assert.AreEqual(section2.Content.Count, 4);

            Assert.AreEqual(section2.Content[0].ContentType, ContentType.Text);
            Assert.AreEqual(section2.Content[0].Text, "text");

            Assert.AreEqual(section2.Content[1].ContentType, ContentType.Code);
            Assert.AreEqual(section2.Content[1].Text, "var code = true;\n\tcode = false><;");

            Assert.AreEqual(section2.Content[2].ContentType, ContentType.Text);
            Assert.AreEqual(section2.Content[2].Text, "normal text continues");

            Assert.AreEqual(section2.Content[3].ContentType, ContentType.Text);
            Assert.AreEqual(section2.Content[3].Text, "and further");
        }
Ejemplo n.º 10
0
        private bool?CompileFile(string path)
        {
            (string folder, string filenamePrefix, string[] exportFormats) = ParsePath(path);

            //get version information
            var metaDataService   = new MetaDataService(_configModel, path);
            var metaData          = metaDataService.Process();
            var fexVersionService = new FexVersionService(metaData, folder, filenamePrefix);

            if (fexVersionService.NoChangesNeeded())
            {
                return(null);
            }

            var document = new DocumentModel()
            {
                MetaDataModel = metaData
            };

            //read out file
            StepStarted("read out lines");
            document.RawLines = _fileService.ReadFile(path);
            StepCompleted();

            //convert to fexLines
            StepStarted("parsing lines");
            var fexService = new FexService(document.RawLines);

            document.FexLines = fexService.Process();
            StepCompleted();

            //create statistic
            StepStarted("gathering statistics");
            var statisticService = new StatisticService(document.FexLines);

            document.StatisticModel = statisticService.Process();
            StepCompleted();

            //convert to content
            StepStarted("processing content");
            var contentService = new ContentService(document.FexLines);

            document.RootSection = contentService.Process();
            StepCompleted();

            var successful = true;

            if (exportFormats.Contains("json") || exportFormats.Contains("xlsx"))
            {
                //learning cards create
                StepStarted("creating learning cards");
                var learningCardsService = new GenerationService(document.StatisticModel, document.MetaDataModel,
                                                                 document.RootSection.Children);
                var cards = learningCardsService.Process();
                StepCompleted();

                if (exportFormats.Contains("json"))
                {
                    //learning cards persist
                    StepStarted("persisting learning cards (json)");
                    var learningCardsExportService = new JsonExportService(cards, folder, filenamePrefix);
                    var learningCardsFeedback      = learningCardsExportService.Process();
                    StepCompleted(learningCardsFeedback);

                    successful &= learningCardsFeedback;
                }

                if (exportFormats.Contains("xlsx"))
                {
                    //learning cards persist
                    StepStarted("persisting learning cards (xlsx)");
                    var learningCardsExportService = new XlsxExportService(cards, folder, filenamePrefix);
                    var learningCardsFeedback      = learningCardsExportService.Process();
                    StepCompleted(learningCardsFeedback);

                    successful &= learningCardsFeedback;
                }
            }

            if (exportFormats.Contains("md"))
            {
                //latex create
                StepStarted("creating & storing markdown");
                var markdownService = new Services.Markdown.ExportService(document.RootSection.Children,
                                                                          document.MetaDataModel.Title, folder, filenamePrefix);
                var markdownFeedback = markdownService.Process();
                StepCompleted();

                successful &= markdownFeedback;
            }

            if (exportFormats.Contains("pdf") || exportFormats.Contains("handout_pdf"))
            {
                //latex create
                StepStarted("creating latex");
                var latexService = new Services.Latex.GenerationService(document.RootSection.Children);
                var latex        = latexService.Process();
                StepCompleted();

                if (exportFormats.Contains("pdf"))
                {
                    //latex template
                    StepStarted("preparing PDF template");
                    var latexTemplateService = new TemplateService(latex, document.StatisticModel, document.MetaDataModel,
                                                                   TemplateService.DefaultTemplate);
                    var templatedLatex = latexTemplateService.Process();
                    StepCompleted();

                    //latex compile
                    StepStarted("compiling PDF latex");
                    var latexCompilerService = new CompilationService(templatedLatex, folder, filenamePrefix);
                    var latexCompileFeedback = latexCompilerService.Process();
                    StepCompleted(latexCompileFeedback);

                    successful &= latexCompileFeedback;
                }

                if (exportFormats.Contains("handout_pdf"))
                {
                    //latex template
                    StepStarted("preparing handout PDF template");
                    var latexTemplateService = new TemplateService(latex, document.StatisticModel, document.MetaDataModel,
                                                                   TemplateService.HandoutTemplate);
                    var templatedLatex = latexTemplateService.Process();
                    StepCompleted();

                    //latex compile
                    StepStarted("compiling handout PDF latex");
                    var latexCompilerService = new CompilationService(templatedLatex, folder, filenamePrefix + "_handout");
                    var latexCompileFeedback = latexCompilerService.Process();
                    StepCompleted(latexCompileFeedback);

                    successful &= latexCompileFeedback;
                }
            }

            if (successful)
            {
                StepStarted("saving version information");
                fexVersionService.MarkFexCompileSuccessful();
                StepCompleted();
            }

            return(successful);
        }
Ejemplo n.º 11
0
        protected override void TestFex(string fileName)
        {
            //arrange
            var fileService    = new FileService();
            var lines          = fileService.ReadFile(TestHelper.GetInputFilePath(fileName));
            var fexService     = new FexService(lines);
            var fexLines       = fexService.Process();
            var contentService = new ContentService(fexLines);
            var root           = contentService.Process();
            var latexService   = new GenerationService(root.Children);
            var dict           = new Dictionary <string, string[]>
            {
                {
                    "simple.fex",
                    new []
                    {
                        @"\textbf{H2}\\",
                        @"hallo\\",
                        @"welt\\"
                    }
                },
                {
                    "advanced.fex",
                    new []
                    {
                        @"\section{H1",
                        @"\subsection{H2",
                        @"\subsubsection{text",
                        @"\textbf{because it has further"
                    }
                },
                {
                    "long.fex",
                    new []
                    {
                        @"\subsection{H3}",
                        @"H3.1\\",
                        @"\section{H4}"
                    }
                },
                {
                    "formulas.fex",
                    new []
                    {
                        @"x$^{2_{32}}$", // looks weird, but rendering checks out
                        @"x$^{2_{32}}$$_{bottom}$(a)",
                        @"$x^2$\\",
                        @"$x^{2^{32}}$\\",
                        @"$x^{2_{32}}$\\",
                        @"$K_{{ab}_{ab}}$\\",
                        @"$x^{-2t}$\\",
                        @"$n^{-1000}$\\",
                        @"$\epsilon$\\",
                        @"hello $\theta$ how are you\\",
                    }
                },
                {
                    "realworld.fex",
                    new []
                    {
                        @"some condition \textasciicircum",
                        @"${\{N\}}_{\{A\}}$\\",
                        @"S $\rightarrow$ B: M, ${\{N_A, K_{AB}\}}_{AS}$, ${\{N_B, K_{AB}\}}_{BS}$\\",
                        @"${\{N\}}_1$\\",
                        @"${\{N_A\}}_1$\\",
                        @"B $\rightarrow$ A: $g^y$, ${\{g^y, g^x, A\}}_{sk(B)}$\\",
                        @"${\{A, B\}}_{sk}$\\",
                        @"${\{A, B\}}_{sk(B)}$\\",
                        @"${p(2)\{2\}}_{20p(8)(9)asd}$ hello\\"
                    }
                },
            };

            //act
            var latex = latexService.Process();

            //assert
            foreach (var s in dict[fileName])
            {
                Assert.IsTrue(latex.Contains(s));
            }
        }