~tyil/raku-hash-merge

da9c10a20bbbf8904f3831511538eff67c27b695 — Patrick Spek 6 years ago e3e0962
Add tests for a unit module
1 files changed, 59 insertions(+), 0 deletions(-)

A t/03-unit.t
A t/03-unit.t => t/03-unit.t +59 -0
@@ 0,0 1,59 @@
#! /usr/bin/env perl6

use v6.c;

use Hash::Merge::Unit;
use Test;

plan 2;

subtest "merge-hash" => {
    plan 2;

    my %original =
        a => "a",
        b => {
            c => "c"
        }
    ;

    my %result =
        a => "a",
        b => {
            c => "c",
            d => "d",
        },
    ;

    is-deeply merge-hash(%original, %(b => %(d => "d"))), %result, "Hash merges correctly";
    is-deeply merge-hash(%original, %()), %original, "Empty Hash doesn't affect original";
}

subtest "merge-hashes" => {
    plan 4;

    my %original =
        a => "a",
        b => {
            c => "c"
        }
    ;

    my %result =
        a => "a",
        b => {
            c => "c",
            d => "d",
        },
    ;

    is-deeply merge-hashes(%original), %original, "Single argument returns original";
    is-deeply merge-hashes(%original, %(b => %(d => "d"))), %result, "Hash merges correctly";
    is-deeply merge-hashes(%original, %()), %original, "Empty Hash doesn't affect original";

    %result<b><e> = "e";

    is-deeply merge-hashes(%original, %(b => %(d => "d")), %(b => %(e => "e"))), %result, "Hash merges correctly";
}

# vim: ft=perl6 ts=4 sw=4 et