Sha256: 66548acf19a993b5debcb2a8c1c9b777601b9abb7b2378299ddaacc2aa52e89f

Contents?: true

Size: 1.54 KB

Versions: 20

Compression:

Stored size: 1.54 KB

Contents

require 'test_helper'
require 'math-to-itex'

class Mathematical::FixturesTest < MiniTest::Test
  # the same SVGs sometimes get random id values, throwing off the tests
  def strip_id(blob)
    blob.gsub(/id="surface.+?"/, '')
  end

  Dir["#{fixtures_dir}/before/*.text"].each do |before|
    name = before.split('/').last

    define_method "test_#{name}" do
      source = File.read(before)

      if ENV['MATHEMATICAL_GENERATE_SAMPLE']
        next unless name.match(/compliance/)
        write_sample(source)
      end

      actual = MathToItex(source).convert do |eq, type|
        svg_content = Mathematical.new(:base64 => true).render(eq)

        %(<img class="#{type}-math" data-math-type="#{type}-math" src="#{svg_content[:data]}"/>)
      end.rstrip

      expected_file = before.sub(/before/, 'after').sub(/text/, 'html')

      File.open(expected_file, 'w') { |file| file.write(actual) } unless ENV['DEBUG_MATHEMATICAL'].nil?

      expected = File.read(expected_file)

      expected = (MathToItex(expected).convert { |string| Mathematical.new.render(string) }).rstrip

      # Travis and OS X each render SVGs differently. For now, let's just be happy
      # that something renders at all.
      unless actual.match('PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My')
        diff = IO.popen("diff -u - #{expected_file}", 'r+') do |f|
          f.write actual
          f.close_write
          f.read
        end

        assert expected == actual, <<-eos
  #{File.basename expected_file}'s contents don't match command output:
  #{diff}
  eos
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mathematical-1.6.14 test/mathematical/fixtures_test.rb
mathematical-1.6.13 test/mathematical/fixtures_test.rb
mathematical-1.6.12 test/mathematical/fixtures_test.rb
mathematical-1.6.11 test/mathematical/fixtures_test.rb
mathematical-1.6.10 test/mathematical/fixtures_test.rb
mathematical-1.6.9 test/mathematical/fixtures_test.rb
mathematical-1.6.8 test/mathematical/fixtures_test.rb
mathematical-1.6.7 test/mathematical/fixtures_test.rb
mathematical-1.6.6 test/mathematical/fixtures_test.rb
mathematical-1.6.5 test/mathematical/fixtures_test.rb
mathematical-1.6.4 test/mathematical/fixtures_test.rb
mathematical-1.6.3 test/mathematical/fixtures_test.rb
mathematical-1.6.2 test/mathematical/fixtures_test.rb
mathematical-1.6.1 test/mathematical/fixtures_test.rb
mathematical-1.6.0 test/mathematical/fixtures_test.rb
mathematical-1.5.12 test/mathematical/fixtures_test.rb
mathematical-1.5.0 test/mathematical/fixtures_test.rb
mathematical-1.4.2 test/mathematical/fixtures_test.rb
mathematical-1.4.1 test/mathematical/fixtures_test.rb
mathematical-1.4.0 test/mathematical/fixtures_test.rb