Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Zamralik authored and SmashingQuasar committed Jun 23, 2022
1 parent 55010f4 commit 6080228
Show file tree
Hide file tree
Showing 10 changed files with 3,120 additions and 2,230 deletions.
1,225 changes: 785 additions & 440 deletions __tests__/TypeAssertion.spec.ts

Large diffs are not rendered by default.

986 changes: 588 additions & 398 deletions __tests__/TypeGuard.spec.ts

Large diffs are not rendered by default.

1,019 changes: 580 additions & 439 deletions __tests__/TypeHint.spec.ts

Large diffs are not rendered by default.

222 changes: 119 additions & 103 deletions __tests__/ValueGuard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,106 +4,122 @@ import { ValueGuard } from "../src/ValueGuard.js";

import { BaseType, DummyClass, GroupType, getInvertedValues } from "./utils/Utils.js";

describe("ValueGuard", (): void => {
describe("IsSimilar", (): void => {
it(`should return true when given the same value twice`, (): void => {
const VALUES: Array<unknown> = getInvertedValues(/* All values */);

for (const value of VALUES) {
expect(ValueGuard.IsSimilar(value, value)).to.be.true;
}
});

it(`should return true when given similar primitives or similar records`, (): void => {
const VALUES_LEFT: Array<unknown> = getInvertedValues(
BaseType.SYMBOL,
BaseType.INSTANTIATED,
GroupType.FUNCTION_CLASS,
);

const VALUES_RIGHT: Array<unknown> = getInvertedValues(
BaseType.SYMBOL,
BaseType.INSTANTIATED,
GroupType.FUNCTION_CLASS,
);

for (const [index, element] of VALUES_LEFT.entries()) {
expect(ValueGuard.IsSimilar(element, VALUES_RIGHT[index])).to.be.true;
}

expect(ValueGuard.IsSimilar(0, -0)).to.be.true;
expect(ValueGuard.IsSimilar(-0, 0)).to.be.true;
});

it(`should return false when given different primitives`, (): void => {
const VALUES: Array<unknown> = getInvertedValues(BaseType.SYMBOL, GroupType.OBJECT, GroupType.FUNCTION_CLASS);

for (let index: number = 1; index < VALUES.length; ++index) {
for (let index_: number = 0; index_ < index; ++index_) {
// Ignore -0 === 0 case
if (VALUES[index] !== 0 || VALUES[index_] !== 0) {
expect(ValueGuard.IsSimilar(VALUES[index], VALUES[index_])).to.be.false;
expect(ValueGuard.IsSimilar(VALUES[index_], VALUES[index])).to.be.false;
}
}
}
});

it(`should return false when given different arrays or records`, (): void => {
expect(
ValueGuard.IsSimilar(
{},
{
answer: 42,
},
),
).to.be.false;

expect(
ValueGuard.IsSimilar(
{
answer: 42,
},
{},
),
).to.be.false;

expect(
ValueGuard.IsSimilar(
{
answer: 0,
},
{
answer: 42,
},
),
).to.be.false;

expect(
ValueGuard.IsSimilar(
{
answer: 42,
},
{
answer: 0,
},
),
).to.be.false;

expect(ValueGuard.IsSimilar([0], [1])).to.be.false;
expect(ValueGuard.IsSimilar([1], [0])).to.be.false;
});

it(`should return false when given symbols, or interchangeable functions, classes, or objects`, (): void => {
/* eslint-disable-next-line symbol-description, @typescript-eslint/no-empty-function -- required for testing */
const VALUES_LEFT: Array<unknown> = [Symbol(), new DummyClass(), (): void => {}, class {}];

/* eslint-disable-next-line symbol-description, @typescript-eslint/no-empty-function -- required for testing */
const VALUES_RIGHT: Array<unknown> = [Symbol(), new DummyClass(), (): void => {}, class {}];

for (const [index, element] of VALUES_LEFT.entries()) {
expect(ValueGuard.IsSimilar(element, VALUES_RIGHT[index])).to.be.false;
}
});
});
});
describe(
"ValueGuard",
(): void =>
{
describe(
"IsSimilar",
(): void =>
{
it(
"should return true when given the same value twice",
(): void =>
{
const ALL_VALUES: Array<unknown> = getInvertedValues();

for (const ITEM of ALL_VALUES)
{
expect(ValueGuard.IsSimilar(ITEM, ITEM)).to.be.true;
}
}
);

it(
"should return true when given similar primitives or similar records",
(): void =>
{
const VALUES_LEFT: Array<unknown> = getInvertedValues(
BaseType.SYMBOL,
BaseType.INSTANTIATED,
GroupType.FUNCTION_CLASS,
);

const VALUES_RIGHT: Array<unknown> = getInvertedValues(
BaseType.SYMBOL,
BaseType.INSTANTIATED,
GroupType.FUNCTION_CLASS,
);

for (let i: number = 0; i < VALUES_LEFT.length; ++i)
{
expect(ValueGuard.IsSimilar(VALUES_LEFT[i], VALUES_RIGHT[i])).to.be.true;
}

expect(ValueGuard.IsSimilar(0, -0)).to.be.true;
expect(ValueGuard.IsSimilar(-0, 0)).to.be.true;
}
);

it(
"should return false when given different primitives",
(): void =>
{
const VALUES: Array<unknown> = getInvertedValues(
BaseType.SYMBOL,
GroupType.OBJECT,
GroupType.FUNCTION_CLASS,
);

for (let i: number = 1; i < VALUES.length; ++i)
{
for (let j: number = 0; j < i; ++j)
{
// Ignore -0 === 0 case
if (VALUES[i] !== 0 || VALUES[j] !== 0)
{
expect(ValueGuard.IsSimilar(VALUES[i], VALUES[j])).to.be.false;
expect(ValueGuard.IsSimilar(VALUES[j], VALUES[i])).to.be.false;
}
}
}
}
);

it(
"should return false when given different arrays or records",
(): void =>
{
expect(ValueGuard.IsSimilar({}, { answer: 42 })).to.be.false;
expect(ValueGuard.IsSimilar({ answer: 42 }, {})).to.be.false;

expect(ValueGuard.IsSimilar({ answer: 0 }, { answer: 42 })).to.be.false;
expect(ValueGuard.IsSimilar({ answer: 42 }, { answer: 0 })).to.be.false;

expect(ValueGuard.IsSimilar([0], [1])).to.be.false;
expect(ValueGuard.IsSimilar([1], [0])).to.be.false;
}
);

it(
"should return false when given symbols, or interchangeable functions, classes, or objects",
(): void =>
{
const VALUES_LEFT: Array<unknown> = [
Symbol(),
new DummyClass(),
(): void =>
{},
class
{},
];

const VALUES_RIGHT: Array<unknown> = [
Symbol(),
new DummyClass(),
(): void =>
{},
class
{},
];

for (let i: number = 0; i < VALUES_LEFT.length; ++i)
{
expect(ValueGuard.IsSimilar(VALUES_LEFT[i], VALUES_RIGHT[i])).to.be.false;
}
}
);
}
);
}
);
Loading

0 comments on commit 6080228

Please sign in to comment.