|
1 | 1 | import { pipe } from "rambda"; |
2 | 2 | import { Just, Nothing, fromNullable, chainM, mapM, unwrapOrM, matchM } from "../src/maybe"; |
| 3 | +import { equalsM } from "../src/maybe/Maybe"; |
3 | 4 |
|
4 | 5 | describe("Maybe", () => { |
5 | 6 | it("should map over Just", () => { |
@@ -45,6 +46,28 @@ describe("Maybe", () => { |
45 | 46 | expect(justMsg).toBe("Temos value"); |
46 | 47 | expect(nothingMsg).toBe("Nada aqui"); |
47 | 48 | }); |
| 49 | + |
| 50 | + it("should check equality between Just and Nothing", () => { |
| 51 | + const just1 = new Just(10); |
| 52 | + const just2 = new Just(10); |
| 53 | + const nothing1 = new Nothing<number>(); |
| 54 | + const nothing2 = new Nothing<number>(); |
| 55 | + |
| 56 | + expect(just1.equals(just2)).toBe(true); |
| 57 | + expect(just1.equals(nothing1)).toBe(false); |
| 58 | + expect(nothing1.equals(nothing2)).toBe(true); |
| 59 | + }); |
| 60 | + |
| 61 | + it("should check equality with different values", () => { |
| 62 | + const just1 = new Just(10); |
| 63 | + const just2 = new Just(20); |
| 64 | + const nothing1 = new Nothing<number>(); |
| 65 | + const nothing2 = new Nothing<number>(); |
| 66 | + |
| 67 | + expect(just1.equals(just2)).toBe(false); |
| 68 | + expect(just1.equals(nothing1)).toBe(false); |
| 69 | + expect(nothing1.equals(nothing2)).toBe(true); |
| 70 | + }); |
48 | 71 | }); |
49 | 72 |
|
50 | 73 | describe("Maybe fromNullable", () => { |
@@ -134,6 +157,29 @@ describe("Maybe - Curried Helpers", () => { |
134 | 157 | ); |
135 | 158 | expect(result).toBe("Nada aqui"); |
136 | 159 | }); |
| 160 | + |
| 161 | + it("should check equality with curried equals", () => { |
| 162 | + const just1 = new Just(10); |
| 163 | + const just2 = new Just(10); |
| 164 | + const nothing1 = new Nothing<number>(); |
| 165 | + const nothing2 = new Nothing<number>(); |
| 166 | + |
| 167 | + expect(pipe(just1, equalsM(just2))).toBe(true); |
| 168 | + expect(pipe(just1, equalsM(nothing1))).toBe(false); |
| 169 | + expect(pipe(nothing1, equalsM(nothing2))).toBe(true); |
| 170 | + }); |
| 171 | + |
| 172 | + it("should check extract value from Just", () => { |
| 173 | + const just = new Just(10); |
| 174 | + const result = just.extract(); |
| 175 | + expect(result).toBe(10); |
| 176 | + }); |
| 177 | + |
| 178 | + it("should check extract value from Nothing", () => { |
| 179 | + const nothing = new Nothing<number>(); |
| 180 | + const result = nothing.extract(); |
| 181 | + expect(result).toBe(undefined); |
| 182 | + }); |
137 | 183 | }); |
138 | 184 |
|
139 | 185 |
|
0 commit comments