Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into update-mtex2mml
Browse files Browse the repository at this point in the history
  • Loading branch information
4e554c4c committed Nov 29, 2023
2 parents ada1353 + 256e981 commit fe164e9
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
script/install_linux_deps
- name: Install MacOS packages
if: ${{ matrix.os == 'macos-11.0' }}
if: ${{ matrix.os == 'macos-latest' }}
run: script/install_macos_deps

- name: Set up Ruby ${{ matrix.ruby-version }}
Expand Down
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ inherit_gem:
rubocop-standard:
- config/default.yml
- config/minitest.yml

AllCops:
Exclude:
- 'ext/mathematical/mtex2MML/**/*'
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Rake::Task[:test].prerequisites
task build: [:clean]

Rake::Task[:clean].enhance do
Dir.chdir(LASEM_DIR) { puts %x(git clean -fdx); }
Dir.chdir(LASEM_DIR) { puts %x(git clean -fdx) }
end

desc "Copy samples to gh-pages"
Expand Down
2 changes: 1 addition & 1 deletion lib/mathematical/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def option_exists?(option)
raise(TypeError, "delimiter type does not exist: #{option}")
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/mathematical/corrections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def apply_corrections(maths)
# inside itex equations. So "<" and ">" are significant.
# To obtain a less-than or greater-than sign, you should use \lt or \gt, respectively.
def adjust_lt_gt(maths)
maths.gsub(/</, '\lt').gsub(/>/, '\gt')
maths.gsub("<", '\lt').gsub(">", '\gt')
end
end
end
2 changes: 1 addition & 1 deletion script/install_linux_deps
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e
export CC=gcc

sudo apt-get -qq -y install bison flex libffi-dev libxml2-dev libgdk-pixbuf2.0-dev libcairo2-dev libpango1.0-dev
sudo apt-get -qq -y install bison flex libffi-dev libxml2-dev libgdk-pixbuf2.0-dev libcairo2-dev libpango1.0-dev libwebp-dev

# not necessary for tests, but is for any production/development environment
if [[ ! -v CI ]]; then
Expand Down
6 changes: 3 additions & 3 deletions test/mathematical/basic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require "test_helper"
require "nokogiri"

module Mathematical
class BasicTest < MiniTest::Test
class Mathematical
class BasicTest < Minitest::Test
def test_it_has_a_version
assert(Mathematical::VERSION)
end
Expand All @@ -14,7 +14,7 @@ def test_multiple_calls
render.render('$\pi$')
output = render.render('$\pi$')[:data]

assert_equal(1, output.scan(/<svg/).size, "should only contain one svg")
assert_equal(1, output.scan("<svg").size, "should only contain one svg")

# assert the SVG actually rendered
doc = Nokogiri::HTML(output)
Expand Down
4 changes: 2 additions & 2 deletions test/mathematical/corrections_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

require "test_helper"

module Mathematical
class CorrectionsTest < MiniTest::Test
class Mathematical
class CorrectionsTest < Minitest::Test
def setup
@render = Mathematical.new
end
Expand Down
4 changes: 2 additions & 2 deletions test/mathematical/delimiters_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

require "test_helper"

module Mathematical
class BasicTest < MiniTest::Test
class Mathematical
class BasicTest < Minitest::Test
def test_single_dollar
render = Mathematical.new(delimiter: :DOLLAR, format: :mathml)

Expand Down
8 changes: 4 additions & 4 deletions test/mathematical/fixtures_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require "test_helper"
require "math-to-itex"

module Mathematical
class FixturesTest < MiniTest::Test
class Mathematical
class FixturesTest < Minitest::Test
# the same SVGs sometimes get random id values, throwing off the tests
def strip_id(blob)
blob.gsub(/id="surface.+?"/, "")
Expand All @@ -17,7 +17,7 @@ def strip_id(blob)
source = File.read(before)

if ENV["MATHEMATICAL_GENERATE_SAMPLE"]
next unless /compliance/.match?(name)
next unless name.include?("compliance")

write_sample(source)
end
Expand All @@ -28,7 +28,7 @@ def strip_id(blob)
%(<img class="#{type}-math" data-math-type="#{type}-math" src="#{svg_content[:data]}"/>)
end.rstrip

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

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

Expand Down
15 changes: 7 additions & 8 deletions test/mathematical/maliciousness_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

require "test_helper"

module Mathematical
class MaliciousnessTest < MiniTest::Test
class Mathematical
class MaliciousnessTest < Minitest::Test
def test_it_does_not_error_on_unrecognized_commands
render = Mathematical.new
# In mtex2MML, we raise a ParseError, but Mathematical suppresses it and returns the string.
Expand Down Expand Up @@ -60,9 +60,8 @@ def test_it_does_not_blow_up_on_bad_options
assert_equal('$a \ne b$', output[:data])
assert_equal(output[:exception].class, Mathematical::MaxsizeError)

render = Mathematical.new({ maxsize: 2**80 })
assert_raises(TypeError) do
render.render('$a \ne b$')
render = Mathematical.new({ maxsize: 2**80 })
end
end

Expand Down Expand Up @@ -123,11 +122,11 @@ def test_it_parses_all_possible_array_elements
end

assert_equal(3, output.length)
assert_equal(Hash, output.first.class)
assert_equal(Hash, output.last.class)
assert_instance_of(Hash, output.first)
assert_instance_of(Hash, output.last)

assert_equal("$/this___istotallyfake$", output[1][:data])
assert_equal(Mathematical::ParseError, output[1][:exception].class)
assert_instance_of(Mathematical::ParseError, output[1][:exception])
assert_match("Failed to parse mtex", output[1][:exception].message)

# array errors also output to STDERR
Expand All @@ -145,7 +144,7 @@ def test_it_passes_a_legible_error_for_maxsize
assert_equal(1, output.length)

assert_equal('$a \ne b$', output[0][:data])
assert_equal(Mathematical::MaxsizeError, output[0][:exception].class)
assert_instance_of(Mathematical::MaxsizeError, output[0][:exception])
assert_match("Size of latex string is greater than the maxsize", output[0][:exception].message)

# array errors also output to STDERR
Expand Down
4 changes: 2 additions & 2 deletions test/mathematical/mathjax_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require "test_helper"
require "nokogiri"

module Mathematical
class MathJaxTest < MiniTest::Test
class Mathematical
class MathJaxTest < Minitest::Test
render_svg = Mathematical.new

SKIPPED = []
Expand Down
4 changes: 2 additions & 2 deletions test/mathematical/mathml_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# rubocop:disable Lint/ImplicitStringConcatenation
require "test_helper"

module Mathematical
class MathMLTest < MiniTest::Test
class Mathematical
class MathMLTest < Minitest::Test
def test_it_returns_mathml
string = ""'
$$
Expand Down
7 changes: 4 additions & 3 deletions test/mathematical/multiples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

require "test_helper"

module Mathematical
class MultiplesTest < MiniTest::Test
class Mathematical
class MultiplesTest < Minitest::Test
def setup
@render = Mathematical.new(base64: true)
end
Expand All @@ -20,7 +20,7 @@ def test_it_works_for_a_single_numbered_equation
output = @render.render([string])
svg = output.first[:data]

assert_equal(1, svg.scan(/svg\+xml;/).size, "should only contain one svg")
assert_equal(1, svg.scan("svg+xml;").size, "should only contain one svg")
assert_match("PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My", svg)
end

Expand All @@ -46,6 +46,7 @@ def test_it_works_for_many_equations
end

def test_it_properly_accounts_for_equations
skip("png tests are currently unsupported")
inputs = []
(1..2).each do |i|
string = """
Expand Down
4 changes: 2 additions & 2 deletions test/mathematical/performance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
require "test_helper"
require "benchmark"

module Mathematical
class BasicTest < MiniTest::Test
class Mathematical
class BasicTest < Minitest::Test
def test_it_handles_big_files
big_file = File.read("test/mathematical/fixtures/performance/big_file.text")
speed = Benchmark.realtime do
Expand Down
5 changes: 3 additions & 2 deletions test/mathematical/png_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

require "test_helper"

module Mathematical
class PNGTest < MiniTest::Test
class Mathematical
class PNGTest < Minitest::Test
def before
File.delete("#{fixtures_dir}/png/pmatrix.png") if File.exist?("#{fixtures_dir}/png/pmatrix.png")
end

def test_it_creates_a_png
skip("png tests are currently unsupported")
string = ""'
$$
\begin{pmatrix}
Expand Down

0 comments on commit fe164e9

Please sign in to comment.