package ledger

import "testing"

func TestLikeBeforeAfter(t *testing.T) {
	if got := LikeBefore("9")(Delta{Date: "2021"}); !got {
		t.Error("got 2021 is NOT before 9")
	}
	if got := LikeBefore("1")(Delta{Date: "2021"}); got {
		t.Error("got 2021 IS before 1")
	}
	if got := LikeAfter("9")(Delta{Date: "2021"}); got {
		t.Error("got 2021 IS after 9")
	}
	if got := LikeAfter("1")(Delta{Date: "2021"}); !got {
		t.Error("got 2021 is NOT after 1")
	}
}

func TestLikeName(t *testing.T) {
	delta := Delta{Name: "x"}
	if got := LikeName("^x$")(delta); !got {
		t.Error(got)
	}
	if got := LikeName("^y$")(delta); got {
		t.Error(got)
	}
}

func TestLikesAll(t *testing.T) {
	delta := Delta{Name: "x"}
	if likes := (Likes{LikeName("^x$")}); !likes.All(delta) {
		t.Error(likes.All(delta))
	}
	if likes := (Likes{LikeName("^y$")}); likes.All(delta) {
		t.Error(likes.All(delta))
	}
}

func TestLikeWith(t *testing.T) {
	delta := Delta{
		Name: "x",
		with: []Delta{
			Delta{Name: "y"},
			Delta{Name: "z"},
		},
	}

	if !LikeWith("x")(delta) {
		t.Error("like with self not caught")
	}
	if !LikeWith("z")(delta) {
		t.Error("like with reverse not caught")
	}
}
