Skip to content

Fix additions#15

Merged
koppen merged 3 commits intomainfrom
fix_additions
Dec 8, 2025
Merged

Fix additions#15
koppen merged 3 commits intomainfrom
fix_additions

Conversation

@koppen
Copy link
Copy Markdown
Member

@koppen koppen commented Dec 8, 2025

Ie doing

Classlist.new("a b c") + Classlist.new("d e")

is the same as

Classlist.new("a b c") + Classlist::Add.new("d e")

and most notably doing

Classlist.new("a") + Classlist::Remove.new("a") + Classlist.new("b")

is the same as

Classlist.new("a") + Classlist::Remove.new("a") + Classlist::Add.new("b")

which it wasn't before.

Adding a "base" Classlist in that manner would merge it into the Remove
operation, effectively turning the statement into

Classlist.new("a") + Classlist::Remove.new("a b")

which is not the intended behavior

Without this we'd get

```
$ ruby -Itest test/classlist/test_operation.rb
Run options: --seed 53158

..EE........E...

Finished in 0.010779s, 1391.5948 runs/s, 1298.8218 assertions/s.

  1) Error:
TestClasslistOperation#test_all_the_operations:
NameError: uninitialized constant Classlist::Reset
    test/classlist/test_operation.rb:97:in 'TestClasslistOperation#test_all_the_operations'

  2) Error:
TestClasslistOperation#test_reset_as_manual_operations:
NameError: uninitialized constant Classlist::Reset
    test/classlist/test_operation.rb:41:in 'TestClasslistOperation#test_reset_as_manual_operations'

  3) Error:
TestClasslistOperation#test_reset:
NameError: uninitialized constant Classlist::Reset
    test/classlist/test_operation.rb:35:in 'TestClasslistOperation#test_reset'
```
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where adding a plain Classlist instance to a chain of Classlist::Operations would incorrectly merge it into the last operation instead of treating it as an implicit Classlist::Add operation. The fix ensures consistent behavior whether you use Classlist.new("foo") or Classlist::Add.new("foo") when chaining operations.

Key changes:

  • Added type conversion logic to treat plain Classlist instances as Classlist::Add operations when used with the + operator
  • Added test coverage for the new behavior with both explicit Classlist::Add and implicit plain Classlist additions
  • Fixed missing require statement for Classlist::Reset in the test file

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
lib/classlist.rb Added logic to convert plain Classlist instances to Classlist::Add operations before processing in the + operator
test/classlist/test_operation.rb Added missing Reset require statement and two new tests verifying the fix works correctly
CHANGELOG.md Documented the bug fix in the Fixed section

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Ie doing

  Classlist.new("a b c") + Classlist.new("d e")

is the same as

  Classlist.new("a b c") + Classlist::Add.new("d e")

and most notably doing

  Classlist.new("a") + Classlist::Remove.new("a") + Classlist.new("b")

is the same as

  Classlist.new("a") + Classlist::Remove.new("a") + Classlist::Add.new("b")

which it wasn't before.

Adding a "base" Classlist in that manner would merge it into the Remove
operation, effectively turning the statement into

  Classlist.new("a") + Classlist::Remove.new("a b")

which is not the intended behavior
>   lib/classlist.rb:12:3: Layout/EmptyLinesAfterModuleInclusion: Add an
>   empty line after module inclusion.
@koppen koppen merged commit 0675d68 into main Dec 8, 2025
6 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.

3 participants