]> gitweb.michael.orlitzky.com - hath.git/blob - src/Maskbits.hs
hath.cabal: add other-modules for the tasty test suite.
[hath.git] / src / Maskbits.hs
1 module Maskbits(
2 Maskbits(..) )
3 where
4
5 import Test.Tasty.QuickCheck ( Arbitrary(arbitrary), elements )
6
7
8 -- | A type representing the number of bits in a CIDR netmask.
9 data Maskbits =
10 Zero
11 | One
12 | Two
13 | Three
14 | Four
15 | Five
16 | Six
17 | Seven
18 | Eight
19 | Nine
20 | Ten
21 | Eleven
22 | Twelve
23 | Thirteen
24 | Fourteen
25 | Fifteen
26 | Sixteen
27 | Seventeen
28 | Eighteen
29 | Nineteen
30 | Twenty
31 | TwentyOne
32 | TwentyTwo
33 | TwentyThree
34 | TwentyFour
35 | TwentyFive
36 | TwentySix
37 | TwentySeven
38 | TwentyEight
39 | TwentyNine
40 | Thirty
41 | ThirtyOne
42 | ThirtyTwo
43 deriving (Enum, Eq, Ord)
44
45
46 instance Show Maskbits where
47 show Zero = "0"
48 show One = "1"
49 show Two = "2"
50 show Three = "3"
51 show Four = "4"
52 show Five = "5"
53 show Six = "6"
54 show Seven = "7"
55 show Eight = "8"
56 show Nine = "9"
57 show Ten = "10"
58 show Eleven = "11"
59 show Twelve = "12"
60 show Thirteen = "13"
61 show Fourteen = "14"
62 show Fifteen = "15"
63 show Sixteen = "16"
64 show Seventeen = "17"
65 show Eighteen = "18"
66 show Nineteen = "19"
67 show Twenty = "20"
68 show TwentyOne = "21"
69 show TwentyTwo = "22"
70 show TwentyThree = "23"
71 show TwentyFour = "24"
72 show TwentyFive = "25"
73 show TwentySix = "26"
74 show TwentySeven = "27"
75 show TwentyEight = "28"
76 show TwentyNine = "29"
77 show Thirty = "30"
78 show ThirtyOne = "31"
79 show ThirtyTwo = "32"
80
81
82 instance Arbitrary Maskbits where
83 arbitrary =
84 elements [ Zero,
85 One,
86 Two,
87 Three,
88 Four,
89 Five,
90 Six,
91 Seven,
92 Eight,
93 Nine,
94 Ten,
95 Eleven,
96 Twelve,
97 Thirteen,
98 Fourteen,
99 Fifteen,
100 Sixteen,
101 Seventeen,
102 Eighteen,
103 Nineteen,
104 Twenty,
105 TwentyOne,
106 TwentyTwo,
107 TwentyThree,
108 TwentyFour,
109 TwentyFive,
110 TwentySix,
111 TwentySeven,
112 TwentyEight,
113 TwentyNine,
114 Thirty,
115 ThirtyOne,
116 ThirtyTwo ]
117
118
119 instance Read Maskbits where
120 readsPrec _ s =
121 case (reads s :: [(Int, String)]) of
122 [] -> []
123 (x,leftover):_ -> go x leftover
124 where
125 go :: Int -> String -> [(Maskbits, String)]
126 go x' leftover'
127 | x' < minBound || x' > maxBound = []
128 | otherwise = [(toEnum x', leftover')]