{"id":15481462,"url":"https://github.com/mikeschinkel/go-diffator","last_synced_at":"2025-06-25T18:04:51.763Z","repository":{"id":209717689,"uuid":"724774078","full_name":"mikeschinkel/go-diffator","owner":"mikeschinkel","description":"Diffator is a Go package to provide a difference string for comparing two Go values during testing. ","archived":false,"fork":false,"pushed_at":"2024-01-14T05:46:19.000Z","size":69,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-20T11:09:36.786Z","etag":null,"topics":["comparison","golang","package","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikeschinkel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-28T19:09:13.000Z","updated_at":"2024-12-10T04:39:29.000Z","dependencies_parsed_at":"2024-01-06T02:43:53.985Z","dependency_job_id":"69c4a5cb-0125-4aee-a828-503d527fe9c0","html_url":"https://github.com/mikeschinkel/go-diffator","commit_stats":{"total_commits":38,"total_committers":1,"mean_commits":38.0,"dds":0.0,"last_synced_commit":"18c353d6899c9e3e36cc661abae3f4cef3a6eab9"},"previous_names":["mikeschinkel/go-diffator"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mikeschinkel/go-diffator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeschinkel%2Fgo-diffator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeschinkel%2Fgo-diffator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeschinkel%2Fgo-diffator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeschinkel%2Fgo-diffator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikeschinkel","download_url":"https://codeload.github.com/mikeschinkel/go-diffator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeschinkel%2Fgo-diffator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261927285,"owners_count":23231367,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["comparison","golang","package","testing"],"created_at":"2024-10-02T05:04:31.999Z","updated_at":"2025-06-25T18:04:51.739Z","avatar_url":"https://github.com/mikeschinkel.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-diffator\nDiffator is a Go package to provide a difference string for **comparing during testing**.\n\nDiffator does NOT output a standard format diff but is instead is optimized for a developer to recognize the difference between a value they want in their test compared with the value they got in their test, where `want==expected` and `got==actual`.\n\n## Usage\nDiffator _(currently)_ offers two (2) types of comparisons:\n\n1. String-to-string comparison\n2. Object-to-object comparison\n\n\n### Usage for String-to-string comparison\n```go\nresult := diffator.CompareStrings(string1, string2, nil)\nprintln(result)\n```\n\n```go\nresult := diffator.CompareStrings(string1,string2,\u0026diffator.StringOpts{\n  MinSubstrLen: diffator.Int(3),\n})\nprintln(result)\n```\n\n```go\nc := NewStringComparator(v1, v2, nil)\nresult := c.Compare()\nprintln(result)\n```\n\n```go\nc := NewStringComparator(v1, v2, \u0026diffator.StringOpts{\n  MinSubstrLen: diffator.Int(3),\n})\nresult := c.Compare()\nprintln(result)\n```\n\nTo understand `diffator.Int(3)`, see [Nillable Option Values](#nillable-types).\n\n#### Diff Output\n```go\n// Assuming:\nstring1 := \"ABC\"\nstring2 := \"\"\n\n// Result: \"\u003c(ABC/)\u003e\"\n```\n\n```go\n// Assuming:\nstring1 := \"\"\nstring2 := \"ABC\"\n\n// Result: \"\u003c(/ABC)\u003e\"\n```\n\n```go\n// Assuming:\nstring1 := \"ABC\"\nstring2 := \"XYZ\"\n\n// Result: \"\u003c(ABC/XYZ)\u003e\"\n```\n\n```go\n// Assuming:\nstring1 := \"ABCDEF\"\nstring2 := \"ABCDXYZ\"\n\n// Result: \"ABCD\u003c(EF/XYZ)\u003e\"\n```\n```go\n// Assuming:\nstring1 := \"ABCDXYZ\"\nstring2 := \"123XYZ\"\n\n// Result: \"\u003c(ABCD/123)\u003eXYZ\"\n```\n```go\n// Assuming:\nstring1 := \"ABCDEF123GHI456JKLMNOP\"\nstring2 := \"ABCDEFGHIJKLMNOP\"\nopts := \u0026StringOpts{\n  MatchingPadLen: diffator.Int(5),\n  MinSubstrLen:   diffator.Int(2),\n}\n// Result: \"BCDEF\u003c(123/)\u003eGHI\u003c(456/)\u003eJKLMN\"\n```\n```go\n// Assuming:\nstring1 := \"Look, it's Batman!!!\"\nstring2 := \"Look, it's Superman!!!\"\n\n// Result: \"Look, it's \u003c(Bat/Super)\u003eman!!!\"\n```\n\n\n### Usage for Object-to-object comparison\n\n```go\nresult := diffator.CompareObjects(value1, value2, nil)\nprintln(result)\n```\n\n```go\nresult := diffator.CompareObjects(value1,value2,\u0026diffator.ObjectOpts{\n  OutputFormat: diffator.String(\"Diff: %s\"),\n})\nprintln(result)\n```\n\n```go\nc := NewObjectComparator(v1, v2, nil)\nresult := c.Compare()\nprintln(result)\n```\n\n```go\nc := NewObjectComparator(v1, v2, \u0026diffator.ObjectOpts{\n  OutputFormat: diffator.String(\"Diff: %s\"),\n})\nresult := c.Compare()\nprintln(result)\n```\nTo understand `diffator.String(\"Diff: %s\")`, see [Nillable Option Values](#nillable-types).\n\n\n#### Diff Output\n```go\n// Assuming:\nvalue1 := 100\nvalue2 := 99\n\n// Result: (100!=99)\n```\n\n```go\n// Assuming:\ntype TestStruct struct {\n\tInt    int\n\tString string\n}\nvalue1 := \u0026TestStruct{}\nvalue2 := \u0026TestStruct{\n  Int:    1,\n  String: \"hello\",\n}\n\n// Result: *TestStruct{Int:(0!=1),String:(!=hello),}\n```\n\n```go\n// Assuming:\nvalue1 := map[string]int{\"Foo\": 1, \"Bar\": 2, \"Baz\": 3}\nvalue2 := map[string]int{\"Foo\": 1, \"Bar\": 20, \"Baz\": 3}\n\n// Result: map[string]int{Bar:(2!=20),}\n```\n\n```go\n// Assuming:\nvalue1 := map[string]int{\"Foo\": 1, \"Bar\": 2, \"Baz\": 3, \"Superman\": 0}\nvalue2 := map[string]int{\"Foo\": 10, \"Bar\": 20, \"Baz\": 30, \"Batman\": 0}\n\n// Result: map[string]int{Bar:(2!=20),Baz:(3!=30),Foo:(1!=10),Superman:\u003cmissing:expected\u003e,Batman:\u003cmissing:actual\u003e,}\n```\n\n_Note that the above is without `ObjectOps.PrettyPrint := true`._\t\t\t\n### Nillable Option Values\nWe decided that in order to allow for setting of default values for `StringOpts` and `ObjectOpts` we would use values of `*diffator.IntValue`, `*diffator.BoolValue`, `*diffator.StringValue` instead of `int`, `bool`, and `string`, respectively.\n\nTo set the values, use the object constructors `diffator.Int()`,  `diffator.Bool()`, and `diffator.String()`, respectively. \n\nTo see example usage, visit the [Usage](#usage) sections, above.\n\n## Status\nIn active use, but only addresses those data types that the author has needed to address his use-case.  \n\nIf you would like to use this and you find it generates a panic for an unimplemented type, [pull requests](https://github.com/mikeschinkel/go-diffator/compare) are accepted and appreciated.\n\n## License\nApache 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikeschinkel%2Fgo-diffator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikeschinkel%2Fgo-diffator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikeschinkel%2Fgo-diffator/lists"}