Skip to content

fix: Calculate the initial indent correctly in a couple edge cases.#45

Merged
JeffFaer merged 5 commits intomainfrom
jfaer/group_prefixes
Oct 25, 2024
Merged

fix: Calculate the initial indent correctly in a couple edge cases.#45
JeffFaer merged 5 commits intomainfrom
jfaer/group_prefixes

Conversation

@JeffFaer
Copy link
Collaborator

  1. When the first seen line is one of the group_prefixes.
  2. When the first seen line is another keep-sorted directive.

Idempotency output before this change:

$ go test ./...
?       github.com/google/keep-sorted   [no test files]
?       github.com/google/keep-sorted/cmd       [no test files]
--- FAIL: TestGoldens (0.66s)
    --- FAIL: TestGoldens/group (0.00s)
        --- FAIL: TestGoldens/group/group (0.66s)
            golden_test.go:105: keep-sorted diff on keep-sorted output (should be idempotent) (-want +got)
                  (
                        """
                        ... // 180 identical lines
                          case 5:
                          // keep-sorted-test end
                -           return 10
                          case 2:
                -           return 2;
                          case 4:
                +         case 6:
                +           return 10
                +           return 2;
                            return 4;
                -         case 6:
                            return 6;
                          // keep-sorted-test end
                        """
                  )
FAIL
FAIL    github.com/google/keep-sorted/goldens   0.686s
ok      github.com/google/keep-sorted/keepsorted        (cached)
FAIL

Also, check the git history to see how group.out evolved.

1. When the first seen line is one of the `group_prefixes`.
2. When the first seen line is another keep-sorted directive.

Idempotency output before this change:

```
$ go test ./...
?       github.com/google/keep-sorted   [no test files]
?       github.com/google/keep-sorted/cmd       [no test files]
--- FAIL: TestGoldens (0.66s)
    --- FAIL: TestGoldens/group (0.00s)
        --- FAIL: TestGoldens/group/group (0.66s)
            golden_test.go:105: keep-sorted diff on keep-sorted output (should be idempotent) (-want +got)
                  (
                        """
                        ... // 180 identical lines
                          case 5:
                          // keep-sorted-test end
                -           return 10
                          case 2:
                -           return 2;
                          case 4:
                +         case 6:
                +           return 10
                +           return 2;
                            return 4;
                -         case 6:
                            return 6;
                          // keep-sorted-test end
                        """
                  )
FAIL
FAIL    github.com/google/keep-sorted/goldens   0.686s
ok      github.com/google/keep-sorted/keepsorted        (cached)
FAIL
```

Also, check the git history to see how group.out evolved.
Copy link
Member

@KatrinaHoffert KatrinaHoffert left a comment

Choose a reason for hiding this comment

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

Good idea, that idempotency check.

@JeffFaer JeffFaer merged commit 3436ef5 into main Oct 25, 2024
@JeffFaer JeffFaer deleted the jfaer/group_prefixes branch October 25, 2024 15:32
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