From 16e4dce253459fa9f4b95526ce707611f518d0f3 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Wed, 29 Jan 2025 13:53:30 +0100 Subject: [PATCH] refactor: use diff for test results and add cases --- go.mod | 5 +++++ media_test.go | 13 ++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index bf80275..66cc473 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,8 @@ module git.javil.eu/jacob1123/dl-rename go 1.22.9 + +require ( + github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 // indirect + github.com/sergi/go-diff v1.3.1 // indirect +) diff --git a/media_test.go b/media_test.go index c0c3c3a..d4d89a1 100644 --- a/media_test.go +++ b/media_test.go @@ -1,6 +1,10 @@ package main -import "testing" +import ( + "testing" + + "github.com/andreyvit/diff" +) func Test(t *testing.T) { m := newMediaElement("Misfits - S02E03 - EN FORCED") @@ -13,12 +17,15 @@ func Test(t *testing.T) { func TestExamples(t *testing.T) { // list of strings with expected output examples := [][]string{ - {"Speak.No.Evil.2024.German.EAC3.DL.1080p.BluRay.x265-VECTOR.mkv", "Speak No Evil (2024) DE 1080P X265.mkv"}, + {"Speak.No.Evil.2024.German.EAC3.DL.1080p.BluRay.x265-VECTOR.nfo", "Speak No Evil (2024) DE 1080p x265.nfo"}, + {"Speak.No.Evil.2024.German.EAC3.DL.1080p.BluRay.x265-VECTOR/Speak.No.Evil.2024.nfo", "Speak No Evil (2024) DE 1080p x265.nfo"}, + {"Speak.No.Evil.2024.nfo", "Speak No Evil (2024).nfo"}, + {"Miracles.from.Heaven.2016.1080p.BluRay.X264-AMIABLE/Miracles.from.Heaven.2016.1080p.BluRay.X264-AMIABLE.mkv", "Miracles from Heaven (2016) 1080p x264.mkv"}, } for _, example := range examples { element := newMediaElement(example[0]) if expected, got := example[1], element.Path(); expected != got { - t.Errorf("Expected %s, got %s", expected, got) + t.Errorf("Result not expected for %s:\n%v", example[0], diff.LineDiff(expected, got)) } } }