pointfreeco / swift-custom-dump

A collection of tools for debugging, diffing, and testing your application's data structures.
MIT License
800 stars 89 forks source link

Some `AttributedString`s don't print any diffs although they are not equal #104

Open oronbz opened 11 months ago

oronbz commented 11 months ago

Describe the bug Some AttributedStrings don't print any diffs although they are not equal

To Reproduce CustomDumpAttributedString.zip

// If you’ll run this test:

    func testAttributedString() throws {
        var stringOne = AttributedString("One")
        stringOne.font = .body

        var stringTwo = AttributedString("One")
        stringTwo.font = .callout

        XCTAssertNoDifference(stringOne, stringTwo)
    }

// It’ll fail, but the printed dump will make it look like there are no differences at all:

XCTAssertNoDifference failed: …

    "One"

(First: −, Second: +)

// Where if I change the text to be different in addition to the font:

    func testAttributedString() throws {
        var stringOne = AttributedString("One")
        stringOne.font = .body

        var stringTwo = AttributedString("Two")
        stringTwo.font = .callout

        XCTAssertNoDifference(stringOne, stringTwo)
    }

// it prints it correctly:

XCTAssertNoDifference failed: …

  − "One"
  + "Two"

(First: −, Second: +)

// This problem is especially prominent when the AttributedString is a property of a State object inside of a Store, the test could fail and you’ll have no idea that the AttributedString is the one which is different:

XCTAssertNoDifference failed: …

    State(
      string: "One",
      number: 3
    )

(First: −, Second: +)

Expected behavior

// In my opinion I would expect at least:

- "One"
+ "One"

Environment