Skip to content

Raise test coverage and fix the bugs the new tests exposed - #203

Merged
tmaier merged 12 commits into
masterfrom
add-tests-for-low-coverage-files
Nov 15, 2026
Merged

tmaier merged 12 commits into
masterfrom
add-tests-for-low-coverage-files

Conversation

@tmaier

@tmaier tmaier commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Five files sat below 85% line coverage and several methods had no tests. This adds tests for them and fixes the bugs the new tests exposed. Each fix comes with a test that failed before the fix.

Coverage

File Before After
bibliography/rdf_converter.rb 57.1% 100%
compatibility.rb 75.0% 100%
error.rb 79.5% 100%
elements.rb 80.4% 98.8%
replaceable.rb 81.5% 100%

Also covered: Names#add, Name#rename_unless, Name.looks_like?, Value#replace and Entry#type?. Overall line coverage goes from 90.2% to 94.0%.

The new tests are unit tests, because the logic is pure and the cucumber features already cover the end-to-end flows. The error.rb tests go through the public parse path (parse, then bib.errors).

Test files

New:

  • test_bibliography_rdf_converter.rb
  • test_compatibility.rb
  • test_error.rb
  • test_replaceable.rb

Extended:

  • test_elements.rb: defaults, conversions, conditions and matching
  • test_names.rb: Names#add, Name.looks_like?, Name#rename_unless
  • test_value.rb: Value#replace
  • test_entry.rb: Entry#type?

Bugs fixed

  • BibTeX::String#to_xml called add_elements, which REXML does not have (NoMethodError).
  • Element#type? and Entry#type? raised NoMethodError for a Class argument. In Element#type? the defined?(type) guard checked a local variable, so the class branch never ran.
  • Element#to_xml with a symbol type produced <>blah</>.
  • The condition prop=~re was split as equality with the value ~re, because the = alternative matched first. It now matches a regular expression, like ~=.
  • Names#add with a String raised TypeError, because it added a Names to an Array.
  • Name.looks_like? raised NameError (undefined local) and had its result inverted.

Behaviour change

prop=~re used to mean equality with ~re. It now means a regular-expression match. The old reading could not have been intended, since =~ is already handled in the operator case. It is listed in History.txt.

Not changed

Name#rename_unless with no conditions never renames. That is the exact complement of rename_if, which renames when no conditions are given, so a test pins it.

Test plan

bundle exec rake passes locally with 1010 unit tests and 141 cucumber scenarios. rubocop is clean.

Copilot AI balanced review requested due to automatic review settings November 14, 2026 23:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@tmaier tmaier changed the title Add tests for low-coverage files and untested methods Raise test coverage and fix the bugs the new tests exposed Nov 14, 2026
@tmaier
tmaier merged commit b448883 into master Nov 15, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants