-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: liquid returns result with type as type of variable
If liquid receives a string containing only one variable substitution, it will return a result with the type as the type of this variable ``` typeof liquid('{{count}}', {count: 10}) === 'number' ```
- Loading branch information
1 parent
fb5e241
commit f5af53c
Showing
6 changed files
with
165 additions
and
11 deletions.
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
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
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
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
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,53 @@ | ||
import {isSingleVariable} from '../../src/transform/liquid/lexical'; | ||
|
||
describe('Lexical functions', () => { | ||
describe('isSingleVariable', () => { | ||
test('Valid single variable without surrounding text', () => { | ||
expect(isSingleVariable('{{variable}}')).toEqual(true); | ||
}); | ||
|
||
test('Two variables should return false', () => { | ||
expect(isSingleVariable('{{variable1}} {{variable2}}')).toEqual(false); | ||
}); | ||
|
||
test('Text before variable should return false', () => { | ||
expect(isSingleVariable('some text {{variable}}')).toEqual(false); | ||
}); | ||
|
||
test('Text after variable should return false', () => { | ||
expect(isSingleVariable('{{variable}} some text')).toEqual(false); | ||
}); | ||
|
||
test('Valid single variable with filter', () => { | ||
expect(isSingleVariable('{{ variable | filter }}')).toEqual(true); | ||
}); | ||
|
||
test('Single variable with leading and trailing space should return false', () => { | ||
expect(isSingleVariable(' {{variable}} ')).toEqual(false); | ||
}); | ||
|
||
test('Single variable with multiple leading and trailing spaces should return false', () => { | ||
expect(isSingleVariable(' {{variable}} ')).toEqual(false); | ||
}); | ||
|
||
test('Single variable with tabs and newlines should return false', () => { | ||
expect(isSingleVariable('\t{{variable}} \n')).toEqual(false); | ||
}); | ||
|
||
test('Empty string should return false', () => { | ||
expect(isSingleVariable('')).toEqual(false); | ||
}); | ||
|
||
test('Text without variables should return false', () => { | ||
expect(isSingleVariable('just some text')).toEqual(false); | ||
}); | ||
|
||
test('Single curly braces should return false', () => { | ||
expect(isSingleVariable('{variable}')).toEqual(false); | ||
}); | ||
|
||
test('Unmatched curly braces should return false', () => { | ||
expect(isSingleVariable('{{variable}')).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