From 46c627563062f90119649d10950c019a9a7d0336 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Tue, 24 Oct 2023 12:45:30 +0200 Subject: [PATCH] fix(lint): make string repetitions constant --- src/segments/brewfather_test.go | 79 +++++++++++++------------- src/segments/git_test.go | 24 ++++---- src/segments/kubectl_test.go | 13 +++-- src/segments/path_test.go | 98 +++++++++++++++++---------------- 4 files changed, 114 insertions(+), 100 deletions(-) diff --git a/src/segments/brewfather_test.go b/src/segments/brewfather_test.go index adbb5324..a394198a 100644 --- a/src/segments/brewfather_test.go +++ b/src/segments/brewfather_test.go @@ -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, diff --git a/src/segments/git_test.go b/src/segments/git_test.go index 80710927..5a95be67 100644 --- a/src/segments/git_test.go +++ b/src/segments/git_test.go @@ -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) diff --git a/src/segments/kubectl_test.go b/src/segments/kubectl_test.go index 99713563..43130de5 100644 --- a/src/segments/kubectl_test.go +++ b/src/segments/kubectl_test.go @@ -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 `, diff --git a/src/segments/path_test.go b/src/segments/path_test.go index 3b3ab94a..8decb2fd 100644 --- a/src/segments/path_test.go +++ b/src/segments/path_test.go @@ -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/*": "",