aboutsummaryrefslogtreecommitdiff
path: root/test/core/joining_segments.spec
blob: f224007ea3a4352e34f977dea5a87f5b8b58f0a7 (plain) (blame)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env zsh
#vim:ft=zsh ts=2 sw=2 sts=2 et fenc=utf-8

# Required for shunit2 to run correctly
setopt shwordsplit
SHUNIT_PARENT=$0

function setUp() {
  export TERM="xterm-256color"
  # Load Powerlevel9k
  source powerlevel9k.zsh-theme
}

function testLeftNormalSegmentsShouldNotBeJoined() {
  local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3 custom_world4_joined custom_world5 custom_world6)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
  local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"
  local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD6="echo world6"
  
  assertEquals "%K{white} %F{black}world1 %K{white}%F{black} %F{black}world2 %K{white}%F{black} %F{black}world4 %K{white}%F{black} %F{black}world6 %k%F{white}%f " "$(build_left_prompt)"
}

function testLeftJoinedSegments() {
  local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"

  assertEquals "%K{white} %F{black}world1 %K{white}%F{black}%F{black}world2 %k%F{white}%f " "$(build_left_prompt)"
}

function testLeftTransitiveJoinedSegments() {
  local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
  local POWERLEVEL9K_CUSTOM_WORLD3="echo world3"

  assertEquals "%K{white} %F{black}world1 %K{white}%F{black}%F{black}world2 %K{white}%F{black}%F{black}world3 %k%F{white}%f " "$(build_left_prompt)"
}

function testLeftTransitiveJoiningWithConditionalJoinedSegment() {
  local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined custom_world4_joined)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
  local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"

  assertEquals "%K{white} %F{black}world1 %K{white}%F{black}%F{black}world2 %K{white}%F{black}%F{black}world4 %k%F{white}%f " "$(build_left_prompt)"
}

function testLeftPromotingSegmentWithConditionalPredecessor() {
  local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD3="echo world3"

  assertEquals "%K{white} %F{black}world1 %K{white}%F{black} %F{black}world3 %k%F{white}%f " "$(build_left_prompt)"
}

function testLeftPromotingSegmentWithJoinedConditionalPredecessor() {
  local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"

  assertEquals "%K{white} %F{black}world1 %K{white}%F{black} %F{black}world4 %k%F{white}%f " "$(build_left_prompt)"
}

function testLeftPromotingSegmentWithDeepJoinedConditionalPredecessor() {
  local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined custom_world5_joined custom_world6_joined)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"
  local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD6="echo world6"

  assertEquals "%K{white} %F{black}world1 %K{white}%F{black} %F{black}world4 %K{white}%F{black}%F{black}world6 %k%F{white}%f " "$(build_left_prompt)"
}

function testLeftJoiningBuiltinSegmentWorks() {
  local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(php_version php_version_joined)
  alias php="echo PHP 1.2.3"

  assertEquals "%K{013} %F{255}PHP 1.2.3 %K{013}%F{255}%F{255}PHP 1.2.3 %k%F{fuchsia}%f " "$(build_left_prompt)"

  unalias php
}

function testRightNormalSegmentsShouldNotBeJoined() {
  local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
  POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3 custom_world4 custom_world5_joined custom_world6)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
  local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"
  local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD6="echo world6"

  assertEquals "%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world2 %f%F{black}%f%K{white}%F{black} world4 %f%F{black}%f%K{white}%F{black} world6%E" "$(build_right_prompt)"
}

function testRightJoinedSegments() {
  local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
  POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"

  assertEquals "%F{white}%f%K{white}%F{black} world1 %f%K{white}%F{black}world2%E" "$(build_right_prompt)"
}

function testRightTransitiveJoinedSegments() {
  local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
  POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
  local POWERLEVEL9K_CUSTOM_WORLD3="echo world3"

  assertEquals "%F{white}%f%K{white}%F{black} world1 %f%K{white}%F{black}world2 %f%K{white}%F{black}world3%E" "$(build_right_prompt)"
}

function testRightTransitiveJoiningWithConditionalJoinedSegment() {
  local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
  POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2_joined custom_world3_joined custom_world4_joined)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo world2"
  local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"

  assertEquals "%F{white}%f%K{white}%F{black} world1 %f%K{white}%F{black}world2 %f%K{white}%F{black}world4%E" "$(build_right_prompt)"
}

function testRightPromotingSegmentWithConditionalPredecessor() {
  local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
  POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD3="echo world3"

  assertEquals "%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world3%E" "$(build_right_prompt)"
}

function testRightPromotingSegmentWithJoinedConditionalPredecessor() {
  local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
  POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"

  assertEquals "%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world4%E" "$(build_right_prompt)"
}

function testRightPromotingSegmentWithDeepJoinedConditionalPredecessor() {
  local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
  POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(custom_world1 custom_world2 custom_world3_joined custom_world4_joined custom_world5_joined custom_world6_joined)
  local POWERLEVEL9K_CUSTOM_WORLD1="echo world1"
  local POWERLEVEL9K_CUSTOM_WORLD2="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD3="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD4="echo world4"
  local POWERLEVEL9K_CUSTOM_WORLD5="echo " # Print nothing to simulate unmet conditions
  local POWERLEVEL9K_CUSTOM_WORLD6="echo world6"

  assertEquals "%F{white}%f%K{white}%F{black} world1 %f%F{black}%f%K{white}%F{black} world4 %f%K{white}%F{black}world6%E" "$(build_right_prompt)"
}

function testRightJoiningBuiltinSegmentWorks() {
  local -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS
  POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(php_version php_version_joined)
  alias php="echo PHP 1.2.3"

  assertEquals "%F{013}%f%K{013}%F{255} PHP 1.2.3 %f%K{013}%F{255}PHP 1.2.3%E" "$(build_right_prompt)"

  unalias php
}
source shunit2/shunit2