-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with filter function with no arguments
- Loading branch information
1 parent
83dfc0b
commit af4845f
Showing
4 changed files
with
65 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
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,47 @@ | ||
import test from 'ava' | ||
|
||
import {compile, generate} from '..' | ||
|
||
test('should generate uri with replacement', (t) => { | ||
const template = 'http://example.com/{section}{?first,max}' | ||
const params = {section: 'news', first: 40, max: 20} | ||
const expected = 'http://example.com/news?first=40&max=20' | ||
|
||
const compiled = compile(template) | ||
const uri = generate(compiled, params) | ||
|
||
t.is(uri, expected) | ||
}) | ||
|
||
test('should generate uri with optional parameters', (t) => { | ||
const template = 'http://example.com/{section}{?first?,max?}' | ||
const params = {section: 'news', max: 20} | ||
const expected = 'http://example.com/news?max=20' | ||
|
||
const compiled = compile(template) | ||
const uri = generate(compiled, params) | ||
|
||
t.is(uri, expected) | ||
}) | ||
|
||
test('should generate uri with filter functions', (t) => { | ||
const template = 'http://example.com/{section|append(_archive)}{?letter=name|max(1)|lower}' | ||
const params = {section: 'news', name: 'John F.'} | ||
const expected = 'http://example.com/news_archive?letter=j' | ||
|
||
const compiled = compile(template) | ||
const uri = generate(compiled, params) | ||
|
||
t.is(uri, expected) | ||
}) | ||
|
||
test('should generate empty string from empty string template', (t) => { | ||
const template = '' | ||
const params = {} | ||
const expected = '' | ||
|
||
const compiled = compile(template) | ||
const uri = generate(compiled, params) | ||
|
||
t.is(uri, expected) | ||
}) |