func Test_convertImage_imageSizeIsTooSmall_removeImageFromHtml(t *testing.T) {
	tests := testutils.ConversionTests{
		{ // image to small dont use
			In: `<html><head></head><body>
<p>That includes detailed discussions of how to foster “obedience” and “conformity”:<br />
<a href="https://firstlook.org/wp-uploads/sites/1/2015/06/jtrig2.png"><img class="aligncenter size-article-medium wp-image-28243" src="https://firstlook.org/wp-uploads/sites/1/2015/06/jtrig2-540x303.png" alt="" height="9" /></a><br />
<p>In response to inquiries, GCHQ refused to provide on-the-record responses beyond its boilerplate claim that all its activities are lawful.</p>
</body></html>`,
			Want: `<html><head></head><body>
<p>That includes detailed discussions of how to foster “obedience” and “conformity”:<br/>
<a href="https://firstlook.org/wp-uploads/sites/1/2015/06/jtrig2.png"></a><br/>
</p><p>In response to inquiries, GCHQ refused to provide on-the-record responses beyond its boilerplate claim that all its activities are lawful.</p>
</body></html>`,
		},
	}

	if err := testutils.RunTestsAndCleanup(tests, convertImages, false); err != nil {
		t.Errorf("strings don't match")
	}
}
func Test_convertImage_hasRef(t *testing.T) {
	tests := testutils.ConversionTests{
		{ // regular images
			In: `<html><head></head><body>
<p><a href="http://www.amazon.com/dp/162779381X/ref=nosim/?tag=tomdispatch-20"><img src="http://www.tomdispatch.com/images/managed/rulesworldchomskyhc.jpg" alt="" hspace="6" align="left" /></a>Test.</p>
 </body></html>`,
			Want: `<html><head></head><body>
<p><a href="http://www.amazon.com/dp/162779381X/ref=nosim/?tag=tomdispatch-20">

\begin{Figure}
	\centering
	\includegraphics[width=0.95\textwidth]{1.jpg}
	\label{fig:1}
\end{Figure}
</a>Test.</p>
 </body></html>`,
		},
	}

	if err := testutils.RunTestsAndCleanup(tests, convertImages, false); err != nil {
		t.Errorf("strings don't match")
	}
}
func Test_convertImage_normalImg_createTexFigure(t *testing.T) {
	tests := testutils.ConversionTests{
		{ // regular images
			In: `<html><head></head><body>
 <p>That includes detailed discussions of how to foster “obedience” and “conformity”:<br />
 <a href="https://firstlook.org/wp-uploads/sites/1/2015/06/jtrig2.png"><img class="aligncenter size-article-medium wp-image-28243" src="https://firstlook.org/wp-uploads/sites/1/2015/06/jtrig2-540x303.png" alt="" /></a><br />
 <a href="https://firstlook.org/wp-uploads/sites/1/2015/06/jtrig4.png"><img class="aligncenter size-article-medium wp-image-28244" src="https://firstlook.org/wp-uploads/sites/1/2015/06/jtrig4-540x253.png" alt="" /></a><br />
 <p>In response to inquiries, GCHQ refused to provide on-the-record responses beyond its boilerplate claim that all its activities are lawful.</p>
 </body></html>`,
			Want: `<html><head></head><body>
 <p>That includes detailed discussions of how to foster “obedience” and “conformity”:<br/>
 <a href="https://firstlook.org/wp-uploads/sites/1/2015/06/jtrig2.png">

\begin{Figure}
	\centering
	\includegraphics[width=0.95\textwidth]{1.png}
	\label{fig:1}
\end{Figure}
</a><br/>
 <a href="https://firstlook.org/wp-uploads/sites/1/2015/06/jtrig4.png">

\begin{Figure}
	\centering
	\includegraphics[width=0.95\textwidth]{2.png}
	\label{fig:2}
\end{Figure}
</a><br/>
 </p><p>In response to inquiries, GCHQ refused to provide on-the-record responses beyond its boilerplate claim that all its activities are lawful.</p>
 </body></html>`,
		},
	}

	if err := testutils.RunTestsAndCleanup(tests, convertImages, false); err != nil {
		t.Errorf("strings don't match")
	}
}
Beispiel #4
0
func Test_convertList(t *testing.T) {
	tests := testutils.ConversionTests{
		{ // regular ol list
			In: `<html><head></head><body>
<p>ordered list.</p>
<ol>
<li>Number of items in the shopping cart</li>
<li>Order history</li>
<li>Customer reviews</li>
</ol>
<p>should lead to enumerate.</p>
</body></html>`,
			Want: `<html><head></head><body>
<p>ordered list.</p>
\begin{enumerate}
	\itemsep0em
	\item Number of items in the shopping cart
	\item Order history
	\item Customer reviews
\end{enumerate}
<p>should lead to enumerate.</p>
</body></html>`,
		},
		{ // regular ul list
			In: `<html><head></head><body>
<p>He called.</p>
<ul>
<li>Number of items in the shopping cart</li>
<li>Order history</li>
<li>Customer reviews</li>
</ul>
<p>The comments.</p>
</body></html>`,
			Want: `<html><head></head><body>
<p>He called.</p>
\begin{itemize}
	\itemsep0em
	\item Number of items in the shopping cart
	\item Order history
	\item Customer reviews
\end{itemize}
<p>The comments.</p>
</body></html>`,
		},
		{ // list with start tag
			In: `<html><head></head><body>
<ol class="c0 lst-kix_list_1-0" start="26">
<li class="c5"><span class="c4 c2">Test 1 </span></li>
<li class="c5"><span class="c4 c2">Test 2 </span></li>
</ol>
</body></html>`,
			Want: `<html><head></head><body>
\begin{enumerate}
	\setcounter{enumi}{25}
	\itemsep0em
	\item <span class="c4 c2">Test 1 </span>
	\item <span class="c4 c2">Test 2 </span>
\end{enumerate}
</body></html>`,
		},
		{ //mixed list
			In: `<html><head></head><body>
<p>He called.</p>
<ul>
<li>Number of items in the shopping cart</li>
<li>Order history</li>
<li>Customer reviews</li>
</ul>
<p>The comments.</p>
<ol>
<li>Number of items in the shopping cart</li>
<li>Order history</li>
<li>Customer reviews</li>
</ol>
<p>The comments.</p>
<ol class="c0 lst-kix_list_1-0" start="26">
<li class="c5"><span class="c4 c2">Test 1 </span></li>
<li class="c5"><span class="c4 c2">Test 2 </span></li>
</ol>
</body></html>`,
			Want: `<html><head></head><body>
<p>He called.</p>
\begin{itemize}
	\itemsep0em
	\item Number of items in the shopping cart
	\item Order history
	\item Customer reviews
\end{itemize}
<p>The comments.</p>
\begin{enumerate}
	\itemsep0em
	\item Number of items in the shopping cart
	\item Order history
	\item Customer reviews
\end{enumerate}
<p>The comments.</p>
\begin{enumerate}
	\setcounter{enumi}{25}
	\itemsep0em
	\item <span class="c4 c2">Test 1 </span>
	\item <span class="c4 c2">Test 2 </span>
\end{enumerate}
</body></html>`,
		},
	}
	if err := testutils.RunTestsAndCleanup(tests, convertList, false); err != nil {
		t.Errorf("strings don't match")
	}
}
Beispiel #5
0
//func Test_convertList_linebreaks(t *testing.T) {
//	tests := testutils.ConversionTests{
//		{ // list with figure and line break
//			In: `<html><head></head><body>
//		<p>He called.</p>
//		<ol>
//		<li>
//	<p><strong>Naming </strong>– we can only guess what does this method calculate and what exactly is the input for these calculations. It is really hard to extract calculation algorithm from this class.<br>
//	Risks:<br>
//	the most important thing in this case is – <strong>time wasting</strong><br>
//	&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<img alt="" src="https://openclipart.org/image/800px/svg_to_png/4077/ernes-clessidra-hourglass.png" style="width: 151px; height: 200px"><br>
//	, if we will get enquiry from business to present them algorithm details or we will have a need to modify this piece of code it will take us ages to understand logic of our <strong>Calculate </strong>method. And if we won’t document it or refactor the code, next time we/other developer will spend the same time to figure out what exactly is happening there. We can make very easily mistake while modifying it as well.</p>
//	</li>
//		</ol>
//		</body></html>`,
//			Want: `<html><head></head><body>
//\begin{enumerate}
//	\itemsep0em
//
//	\item \textbf{Naming}– we can only guess what does this method calculate and what exactly is the input for these calculations. It is really hard to extract calculation algorithm from this class.
//
//	Risks:
//
//	the most important thing in this case is \textendash{} \textbf{time wasting}
//
//<img alt="" src="https://openclipart.org/image/800px/svg_to_png/4077/ernes-clessidra-hourglass.png" style="width: 151px; height: 200px">
//
//	, if we will get enquiry from business to present them algorithm details or we will have a need to modify this piece of code it will take us ages to understand logic of our \textbf{Calculate} method. And if we won't document it or refactor the code, next time we/other developer will spend the same time to figure out what exactly is happening there. We can make very easily mistake while modifying it as well.
//\end{enumerate}
//		</body></html>`,
//		},
//	}
//	if err := testutils.RunTestsAndCleanup(tests, convertList, false); err != nil {
//		t.Errorf("strings don't match")
//	}
//}
//
func Test_convertList_nestedLists(t *testing.T) {
	tests := testutils.ConversionTests{
		{ // only unordered
			In: `<html><head></head><body>
<p>Test nested list.</p>
<ul>
  <li>Entities folder</li>
  <ul>
    <li>Entities\Game.cs</li>
    <li>Entities\Gender.cs</li>
  </ul>
  <li>Services folder</li>
  <ul>
    <li>Services\EntityService.cs</li>
    <li>Services\GameService.cs</li>
  </ul>
  <li>MongoConnectionHandler.cs</li>
</ul>
<p>Test</p>
</body></html>`,
			Want: `<html><head></head><body>
<p>Test nested list.</p>
\begin{itemize}
	\itemsep0em
  	\item Entities folder
  	\begin{itemize}
	\itemsep0em
    	\item Entities\Game.cs
    	\item Entities\Gender.cs
  	\end{itemize}
  	\item Services folder
  	\begin{itemize}
	\itemsep0em
    	\item Services\EntityService.cs
    	\item Services\GameService.cs
  	\end{itemize}
  	\item MongoConnectionHandler.cs
\end{itemize}
<p>Test</p>
</body></html>`,
		},
		{ //mixed
			In: `<html><head></head><body>
<p>Test nested list.</p>
<ul>
  <li>Entities folder</li>
  <ol>
    <li>Entities\Game.cs</li>
    <li>Entities\Gender.cs</li>
  </ol>
  <li>Services folder</li>
  <ul>
    <li>Services\EntityService.cs</li>
    <li>Services\GameService.cs</li>
  </ul>
  <li>MongoConnectionHandler.cs</li>
</ul>
<p>Test</p>
</body></html>`,
			Want: `<html><head></head><body>
<p>Test nested list.</p>
\begin{itemize}
	\itemsep0em
  	\item Entities folder
  	\begin{enumerate}
	\itemsep0em
    	\item Entities\Game.cs
    	\item Entities\Gender.cs
  	\end{enumerate}
  	\item Services folder
  	\begin{itemize}
	\itemsep0em
    	\item Services\EntityService.cs
    	\item Services\GameService.cs
  	\end{itemize}
  	\item MongoConnectionHandler.cs
\end{itemize}
<p>Test</p>
</body></html>`,
		},
	}
	if err := testutils.RunTestsAndCleanup(tests, convertList, false); err != nil {
		t.Errorf("strings don't match")
	}

}