Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add
toString
methods to all primitive data types
The `toString` method is very useful for debugging purposes. Hence, I added it to all the primitive data types.
- Loading branch information
1 parent
596858d
commit 271a7bd
Showing
10 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
import fc from "fast-check"; | ||
|
||
import type { All, Any, Bool } from "../src/bool.js"; | ||
|
||
import { all, any, bool } from "./arbitraries.js"; | ||
|
||
const boolToStringDefinition = (m: Bool): void => { | ||
expect(m.toString()).toStrictEqual(`Bool(${m.value})`); | ||
}; | ||
|
||
const anyToStringDefinition = (m: Any): void => { | ||
expect(m.toString()).toStrictEqual(`Any(${m.value})`); | ||
}; | ||
|
||
const allToStringDefinition = (m: All): void => { | ||
expect(m.toString()).toStrictEqual(`All(${m.value})`); | ||
}; | ||
|
||
describe("Bool", () => { | ||
describe("toString", () => { | ||
it("should convert Bool to a string", () => { | ||
expect.assertions(100); | ||
|
||
fc.assert(fc.property(bool, boolToStringDefinition)); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Any", () => { | ||
describe("toString", () => { | ||
it("should convert Any to a string", () => { | ||
expect.assertions(100); | ||
|
||
fc.assert(fc.property(any, anyToStringDefinition)); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("All", () => { | ||
describe("toString", () => { | ||
it("should convert All to a string", () => { | ||
expect.assertions(100); | ||
|
||
fc.assert(fc.property(all, allToStringDefinition)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
import fc from "fast-check"; | ||
|
||
import type { DateTime } from "../src/datetime.js"; | ||
|
||
import { datetime } from "./arbitraries.js"; | ||
|
||
const toStringDefinition = (m: DateTime): void => { | ||
expect(m.toString()).toStrictEqual(`DateTime(${m.value.getTime()})`); | ||
}; | ||
|
||
describe("DateTime", () => { | ||
describe("toString", () => { | ||
it("should convert DateTime to a string", () => { | ||
expect.assertions(100); | ||
|
||
fc.assert(fc.property(datetime, toStringDefinition)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
import fc from "fast-check"; | ||
|
||
import type { Double } from "../src/double.js"; | ||
|
||
import { double } from "./arbitraries.js"; | ||
|
||
const toStringDefinition = (m: Double): void => { | ||
expect(m.toString()).toStrictEqual(`Double(${m.value})`); | ||
}; | ||
|
||
describe("Double", () => { | ||
describe("toString", () => { | ||
it("should convert Double to a string", () => { | ||
expect.assertions(100); | ||
|
||
fc.assert(fc.property(double, toStringDefinition)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
import fc from "fast-check"; | ||
|
||
import type { Integer, Product, Sum } from "../src/integer.js"; | ||
|
||
import { integer, product, sum } from "./arbitraries.js"; | ||
|
||
const integerToStringDefinition = (m: Integer): void => { | ||
expect(m.toString()).toStrictEqual(`Integer(${m.value})`); | ||
}; | ||
|
||
const sumToStringDefinition = (m: Sum): void => { | ||
expect(m.toString()).toStrictEqual(`Sum(${m.value})`); | ||
}; | ||
|
||
const productToStringDefinition = (m: Product): void => { | ||
expect(m.toString()).toStrictEqual(`Product(${m.value})`); | ||
}; | ||
|
||
describe("Integer", () => { | ||
describe("toString", () => { | ||
it("should convert Integer to a string", () => { | ||
expect.assertions(100); | ||
|
||
fc.assert(fc.property(integer, integerToStringDefinition)); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Sum", () => { | ||
describe("toString", () => { | ||
it("should convert Sum to a string", () => { | ||
expect.assertions(100); | ||
|
||
fc.assert(fc.property(sum, sumToStringDefinition)); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Product", () => { | ||
describe("toString", () => { | ||
it("should convert Product to a string", () => { | ||
expect.assertions(100); | ||
|
||
fc.assert(fc.property(product, productToStringDefinition)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
import fc from "fast-check"; | ||
|
||
import type { Text } from "../src/text.js"; | ||
|
||
import { text } from "./arbitraries.js"; | ||
|
||
const toStringDefinition = (m: Text): void => { | ||
expect(m.toString()).toStrictEqual(`Text(${JSON.stringify(m.value)})`); | ||
}; | ||
|
||
describe("Text", () => { | ||
describe("toString", () => { | ||
it("should convert Text to a string", () => { | ||
expect.assertions(100); | ||
|
||
fc.assert(fc.property(text, toStringDefinition)); | ||
}); | ||
}); | ||
}); |