mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
Drop additions that the UX plan does not ask for: - the interactive label edit form; label edit now requires a flag - label clone and the skip mode of label creation it needed - repo rename rewriting the Git remote or tea.repository; it now warns that the remote still points to the old name - the extra "source" remote on clones of pull mirrors - run artifact download, which duplicates run download --zip - 256-color and 24-bit label swatches; colors stay ANSI 16 - config list --show-source (config get keeps it) - the membership and access GETs before team member/repo add and remove; Gitea's PUT and DELETE are idempotent label edit/delete keep --by-name: it is the only way to address a label whose name is a number that is also another label's ID. Signed-off-by: bircni <bircni@icloud.com>
62 lines
2.3 KiB
Go
62 lines
2.3 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package terminal
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func env(vars map[string]string) func(string) string {
|
|
return func(key string) string { return vars[key] }
|
|
}
|
|
|
|
func TestColorEnabledRespectsPreferenceAndEnvironment(t *testing.T) {
|
|
noColor := env(map[string]string{"NO_COLOR": "1"})
|
|
require.True(t, ColorEnabled("always", false, nil))
|
|
require.False(t, ColorEnabled("never", true, nil))
|
|
require.True(t, ColorEnabled("auto", true, env(nil)))
|
|
require.False(t, ColorEnabled("auto", false, env(nil)))
|
|
require.False(t, ColorEnabled("auto", true, noColor))
|
|
require.True(t, ColorEnabled("always", true, noColor))
|
|
require.False(t, ColorEnabled("auto", true, env(map[string]string{"TERM": "dumb"})))
|
|
}
|
|
|
|
func TestHyperlinksEnabledIgnoresColorPolicy(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
preference string
|
|
tty bool
|
|
env map[string]string
|
|
want bool
|
|
}{
|
|
{"auto", true, nil, true},
|
|
{"", true, map[string]string{"NO_COLOR": "1"}, true},
|
|
{"auto", false, nil, false},
|
|
{"auto", true, map[string]string{"TERM": "dumb"}, false},
|
|
{"always", false, map[string]string{"TERM": "dumb"}, true},
|
|
{"never", true, nil, false},
|
|
} {
|
|
require.Equal(t, tc.want, HyperlinksEnabled(tc.preference, tc.tty, env(tc.env)), "%+v", tc)
|
|
}
|
|
}
|
|
|
|
func TestColorizeAndEmphasis(t *testing.T) {
|
|
require.Equal(t, "bug", Colorize("ff0000", "bug", false))
|
|
require.Equal(t, "bug", Colorize("bad", "bug", true))
|
|
require.Equal(t, "bug", Colorize("#ff0000", "bug", true))
|
|
require.Equal(t, "\x1b[32mopen\x1b[0m", Colorize("green", "open", true))
|
|
require.Equal(t, "\x1b[90mdraft\x1b[0m", Colorize("muted", "draft", true))
|
|
require.Equal(t, "open", Emphasis("open", false))
|
|
require.Equal(t, "\x1b[1mopen\x1b[0m", Emphasis("open", true))
|
|
}
|
|
|
|
func TestHyperlink(t *testing.T) {
|
|
require.Equal(t, "#7", Hyperlink("https://example.org/i/7", "#7", false))
|
|
require.Equal(t, "\x1b]8;;https://example.org/i/7\x1b\\#7\x1b]8;;\x1b\\", Hyperlink("https://example.org/i/7", "#7", true))
|
|
require.Equal(t, "#7", Hyperlink("", "#7", true))
|
|
require.Equal(t, "#7", Hyperlink("https://example.org/\x1b[2J", "#7", true))
|
|
require.Equal(t, "#7", Hyperlink("https://example.org/\u009b2J", "#7", true))
|
|
}
|