task_test.go 1,9 КБ
Newer Older
keewek's avatar
keewek включено в состав коммита
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-FileCopyrightText: 2023 Alexander Bugrov <abugrov+dev@gmail.com>
//
// SPDX-License-Identifier: MIT

package processor

import (
	"testing"

	"github.com/google/go-cmp/cmp"
)

func Test_Task(t *testing.T) {
	task := &Task{Block: "Block", Name: "Name", Tags: "Tags"}

	t.Run("Implements 'Stringer' interface", func(t *testing.T) {
		got := task.String()
		want := "Block: Name    TAGS: Tags"

		if diff := cmp.Diff(want, got); diff != "" {
			t.Errorf("(-want +got): \n%s", diff)
		}
	})

	t.Run("Description(): returns 'Name' field when 'Block' field is empty", func(t *testing.T) {
		task := &Task{Block: "", Name: "Name", Tags: "Tags"}

		got := task.Description()
		want := "Name"

		if diff := cmp.Diff(want, got); diff != "" {
			t.Errorf("(-want +got): \n%s", diff)
		}
	})

	t.Run("Description(): returns a join of 'Block' and 'Name' fields when 'Block' field is not empty", func(t *testing.T) {
		task := &Task{Block: "Block", Name: "Name", Tags: "Tags"}

		got := task.Description()
		want := "Block: Name"

		if diff := cmp.Diff(want, got); diff != "" {
			t.Errorf("(-want +got): \n%s", diff)
		}
	})

}

func Test_Tasks(t *testing.T) {

	items := []*Task{
		{Block: "Block_1", Name: "Name_1", Tags: "Tags_1"},
		{Block: "Block_2", Name: "Name_2", Tags: "Tags_2"},
		{Block: "Block_3", Name: "Name_3", Tags: "Tags_3"},
	}

	task04 := &Task{Block: "Block_4", Name: "Name_4", Tags: "Tags_4"}

	tasks := &Tasks{PlayNumber: 42, Tasks: items}

	t.Run("Implements 'Stringer' interface", func(t *testing.T) {
		got := tasks.String()
		want := "[Play #42 - Tasks]"

		if diff := cmp.Diff(want, got); diff != "" {
			t.Errorf("Play.String() mismatch (-want +got): \n%s", diff)
		}
	})

	t.Run("Add(): adds task", func(t *testing.T) {
		want := make([]*Task, len(items))

		copy(want, items)
		want = append(want, task04)

		tasks.Add(task04)

		got := tasks.Tasks

		if diff := cmp.Diff(want, got); diff != "" {
			t.Errorf("Play.String() mismatch (-want +got): \n%s", diff)
		}
	})

}