File: InvalidateCacheTestCommon.hs

package info (click to toggle)
haskell-expiring-cache-map 0.0.6.1-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 232 kB
  • sloc: haskell: 2,209; makefile: 5
file content (59 lines) | stat: -rw-r--r-- 1,403 bytes parent folder | download | duplicates (5)
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
{-# LANGUAGE OverloadedStrings #-}

module InvalidateCacheTestCommon (test1Common) where

import qualified Data.ByteString.Char8 as BS

test1Common lookup3 keysCached3 invalidateCache3 = do

  b <- lookup3 ("file1" :: BS.ByteString)
  b <- lookup3 "file2"
  b <- lookup3 "file3"
  b <- lookup3 "file2"
  b <- lookup3 "file3"
  shouldBe 3 "file3"
  
  b <- lookup3 "file1"
  b <- lookup3 "file2"
  b <- lookup3 "file3"
  b <- lookup3 "file1"
  shouldBe 3 "file1"
  
  b <- lookup3 "file1"
  b <- lookup3 "file2"
  b <- lookup3 "file3"
  b <- lookup3 "file4"
  b <- lookup3 "file5"
  b <- lookup3 "file2"
  shouldBe 5 "file2"
  
  b <- lookup3 "file1"
  b <- lookup3 "file2"
  b <- lookup3 "file3"
  b <- lookup3 "file4"
  b <- lookup3 "file5"
  b <- lookup3 "file6"
  b <- lookup3 "file7"
  b <- lookup3 "file8"
  b <- lookup3 "file9"
  b <- lookup3 "file3"
  shouldBe 9 "file3" 
  
  return ()
  
  where

    shouldBe count lastkey = do
      l <- keysCached3
      putStrLn $ show l
      if count == (length l) 
        then do
          kv <- invalidateCache3
          putStrLn $ show kv
          case kv of
            Just (k, v) | k == lastkey -> do
              l2 <- keysCached3
              if 0 == (length l2)
                then return ()
                else error "Did not fully invalidate"
        else error "Wrong length"