@@ -8,15 +8,18 @@ import (
88
99func TestTextSegment (t * testing.T ) {
1010 cases := []struct {
11- Case string
12- ExpectedString string
13- Text string
11+ Case string
12+ ExpectedString string
13+ Text string
14+ ExpectedDisabled bool
1415 }{
1516 {Case : "standard text" , ExpectedString : "hello" , Text : "hello" },
1617 {Case : "template text with env var" , ExpectedString : "hello world" , Text : "{{ .Env.HELLO }} world" },
1718 {Case : "template text with shell name" , ExpectedString : "hello world from terminal" , Text : "{{ .Env.HELLO }} world from {{ .Shell }}" },
1819 {Case : "template text with folder" , ExpectedString : "hello world in posh" , Text : "{{ .Env.HELLO }} world in {{ .Folder }}" },
1920 {Case : "template text with user" , ExpectedString : "hello Posh" , Text : "{{ .Env.HELLO }} {{ .User }}" },
21+ {Case : "empty text" , Text : "" , ExpectedDisabled : true },
22+ {Case : "empty template result" , Text : "{{ .Env.WORLD }}" , ExpectedDisabled : true },
2023 }
2124
2225 for _ , tc := range cases {
@@ -27,6 +30,7 @@ func TestTextSegment(t *testing.T) {
2730 env .On ("isRunningAsRoot" , nil ).Return (true )
2831 env .On ("getShellName" , nil ).Return ("terminal" )
2932 env .On ("getenv" , "HELLO" ).Return ("hello" )
33+ env .On ("getenv" , "WORLD" ).Return ("" )
3034 env .On ("getCurrentUser" , nil ).Return ("Posh" )
3135 env .On ("getHostName" , nil ).Return ("MyHost" , nil )
3236 props := & properties {
@@ -38,6 +42,7 @@ func TestTextSegment(t *testing.T) {
3842 env : env ,
3943 props : props ,
4044 }
45+ assert .Equal (t , tc .ExpectedDisabled , ! txt .enabled (), tc .Case )
4146 assert .Equal (t , tc .ExpectedString , txt .string (), tc .Case )
4247 }
4348}
0 commit comments