From eb064258cfdf3e8a389c72ed44716a0fb0740e3e Mon Sep 17 00:00:00 2001 From: HassanAkbar Date: Tue, 26 Mar 2024 15:42:56 +0500 Subject: [PATCH] added test cases --- jekyll-geolexica.gemspec | 2 + lib/jekyll/geolexica.rb | 1 + lib/jekyll/geolexica/hooks.rb | 2 +- spec/unit/jekyll/geolexica/hooks_spec.rb | 70 ++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 spec/unit/jekyll/geolexica/hooks_spec.rb diff --git a/jekyll-geolexica.gemspec b/jekyll-geolexica.gemspec index a5d84b3..1fbcfe2 100644 --- a/jekyll-geolexica.gemspec +++ b/jekyll-geolexica.gemspec @@ -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" diff --git a/lib/jekyll/geolexica.rb b/lib/jekyll/geolexica.rb index f4a8b4f..3d36d94 100644 --- a/lib/jekyll/geolexica.rb +++ b/lib/jekyll/geolexica.rb @@ -3,6 +3,7 @@ require "jekyll" require "glossarist" +require "plurimath" module Jekyll module Geolexica diff --git a/lib/jekyll/geolexica/hooks.rb b/lib/jekyll/geolexica/hooks.rb index 53c5320..ff9e869 100644 --- a/lib/jekyll/geolexica/hooks.rb +++ b/lib/jekyll/geolexica/hooks.rb @@ -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 diff --git a/spec/unit/jekyll/geolexica/hooks_spec.rb b/spec/unit/jekyll/geolexica/hooks_spec.rb new file mode 100644 index 0000000..47272c0 --- /dev/null +++ b/spec/unit/jekyll/geolexica/hooks_spec.rb @@ -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 + + + a + 2 + + + + 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 a 2 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