1 /*
2  markdown_benchmark.cpp     MindForger markdown test
3 
4  Copyright (C) 2016-2020 Martin Dvorak <martin.dvorak@mindforger.com>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <cstdlib>
21 #include <iostream>
22 #include <memory>
23 #include <cstdio>
24 #ifndef _WIN32
25 #  include <unistd.h>
26 #endif //_WIN32
27 
28 #include <gtest/gtest.h>
29 
30 #include "../test_gear.h"
31 #include "representations/html/html_outline_representation.h"
32 #include "mind/mind.h"
33 #include "persistence/filesystem_persistence.h"
34 
35 using namespace std;
36 
37 extern char* getMindforgerGitHomePath();
38 
TEST(HtmlTestCase,Outline)39 TEST(HtmlTestCase, Outline)
40 {
41     string fileName{"/lib/test/resources/benchmark-repository/memory/meta.md"};
42     fileName.insert(0, getMindforgerGitHomePath());
43 
44     m8r::Configuration& config = m8r::Configuration::getInstance();
45     config.clear();
46     config.setConfigFilePath("/tmp/cfg-htc-o.md");
47     config.setActiveRepository(config.addRepository(m8r::RepositoryIndexer::getRepositoryForPath(fileName)));
48     m8r::Mind mind(config);
49     m8r::DummyHtmlColors dummyColors{};
50     m8r::HtmlOutlineRepresentation htmlRepresentation{mind.remind().getOntology(),dummyColors,nullptr};
51     m8r::MarkdownOutlineRepresentation markdownRepresentation(mind.remind().getOntology(),nullptr);
52     mind.learn();
53     mind.think().get();
54 
55     ASSERT_GE(mind.remind().getOutlinesCount(), 1);
56 
57     // MD: 1.1MiB
58     string markdown{};
59     markdownRepresentation.to(mind.remind().getOutlines()[0], &markdown);
60     cout << "Markdown " << markdown.size() << "B" << endl;
61 
62     string html{};
63     htmlRepresentation.to(&markdown, &html);
64 
65     // HTML not printed - it is huge
66     // cout << "= BEGIN HTML =" << endl << html << endl << "= END HTML =" << endl;
67 
68     EXPECT_NE(std::string::npos, html.find("increment"));
69     EXPECT_NE(std::string::npos, html.find("Meyers"));
70     EXPECT_NE(std::string::npos, html.find("Stroustrup"));
71 }
72 
TEST(HtmlTestCase,Note)73 TEST(HtmlTestCase, Note)
74 {
75     string fileName{"/lib/test/resources/benchmark-repository/memory/meta.md"};
76     fileName.insert(0, getMindforgerGitHomePath());
77 
78     m8r::Configuration& config = m8r::Configuration::getInstance();
79     config.clear();
80     config.setConfigFilePath("/tmp/cfg-htc-n.md");
81     config.setActiveRepository(config.addRepository(m8r::RepositoryIndexer::getRepositoryForPath(fileName)));
82     m8r::Mind mind(config);
83     m8r::DummyHtmlColors dummyColors{};
84     m8r::HtmlOutlineRepresentation htmlRepresentation{mind.remind().getOntology(),dummyColors,nullptr};
85     mind.learn();
86     mind.think().get();
87 
88     ASSERT_GE(mind.remind().getOutlinesCount(), 1);
89 
90     string html{};
91     htmlRepresentation.to(mind.remind().getOutlines()[0]->getNotes()[0], &html);
92 
93     cout << "= BEGIN HTML =" << endl << html << endl << "= END HTML =" << endl;
94 }
95 
TEST(HtmlTestCase,NoteLinks)96 TEST(HtmlTestCase, NoteLinks)
97 {
98     string fileName{"/lib/test/resources/markdown-repository/memory/feature-html-links.md"};
99     fileName.insert(0, getMindforgerGitHomePath());
100 
101     m8r::Configuration& config = m8r::Configuration::getInstance();
102     config.clear();
103     config.setConfigFilePath("/tmp/cfg-antc-nl.md");
104     config.setActiveRepository(config.addRepository(m8r::RepositoryIndexer::getRepositoryForPath(fileName)));
105     m8r::Mind mind(config);
106     m8r::DummyHtmlColors dummyColors{};
107     m8r::HtmlOutlineRepresentation htmlRepresentation{mind.remind().getOntology(),dummyColors,nullptr};
108     mind.learn();
109     mind.think().get();
110 
111     ASSERT_GE(mind.remind().getOutlinesCount(), 1);
112 
113     string html{};
114     htmlRepresentation.to(mind.remind().getOutlines()[0]->getNotes()[0], &html);
115 
116     // links are NOT resolved - they are kept as they are
117     cout << "= BEGIN HTML =" << endl << html << endl << "= END HTML =" << endl;
118 }
119 
TEST(HtmlTestCase,TaskList)120 TEST(HtmlTestCase, TaskList)
121 {
122     string fileName{"/lib/test/resources/markdown-repository/memory/feature-task-list.md"};
123     fileName.insert(0, getMindforgerGitHomePath());
124 
125     m8r::Configuration& config = m8r::Configuration::getInstance();
126     config.clear();
127     config.setConfigFilePath("/tmp/cfg-antc-tl.md");
128     config.setActiveRepository(config.addRepository(m8r::RepositoryIndexer::getRepositoryForPath(fileName)));
129     m8r::Mind mind(config);
130     m8r::DummyHtmlColors dummyColors{};
131     m8r::HtmlOutlineRepresentation htmlRepresentation{mind.remind().getOntology(),dummyColors,nullptr};
132     mind.learn();
133     mind.think().get();
134 
135     ASSERT_GE(mind.remind().getOutlinesCount(), 1);
136 
137     string html{};
138     // O header
139     htmlRepresentation.to(mind.remind().getOutlines()[0]->getOutlineDescriptorAsNote(), &html);
140     cout << "= BEGIN O HTML =" << endl << html << endl << "= END O HTML =" << endl;
141     EXPECT_NE(std::string::npos, html.find("input"));
142     // N
143     html.clear();
144     htmlRepresentation.to(mind.remind().getOutlines()[0]->getNotes()[0], &html);
145     cout << "= BEGIN N HTML =" << endl << html << endl << "= END N HTML =" << endl;
146     EXPECT_NE(std::string::npos, html.find("input"));
147 }
148