Skip to content

Commit 00a6aff

Browse files
authoredOct 11, 2023
Merge pull request #869 from antoineveldhoven/is-empty-on-boolean
Make is empty return false for boolean true.
2 parents caced6b + 24c4581 commit 00a6aff

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
 

‎src/twig.tests.js

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ module.exports = function (Twig) {
55
'use strict';
66
Twig.tests = {
77
empty(value) {
8+
// Handle boolean true
9+
if (value === true) {
10+
return false;
11+
}
12+
13+
// Handle null or undefined
814
if (value === null || value === undefined) {
915
return true;
1016
}

‎test/test.tests.js

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ describe('Twig.js Tests ->', function () {
2222
twig({data: '{{ ["1"] is empty }}'}).render().should.equal('false');
2323
});
2424

25+
it('should identify booleans', function () {
26+
// Array
27+
twig({data: '{{ foo is empty }}'}).render( { foo: true } ).should.equal('false');
28+
twig({data: '{{ foo is empty }}'}).render( { foo: false }).should.equal('true');
29+
});
30+
31+
it('should identify null or undefined', function () {
32+
// Array
33+
twig({data: '{{ foo is empty }}'}).render( {foo: null} ).should.equal('true');
34+
twig({data: '{{ foo is empty }}'}).render( {foo: undefined} ).should.equal('true');
35+
});
36+
2537
it('should identify empty objects', function () {
2638
// Object
2739
twig({data: '{{ {} is empty }}'}).render().should.equal('true');

0 commit comments

Comments
 (0)
Please sign in to comment.