-
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.
feat(API): support CASE(,,,) as an alias to array[,,,] close#2
- Loading branch information
jhe
committed
Jul 6, 2016
1 parent
ae4f1f9
commit 149f450
Showing
9 changed files
with
122 additions
and
92 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 |
---|---|---|
@@ -1,53 +1,61 @@ | ||
import chai from 'chai'; | ||
import {_, otherwise, id, match} from '../lib/match-js'; | ||
import {match, _, otherwise, id, CASE} from '../lib/match-js'; | ||
|
||
chai.expect(); | ||
const expect = chai.expect; | ||
|
||
describe('Miscellaneous useages', function () { | ||
it('execute statements should be allowed', () => { | ||
const m = match(10)( | ||
[1, "ONE"], | ||
[1, 'ONE'], | ||
[10, ()=>{ | ||
return "TEN"; | ||
return 'TEN'; | ||
}, null] | ||
) | ||
expect(m).to.be.equal('TEN'); | ||
}); | ||
it('pass additional parameters to matched patial function', () => { | ||
const m = match(1)( | ||
[1, (x,y,z)=>{ | ||
return "Match "+x+" "+y+" "+z; | ||
return 'Match '+x+' '+y+' '+z; | ||
}, 2,3] | ||
) | ||
expect(m).to.be.equal('Match 1 2 3'); | ||
}); | ||
it('default pattern (_) that matches everything', () => { | ||
const i = 3; | ||
const m = match(i)( | ||
[1, "ONE"], | ||
[2, "TOW"], | ||
[_, ()=>"_ matches "+i] | ||
[1, 'ONE'], | ||
[2, 'TWO'], | ||
[_, ()=>'_ matches '+i] | ||
) | ||
expect(m).to.be.equal('_ matches 3'); | ||
}); | ||
it('default pattern (otherwise) that matches everything', () => { | ||
const i = 3; | ||
const m = match(i)( | ||
[1, "ONE"], | ||
[2, "TOW"], | ||
[otherwise, ()=>"otherwise matches "+i+""] | ||
[1, 'ONE'], | ||
[2, 'TWO'], | ||
[otherwise, ()=>'otherwise matches '+i+''] | ||
) | ||
expect(m).to.be.equal('otherwise matches 3'); | ||
}); | ||
it('id functions returns the same input value', () => { | ||
const x = 10; | ||
const m = match(x)( | ||
[1, "ONE"], | ||
[2, "TOW"], | ||
[1, 'ONE'], | ||
[2, 'TWO'], | ||
[10, id] | ||
) | ||
expect(m).to.be.equal(x); | ||
}); | ||
|
||
it('CASE statements test', function() { | ||
const i = 10; | ||
const m = match(i)( | ||
CASE(1, (x,y,z)=>{ return 'Match '+x+' '+y+' '+z; }, 2,3), | ||
CASE(2, 'TWO'), | ||
CASE(_, ()=>'_ matches '+i) | ||
); | ||
expect(m).to.be.equal('_ matches 10'); | ||
}); | ||
}); |
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
Oops, something went wrong.
149f450
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close #2