Giter Site home page Giter Site logo

test_match's Introduction

Hex.pm Downloads Build Status Coverage Status Inline docs

RecursiveMatch

Module for matching

What difference between Kernel.match?/2 and RecursiveMatch.match_r/3?

When you use Kernel.match?/2

  • can't use functions as pattern
  • can't match not strict equality (only ===, no ==)

RecursiveMatch.match_r/3 allows you:

  • use functions as patterns
  • match not strictly (with option strict: false)
  • ignore order of lists item (with option ignore_order: true)

What is for assert_match/3 and refute_match/3?

It is same as assert RecursiveMatch.match_r, but with detailed fail message.
ExUnit has no special message for match_r/3 and even no special message for match?/2 is not detailed enough, it has no diff in fail message.

assert_match/3 provides diff in test fail message

Installation

If available in Hex, the package can be installed by adding test_match to your list of dependencies in mix.exs:

Requires elixir ~> 1.5

def deps do
  [
    {:test_match, "~> 2.0"}
  ]
end

Usage

defmodule YourModule do
  import RecursiveMatch

  def function1 do
    ...
  end
  
  def function2 do
    ...
    match_r 1, 2 
    match_r a, b
    match_r :_, b
    match_r function1(), 1
    match_r [1, 2], [2, 1], ignore_order: true # true
    match_r 1, 1.0, strict: true               # false
    match_r {1, 2}, {2, 1}, ignore_order: true # false, nope :)
    ...
  end
end
defmodule YourModuleTest do
  use ExUnit.Case
  import RecursiveMatch

  test "some test" do
    ...
    assert_match 1, 2 # false
    assert_match :_, b
    assert_match a, b
    assert_match [1, 2], [2, 1], ignore_order: true
    refute_match 1, 1.0
    assert_match 1, 1.0, strict: false          
    refute_match a, c
    assert_match YourModule.function1(), 1
    ...
  end
end

Options

  • strict: when true compare using ===, when false compare using ==, default true
  • ignore_order, when true - ignore order of items in lists, default false
  • message: Custom message on fail

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/test_match.

test_match's People

Contributors

apelsinka223 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

test_match's Issues

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.