UNPKG

@raccoons-co/ethics

Version:
142 lines (141 loc) 11.1 kB
"use strict"; var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) { var useValue = arguments.length > 2; for (var i = 0; i < initializers.length; i++) { value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); } return useValue ? value : void 0; }; var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; } var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); var _, done = false; for (var i = decorators.length - 1; i >= 0; i--) { var context = {}; for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; for (var p in contextIn.access) context.access[p] = contextIn.access[p]; context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); }; var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context); if (kind === "accessor") { if (result === void 0) continue; if (result === null || typeof result !== "object") throw new TypeError("Object expected"); if (_ = accept(result.get)) descriptor.get = _; if (_ = accept(result.set)) descriptor.set = _; if (_ = accept(result.init)) initializers.unshift(_); } else if (_ = accept(result)) { if (kind === "field") initializers.unshift(_); else descriptor[key] = _; } } if (target) Object.defineProperty(target, contextIn.name, descriptor); done = true; }; var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) { if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : ""; return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const cleanway_1 = require("@raccoons-co/cleanway"); const chai_1 = require("chai"); const NoSuchElementException_1 = __importDefault(require("../main/NoSuchElementException")); const main_1 = require("../main"); let EmptyOptionalTest = (() => { let _classDecorators = [cleanway_1.TestClass]; let _classDescriptor; let _classExtraInitializers = []; let _classThis; let _instanceExtraInitializers = []; let _returnsInstanceOfOptional_decorators; let _returnsTrueEmptinessIfEmpty_decorators; let _returnsFalsePresenceIfEmpty_decorators; let _throwsExceptionForGetIfEmpty_decorators; let _throwsExceptionForElseThrowIfEmpty_decorators; let _returnsEmptyIfValueIsNull_decorators; let _returnsEmptyIfValueIsUndefined_decorators; let _doesNothing_decorators; let _returnsCorrectOtherValueForOrElse_decorators; let _performsGivenEmptyActionIfEmpty_decorators; var EmptyOptionalTest = _classThis = class { constructor() { this.emptyOptional = (__runInitializers(this, _instanceExtraInitializers), main_1.Optional.empty()); } returnsInstanceOfOptional() { chai_1.assert.instanceOf(this.emptyOptional, main_1.Optional); } returnsTrueEmptinessIfEmpty() { chai_1.assert.isTrue(this.emptyOptional.isEmpty()); } returnsFalsePresenceIfEmpty() { chai_1.assert.isFalse(this.emptyOptional.isPresent()); } throwsExceptionForGetIfEmpty() { chai_1.assert.throws(() => this.emptyOptional.get(), NoSuchElementException_1.default); } throwsExceptionForElseThrowIfEmpty() { chai_1.assert.throws(() => this.emptyOptional.orElseThrow(), NoSuchElementException_1.default); } returnsEmptyIfValueIsNull() { const optional = main_1.Optional.ofNullable(null); chai_1.assert.isTrue(optional.isEmpty()); } returnsEmptyIfValueIsUndefined() { const optional = main_1.Optional.ofNullable(undefined); chai_1.assert.isTrue(optional.isEmpty()); } doesNothing() { chai_1.assert.doesNotThrow(() => { this.emptyOptional.ifPresent((value) => { chai_1.assert.fail("This statement should not be executed"); }); }); } returnsCorrectOtherValueForOrElse() { chai_1.assert.equal(this.emptyOptional.orElse(8), 8); } performsGivenEmptyActionIfEmpty() { chai_1.assert.throws(() => { this.emptyOptional.ifPresentOrElse((value) => { chai_1.assert.ok("This statement should not be executed"); }, () => { chai_1.assert.fail("Fails intentionally"); }); }); } }; __setFunctionName(_classThis, "EmptyOptionalTest"); (() => { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; _returnsInstanceOfOptional_decorators = [cleanway_1.Test, (0, cleanway_1.DisplayName)("Optional.empty() returns instance of Optional")]; _returnsTrueEmptinessIfEmpty_decorators = [cleanway_1.Test, (0, cleanway_1.DisplayName)("isEmpty() returns `True` if empty")]; _returnsFalsePresenceIfEmpty_decorators = [cleanway_1.Test, (0, cleanway_1.DisplayName)("isPresent() returns `False` if empty ")]; _throwsExceptionForGetIfEmpty_decorators = [cleanway_1.Test, (0, cleanway_1.DisplayName)("get() throws `NoSuchElementException` if empty")]; _throwsExceptionForElseThrowIfEmpty_decorators = [cleanway_1.Test, (0, cleanway_1.DisplayName)("orElseThrow() throws `NoSuchElementException` if empty")]; _returnsEmptyIfValueIsNull_decorators = [cleanway_1.Test, (0, cleanway_1.DisplayName)("Optional.ofNullable(null) returns empty optional ")]; _returnsEmptyIfValueIsUndefined_decorators = [cleanway_1.Test, (0, cleanway_1.DisplayName)("Optional.ofNullable(undefined) returns empty optional")]; _doesNothing_decorators = [cleanway_1.Test, (0, cleanway_1.DisplayName)("ifPresent() does nothing if empty")]; _returnsCorrectOtherValueForOrElse_decorators = [cleanway_1.Test, (0, cleanway_1.DisplayName)("orElse(otherValue) returns correct other value if empty")]; _performsGivenEmptyActionIfEmpty_decorators = [cleanway_1.Test, (0, cleanway_1.DisplayName)("ifPresentOrElse() performs given empty-based action if empty")]; __esDecorate(_classThis, null, _returnsInstanceOfOptional_decorators, { kind: "method", name: "returnsInstanceOfOptional", static: false, private: false, access: { has: obj => "returnsInstanceOfOptional" in obj, get: obj => obj.returnsInstanceOfOptional }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_classThis, null, _returnsTrueEmptinessIfEmpty_decorators, { kind: "method", name: "returnsTrueEmptinessIfEmpty", static: false, private: false, access: { has: obj => "returnsTrueEmptinessIfEmpty" in obj, get: obj => obj.returnsTrueEmptinessIfEmpty }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_classThis, null, _returnsFalsePresenceIfEmpty_decorators, { kind: "method", name: "returnsFalsePresenceIfEmpty", static: false, private: false, access: { has: obj => "returnsFalsePresenceIfEmpty" in obj, get: obj => obj.returnsFalsePresenceIfEmpty }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_classThis, null, _throwsExceptionForGetIfEmpty_decorators, { kind: "method", name: "throwsExceptionForGetIfEmpty", static: false, private: false, access: { has: obj => "throwsExceptionForGetIfEmpty" in obj, get: obj => obj.throwsExceptionForGetIfEmpty }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_classThis, null, _throwsExceptionForElseThrowIfEmpty_decorators, { kind: "method", name: "throwsExceptionForElseThrowIfEmpty", static: false, private: false, access: { has: obj => "throwsExceptionForElseThrowIfEmpty" in obj, get: obj => obj.throwsExceptionForElseThrowIfEmpty }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_classThis, null, _returnsEmptyIfValueIsNull_decorators, { kind: "method", name: "returnsEmptyIfValueIsNull", static: false, private: false, access: { has: obj => "returnsEmptyIfValueIsNull" in obj, get: obj => obj.returnsEmptyIfValueIsNull }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_classThis, null, _returnsEmptyIfValueIsUndefined_decorators, { kind: "method", name: "returnsEmptyIfValueIsUndefined", static: false, private: false, access: { has: obj => "returnsEmptyIfValueIsUndefined" in obj, get: obj => obj.returnsEmptyIfValueIsUndefined }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_classThis, null, _doesNothing_decorators, { kind: "method", name: "doesNothing", static: false, private: false, access: { has: obj => "doesNothing" in obj, get: obj => obj.doesNothing }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_classThis, null, _returnsCorrectOtherValueForOrElse_decorators, { kind: "method", name: "returnsCorrectOtherValueForOrElse", static: false, private: false, access: { has: obj => "returnsCorrectOtherValueForOrElse" in obj, get: obj => obj.returnsCorrectOtherValueForOrElse }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(_classThis, null, _performsGivenEmptyActionIfEmpty_decorators, { kind: "method", name: "performsGivenEmptyActionIfEmpty", static: false, private: false, access: { has: obj => "performsGivenEmptyActionIfEmpty" in obj, get: obj => obj.performsGivenEmptyActionIfEmpty }, metadata: _metadata }, null, _instanceExtraInitializers); __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers); EmptyOptionalTest = _classThis = _classDescriptor.value; if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); __runInitializers(_classThis, _classExtraInitializers); })(); return EmptyOptionalTest = _classThis; })(); exports.default = EmptyOptionalTest;