-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Null" and "Undefined" specifications (and tests)
- Loading branch information
1 parent
367f671
commit fede4e4
Showing
5 changed files
with
127 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
**New Features** | ||
|
||
* Added a `Changes` specification. | ||
* Added an `Exists` specification. | ||
* Added a `Null` specification. | ||
* Added an `Undefined` specification. |
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,31 @@ | ||
const is = require('./../lang/is'); | ||
|
||
const Specification = require('./Specification'); | ||
|
||
module.exports = (() => { | ||
'use strict'; | ||
|
||
/** | ||
* A {@link Specification} that passes when a data item is a null value. | ||
* | ||
* @public | ||
* @extends {Specification} | ||
*/ | ||
class Null extends Specification { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
_evaluate(data) { | ||
return is.null(data); | ||
} | ||
|
||
toString() { | ||
return '[Null]'; | ||
} | ||
} | ||
|
||
return Null; | ||
})(); | ||
|
||
|
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,31 @@ | ||
const is = require('./../lang/is'); | ||
|
||
const Specification = require('./Specification'); | ||
|
||
module.exports = (() => { | ||
'use strict'; | ||
|
||
/** | ||
* A {@link Specification} that passes when a data item is an undefined value. | ||
* | ||
* @public | ||
* @extends {Specification} | ||
*/ | ||
class Undefined extends Specification { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
_evaluate(data) { | ||
return is.undefined(data); | ||
} | ||
|
||
toString() { | ||
return '[Undefined]'; | ||
} | ||
} | ||
|
||
return Undefined; | ||
})(); | ||
|
||
|
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,31 @@ | ||
const Null = require('./../../../specifications/Null'); | ||
|
||
describe('When a Null specification is constructed', () => { | ||
'use strict'; | ||
|
||
let specification; | ||
|
||
beforeEach(() => { | ||
specification = new Null(); | ||
}); | ||
|
||
it('should pass a null value', () => { | ||
expect(specification.evaluate(null)).toEqual(true); | ||
}); | ||
|
||
it('should not pass an implicit undefined value', () => { | ||
expect(specification.evaluate()).toEqual(false); | ||
}); | ||
|
||
it('should not pass an explicit undefined value', () => { | ||
expect(specification.evaluate(undefined)).toEqual(false); | ||
}); | ||
|
||
it('should not pass a zero value', () => { | ||
expect(specification.evaluate(0)).toEqual(false); | ||
}); | ||
|
||
it('should not pass an empty-length string value', () => { | ||
expect(specification.evaluate('')).toEqual(false); | ||
}); | ||
}); |
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,32 @@ | ||
const Undefined = require('./../../../specifications/Undefined'); | ||
|
||
describe('When a Undefined specification is constructed', () => { | ||
'use strict'; | ||
|
||
let specification; | ||
|
||
beforeEach(() => { | ||
specification = new Undefined(); | ||
}); | ||
|
||
it('should not pass a null value', () => { | ||
expect(specification.evaluate(null)).toEqual(false); | ||
}); | ||
|
||
it('should pass an implicit undefined value', () => { | ||
expect(specification.evaluate()).toEqual(true); | ||
}); | ||
|
||
it('should pass an explicit undefined value', () => { | ||
expect(specification.evaluate(undefined)).toEqual(true); | ||
}); | ||
|
||
|
||
it('should not pass a zero value', () => { | ||
expect(specification.evaluate(0)).toEqual(false); | ||
}); | ||
|
||
it('should not pass an empty-length string value', () => { | ||
expect(specification.evaluate('')).toEqual(false); | ||
}); | ||
}); |