cmp,cmpopts: add examples for AllowUnexported and IgnoreUnexported#392
Draft
MukundaKatta wants to merge 1 commit intogoogle:masterfrom
Draft
cmp,cmpopts: add examples for AllowUnexported and IgnoreUnexported#392MukundaKatta wants to merge 1 commit intogoogle:masterfrom
MukundaKatta wants to merge 1 commit intogoogle:masterfrom
Conversation
Add testable examples demonstrating cmp.AllowUnexported and cmpopts.IgnoreUnexported. Each example uses a small struct with one unexported field, shows the equal/non-equal cases, and prints a Diff to clarify how the option affects the output. Fixes google#130
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #130. Adds testable
Examplefunctions forcmp.AllowUnexportedandcmpopts.IgnoreUnexportedthat demonstrate the difference between the two options on a struct with an unexported field.What's added
cmp/example_test.go—ExampleAllowUnexported(account struct with unexportedbalance; equal vs unequal cases pluscmp.Diffoutput).cmp/cmpopts/example_test.go—ExampleIgnoreUnexported(user struct with unexportedcache; equal-despite-differing-cache case plus the "1 ignored field" diff).Each example has an
// Output:block sogo testverifies it. Style follows the existingExampleDiff_testingandExampleIgnoreFields_testingpatterns.Test plan
go test ./cmp -run Example -v— all example tests pass.go test ./...— full suite green.gofmt -lclean.