Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing specs #2

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@

# rspec failure tracking
.rspec_status
Gemfile.lock
input.xml
output.xml
13 changes: 13 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ require:
- rubocop-rake
- rubocop-rspec

Metrics/BlockLength:
Enabled: false

Metrics/MethodLength:
Enabled: false

Metrics/AbcSize:
Enabled: false

Layout/LineLength:
Max: 160

AllCops:
TargetRubyVersion: 3.0
SuggestExtensions: false
NewCops: enable
Exclude:
- 'vendor/**/*'
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ source "https://rubygems.org"
gemspec

gem "nokogiri"
gem "pry"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0"
gem "rubocop", "~> 1.21"
Expand Down
21 changes: 21 additions & 0 deletions lib/oasis/etm/bold.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Oasis
module Etm
class Bold < Lutaml::Model::Serializable
attribute :content, :string
attribute :id, :string
attribute :specific_use, :string
attribute :toggle, :string

xml do
root "bold", mixed: true

map_content to: :content
map_attribute "id", to: :id
map_attribute "specific-use", to: :specific_use
map_attribute "toggle", to: :toggle
end
end
end
end
1 change: 1 addition & 0 deletions lib/oasis/etm/colspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Colspec < Lutaml::Model::Serializable

xml do
root "colspec"
namespace "-//OASIS//DTD XML Exchange Table Model 19990315//EN", "oasis"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This namespace is problematic.

  1. In newer versions of NISO JATS, they use:

https://github.com/ncbi/niso-jats/blob/master/publishing/1.1d3/Smallsamples/samplepub-oasis-and-xhtml1-mathml3.xml

xmlns:oasis="http://www.niso.org/standards/z39-96/ns/oasis-exchange/table"

  1. Also, in NISO STS, the namespace is:

xmlns:oasis (fixed value = http://www.niso.org/standards/z39-96/ns/oasis-exchange/table)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm thinking is that we provide a default namespace in the gem and at the same time we set a different namespace in niso-jats gem.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that we should not include the fixture spec/fixtures/niso-jats/niso-jats-table-wrap.xml in this gem.


map_attribute "colnum", to: :colnum
map_attribute "colname", to: :colname
Expand Down
14 changes: 12 additions & 2 deletions lib/oasis/etm/entry.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require_relative "xref"
require_relative "bold"

module Oasis
module Etm
class Entry < Lutaml::Model::Serializable
Expand All @@ -6,18 +9,21 @@ class Entry < Lutaml::Model::Serializable
attribute :namest, :string
attribute :nameend, :string
attribute :morerows, :integer
attribute :colsep, :integer, values: [0, 1]
attribute :rowsep, :integer, values: [0, 1]
attribute :colsep, :string, values: ["0", "1", "yes", "no"]
attribute :rowsep, :string, values: ["0", "1", "yes", "no"]
attribute :align, :string, values: %w[left right center justify char]
attribute :char, :string
attribute :charoff, :string
attribute :valign, :string, values: %w[top middle bottom]

# Content
attribute :content, :string, raw: true
attribute :xref, Xref, collection: true
attribute :bold, Bold, collection: true

xml do
root "entry"
namespace "-//OASIS//DTD XML Exchange Table Model 19990315//EN", "oasis"

# Attribute mappings
map_attribute "colname", to: :colname
Expand All @@ -33,6 +39,10 @@ class Entry < Lutaml::Model::Serializable

# Content mapping
map_content to: :content

# Child elements
map_element "xref", to: :xref
map_element "bold", to: :bold
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/oasis/etm/row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Row < Lutaml::Model::Serializable

xml do
root "row"
namespace "-//OASIS//DTD XML Exchange Table Model 19990315//EN", "oasis"

map_attribute "rowsep", to: :rowsep
map_attribute "valign", to: :valign
Expand Down
7 changes: 4 additions & 3 deletions lib/oasis/etm/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ module Etm
class Table < Lutaml::Model::Serializable
# Table attributes
attribute :frame, :string, values: %w[top bottom topbot all sides none]
attribute :colsep, :integer, values: [0, 1]
attribute :rowsep, :integer, values: [0, 1]
attribute :pgwide, :integer, values: [0, 1]
attribute :colsep, :string, values: ["0", "1", "yes", "no"]
attribute :rowsep, :string, values: ["0", "1", "yes", "no"]
attribute :pgwide, :string, values: ["0", "1", "yes", "no"]

# Table content
attribute :title, :string
attribute :tgroups, Tgroup, collection: true

xml do
root "table", ordered: true
namespace "-//OASIS//DTD XML Exchange Table Model 19990315//EN", "oasis"

# Frame mappings
map_attribute "frame", to: :frame
Expand Down
1 change: 1 addition & 0 deletions lib/oasis/etm/tbody.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Tbody < Lutaml::Model::Serializable

xml do
root "tbody"
namespace "-//OASIS//DTD XML Exchange Table Model 19990315//EN", "oasis"

map_attribute "valign", to: :valign
map_element "row", to: :rows
Expand Down
1 change: 1 addition & 0 deletions lib/oasis/etm/tcol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Colspec < Lutaml::Model::Serializable

xml do
root "colspec"
namespace "-//OASIS//DTD XML Exchange Table Model 19990315//EN", "oasis"

map_attribute "colnum", to: :colnum
map_attribute "colname", to: :colname
Expand Down
1 change: 1 addition & 0 deletions lib/oasis/etm/tgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Tgroup < Lutaml::Model::Serializable

xml do
root "tgroup", ordered: true
namespace "-//OASIS//DTD XML Exchange Table Model 19990315//EN", "oasis"

# Attribute mappings
map_attribute "cols", to: :cols
Expand Down
1 change: 1 addition & 0 deletions lib/oasis/etm/thead.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Thead < Lutaml::Model::Serializable

xml do
root "thead"
namespace "-//OASIS//DTD XML Exchange Table Model 19990315//EN", "oasis"

map_attribute "valign", to: :valign
map_element "row", to: :rows
Expand Down
28 changes: 28 additions & 0 deletions lib/oasis/etm/xref.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Oasis
module Etm
class Xref < Lutaml::Model::Serializable
attribute :content, :string
attribute :alt, :string
attribute :custom_type, :string
attribute :id, :string
attribute :ref_type, :string
attribute :rid, :string
attribute :specific_use, :string
attribute :lang, :string

xml do
root "xref"
namespace "-//OASIS//DTD XML Exchange Table Model 19990315//EN", "oasis"

map_content to: :content
map_attribute "alt", to: :alt
map_attribute "custom-type", to: :custom_type
map_attribute "id", to: :id
map_attribute "ref-type", to: :ref_type
map_attribute "rid", to: :rid
map_attribute "specific-use", to: :specific_use
map_attribute "lang", to: :lang, namespace: "http://www.w3.org/XML/1998/namespace", prefix: "xml"
end
end
end
end
156 changes: 82 additions & 74 deletions spec/oasis/etm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,87 @@
require "pathname"

RSpec.describe Oasis::Etm do
fixtures_dir = Pathname.new(__dir__).join("../fixtures")

describe "XML round-trip conversion" do
describe "native XML" do
xml_files = Dir[fixtures_dir.join("native", "*.xml")]

xml_files.each do |file_path|
context "with file #{Pathname.new(file_path).relative_path_from(fixtures_dir)}" do
let(:xml_string) { File.read(file_path) }

it "performs lossless round-trip conversion" do
parsed = Oasis::Etm::Table.from_xml(xml_string)
generated = parsed.to_xml(
pretty: true,
declaration: true,
encoding: "utf-8",
)

cleaned_xml_string = xml_string
.gsub(/^<\?xml.*\n/, "")

expect(generated).to be_analogous_with(cleaned_xml_string)
end
end
end
end

describe "namespaced XML (ISOSTS)" do
xml_files = Dir[fixtures_dir.join("isosts", "*.xml")]

xml_files.each do |file_path|
context "with file #{Pathname.new(file_path).relative_path_from(fixtures_dir)}" do
let(:xml_string) { File.read(file_path) }

it "performs lossless round-trip conversion" do
parsed = Oasis::Etm::Table.from_xml(xml_string)
generated = parsed.to_xml(
pretty: true,
declaration: true,
encoding: "utf-8",
)

cleaned_xml_string = xml_string
.gsub(/^<\?xml.*\n/, "")

expect(generated).to be_analogous_with(cleaned_xml_string)
end
end
end
end

describe "namespaced XML (NISO JATS)" do
xml_files = Dir[fixtures_dir.join("niso-jats", "*.xml")]

xml_files.each do |file_path|
context "with file #{Pathname.new(file_path).relative_path_from(fixtures_dir)}" do
let(:xml_string) { File.read(file_path) }

it "performs lossless round-trip conversion" do
parsed = Oasis::Etm::Table.from_xml(xml_string)
generated = parsed.to_xml(
pretty: true,
declaration: true,
encoding: "utf-8",
)

cleaned_xml_string = xml_string
.gsub(/^<\?xml.*\n/, "")

expect(generated).to be_analogous_with(cleaned_xml_string)
end
end
end
end
context "with isosts/isosts_tables.cals.01.xml" do
let(:fixture) { file_fixture("isosts/isosts_tables.cals.01.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with isosts/isosts_tables.cals.02.xml" do
let(:fixture) { file_fixture("isosts/isosts_tables.cals.02.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with isosts/isosts_tables.cals.03.xml" do
let(:fixture) { file_fixture("isosts/isosts_tables.cals.03.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with isosts/isosts_tables.cals.04.xml" do
let(:fixture) { file_fixture("isosts/isosts_tables.cals.04.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with isosts/isosts_tables.cals.05.xml" do
let(:fixture) { file_fixture("isosts/isosts_tables.cals.05.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with isosts/isosts_tables.cals.06.xml" do
let(:fixture) { file_fixture("isosts/isosts_tables.cals.06.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with isosts/isosts_tables.cals.07.xml" do
let(:fixture) { file_fixture("isosts/isosts_tables.cals.07.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with isosts/isosts_tables.cals.08.xml" do
let(:fixture) { file_fixture("isosts/isosts_tables.cals.08.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with isosts/isosts_tables.cals.09.xml" do
let(:fixture) { file_fixture("isosts/isosts_tables.cals.09.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with isosts/isosts_tables.cals.10.xml" do
let(:fixture) { file_fixture("isosts/isosts_tables.cals.10.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with isosts/isosts_tables.cals.11.xml" do
let(:fixture) { file_fixture("isosts/isosts_tables.cals.11.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with isosts/isosts_tables.cals.12.xml" do
let(:fixture) { file_fixture("isosts/isosts_tables.cals.12.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with native/docbook_example.xml" do
let(:fixture) { file_fixture("native/docbook_example.xml") }

it_behaves_like "lossless round-trip converter"
end

context "with niso-jats/niso-jats-table-wrap.xml" do
let(:fixture) { file_fixture("niso-jats/niso-jats-table-wrap.xml") }

it_behaves_like "lossless round-trip converter"
end
end
3 changes: 3 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
require "oasis-etm"
require "nokogiri"
require "xml-c14n"
require "pry"

# Require all support files
Dir[File.join(__dir__, "support", "**", "*.rb")].each { |f| require f }

RSpec.configure do |config|
include Helper

# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"

Expand Down
9 changes: 9 additions & 0 deletions spec/support/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Helper
def file_fixture(name)
Pathname.new(fixtures_path(name))
end

def fixtures_path(name)
File.join("spec/fixtures", name)
end
end
13 changes: 13 additions & 0 deletions spec/support/shared_examples/lossless_round_trip_examples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
RSpec.shared_examples "lossless round-trip converter" do
it "performs lossless round-trip conversion" do
input = fixture.read

serialized = Oasis::Etm::Table.from_xml(input)
output = serialized.to_xml(pretty: true, declaration: true, encoding: "utf-8")

File.write("output.xml", output)
File.write("input.xml", input)

expect(output).to be_analogous_with(input)
end
end