summaryrefslogtreecommitdiff
path: root/test/segments/vcs.spec
blob: 3be7aa0f72179fc0e26976f0eb8b0ee2241df047 (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
#!/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 testColorOverridingForCleanStateWorks() {
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
  POWERLEVEL9K_VCS_CLEAN_FOREGROUND='cyan'
  POWERLEVEL9K_VCS_CLEAN_BACKGROUND='white'

  FOLDER=/tmp/powerlevel9k-test/vcs-test
  mkdir -p $FOLDER
  cd $FOLDER
  git init 1>/dev/null

  assertEquals "%K{015} %F{014} master %k%F{015}%f " "$(build_left_prompt)"

  cd -
  rm -fr /tmp/powerlevel9k-test

  unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  unset POWERLEVEL9K_VCS_CLEAN_FOREGROUND
  unset POWERLEVEL9K_VCS_CLEAN_BACKGROUND
}

function testColorOverridingForModifiedStateWorks() {
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
  POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='red'
  POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='yellow'

  FOLDER=/tmp/powerlevel9k-test/vcs-test
  mkdir -p $FOLDER
  cd $FOLDER
  git init 1>/dev/null
  git config user.email "test@powerlevel9k.theme"
  git config user.name  "Testing Tester"
  touch testfile
  git add testfile
  git commit -m "test" 1>/dev/null
  echo "test" > testfile

  assertEquals "%K{011} %F{009} master ● %k%F{011}%f " "$(build_left_prompt)"

  cd -
  rm -fr /tmp/powerlevel9k-test

  unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  unset POWERLEVEL9K_VCS_MODIFIED_FOREGROUND
  unset POWERLEVEL9K_VCS_MODIFIED_BACKGROUND
}

function testColorOverridingForUntrackedStateWorks() {
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
  POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='cyan'
  POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='yellow'

  FOLDER=/tmp/powerlevel9k-test/vcs-test
  mkdir -p $FOLDER
  cd $FOLDER
  git init 1>/dev/null
  touch testfile

  assertEquals "%K{011} %F{014} master ? %k%F{011}%f " "$(build_left_prompt)"

  cd -
  rm -fr /tmp/powerlevel9k-test

  unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  unset POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND
  unset POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND
}

function testBranchNameTruncatingShortenLength() {
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
  POWERLEVEL9K_VCS_SHORTEN_LENGTH=6
  POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=3
  POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right"

  FOLDER=/tmp/powerlevel9k-test/vcs-test
  mkdir -p $FOLDER
  cd $FOLDER
  git init 1>/dev/null
  touch testfile

  assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)"

  POWERLEVEL9K_VCS_SHORTEN_LENGTH=3
  assertEquals "%K{002} %F{000} mas… ? %k%F{002}%f " "$(build_left_prompt)"

  cd -
  rm -fr /tmp/powerlevel9k-test

  unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  unset POWERLEVEL9K_VCS_SHORTEN_LENGTH
  unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH
  unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY
}

function testBranchNameTruncatingMinLength() {
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
  POWERLEVEL9K_VCS_SHORTEN_LENGTH=3
  POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=6
  POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right"

  FOLDER=/tmp/powerlevel9k-test/vcs-test
  mkdir -p $FOLDER
  cd $FOLDER
  git init 1>/dev/null
  touch testfile

  assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)"

  POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=7

  assertEquals "%K{002} %F{000} master ? %k%F{002}%f " "$(build_left_prompt)"

  cd -
  rm -fr /tmp/powerlevel9k-test

  unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  unset POWERLEVEL9K_VCS_SHORTEN_LENGTH
  unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH
  unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY
}

function testBranchNameTruncatingShortenStrategy() {
  POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs)
  POWERLEVEL9K_VCS_SHORTEN_LENGTH=3
  POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=3
  POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_from_right"

  FOLDER=/tmp/powerlevel9k-test/vcs-test
  mkdir -p $FOLDER
  cd $FOLDER
  git init 1>/dev/null
  touch testfile

  assertEquals "%K{002} %F{000} mas… ? %k%F{002}%f " "$(build_left_prompt)"

  POWERLEVEL9K_VCS_SHORTEN_STRATEGY="truncate_middle"

  assertEquals "%K{002} %F{000} mas…ter ? %k%F{002}%f " "$(build_left_prompt)"

  cd -
  rm -fr /tmp/powerlevel9k-test

  unset POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
  unset POWERLEVEL9K_VCS_SHORTEN_LENGTH
  unset POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH
  unset POWERLEVEL9K_VCS_SHORTEN_STRATEGY
}

source shunit2/source/2.1/src/shunit2