1# encoding: UTF-8 2 3Given /^I am( not)? testing (.*?)$/ do |not_word, engine| 4 # TODO Check that engine actually exists somewhere. 5 @tex = TeXRunner.new(@class_name) unless @tex 6 engines = engine.split(" and ") 7 if not_word 8 engines.each { |engine| @tex.exclude_engine(engine) } 9 else 10 @tex.set_engines(engines) 11 end 12end 13 14Given /^the main language is (.*?)(?: with (.*))?$/ do |language, options| 15 `kpsewhich gloss-#{language.downcase}.ldf`.should be_true 16 $?.exitstatus.should == 0 17 step "I use package polyglossia" 18 opts = if options then "[#{options.split(/\s+and\s+/).join(',')}]" else "" end 19 @tex.append "\\setmainlanguage#{opts.downcase}{#{language.downcase}}" 20end 21 22Given /^I use package (.*?)(?: with (.*))?$/ do |package, options| 23 `kpsewhich #{package.downcase}.sty` 24 $?.exitstatus.should == 0 25 @tex = TeXRunner.new(@class_name) unless @tex 26 opts = if options then "[#{options.split(/\s+and\s+/).join(',')}]" else "" end 27 @tex.append "\\usepackage#{opts.downcase}{#{package.downcase}}" 28end 29 30Given /^I state (.*)$/ do |statement| 31 # TODO Call inside_body? when it exists 32 @tex.append statement 33end 34 35When /^I set "(.*?)"( in a very narrow paragraph)?$/ do |text, narrow| 36 @tex.ensure_inside_body 37 @tex.append "\\begin{minipage}{1sp}" if narrow 38 @tex.append "\\hskip1sp" if narrow 39 @tex.append "\\lccode\"2019=\"2019" if narrow 40 @tex.append text 41 @tex.append "\\end{minipage}" if narrow 42end 43 44Then /^I should see ("|\/)(.*)("|\/)(?: with (.*?))?$/ do |od, expected, cd, tested_engine| 45 def massage_output(output) 46 ret = output.gsub(/-\n/m, '-').gsub(/\n/m, ' ').gsub(/\u202A|\u202B|\u202C/, '').gsub(/\uFB00/, 'ff') 47 ret.gsub!(/[,'"]/, '') if @strip_punct 48 ret 49 end 50 51 if od == '/' 52 expected_result = /#{expected}/ 53 else 54 expected_result = expected 55 end 56 57 raise "Testing engine that has not been requested in Given step." unless @tex.has_engine(tested_engine) 58 results = @tex.text(tested_engine) 59 60 results.each do |engine, text| 61 results[engine] = massage_output(text) 62 end 63 results.should equal_or_match_for_all_values expected_result 64 65 @tex.cleanup 66end 67