Coder Social home page Coder Social logo

messagediff's Introduction

messagediff Build Status Coverage Status GoDoc

A library for doing diffs of arbitrary Golang structs.

If the unsafe package is available messagediff will diff unexported fields in addition to exported fields. This is primarily used for testing purposes as it allows for providing informative error messages.

Example Usage

In a normal file:

package main

import "gopkg.in/d4l3k/messagediff.v1"

type someStruct struct {
  A, b int
  C []int
}

func main() {
			a := someStruct{1, 2, []int{1}}
			b := someStruct{1, 3, []int{1, 2}}
      diff, equal := messagediff.PrettyDiff(a, b)
      /*
        diff =
          `added: .C[1] = 2
          modified: .b = 3`

        equal = false
      */
}

In a test:

import "gopkg.in/d4l3k/messagediff.v1"

...

type someStruct struct {
  A, b int
  C []int
}

func TestSomething(t *testing.T) {
  want := someStruct{1, 2, []int{1}}
  got := someStruct{1, 3, []int{1, 2}}
  if diff, equal := messagediff.PrettyDiff(want, got); !equal {
    t.Errorf("Something() = %#v\n%s", got, diff)
  }
}

See the DeepDiff function for using the diff results programmatically.

License

Copyright (c) 2015 Tristan Rice [email protected]

messagediff is licensed under the MIT license. See the LICENSE file for more information.

bypass.go and bypasssafe.go are borrowed from go-spew and have a seperate copyright notice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.