Skip to content

Commit

Permalink
Merge pull request #915 from metanorma/fix/dupe-term-reporting
Browse files Browse the repository at this point in the history
improved reporting of duplicate terms: https://github.com/metanorma/m…
  • Loading branch information
opoudjis authored Aug 15, 2024
2 parents 4358e63 + 7f949ed commit 26f6190
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
16 changes: 9 additions & 7 deletions lib/metanorma/standoc/validate_term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,24 @@ def concept_validate_msg(_doc, tag, refterm, xref)
end

def preferred_validate(doc)
out = []
ret = doc.xpath("//term").each_with_object({}) do |t, m|
prefix = t.at("./domain")&.text
t.xpath("./preferred//name").each do |n|
ret = n.text
prefix and ret = "<#{prefix}> #{ret}"
(m[ret] and out << ret) or m[ret] = t
m[ret] ||= []
m[ret] << t
end
end
preferred_validate_report(out, ret)
preferred_validate_report(ret)
end

def preferred_validate_report(terms, locations)
terms.each do |e|
err = "Term #{e} occurs twice as preferred designation"
@log.add("Terms", locations[e], err, severity: 1)
def preferred_validate_report(terms)
terms.each do |k, v|
v.size > 1 or next
loc = v.map { |x| x["id"] }.join(", ")
err = "Term #{k} occurs twice as preferred designation: #{loc}"
@log.add("Terms", v.first, err, severity: 1)
end
end
end
Expand Down
8 changes: 6 additions & 2 deletions spec/metanorma/validate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,10 @@
== Terms and Definitions
[[a]]
=== Term1
[[b]]
=== Term1
INPUT
expect do
Expand All @@ -1513,7 +1515,7 @@
rescue SystemExit
end
expect(File.read("test.err.html"))
.to include "Term Term1 occurs twice as preferred designation"
.to include "Term Term1 occurs twice as preferred designation: a, b"

FileUtils.rm_f "test.xml"
FileUtils.rm_f "test.err.html"
Expand All @@ -1526,8 +1528,10 @@
== Terms and Definitions
[[a]]
=== Term1
[[b]]
=== Term2
preferred:[Term1]
Expand All @@ -1538,7 +1542,7 @@
rescue SystemExit
end
expect(File.read("test.err.html"))
.to include "Term Term1 occurs twice as preferred designation"
.to include "Term Term1 occurs twice as preferred designation: a, b"
end

it "warns if image is too big for Data URI encoding" do
Expand Down

0 comments on commit 26f6190

Please sign in to comment.