From eb547701d4b71a3234df1ccb69537a9108daf539 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sat, 15 Mar 2008 11:06:44 +0100 Subject: [PATCH] Unit tests for metapost --- test/expected_dir/metapost.mp/metapost/blanks | 1 + test/expected_dir/metapost.mp/metapost/code | 29 +++++++++ .../expected_dir/metapost.mp/metapost/comment | 8 +++ test/expected_dir/metapost.mp/tex/blanks | 1 + test/expected_dir/metapost.mp/tex/code | 16 +++++ test/expected_dir/metapost.mp/tex/comment | 1 + test/src_dir/metapost.mp | 62 +++++++++++++++++++ test/unit/metapost_test.rb | 12 ++++ 8 files changed, 130 insertions(+) create mode 100644 test/expected_dir/metapost.mp/metapost/blanks create mode 100644 test/expected_dir/metapost.mp/metapost/code create mode 100644 test/expected_dir/metapost.mp/metapost/comment create mode 100644 test/expected_dir/metapost.mp/tex/blanks create mode 100644 test/expected_dir/metapost.mp/tex/code create mode 100644 test/expected_dir/metapost.mp/tex/comment create mode 100644 test/src_dir/metapost.mp create mode 100644 test/unit/metapost_test.rb diff --git a/test/expected_dir/metapost.mp/metapost/blanks b/test/expected_dir/metapost.mp/metapost/blanks new file mode 100644 index 0000000..301160a --- /dev/null +++ b/test/expected_dir/metapost.mp/metapost/blanks @@ -0,0 +1 @@ +8 \ No newline at end of file diff --git a/test/expected_dir/metapost.mp/metapost/code b/test/expected_dir/metapost.mp/metapost/code new file mode 100644 index 0000000..68ca6e4 --- /dev/null +++ b/test/expected_dir/metapost.mp/metapost/code @@ -0,0 +1,29 @@ +verbatimtex +etex +u:=25; % 25 = 25bp = 25 PostScript points = 30/72 in +wi:=10; % width in units u +he:=7; % height in units u +hoehe:=he*u; % height +breite:=wi*u; % width +picture lab; +beginfig(1) +for i=0 upto he: +draw (0, i*u)--(breite, i*u) withcolor .7white; +endfor +for j=0 upto wi: +draw (j*u, 0)--(j*u, hoehe) withcolor .7white; +endfor +draw (0, 0)--(breite, 0)--(breite, hoehe)--(0, hoehe)--cycle; +for i=0 upto 5: +draw .5(u, u){dir 20i}..{dir 20i}(9.5u, 4u); +endfor +lab:=\thelabel( +btex +etex, +(.5breite, hoehe-1.5u) +); +unfill bbox lab; +draw lab; +label.ulft(btex \cyr C\char24 rih, 08.09.2002 etex, (breite, 0)); +endfig; +end diff --git a/test/expected_dir/metapost.mp/metapost/comment b/test/expected_dir/metapost.mp/metapost/comment new file mode 100644 index 0000000..34d49cf --- /dev/null +++ b/test/expected_dir/metapost.mp/metapost/comment @@ -0,0 +1,8 @@ +% Sample MetaPost with embedded LaTeX, used as unit test for ohcount +% +% The MetaPost code is taken of LaTeXLabels.mp from +% the excellent MetaPost tutorial by Urs Oswald +% http://www.ursoswald.ch/metapost/tutorial.html +% +% --- Grid --- +% --- End Grid --- diff --git a/test/expected_dir/metapost.mp/tex/blanks b/test/expected_dir/metapost.mp/tex/blanks new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/test/expected_dir/metapost.mp/tex/blanks @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/test/expected_dir/metapost.mp/tex/code b/test/expected_dir/metapost.mp/tex/code new file mode 100644 index 0000000..334d27a --- /dev/null +++ b/test/expected_dir/metapost.mp/tex/code @@ -0,0 +1,16 @@ +\documentclass{article} +\newcommand{\uB}{\upshape{B\'ezier}} % up: upright +\newcommand{\iB}{\itshape{B\'ezier}} % it: italic +\newcommand{\lB}{\slshape{B\'ezier}} % sl: slanted +\newcommand{\cB}{\scshape{B\'ezier}} % sc: small caps +\newfont{\cyr}{wncyr10} +\begin{document} +\begin{tabular}{|r|l|l|l|l|} +\hline +\textbf{md} & upright & italic & slanted & smallcaps \\ +\hline +rm & \textrm{\uB} & \textrm{\iB} & \textrm{\lB} &\textrm{\cB} \\ +sf & \textsf{\uB} & \textsf{\iB} &\textsf{\lB} &\textsf{\cB} \\ +tt & \texttt{\uB} & \texttt{\iB} &\texttt{\lB} &\texttt{\cB} \\ +\hline +\end{tabular} diff --git a/test/expected_dir/metapost.mp/tex/comment b/test/expected_dir/metapost.mp/tex/comment new file mode 100644 index 0000000..68d8154 --- /dev/null +++ b/test/expected_dir/metapost.mp/tex/comment @@ -0,0 +1 @@ +%&latex diff --git a/test/src_dir/metapost.mp b/test/src_dir/metapost.mp new file mode 100644 index 0000000..ee90ad4 --- /dev/null +++ b/test/src_dir/metapost.mp @@ -0,0 +1,62 @@ +% Sample MetaPost with embedded LaTeX, used as unit test for ohcount +% +% The MetaPost code is taken of LaTeXLabels.mp from +% the excellent MetaPost tutorial by Urs Oswald +% http://www.ursoswald.ch/metapost/tutorial.html +% +verbatimtex +%&latex +\documentclass{article} +\newcommand{\uB}{\upshape{B\'ezier}} % up: upright +\newcommand{\iB}{\itshape{B\'ezier}} % it: italic +\newcommand{\lB}{\slshape{B\'ezier}} % sl: slanted +\newcommand{\cB}{\scshape{B\'ezier}} % sc: small caps +\newfont{\cyr}{wncyr10} +\begin{document} +etex + +u:=25; % 25 = 25bp = 25 PostScript points = 30/72 in +wi:=10; % width in units u +he:=7; % height in units u +hoehe:=he*u; % height +breite:=wi*u; % width +picture lab; + +beginfig(1) + % --- Grid --- + for i=0 upto he: + draw (0, i*u)--(breite, i*u) withcolor .7white; + endfor + for j=0 upto wi: + draw (j*u, 0)--(j*u, hoehe) withcolor .7white; + endfor + % --- End Grid --- + + draw (0, 0)--(breite, 0)--(breite, hoehe)--(0, hoehe)--cycle; + + for i=0 upto 5: + draw .5(u, u){dir 20i}..{dir 20i}(9.5u, 4u); + endfor + + lab:=\thelabel( + btex + \begin{tabular}{|r|l|l|l|l|} + \hline + \textbf{md} & upright & italic & slanted & smallcaps \\ + \hline + rm & \textrm{\uB} & \textrm{\iB} & \textrm{\lB} &\textrm{\cB} \\ + sf & \textsf{\uB} & \textsf{\iB} &\textsf{\lB} &\textsf{\cB} \\ + tt & \texttt{\uB} & \texttt{\iB} &\texttt{\lB} &\texttt{\cB} \\ + \hline + \end{tabular} + etex, + (.5breite, hoehe-1.5u) + ); + + unfill bbox lab; + draw lab; + + label.ulft(btex \cyr C\char24 rih, 08.09.2002 etex, (breite, 0)); +endfig; + +end diff --git a/test/unit/metapost_test.rb b/test/unit/metapost_test.rb new file mode 100644 index 0000000..4390ef7 --- /dev/null +++ b/test/unit/metapost_test.rb @@ -0,0 +1,12 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class Ohcount::MetaPostTest < Ohcount::Test + def test_comment + lb = [Ohcount::LanguageBreakdown.new("metapost", "", "% comment", 0)] + assert_equal lb, Ohcount::parse(" % comment", "metapost") + end + + def test_comprehensive + verify_parse("metapost.mp") + end +end -- 2.32.0.93.g670b81a890