aboutsummaryrefslogtreecommitdiff
path: root/modules/label/parser_test.go
blob: 5c8042f66863ceea8fd4111297e4be9712c079f6 (plain)
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
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package label

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestYamlParser(t *testing.T) {
	data := []byte(`labels:
  - name: priority/low
    exclusive: true
    color: "#0000ee"
    description: "Low priority"
  - name: priority/medium
    exclusive: true
    color: "0e0"
    description: "Medium priority"
  - name: priority/high
    exclusive: true
    color: "#ee0000"
    description: "High priority"
  - name: type/bug
    color: "#f00"
    description: "Bug"`)

	labels, err := parseYamlFormat("test", data)
	require.NoError(t, err)
	require.Len(t, labels, 4)
	assert.Equal(t, "priority/low", labels[0].Name)
	assert.True(t, labels[0].Exclusive)
	assert.Equal(t, "#0000ee", labels[0].Color)
	assert.Equal(t, "Low priority", labels[0].Description)
	assert.Equal(t, "priority/medium", labels[1].Name)
	assert.True(t, labels[1].Exclusive)
	assert.Equal(t, "#00ee00", labels[1].Color)
	assert.Equal(t, "Medium priority", labels[1].Description)
	assert.Equal(t, "priority/high", labels[2].Name)
	assert.True(t, labels[2].Exclusive)
	assert.Equal(t, "#ee0000", labels[2].Color)
	assert.Equal(t, "High priority", labels[2].Description)
	assert.Equal(t, "type/bug", labels[3].Name)
	assert.False(t, labels[3].Exclusive)
	assert.Equal(t, "#ff0000", labels[3].Color)
	assert.Equal(t, "Bug", labels[3].Description)
}

func TestLegacyParser(t *testing.T) {
	data := []byte(`#ee0701 bug   ;   Something is not working
#cccccc   duplicate ; This issue or pull request already exists
#84b6eb enhancement`)

	labels, err := parseLegacyFormat("test", data)
	require.NoError(t, err)
	require.Len(t, labels, 3)
	assert.Equal(t, "bug", labels[0].Name)
	assert.False(t, labels[0].Exclusive)
	assert.Equal(t, "#ee0701", labels[0].Color)
	assert.Equal(t, "Something is not working", labels[0].Description)
	assert.Equal(t, "duplicate", labels[1].Name)
	assert.False(t, labels[1].Exclusive)
	assert.Equal(t, "#cccccc", labels[1].Color)
	assert.Equal(t, "This issue or pull request already exists", labels[1].Description)
	assert.Equal(t, "enhancement", labels[2].Name)
	assert.False(t, labels[2].Exclusive)
	assert.Equal(t, "#84b6eb", labels[2].Color)
	assert.Empty(t, labels[2].Description)
}