Skip to content

Handy and reusable functions for testing slices 🍕

License

Notifications You must be signed in to change notification settings

kampanosg/match

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

match 🍕

Go

Handy and reusable functions that I have been using when writing tests for slices. All functions accept *testing.T and you can use them directly in your unit tests.

At the moment the following functions are available:

  • Exactly: The slices have to match exactly, including size and order of elements,
  • Elements: The slices have to match in size, but the order of the elements can be different.

⚠️ If you're already using https://github.com/stretchr/testify, they provide ElementsMatch, that has the same functionality.

Usage

Import the package alongside testing

import (
  "testing"
  "github.com/kampanosg/match"
)

You can then use it in your tests

func TestExample(t *testing.T) {
  slice1 := []int{1, 2, 3}
  slice2 := []int{1, 2, 3}
  match.Exactly(t, slice1, slice2)
  match.Elements(t, slice1, slice2)
}

Building and Testing

A Makefile is provided that allows you to build and test the module

make build
make test

About

Handy and reusable functions for testing slices 🍕

Topics

Resources

License

Stars

Watchers

Forks