require 'test/unit' require 'syntax/convertors/latex' class TC_Convertors_Latex < Test::Unit::TestCase def setup @convertor = Syntax::Convertors::LaTeX.for_syntax "ruby" end def test_latex_escape tests = {"I have $30, and new\\\nline" => "I have \\$30, and new$\\backslash$\nline", 'I like "clean & simple" things just best than {obscure,complicated}' => 'I like "{}clean \& simple"{} things just best than \{obscure,complicated\}', "The string '\\'' is valid –in C" => "The string '$\\backslash$'' is valid ---in C", "Escape dollars as \\$, and continue line, backslash at the end, like so: \\\n" => "Escape dollars as $\\backslash$\\$, and continue line, backslash at the end, like so: $\\backslash$\n", "Perl: $foo{some_key} =~ /^#.*$/" => "Perl: \\$foo\\{some\\_key\\} =\\~{} /\\^{}\\#.*\\$/", "Double backslash escaping: \\\\" => "Double backslash escaping: $\\backslash$$\\backslash$", "\"Some\nmultiline\nstring\"" => "\"{}Some\nmultiline\nstring\"{}"} tests.each_pair do |k,v| assert_equal(v, @convertor.send(:latex_escape, k)) end end def test_output expected = <<'EOD' \begin{semiverbatim} \synkeyword{class }\synclass{Curso} \synpunct{<} \synconstant{ActiveRecord}\synpunct{::}\synconstant{Base} \synident{has\_many} \synsymbol{:documentos} \synident{has\_many} \synsymbol{:examenes}\synpunct{,} \synsymbol{:class\_name} \synpunct{=>} \synpunct{'}\synstring{Documento}\synpunct{',} \synsymbol{:conditions} \synpunct{=>} \synpunct{"{}}\synstring{tipo = 'examen'}\synpunct{"{}} \synident{has\_and\_belongs\_to\_many} \synsymbol{:alumnos}\synpunct{,} \synsymbol{:order} \synpunct{=>} \synpunct{'}\synstring{nombre}\synpunct{'} \synident{belongs\_to} \synsymbol{:temporada}\synpunct{,} \synsymbol{:class\_name} \synpunct{=>} \synpunct{'}\synstring{AnoAcademico}\synpunct{',} \synsymbol{:foreign\_key} \synpunct{=>} \synpunct{'}\synstring{curso\_id}\synpunct{'} \synkeyword{end} \synident{curso} \synpunct{=} \synconstant{Curso}\synpunct{.}\synident{find}\synpunct{(}\synident{params}\synpunct{[}\synsymbol{:id}\synpunct{])} \synident{curso}\synpunct{.}\synident{find}\synpunct{(}\synsymbol{:all}\synpunct{,} \synsymbol{:order} \synpunct{=>} \synpunct{'}\synstring{nombre}\synpunct{',} \synsymbol{:limit} \synpunct{=>} \synnumber{5}\synpunct{).} \synident{map} \synpunct{\{|}\synident{c}\synpunct{|} \synident{c}\synpunct{.}\synident{examenes}\synpunct{\}.}\synident{flatten} \end{semiverbatim} EOD source = <<'EOD' class Curso < ActiveRecord::Base has_many :documentos has_many :examenes, :class_name => 'Documento', :conditions => "tipo = 'examen'" has_and_belongs_to_many :alumnos, :order => 'nombre' belongs_to :temporada, :class_name => 'AnoAcademico', :foreign_key => 'curso_id' end curso = Curso.find(params[:id]) curso.find(:all, :order => 'nombre', :limit => 5). map {|c| c.examenes}.flatten EOD assert_equal(expected, @convertor.convert(source)) end def teardown @convertor = nil end end