mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-30 04:21:19 -08:00
fix(lint): make string repetitions constant
This commit is contained in:
parent
7b89595658
commit
46c6275630
|
@ -36,6 +36,20 @@ func TestBrewfatherSegment(t *testing.T) {
|
|||
FakeReading3DateString := fmt.Sprintf("%d", FakeReading3Date.UnixMilli())
|
||||
FakeBottlingDateString := fmt.Sprintf("%d", FakeBottlingDate.UnixMilli())
|
||||
|
||||
// TODO: make this smarter
|
||||
|
||||
beerRecipeText := `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":`
|
||||
bottlingDate := `,"bottlingDate":`
|
||||
batchText := `,"name":"Batch","measuredAbv": 1.3}`
|
||||
batchNumberFermenting := `{"batchNo":18,"status":"Fermenting","brewDate":`
|
||||
manualType := `,"type":"manual"}]`
|
||||
|
||||
jsonFiller := FakeBrewDateString + bottlingDate + FakeBottlingDateString + beerRecipeText + FakeFermStartDateString + batchText
|
||||
|
||||
batchReadingJSON := `[{"id":"manual","temp":19.5,"comment":"","sg":1.066,"time":`
|
||||
batchReadingJSON2 := `,"type":"manual"}, {"id":"manual","temp":21,"comment":"","sg":1.063,"time":`
|
||||
batchReadingJSON3 := `,"type":"manual"}, {"id":"manual","temp":15,"comment":"","sg":1.050,"time":`
|
||||
|
||||
cases := []struct {
|
||||
Case string
|
||||
BatchJSONResponse string
|
||||
|
@ -48,90 +62,81 @@ func TestBrewfatherSegment(t *testing.T) {
|
|||
Error error
|
||||
}{
|
||||
{
|
||||
Case: "Planning Status",
|
||||
BatchJSONResponse: `
|
||||
{"batchNo":18,"status":"Planning","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll
|
||||
Case: "Planning Status",
|
||||
BatchJSONResponse: `{"batchNo":18,"status":"Planning","brewDate":` + jsonFiller,
|
||||
BatchReadingsJSONResponse: `[]`,
|
||||
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
|
||||
ExpectedString: " Fake Beer 1.3%",
|
||||
ExpectedEnabled: true,
|
||||
},
|
||||
{
|
||||
Case: "Brewing Status",
|
||||
BatchJSONResponse: `
|
||||
{"batchNo":18,"status":"Brewing","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll
|
||||
Case: "Brewing Status",
|
||||
BatchJSONResponse: `{"batchNo":18,"status":"Brewing","brewDate":` + jsonFiller,
|
||||
BatchReadingsJSONResponse: `[]`,
|
||||
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
|
||||
ExpectedString: " Fake Beer 1.3%",
|
||||
ExpectedEnabled: true,
|
||||
},
|
||||
{
|
||||
Case: "Fermenting Status, no readings",
|
||||
BatchJSONResponse: `
|
||||
{"batchNo":18,"status":"Fermenting","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll
|
||||
Case: "Fermenting Status, no readings",
|
||||
BatchJSONResponse: batchNumberFermenting + jsonFiller,
|
||||
BatchReadingsJSONResponse: `[]`,
|
||||
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
|
||||
ExpectedString: " 19d Fake Beer 1.3%",
|
||||
ExpectedEnabled: true,
|
||||
},
|
||||
{
|
||||
Case: "Fermenting Status, one reading",
|
||||
BatchJSONResponse: `
|
||||
{"batchNo":18,"status":"Fermenting","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll
|
||||
BatchReadingsJSONResponse: `[{"id":"manual","temp":19.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + `,"type":"manual"}]`,
|
||||
Case: "Fermenting Status, one reading",
|
||||
BatchJSONResponse: batchNumberFermenting + jsonFiller,
|
||||
BatchReadingsJSONResponse: batchReadingJSON + FakeReading1DateString + manualType,
|
||||
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
|
||||
ExpectedString: " 19d Fake Beer 1.3%: 1.066 19.5° →",
|
||||
ExpectedEnabled: true,
|
||||
},
|
||||
{
|
||||
Case: "Fermenting Status, two readings, temp trending up",
|
||||
BatchJSONResponse: `
|
||||
{"batchNo":18,"status":"Fermenting","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll
|
||||
BatchReadingsJSONResponse: `[{"id":"manual","temp":19.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + `,"type":"manual"}, {"id":"manual","temp":21,"comment":"","sg":1.063,"time":` + FakeReading2DateString + `,"type":"manual"}]`, //nolint:lll
|
||||
Case: "Fermenting Status, two readings, temp trending up",
|
||||
BatchJSONResponse: batchNumberFermenting + jsonFiller, //nolint:lll
|
||||
BatchReadingsJSONResponse: batchReadingJSON + FakeReading1DateString + batchReadingJSON2 + FakeReading2DateString + manualType, //nolint:lll
|
||||
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
|
||||
ExpectedString: " 19d Fake Beer 1.3%: 1.063 21° ↗",
|
||||
ExpectedEnabled: true,
|
||||
},
|
||||
{
|
||||
Case: "Fermenting Status, three readings, temp trending hard down, include age of most recent reading",
|
||||
BatchJSONResponse: `
|
||||
{"batchNo":18,"status":"Fermenting","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll
|
||||
BatchReadingsJSONResponse: `[{"id":"manual","temp":19.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + `,"type":"manual"}, {"id":"manual","temp":21,"comment":"","sg":1.063,"time":` + FakeReading2DateString + `,"type":"manual"}, {"id":"manual","temp":15,"comment":"","sg":1.050,"time":` + FakeReading3DateString + `,"type":"manual"}]`, //nolint:lll
|
||||
Template: "{{.StatusIcon}} {{.ReadingAge}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
|
||||
Case: "Fermenting Status, three readings, temp trending hard down, include age of most recent reading",
|
||||
BatchJSONResponse: batchNumberFermenting + jsonFiller, //nolint:lll
|
||||
BatchReadingsJSONResponse: batchReadingJSON + FakeReading1DateString + batchReadingJSON2 + FakeReading2DateString + batchReadingJSON3 + FakeReading3DateString + manualType, //nolint:lll
|
||||
Template: "{{.StatusIcon}} {{.ReadingAge}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
|
||||
ExpectedString: " 451 19d Fake Beer 1.3%: 1.05 15° ↓↓",
|
||||
ExpectedEnabled: true,
|
||||
},
|
||||
{
|
||||
Case: "Bad batch json, readings fine",
|
||||
BatchJSONResponse: ``,
|
||||
BatchReadingsJSONResponse: `[{"id":"manual","temp":19.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + `,"type":"manual"}, {"id":"manual","temp":21,"comment":"","sg":1.063,"time":` + FakeReading2DateString + `,"type":"manual"}, {"id":"manual","temp":15,"comment":"","sg":1.050,"time":` + FakeReading3DateString + `,"type":"manual"}]`, //nolint:lll
|
||||
Template: "{{.StatusIcon}} {{.ReadingAge}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
|
||||
BatchReadingsJSONResponse: batchReadingJSON + FakeReading1DateString + batchReadingJSON2 + FakeReading2DateString + batchReadingJSON3 + FakeReading3DateString + manualType, //nolint:lll
|
||||
Template: "{{.StatusIcon}} {{.ReadingAge}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
|
||||
ExpectedString: "",
|
||||
ExpectedEnabled: false,
|
||||
},
|
||||
{
|
||||
Case: "Conditioning Status",
|
||||
BatchJSONResponse: `
|
||||
{"batchNo":18,"status":"Conditioning","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll
|
||||
BatchReadingsJSONResponse: `[{"id":"manual","temp":19.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + `,"type":"manual"}, {"id":"manual","temp":21,"comment":"","sg":1.063,"time":` + FakeReading2DateString + `,"type":"manual"}, {"id":"manual","temp":15,"comment":"","sg":1.050,"time":` + FakeReading3DateString + `,"type":"manual"}]`, //nolint:lll
|
||||
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
|
||||
Case: "Conditioning Status",
|
||||
BatchJSONResponse: `{"batchNo":18,"status":"Conditioning","brewDate":` + jsonFiller, //nolint:lll
|
||||
BatchReadingsJSONResponse: batchReadingJSON + FakeReading1DateString + batchReadingJSON2 + FakeReading2DateString + batchReadingJSON3 + FakeReading3DateString + manualType, //nolint:lll
|
||||
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
|
||||
ExpectedString: " 5d Fake Beer 1.3%",
|
||||
ExpectedEnabled: true,
|
||||
},
|
||||
{
|
||||
Case: "Fermenting Status, test all unit conversions",
|
||||
BatchJSONResponse: `
|
||||
{"batchNo":18,"status":"Fermenting","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll
|
||||
BatchReadingsJSONResponse: `[{"id":"manual","temp":34.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + `,"type":"manual"}]`,
|
||||
Case: "Fermenting Status, test all unit conversions",
|
||||
BatchJSONResponse: batchNumberFermenting + jsonFiller,
|
||||
BatchReadingsJSONResponse: `[{"id":"manual","temp":34.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + manualType,
|
||||
Template: "{{ if and (.Reading) (eq .Status \"Fermenting\") }}SG: ({{.Reading.Gravity}} Bx:{{.SGToBrix .Reading.Gravity}} P:{{.SGToPlato .Reading.Gravity}}), Temp: (C:{{.Reading.Temperature}} F:{{.DegCToF .Reading.Temperature}} K:{{.DegCToKelvin .Reading.Temperature}}){{end}}", //nolint:lll
|
||||
ExpectedString: "SG: (1.066 Bx:16.13 P:16.13), Temp: (C:34.5 F:94.1 K:307.7)",
|
||||
ExpectedEnabled: true,
|
||||
},
|
||||
{
|
||||
Case: "Fermenting Status, test all unit conversions 2",
|
||||
BatchJSONResponse: `
|
||||
{"batchNo":18,"status":"Fermenting","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll
|
||||
BatchReadingsJSONResponse: `[{"id":"manual","temp":3.5,"comment":"","sg":1.004,"time":` + FakeReading1DateString + `,"type":"manual"}]`,
|
||||
Case: "Fermenting Status, test all unit conversions 2",
|
||||
BatchJSONResponse: batchNumberFermenting + jsonFiller,
|
||||
BatchReadingsJSONResponse: `[{"id":"manual","temp":3.5,"comment":"","sg":1.004,"time":` + FakeReading1DateString + manualType,
|
||||
Template: "{{ if and (.Reading) (eq .Status \"Fermenting\") }}SG: ({{.Reading.Gravity}} Bx:{{.SGToBrix .Reading.Gravity}} P:{{.SGToPlato .Reading.Gravity}}), Temp: (C:{{.Reading.Temperature}} F:{{.DegCToF .Reading.Temperature}} K:{{.DegCToKelvin .Reading.Temperature}}){{end}}", //nolint:lll
|
||||
ExpectedString: "SG: (1.004 Bx:1.03 P:1.03), Temp: (C:3.5 F:38.3 K:276.7)",
|
||||
ExpectedEnabled: true,
|
||||
|
|
|
@ -18,7 +18,9 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
branchName = "main"
|
||||
branchName = "main"
|
||||
dotGit = "dev/.git"
|
||||
dotGitSubmodule = "dev/.git/modules/submodule"
|
||||
)
|
||||
|
||||
func TestEnabledGitNotFound(t *testing.T) {
|
||||
|
@ -88,23 +90,23 @@ func TestEnabledInWorktree(t *testing.T) {
|
|||
WorkingFolderContent: TestRootPath + "dev/worktree.git\n",
|
||||
ExpectedWorkingFolder: TestRootPath + "dev/.git/worktrees/folder_worktree",
|
||||
ExpectedRealFolder: TestRootPath + "dev/worktree",
|
||||
ExpectedRootFolder: TestRootPath + "dev/.git",
|
||||
ExpectedRootFolder: TestRootPath + dotGit,
|
||||
},
|
||||
{
|
||||
Case: "submodule",
|
||||
ExpectedEnabled: true,
|
||||
WorkingFolder: "./.git/modules/submodule",
|
||||
ExpectedWorkingFolder: TestRootPath + "dev/.git/modules/submodule",
|
||||
ExpectedRealFolder: TestRootPath + "dev/.git/modules/submodule",
|
||||
ExpectedRootFolder: TestRootPath + "dev/.git/modules/submodule",
|
||||
ExpectedWorkingFolder: TestRootPath + dotGitSubmodule,
|
||||
ExpectedRealFolder: TestRootPath + dotGitSubmodule,
|
||||
ExpectedRootFolder: TestRootPath + dotGitSubmodule,
|
||||
},
|
||||
{
|
||||
Case: "submodule with root working folder",
|
||||
ExpectedEnabled: true,
|
||||
WorkingFolder: TestRootPath + "repo/.git/modules/submodule",
|
||||
ExpectedWorkingFolder: TestRootPath + "repo/.git/modules/submodule",
|
||||
ExpectedRealFolder: TestRootPath + "repo/.git/modules/submodule",
|
||||
ExpectedRootFolder: TestRootPath + "repo/.git/modules/submodule",
|
||||
WorkingFolder: TestRootPath + dotGitSubmodule,
|
||||
ExpectedWorkingFolder: TestRootPath + dotGitSubmodule,
|
||||
ExpectedRealFolder: TestRootPath + dotGitSubmodule,
|
||||
ExpectedRootFolder: TestRootPath + dotGitSubmodule,
|
||||
},
|
||||
{
|
||||
Case: "submodule with worktrees",
|
||||
|
@ -126,12 +128,12 @@ func TestEnabledInWorktree(t *testing.T) {
|
|||
},
|
||||
}
|
||||
fileInfo := &platform.FileInfo{
|
||||
Path: TestRootPath + "dev/.git",
|
||||
Path: TestRootPath + dotGit,
|
||||
ParentFolder: TestRootPath + "dev",
|
||||
}
|
||||
for _, tc := range cases {
|
||||
env := new(mock.MockedEnvironment)
|
||||
env.On("FileContent", TestRootPath+"dev/.git").Return(fmt.Sprintf("gitdir: %s", tc.WorkingFolder))
|
||||
env.On("FileContent", TestRootPath+dotGit).Return(fmt.Sprintf("gitdir: %s", tc.WorkingFolder))
|
||||
env.On("FileContent", filepath.Join(tc.WorkingFolder, tc.WorkingFolderAddon)).Return(tc.WorkingFolderContent)
|
||||
env.On("HasFilesInDir", tc.WorkingFolder, tc.WorkingFolderAddon).Return(true)
|
||||
env.On("HasFilesInDir", tc.WorkingFolder, "HEAD").Return(true)
|
||||
|
|
|
@ -13,7 +13,10 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const testKubectlAllInfoTemplate = "{{.Context}} :: {{.Namespace}} :: {{.User}} :: {{.Cluster}}"
|
||||
const (
|
||||
testKubectlAllInfoTemplate = "{{.Context}} :: {{.Namespace}} :: {{.User}} :: {{.Cluster}}"
|
||||
contextMarker = "currentcontextmarker"
|
||||
)
|
||||
|
||||
func TestKubectlSegment(t *testing.T) {
|
||||
standardTemplate := "{{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}}"
|
||||
|
@ -40,7 +43,7 @@ func TestKubectlSegment(t *testing.T) {
|
|||
Case: "kubeconfig incomplete",
|
||||
Template: testKubectlAllInfoTemplate,
|
||||
ParseKubeConfig: true,
|
||||
Kubeconfig: "currentcontextmarker" + lsep + "contextdefinitionincomplete",
|
||||
Kubeconfig: contextMarker + lsep + "contextdefinitionincomplete",
|
||||
Files: testKubeConfigFiles,
|
||||
ExpectedString: "ctx :: :: ::",
|
||||
ExpectedEnabled: true,
|
||||
|
@ -101,7 +104,7 @@ func TestKubectlSegment(t *testing.T) {
|
|||
Case: "kubeconfig multiple current marker first",
|
||||
Template: testKubectlAllInfoTemplate,
|
||||
ParseKubeConfig: true,
|
||||
Kubeconfig: "" + lsep + "currentcontextmarker" + lsep + "contextdefinition" + lsep + "contextredefinition",
|
||||
Kubeconfig: "" + lsep + contextMarker + lsep + "contextdefinition" + lsep + "contextredefinition",
|
||||
Files: testKubeConfigFiles,
|
||||
ExpectedString: "ctx :: ns :: usr :: cl",
|
||||
ExpectedEnabled: true,
|
||||
|
@ -109,7 +112,7 @@ func TestKubectlSegment(t *testing.T) {
|
|||
{
|
||||
Case: "kubeconfig multiple context first",
|
||||
Template: testKubectlAllInfoTemplate, ParseKubeConfig: true,
|
||||
Kubeconfig: "contextdefinition" + lsep + "contextredefinition" + lsep + "currentcontextmarker" + lsep,
|
||||
Kubeconfig: "contextdefinition" + lsep + "contextredefinition" + lsep + contextMarker + lsep,
|
||||
Files: testKubeConfigFiles,
|
||||
ExpectedString: "ctx :: ns :: usr :: cl",
|
||||
ExpectedEnabled: true,
|
||||
|
@ -185,7 +188,7 @@ contexts:
|
|||
namespace: ns
|
||||
name: ctx
|
||||
`,
|
||||
"currentcontextmarker": `
|
||||
contextMarker: `
|
||||
apiVersion: v1
|
||||
current-context: ctx
|
||||
`,
|
||||
|
|
|
@ -14,6 +14,15 @@ import (
|
|||
mock2 "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
const (
|
||||
homeDir = "/home/someone"
|
||||
homeDirWindows = "C:\\Users\\someone"
|
||||
fooBarMan = "\\foo\\bar\\man"
|
||||
abc = "/abc"
|
||||
abcd = "/a/b/c/d"
|
||||
cdefg = "/c/d/e/f/g"
|
||||
)
|
||||
|
||||
func renderTemplateNoTrimSpace(env *mock.MockedEnvironment, segmentTemplate string, context any) string {
|
||||
found := false
|
||||
for _, call := range env.Mock.ExpectedCalls {
|
||||
|
@ -46,11 +55,6 @@ func renderTemplate(env *mock.MockedEnvironment, segmentTemplate string, context
|
|||
return strings.TrimSpace(renderTemplateNoTrimSpace(env, segmentTemplate, context))
|
||||
}
|
||||
|
||||
const (
|
||||
homeDir = "/home/someone"
|
||||
homeDirWindows = "C:\\Users\\someone"
|
||||
)
|
||||
|
||||
func TestParent(t *testing.T) {
|
||||
cases := []struct {
|
||||
Case string
|
||||
|
@ -529,7 +533,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
|||
Style: AgnosterShort,
|
||||
Expected: ".. > bar > man",
|
||||
HomePath: homeDirWindows,
|
||||
Pwd: homeDirWindows + "\\foo\\bar\\man",
|
||||
Pwd: homeDirWindows + fooBarMan,
|
||||
GOOS: platform.WINDOWS,
|
||||
PathSeparator: "\\",
|
||||
FolderSeparatorIcon: " > ",
|
||||
|
@ -677,7 +681,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
|||
Style: AgnosterShort,
|
||||
Expected: "~ > .. > bar > man",
|
||||
HomePath: homeDirWindows,
|
||||
Pwd: homeDirWindows + "\\foo\\bar\\man",
|
||||
Pwd: homeDirWindows + fooBarMan,
|
||||
GOOS: platform.WINDOWS,
|
||||
PathSeparator: "\\",
|
||||
FolderSeparatorIcon: " > ",
|
||||
|
@ -687,7 +691,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
|||
Style: AgnosterShort,
|
||||
Expected: "~ > foo > bar > man",
|
||||
HomePath: homeDirWindows,
|
||||
Pwd: homeDirWindows + "\\foo\\bar\\man",
|
||||
Pwd: homeDirWindows + fooBarMan,
|
||||
GOOS: platform.WINDOWS,
|
||||
PathSeparator: "\\",
|
||||
FolderSeparatorIcon: " > ",
|
||||
|
@ -774,26 +778,26 @@ func TestFullAndFolderPath(t *testing.T) {
|
|||
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", Expected: "/"},
|
||||
{Style: Full, Pwd: "/", Expected: "/"},
|
||||
{Style: Full, Pwd: homeDir, Expected: "~"},
|
||||
{Style: Full, Pwd: homeDir + "/abc", Expected: "~/abc"},
|
||||
{Style: Full, Pwd: homeDir + "/abc", Expected: homeDir + "/abc", DisableMappedLocations: true},
|
||||
{Style: Full, Pwd: "/a/b/c/d", Expected: "/a/b/c/d"},
|
||||
{Style: Full, Pwd: homeDir + abc, Expected: "~/abc"},
|
||||
{Style: Full, Pwd: homeDir + abc, Expected: homeDir + abc, DisableMappedLocations: true},
|
||||
{Style: Full, Pwd: abcd, Expected: abcd},
|
||||
|
||||
{Style: Full, FolderSeparatorIcon: "|", Pwd: homeDir, Expected: "~"},
|
||||
{Style: Full, FolderSeparatorIcon: "|", Pwd: homeDir, Expected: "/home|someone", DisableMappedLocations: true},
|
||||
{Style: Full, FolderSeparatorIcon: "|", Pwd: homeDir + "/abc", Expected: "~|abc"},
|
||||
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/a/b/c/d", Expected: "/a|b|c|d"},
|
||||
{Style: Full, FolderSeparatorIcon: "|", Pwd: homeDir + abc, Expected: "~|abc"},
|
||||
{Style: Full, FolderSeparatorIcon: "|", Pwd: abcd, Expected: "/a|b|c|d"},
|
||||
|
||||
{Style: Folder, Pwd: "/", Expected: "/"},
|
||||
{Style: Folder, Pwd: homeDir, Expected: "~"},
|
||||
{Style: Folder, Pwd: homeDir, Expected: "someone", DisableMappedLocations: true},
|
||||
{Style: Folder, Pwd: homeDir + "/abc", Expected: "abc"},
|
||||
{Style: Folder, Pwd: "/a/b/c/d", Expected: "d"},
|
||||
{Style: Folder, Pwd: homeDir + abc, Expected: "abc"},
|
||||
{Style: Folder, Pwd: abcd, Expected: "d"},
|
||||
|
||||
{Style: Folder, FolderSeparatorIcon: "|", Pwd: "/", Expected: "/"},
|
||||
{Style: Folder, FolderSeparatorIcon: "|", Pwd: homeDir, Expected: "~"},
|
||||
{Style: Folder, FolderSeparatorIcon: "|", Pwd: homeDir, Expected: "someone", DisableMappedLocations: true},
|
||||
{Style: Folder, FolderSeparatorIcon: "|", Pwd: homeDir + "/abc", Expected: "abc"},
|
||||
{Style: Folder, FolderSeparatorIcon: "|", Pwd: "/a/b/c/d", Expected: "d"},
|
||||
{Style: Folder, FolderSeparatorIcon: "|", Pwd: homeDir + abc, Expected: "abc"},
|
||||
{Style: Folder, FolderSeparatorIcon: "|", Pwd: abcd, Expected: "d"},
|
||||
|
||||
// for Windows paths
|
||||
{Style: Folder, FolderSeparatorIcon: "\\", Pwd: "C:\\", Expected: "C:\\", PathSeparator: "\\", GOOS: platform.WINDOWS},
|
||||
|
@ -806,41 +810,41 @@ func TestFullAndFolderPath(t *testing.T) {
|
|||
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: 2, Expected: "2 /"},
|
||||
{Style: Full, Pwd: "/", StackCount: 2, Expected: "2 /"},
|
||||
{Style: Full, Pwd: homeDir, StackCount: 2, Expected: "2 ~"},
|
||||
{Style: Full, Pwd: homeDir + "/abc", StackCount: 2, Expected: "2 ~/abc"},
|
||||
{Style: Full, Pwd: homeDir + "/abc", StackCount: 2, Expected: "2 " + homeDir + "/abc", DisableMappedLocations: true},
|
||||
{Style: Full, Pwd: "/a/b/c/d", StackCount: 2, Expected: "2 /a/b/c/d"},
|
||||
{Style: Full, Pwd: homeDir + abc, StackCount: 2, Expected: "2 ~/abc"},
|
||||
{Style: Full, Pwd: homeDir + abc, StackCount: 2, Expected: "2 " + homeDir + abc, DisableMappedLocations: true},
|
||||
{Style: Full, Pwd: abcd, StackCount: 2, Expected: "2 /a/b/c/d"},
|
||||
|
||||
// StackCountEnabled=false and StackCount=2
|
||||
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", Template: "{{ .Path }}", StackCount: 2, Expected: "/"},
|
||||
{Style: Full, Pwd: "/", Template: "{{ .Path }}", StackCount: 2, Expected: "/"},
|
||||
{Style: Full, Pwd: homeDir, Template: "{{ .Path }}", StackCount: 2, Expected: "~"},
|
||||
|
||||
{Style: Full, Pwd: homeDir + "/abc", Template: "{{ .Path }}", StackCount: 2, Expected: homeDir + "/abc", DisableMappedLocations: true},
|
||||
{Style: Full, Pwd: "/a/b/c/d", Template: "{{ .Path }}", StackCount: 2, Expected: "/a/b/c/d"},
|
||||
{Style: Full, Pwd: homeDir + abc, Template: "{{ .Path }}", StackCount: 2, Expected: homeDir + abc, DisableMappedLocations: true},
|
||||
{Style: Full, Pwd: abcd, Template: "{{ .Path }}", StackCount: 2, Expected: abcd},
|
||||
|
||||
// StackCountEnabled=true and StackCount=0
|
||||
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: 0, Expected: "/"},
|
||||
{Style: Full, Pwd: "/", StackCount: 0, Expected: "/"},
|
||||
{Style: Full, Pwd: homeDir, StackCount: 0, Expected: "~"},
|
||||
{Style: Full, Pwd: homeDir + "/abc", StackCount: 0, Expected: "~/abc"},
|
||||
{Style: Full, Pwd: homeDir + "/abc", StackCount: 0, Expected: homeDir + "/abc", DisableMappedLocations: true},
|
||||
{Style: Full, Pwd: "/a/b/c/d", StackCount: 0, Expected: "/a/b/c/d"},
|
||||
{Style: Full, Pwd: homeDir + abc, StackCount: 0, Expected: "~/abc"},
|
||||
{Style: Full, Pwd: homeDir + abc, StackCount: 0, Expected: homeDir + abc, DisableMappedLocations: true},
|
||||
{Style: Full, Pwd: abcd, StackCount: 0, Expected: abcd},
|
||||
|
||||
// StackCountEnabled=true and StackCount<0
|
||||
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: -1, Expected: "/"},
|
||||
{Style: Full, Pwd: "/", StackCount: -1, Expected: "/"},
|
||||
{Style: Full, Pwd: homeDir, StackCount: -1, Expected: "~"},
|
||||
{Style: Full, Pwd: homeDir + "/abc", StackCount: -1, Expected: "~/abc"},
|
||||
{Style: Full, Pwd: homeDir + "/abc", StackCount: -1, Expected: homeDir + "/abc", DisableMappedLocations: true},
|
||||
{Style: Full, Pwd: "/a/b/c/d", StackCount: -1, Expected: "/a/b/c/d"},
|
||||
{Style: Full, Pwd: homeDir + abc, StackCount: -1, Expected: "~/abc"},
|
||||
{Style: Full, Pwd: homeDir + abc, StackCount: -1, Expected: homeDir + abc, DisableMappedLocations: true},
|
||||
{Style: Full, Pwd: abcd, StackCount: -1, Expected: abcd},
|
||||
|
||||
// StackCountEnabled=true and StackCount not set
|
||||
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", Expected: "/"},
|
||||
{Style: Full, Pwd: "/", Expected: "/"},
|
||||
{Style: Full, Pwd: homeDir, Expected: "~"},
|
||||
{Style: Full, Pwd: homeDir + "/abc", Expected: "~/abc"},
|
||||
{Style: Full, Pwd: homeDir + "/abc", Expected: homeDir + "/abc", DisableMappedLocations: true},
|
||||
{Style: Full, Pwd: "/a/b/c/d", Expected: "/a/b/c/d"},
|
||||
{Style: Full, Pwd: homeDir + abc, Expected: "~/abc"},
|
||||
{Style: Full, Pwd: homeDir + abc, Expected: homeDir + abc, DisableMappedLocations: true},
|
||||
{Style: Full, Pwd: abcd, Expected: abcd},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
@ -895,14 +899,14 @@ func TestFullPathCustomMappedLocations(t *testing.T) {
|
|||
PathSeparator string
|
||||
Expected string
|
||||
}{
|
||||
{Pwd: "/a/b/c/d", MappedLocations: map[string]string{"{{ .Env.HOME }}/d": "#"}, Expected: "#"},
|
||||
{Pwd: "/a/b/c/d", MappedLocations: map[string]string{"/a/b/c/d": "#"}, Expected: "#"},
|
||||
{Pwd: abcd, MappedLocations: map[string]string{"{{ .Env.HOME }}/d": "#"}, Expected: "#"},
|
||||
{Pwd: abcd, MappedLocations: map[string]string{abcd: "#"}, Expected: "#"},
|
||||
{Pwd: "\\a\\b\\c\\d", MappedLocations: map[string]string{"\\a\\b": "#"}, GOOS: platform.WINDOWS, PathSeparator: "\\", Expected: "#\\c\\d"},
|
||||
{Pwd: "/a/b/c/d", MappedLocations: map[string]string{"/a/b": "#"}, Expected: "#/c/d"},
|
||||
{Pwd: "/a/b/c/d", MappedLocations: map[string]string{"/a/b": "/e/f"}, Expected: "/e/f/c/d"},
|
||||
{Pwd: homeDir + "/a/b/c/d", MappedLocations: map[string]string{"~/a/b": "#"}, Expected: "#/c/d"},
|
||||
{Pwd: abcd, MappedLocations: map[string]string{"/a/b": "#"}, Expected: "#/c/d"},
|
||||
{Pwd: abcd, MappedLocations: map[string]string{"/a/b": "/e/f"}, Expected: "/e/f/c/d"},
|
||||
{Pwd: homeDir + abcd, MappedLocations: map[string]string{"~/a/b": "#"}, Expected: "#/c/d"},
|
||||
{Pwd: "/a" + homeDir + "/b/c/d", MappedLocations: map[string]string{"/a~": "#"}, Expected: "/a" + homeDir + "/b/c/d"},
|
||||
{Pwd: homeDir + "/a/b/c/d", MappedLocations: map[string]string{"/a/b": "#"}, Expected: homeDir + "/a/b/c/d"},
|
||||
{Pwd: homeDir + abcd, MappedLocations: map[string]string{"/a/b": "#"}, Expected: homeDir + abcd},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
@ -975,7 +979,7 @@ func TestPowerlevelMappedLocations(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFolderPathCustomMappedLocations(t *testing.T) {
|
||||
pwd := "/a/b/c/d"
|
||||
pwd := abcd
|
||||
env := new(mock.MockedEnvironment)
|
||||
env.On("PathSeparator").Return("/")
|
||||
env.On("Home").Return(homeDir)
|
||||
|
@ -992,7 +996,7 @@ func TestFolderPathCustomMappedLocations(t *testing.T) {
|
|||
props: properties.Map{
|
||||
properties.Style: Folder,
|
||||
MappedLocations: map[string]string{
|
||||
"/a/b/c/d": "#",
|
||||
abcd: "#",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -1349,16 +1353,16 @@ func TestGetPwd(t *testing.T) {
|
|||
{MappedLocationsEnabled: true, Pwd: homeDir + "-test", Expected: homeDir + "-test"},
|
||||
{MappedLocationsEnabled: true},
|
||||
{MappedLocationsEnabled: true, Pwd: "/usr", Expected: "/usr"},
|
||||
{MappedLocationsEnabled: true, Pwd: homeDir + "/abc", Expected: "~/abc"},
|
||||
{MappedLocationsEnabled: true, Pwd: "/a/b/c/d", Expected: "#"},
|
||||
{MappedLocationsEnabled: true, Pwd: homeDir + abc, Expected: "~/abc"},
|
||||
{MappedLocationsEnabled: true, Pwd: abcd, Expected: "#"},
|
||||
{MappedLocationsEnabled: true, Pwd: "/a/b/c/d/e/f/g", Expected: "#/e/f/g"},
|
||||
{MappedLocationsEnabled: true, Pwd: "/z/y/x/w", Expected: "/z/y/x/w"},
|
||||
|
||||
{MappedLocationsEnabled: false},
|
||||
{MappedLocationsEnabled: false, Pwd: homeDir + "/abc", Expected: homeDir + "/abc"},
|
||||
{MappedLocationsEnabled: false, Pwd: homeDir + abc, Expected: homeDir + abc},
|
||||
{MappedLocationsEnabled: false, Pwd: "/a/b/c/d/e/f/g", Expected: "#/e/f/g"},
|
||||
{MappedLocationsEnabled: false, Pwd: homeDir + "/c/d/e/f/g", Expected: homeDir + "/c/d/e/f/g"},
|
||||
{MappedLocationsEnabled: true, Pwd: homeDir + "/c/d/e/f/g", Expected: "~/c/d/e/f/g"},
|
||||
{MappedLocationsEnabled: false, Pwd: homeDir + cdefg, Expected: homeDir + cdefg},
|
||||
{MappedLocationsEnabled: true, Pwd: homeDir + cdefg, Expected: "~/c/d/e/f/g"},
|
||||
|
||||
{MappedLocationsEnabled: true, Pwd: "/w/d/x/w", Pswd: "/z/y/x/w", Expected: "/z/y/x/w"},
|
||||
{MappedLocationsEnabled: false, Pwd: "/f/g/k/d/e/f/g", Pswd: "/a/b/c/d/e/f/g", Expected: "#/e/f/g"},
|
||||
|
@ -1381,7 +1385,7 @@ func TestGetPwd(t *testing.T) {
|
|||
props: properties.Map{
|
||||
MappedLocationsEnabled: tc.MappedLocationsEnabled,
|
||||
MappedLocations: map[string]string{
|
||||
"/a/b/c/d": "#",
|
||||
abcd: "#",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -1468,7 +1472,7 @@ func TestReplaceMappedLocations(t *testing.T) {
|
|||
{Pwd: "/c/l/k/f", Expected: "f"},
|
||||
{Pwd: "/f/g/h", Expected: "/f/g/h"},
|
||||
{Pwd: "/f/g/h/e", Expected: "^/e"},
|
||||
{Pwd: "/a/b/c/d", Expected: "#"},
|
||||
{Pwd: abcd, Expected: "#"},
|
||||
{Pwd: "/a/b/c/d/e", Expected: "#/e"},
|
||||
{Pwd: "/a/b/c/d/e", Expected: "#/e"},
|
||||
{Pwd: "/a/b/k/j/e", Expected: "e"},
|
||||
|
@ -1487,7 +1491,7 @@ func TestReplaceMappedLocations(t *testing.T) {
|
|||
props: properties.Map{
|
||||
MappedLocationsEnabled: false,
|
||||
MappedLocations: map[string]string{
|
||||
"/a/b/c/d": "#",
|
||||
abcd: "#",
|
||||
"/f/g/h/*": "^",
|
||||
"/c/l/k/*": "",
|
||||
"~/j/*": "",
|
||||
|
|
Loading…
Reference in a new issue