Example #1
0
func Test_getLatexBody(t *testing.T) {
	a := Article{
		BaseName:    "test_article",
		Title:       "Testing Title",
		Authors:     []string{"Author One"},
		Content:     `Test Text.`,
		Abstract:    "This is the abstract.",
		Date:        "2 June 2015",
		Journal:     "Test Journal",
		Url:         "http://www.test.com",
		LatexEscUrl: "http://www.test.com",
	}

	a.Pdf()

	got := GetLatexBody(a.BaseName + ".tex")

	want := `\renewcommand{\title}{{\LARGE{\textbf{Testing Title}}}}
\renewcommand{\author}{{By Author One.}}

\begin{document}

\begin{center}
  \title    \\[0.5em]
  \author   \\[0.5em]

  \begin{abstract}
    This is the abstract.
  \end{abstract}

\end{center}

\begin{multicols}{2}
Test Text.
\end{multicols}

\vspace{1ex}
\par\noindent\rule{0.1\textwidth}{0.5pt}\\
\footnotesize{Published on 2 June 2015 in Test Journal}

\footnotesize{\href{http://www.test.com}{\nolinkurl{http://www.test.com}}.}

\end{document}
`

	if err := testutils.MustBeEqual(got, want); err != nil {
		t.Errorf("strings don't match")
	}

	logger.Err(os.Remove("test_article.tex"))
	logger.Err(os.Remove("test_article.pdf"))
}
Example #2
0
func mustHaveEqualText(test IntegrationTest, article Article) error {
	fileName := article.BaseName + ".tex"
	got := GetLatexBody(fileName)
	want := GetLatexBody(test.file + ".tex")

	got = removeHrefFromCaption(got)
	want = removeHrefFromCaption(want)

	if err := testutils.MustBeEqual(got, want); err != nil {
		return err
	}

	return nil
}
Example #3
0
func Test_CreateLatex_Abstract(t *testing.T) {
	a := Article{
		Title:       "Testing Title",
		Authors:     []string{"Author One"},
		Content:     "This is the text body.",
		Abstract:    "This is the abstract.",
		Date:        "2 June 2015",
		Journal:     "Test Journal",
		Url:         "http://www.test.com",
		LatexEscUrl: "http://www.test.com",
	}

	got := createLatex(a)

	want := GetPreamble(texTemplate) + `\renewcommand{\title}{{\LARGE{\textbf{Testing Title}}}}
\renewcommand{\author}{{By Author One.}}

\begin{document}

\begin{center}
  \title    \\[0.5em]
  \author   \\[0.5em]

  \begin{abstract}
    This is the abstract.
  \end{abstract}

\end{center}

\begin{multicols}{2}
This is the text body.
\end{multicols}

\vspace{1ex}
\par\noindent\rule{0.1\textwidth}{0.5pt}\\
\footnotesize{Published on 2 June 2015 in Test Journal}

\footnotesize{\href{http://www.test.com}{\nolinkurl{http://www.test.com}}.}

\end{document}
`

	if err := testutils.MustBeEqual(got, want); err != nil {
		t.Errorf("strings don't match")
	}
	cleanup()
}
Example #4
0
func comparePdfImages(gotFileName, wantFileName string) error {
	cmd := "pdfimages"

	args := []string{"-list", gotFileName}
	got, err1 := exec.Command(cmd, args...).Output()

	args = []string{"-list", wantFileName}
	want, err2 := exec.Command(cmd, args...).Output()

	if err1 != nil {
		return err1
	}
	if err2 != nil {
		return err2
	}
	if err := testutils.MustBeEqual(string(got), string(want)); err != nil {
		return err
	}

	return nil
}
Example #5
0
func Test_guessSourceURL_regularImageClass_getCorrectURL(t *testing.T) {
	tests := testutils.ConversionTests{
		{
			In: `<html><head></head><body>
<p>In this figure.</p>
<div id="attachment_592" style="width: 690px" class="wp-caption aligncenter">
	<a href="http://coding-geek.com/wp-content/uploads/2015/05/sine_wave-min.png">
		<img class="wp-image-592" src="http://coding-geek.com/wp-content/uploads/2015/05/sine_wave-min.png.pagespeed.ce.4qmecFS6zo.png" alt="pure sinewave at 20 Hz" width="680" height="431" pagespeed_url_hash="1382721686" data-pagespeed-onload="pagespeed.CriticalImages.checkImageForCriticality(this);" onload="var elem=this;if (this==window) elem=document.body;elem.setAttribute('data-pagespeed-loaded', 1)"/>
	</a>
	<p class="wp-caption-text">pure sinewave at 20 Hz</p>
</div>
<p>In this figure.</p>
</body></html>`,

			Want: "http://coding-geek.com/wp-content/uploads/2015/05/sine_wave-min.png.pagespeed.ce.4qmecFS6zo.png",
		},
	}

	for _, test := range tests {

		node, _ := html.Parse(strings.NewReader(test.In))
		doc := goquery.NewDocumentFromNode(node)

		imgSelections, _ := guessImgTag(doc)

		// initialize with random string so we can also test for empty strings,
		// when  no caption was found
		got := "mklkmkloijiklj"

		for _, imgSel := range imgSelections {
			imgSel.Each(func(_ int, s *goquery.Selection) {
				got = guessSourceURL(s, doc.Url)
			})
		}
		if err := testutils.MustBeEqual(got, test.Want); err != nil {
			t.Errorf("strings don't match")
		}
	}

}
Example #6
0
func Test_sanatizeCaption_getDirtyCaption_sanatizeCaption(t *testing.T) {
	tests := testutils.ConversionTests{
		{
			In: `Figure 1: Testing 
			test`,
			Want: `Testing test`,
		},
		{
			In: `Fig. 100: Testing 

			test`,
			Want: `Testing test`,
		},
	}

	for _, test := range tests {
		got := sanatizeCaptions(test.In)
		if err := testutils.MustBeEqual(got, test.Want); err != nil {
			t.Errorf("strings don't match")
		}
	}
}
Example #7
0
func Test_handleTextFieldCharEncoding_authorWithLatexMetaChar_escapeMetaChar(t *testing.T) {
	a := Article{
		Title:       "Testing Title",
		Authors:     []string{"Author_One"},
		Content:     "This is the text body.",
		Date:        "2 June 2015",
		Journal:     "Test Journal",
		Url:         "http://www.test.com",
		LatexEscUrl: "http://www.test.com",
	}

	a.handleTextFieldCharEncoding()

	got := a.Authors[0]
	want := "Author\\_One"

	if err := testutils.MustBeEqual(got, want); err != nil {
		t.Errorf("strings don't match")
	}
	cleanup()

}
Example #8
0
func runCaptionTest(tests testutils.ConversionTests) error {
	for _, test := range tests {

		doc := newDocFromString(test.In)

		imgSelections, imgTag := guessImgTag(doc)

		// initialize with random string so we can also test for empty strings,
		// when  no caption was found
		got := "mklkmkloijiklj"

		for _, imgSel := range imgSelections {
			imgSel.Each(func(_ int, s *goquery.Selection) {
				figEnv := guessImgEnvironment(s)
				got = guessCaption(figEnv, imgTag)
			})
		}

		if err := testutils.MustBeEqual(got, test.Want); err != nil {
			return err
		}
	}
	return nil
}