jsoncmp

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2019 License: MIT Imports: 3 Imported by: 0

README

JSON value comparison

Build Status Coverage Status GoDoc Go Report Card license

A Go JSON value comparison library for testing. It wraps github.com/google/go-cmp function. See the GoDoc documentation for more information.

Install

go get -u github.com/hgsgtk/jsoncmp

Usage

func TestDiff() {
	x := `
{
	"name": "Tom Bake",
	"age": 41
}`
	y := `
{
	"name": "Tom Bake",
	"age": 42
}
`
	var t stubT
	if diff := jsoncmp.Diff(x, y); diff != "" {
		t.Errorf("jsoncmp.Diff() got differs: (-got +want)\n%s", diff)
	}
}

License

MIT - See LICENSE file

Documentation

Overview

Package jsoncmp is a Go JSON value comparison library for testing.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(x, y string) string

Diff returns a compared result of differences between two values. It returns an empty string if there is no differences, but else returns a report as string.

Example

Use Diff for comparing two JSON values and printing out human-redable errors.

package main

import (
	"fmt"
	"github.com/hgsgtk/jsoncmp"
)

// Use Diff for comparing two JSON values and printing out human-redable errors.
func main() {
	x := `
{
	"name": "Tom Bake",
	"age": 41
}`
	y := `
{
	"name": "Tom Bake",
	"age": 42
}
`
	var t stubT
	if diff := jsoncmp.Diff(x, y); diff != "" {
		t.Errorf("jsoncmp.Diff() got differs: (-got +want)\n%s", diff)
	}
}

type stubT struct{}

func (t *stubT) Errorf(format string, args ...interface{}) {
	fmt.Printf(format+"\n", args...)
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL