Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make is empty return false for boolean true. #869

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/twig.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ module.exports = function (Twig) {
'use strict';
Twig.tests = {
empty(value) {
// Handle boolean true
if (value === true) {
return false;
}

// Handle null or undefined
if (value === null || value === undefined) {
return true;
}
Expand Down
12 changes: 12 additions & 0 deletions test/test.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ describe('Twig.js Tests ->', function () {
twig({data: '{{ ["1"] is empty }}'}).render().should.equal('false');
});

it('should identify booleans', function () {
// Array
twig({data: '{{ foo is empty }}'}).render( { foo: true } ).should.equal('false');
twig({data: '{{ foo is empty }}'}).render( { foo: false }).should.equal('true');
});

it('should identify null or undefined', function () {
// Array
twig({data: '{{ foo is empty }}'}).render( {foo: null} ).should.equal('true');
twig({data: '{{ foo is empty }}'}).render( {foo: undefined} ).should.equal('true');
});

it('should identify empty objects', function () {
// Object
twig({data: '{{ {} is empty }}'}).render().should.equal('true');
Expand Down