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

content test: Compare parse trees via Diagnosticable #206

Merged
merged 2 commits into from
Jun 28, 2023

Conversation

gnprice
Copy link
Member

@gnprice gnprice commented Jun 28, 2023

I merged #205, and then a half-hour later saw a nicer way to do it. Better output on failure, and also less boilerplate code to write and update.

Happily none of the test cases change at all ­— only the infrastructure under them.

Before (if I artificially break one of the tests):

00:01 +16 -1: parse two plain-text paragraphs [E]                               
  Expected: a ZulipContent that:
    is a ZulipContent
    has nodes that:
      is deeply equal to (A value that:
        is a BlockContentNode
        is a ParagraphNode
        has wasImplicit that:
          equals <false>
        has nodes that:
          is deeply equal to (A value that:
            is a InlineContentNode
            equals <TextNode
               "hello">),
      A value that:
        is a BlockContentNode
        is a ParagraphNode
        has wasImplicit that:
          equals <false>
        has nodes that:
          is deeply equal to (A value that:
            is a InlineContentNode
            equals <TextNode
               "wrld">))
  Actual: a ZulipContent that:
    is a ZulipContent
    has nodes that:
    Actual: [ParagraphNode
     └─TextNode
         "hello",
    ParagraphNode
     └─TextNode
         "world"]
    Which: has an element at [<1>] that:
        is a BlockContentNode
        is a ParagraphNode
        has wasImplicit that:
          equals <false>
        has nodes that:
        Actual: [TextNode
           "world"]
        which has an element at [<0>] that:
          Actual: <TextNode
             "world">
          which are not equal
  package:checks/src/checks.dart 72:9                 check.<fn>
  package:checks/src/checks.dart 717:12               _TestContext.expect
  package:checks/src/extensions/iterable.dart 174:12  IterableChecks.deepEquals
  test/model/content_checks.dart 67:5                 BlockContentNodeListChecks.equalsNodes
  test/model/content_checks.dart 14:16                ContentNodeChecks.equalsNode
  test/model/content_test.dart 11:8                   testParse.<fn>
  

To run this test again: /home/greg/n/flutter/flutter/bin/cache/dart-sdk/bin/dart test /home/greg/z/flutterz/test/model/content_test.dart -p vm --plain-name 'parse two plain-text paragraphs'

After, with less noise and more information:

00:01 +16 -1: parse two plain-text paragraphs [E]                               
  Expected: a ZulipContent that:
    equals <ZulipContent
     ├─ParagraphNode
     │ └─TextNode
     │     "hello"
     │
     └─ParagraphNode
       └─TextNode
           "wrld">
  Actual: <ZulipContent
   ├─ParagraphNode
   │ └─TextNode
   │     "hello"
   │
   └─ParagraphNode
     └─TextNode
         "world">
  Which: differs in that it:
    has child 1 (ParagraphNode) that:
      has child 0 (TextNode) that:
        has text that:
          is 'world'
          expected: 'wrld'
  package:checks/src/checks.dart 72:9    check.<fn>
  package:checks/src/checks.dart 717:12  _TestContext.expect
  test/model/content_checks.dart 7:20    ContentNodeChecks.equalsNode
  test/model/content_test.dart 11:8      testParse.<fn>
  

To run this test again: /home/greg/n/flutter/flutter/bin/cache/dart-sdk/bin/dart test /home/greg/z/flutterz/test/model/content_test.dart -p vm --plain-name 'parse two plain-text paragraphs'

gnprice added 2 commits June 27, 2023 23:24
This makes for significantly cleaner and more informative output
when a test fails (resolving all the TODO-comments), by taking
more control of how the comparison is done.

At the same time, it makes for less boilerplate and fewer places
to update when adding more features in the ContentNode parse trees.
Effectively it deduplicates some of the boilerplate, by reusing
for comparing the trees the metadata that we're already prepared
to generate for printing them out when a comparison fails.
@chrisbobbe
Copy link
Collaborator

Great! Thanks; LGTM, merging.

@chrisbobbe chrisbobbe merged commit 9c8a283 into zulip:main Jun 28, 2023
@gnprice gnprice deleted the pr-content-test branch June 29, 2023 00:26
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