@@ -70,6 +70,7 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
7070 b :
7171 x : 2
7272 y : 3
73+ otp : randomString 10
7374 return
7475
7576 it " set key" , () ->
@@ -103,6 +104,50 @@ describe "`#{pkg.name}@#{pkg.version}` on `node@#{process.version}`", () ->
103104 0 .should .eql count
104105 return
105106
107+ it " take key" , () ->
108+ # make sure we are starting fresh
109+ res = localCache .has (" otp" )
110+ res .should .eql false
111+
112+ # taking a non-exitent value should be fine
113+ res = localCache .take (" otp" )
114+ should .not .exist (res)
115+
116+ # check if otp insertion suceeded
117+ res = localCache .set " otp" , state .otp , 0
118+ true .should .eql res
119+
120+ # are we able to check the presence of the key?
121+ res = localCache .has (" otp" )
122+ res .should .eql true
123+
124+ # not once, but twice?
125+ # This proves that keys can be accessed as many times as required, but
126+ # not the value. The `take()` method makes the values as single-read, not the keys.
127+ res = localCache .has (" otp" )
128+ res .should .eql true
129+
130+ # take the value
131+ otp = localCache .take (" otp" )
132+ otp .should .eql state .otp
133+
134+ # key should not be present anymore once the value is read
135+ res = localCache .has (" otp" )
136+ res .should .eql false
137+
138+ # and, re-insertions are not probhitied
139+ res = localCache .set " otp" , " some other value"
140+ true .should .eql res
141+
142+ # should be able take the value again
143+ otp = localCache .take (" otp" )
144+ otp .should .eql " some other value"
145+
146+ # key should not be present anymore, again
147+ res = localCache .has (" otp" )
148+ res .should .eql false
149+ return
150+
106151 it " update key (and get it to check if the update worked)" , () ->
107152 res = localCache .set state .key , state .value2 , 0
108153 true .should .eql res
0 commit comments