Skip to content

Commit

Permalink
Merged PR 78: Feature 193
Browse files Browse the repository at this point in the history
Related work items: #193, #194
  • Loading branch information
mlhaufe committed Sep 30, 2019
2 parents 7d14765 + 653dc16 commit 495d4b6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![Build Status](https://dev.azure.com/thenewobjective/decorator-contracts/_apis/build/status/Build?branchName=master)](https://dev.azure.com/thenewobjective/decorator-contracts/_build/latest?definitionId=11&branchName=master)

[Code Contracts](https://en.wikipedia.org/wiki/Design_by_contract) are

TODO:

## Library Installation
Expand Down Expand Up @@ -44,7 +46,7 @@ no-ops for run-time efficiency. As the number of contract definitions can
be numerous, using the appropriate mode becomes increasingly important.

You are not prevented from mixing modes in the event you desire you maintain
a number of checks in a production library.
a number of checks in a production environment.

### Assertions

Expand Down
19 changes: 19 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @license
* Copyright (C) #{YEAR}# Michael L Haufe
* SPDX-License-Identifier: GPL-2.0-only
*
* Unit tests for the Contructor class
*/
import Contracts from './';

/**
* Requirement 194
* https://dev.azure.com/thenewobjective/decorator-contracts/_workitems/edit/194
*/
describe('', () => {
test('Construction', () => {
expect(new Contracts(true).debugMode).toBe(true);
expect(new Contracts(false).debugMode).toBe(false);
});
});
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import InvariantDecorator from './InvariantDecorator';
import OverrideDecorator from './OverrideDecorator';
import RequiresDecorator from './RequiresDecorator';

/**
* The Contracts class defines methods that can be used to define and enforce
* specifications for other classes. These are exposed as decorator factories and
* an assertion function.
*/
export default class Contracts {
assert: typeof Assertion.prototype.assert;
ensures: typeof EnsuresDecorator.prototype.ensures;
Expand All @@ -23,7 +28,12 @@ export default class Contracts {
override: typeof OverrideDecorator.prototype.override;
requires: typeof RequiresDecorator.prototype.requires;

constructor(protected debugMode: boolean) {
/**
* Constructs a new instance of Contracts in the specified mode
*
* @param debugMode - enables assertions
*/
constructor(readonly debugMode: boolean) {
this.assert = new Assertion(debugMode).assert;
this.ensures = new EnsuresDecorator(debugMode).ensures;
this.invariant = new InvariantDecorator(debugMode).invariant;
Expand Down

0 comments on commit 495d4b6

Please sign in to comment.