Skip to content

Commit

Permalink
added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanAkbar committed Mar 26, 2024
1 parent 758416b commit eb06425
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
2 changes: 2 additions & 0 deletions jekyll-geolexica.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Gem::Specification.new do |spec|
# Pin logger to <= 1.5.3 due to incompatibility of logger 1.6.0 with Jekyll 4.3.2
spec.add_runtime_dependency "logger", "<= 1.5.3"
spec.add_runtime_dependency "relaton"
spec.add_runtime_dependency "unitsml"
spec.add_runtime_dependency "plurimath"

# Zeitwerk::Loader#push_dir supports :namespace argument from v. 2.4.
spec.add_runtime_dependency "zeitwerk", "~> 2.4"
Expand Down
1 change: 1 addition & 0 deletions lib/jekyll/geolexica.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require "jekyll"
require "glossarist"
require "plurimath"

module Jekyll
module Geolexica
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/geolexica/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def convert_math(page)
page.output.gsub!(/stem:\[([^\]]*?)\]/) do
ascii_equation = CGI.unescapeHTML(Regexp.last_match[1])

mathml_equation = Plurimath::Math
mathml_equation = ::Plurimath::Math
.parse(ascii_equation, :asciimath)
.to_mathml

Expand Down
70 changes: 70 additions & 0 deletions spec/unit/jekyll/geolexica/hooks_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# (c) Copyright 2020 Ribose Inc.
#

RSpec.describe ::Jekyll::Geolexica::Hooks do
subject do
w = Object.new
w.extend(described_class)
w
end

let(:page) do
instance_double(
Jekyll::Geolexica::ConceptPage::HTML,
output: page_output,
html?: is_html,
)
end

describe ".convert_math" do
context "when page is HTML" do
let(:is_html) { true }

let(:page_output) do
"foo stem:[a_2] bar"
end

let(:expected_output) do
<<~OUTPUT.strip
foo <math xmlns="http://www.w3.org/1998/Math/MathML" display="inline">
<mstyle displaystyle="true">
<msub>
<mi>a</mi>
<mn>2</mn>
</msub>
</mstyle>
</math>
bar
OUTPUT
end

it "should convert stem:[] to MathML" do
expect { subject.send(:convert_math, page) }
.to change { page.output }
.from(page_output)
.to(expected_output)
end
end

context "when page is not HTML" do
let(:is_html) { false }

let(:page_output) do
"foo stem:[a_2] bar"
end

let(:expected_output) do
<<~OUTPUT.strip
foo <math xmlns=\\"http://www.w3.org/1998/Math/MathML\\" display=\\"inline\\"> <mstyle displaystyle=\\"true\\"> <msub> <mi>a</mi> <mn>2</mn> </msub> </mstyle></math> bar
OUTPUT
end

it "should convert stem:[] to MathML" do
expect { subject.send(:convert_math, page) }
.to change { page.output }
.from(page_output)
.to(expected_output)
end
end
end
end

0 comments on commit eb06425

Please sign in to comment.