diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-14 21:27:29 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-14 21:27:29 +0400 |
commit | 39b3fd7d872153e1eafff38565b1df5d19adbe75 (patch) | |
tree | 3b5c9c6bc419758ed71574bfc333196493296c94 | |
parent | 40f95ab06298d1f9d5e0b5d07ca14b9f81264692 (diff) |
Group FileMap tests by function
-rw-r--r-- | tests/System/Torrent/FileMapSpec.hs | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/tests/System/Torrent/FileMapSpec.hs b/tests/System/Torrent/FileMapSpec.hs index 43c99d34..36632b3e 100644 --- a/tests/System/Torrent/FileMapSpec.hs +++ b/tests/System/Torrent/FileMapSpec.hs | |||
@@ -24,7 +24,7 @@ layout = | |||
24 | 24 | ||
25 | spec :: Spec | 25 | spec :: Spec |
26 | spec = do | 26 | spec = do |
27 | describe "FileMap" $ do | 27 | describe "mmapFiles" $ do |
28 | it "creates new files" $ do | 28 | it "creates new files" $ do |
29 | m <- mmapFiles ReadWriteEx layout | 29 | m <- mmapFiles ReadWriteEx layout |
30 | unmapFiles m | 30 | unmapFiles m |
@@ -32,17 +32,35 @@ spec = do | |||
32 | (doesFileExist . fst) `allM` layout | 32 | (doesFileExist . fst) `allM` layout |
33 | `shouldReturn` True | 33 | `shouldReturn` True |
34 | 34 | ||
35 | it "have specified size" $ do | 35 | describe "size" $ do |
36 | it "is equal to the layout size" $ do | ||
36 | m <- mmapFiles ReadOnly layout | 37 | m <- mmapFiles ReadOnly layout |
37 | FM.size m `shouldBe` L.sum (L.map snd layout) | 38 | FM.size m `shouldBe` L.sum (L.map snd layout) |
38 | unmapFiles m | 39 | unmapFiles m |
39 | 40 | ||
41 | describe "readBytes" $ do | ||
40 | it "read from files" $ do | 42 | it "read from files" $ do |
41 | let thisFile = [("tests/System/Torrent/FileMapSpec.hs", 15)] | 43 | let thisFile = [("tests/System/Torrent/FileMapSpec.hs", 15)] |
42 | m <- mmapFiles ReadOnly thisFile | 44 | m <- mmapFiles ReadOnly thisFile |
43 | readBytes 3 15 m `shouldReturn` "this is test" | 45 | readBytes 3 15 m `shouldReturn` "this is test" |
44 | unmapFiles m | 46 | unmapFiles m |
45 | 47 | ||
48 | it "ignore underflow reads" $ do | ||
49 | m <- mmapFiles ReadOnly layout | ||
50 | readBytes (-1) 1 m `shouldReturn` "" | ||
51 | readBytes (-5) 12 m `shouldReturn` "" | ||
52 | unmapFiles m | ||
53 | |||
54 | it "crop overflow reads" $ do | ||
55 | _m <- mmapFiles ReadWrite layout | ||
56 | writeBytes 5 "cc" _m | ||
57 | unmapFiles _m | ||
58 | |||
59 | m <- mmapFiles ReadOnly layout | ||
60 | readBytes 5 10 m `shouldReturn` "cc" | ||
61 | unmapFiles m | ||
62 | |||
63 | describe "writeBytes" $ do | ||
46 | it "writes to files" $ do | 64 | it "writes to files" $ do |
47 | m <- mmapFiles ReadWriteEx layout | 65 | m <- mmapFiles ReadWriteEx layout |
48 | writeBytes 0 "a" m | 66 | writeBytes 0 "a" m |
@@ -75,38 +93,24 @@ spec = do | |||
75 | writeBytes 5 long_bs m | 93 | writeBytes 5 long_bs m |
76 | unmapFiles m | 94 | unmapFiles m |
77 | 95 | ||
78 | it "ignore underflow reads" $ do | ||
79 | m <- mmapFiles ReadOnly layout | ||
80 | readBytes (-1) 1 m `shouldReturn` "" | ||
81 | readBytes (-5) 12 m `shouldReturn` "" | ||
82 | unmapFiles m | ||
83 | |||
84 | it "ignore underflow writes" $ do | 96 | it "ignore underflow writes" $ do |
85 | m <- mmapFiles ReadWrite layout | 97 | _m <- mmapFiles ReadWrite layout |
86 | writeBytes 0 "aa" m | 98 | writeBytes 0 "aa" _m |
87 | unmapFiles m | 99 | unmapFiles _m |
88 | 100 | ||
89 | m <- mmapFiles ReadWrite layout | 101 | m <- mmapFiles ReadWrite layout |
90 | writeBytes (-1) "hhh" m | 102 | writeBytes (-1) "hhh" m |
91 | unmapFiles m | 103 | unmapFiles m |
92 | BL.readFile (fst (layout !! 0)) `shouldReturn` "aa" | 104 | BL.readFile (fst (layout !! 0)) `shouldReturn` "aa" |
93 | 105 | ||
94 | it "crop overflow reads" $ do | ||
95 | m <- mmapFiles ReadWrite layout | ||
96 | writeBytes 5 "cc" m | ||
97 | unmapFiles m | ||
98 | |||
99 | m <- mmapFiles ReadOnly layout | ||
100 | readBytes 5 10 m `shouldReturn` "cc" | ||
101 | unmapFiles m | ||
102 | |||
103 | it "crop overflow writes" $ do | 106 | it "crop overflow writes" $ do |
104 | m <- mmapFiles ReadWrite layout | 107 | m <- mmapFiles ReadWrite layout |
105 | writeBytes 5 "ddddddddd" m | 108 | writeBytes 5 "ddddddddd" m |
106 | unmapFiles m | 109 | unmapFiles m |
107 | BL.readFile (fst (layout !! 2)) `shouldReturn` "dd" | 110 | BL.readFile (fst (layout !! 2)) `shouldReturn` "dd" |
108 | 111 | ||
112 | describe "from/to lazy bytestring" $ do | ||
109 | it "isomorphic to lazy bytestring" $ do | 113 | it "isomorphic to lazy bytestring" $ do |
110 | m <- mmapFiles ReadOnly layout | 114 | m <- mmapFiles ReadOnly layout |
111 | fromLazyByteString (toLazyByteString m) `shouldBe` m | 115 | fromLazyByteString (toLazyByteString m) `shouldBe` m |
112 | unmapFiles m \ No newline at end of file | 116 | unmapFiles m |