File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import match , { Switch } from "../src" ;
2+
3+ describe ( "Switch" , ( ) => {
4+ it ( "should exist" , ( ) => {
5+ expect ( Switch ) . not . toBe ( undefined ) ;
6+ } ) ;
7+
8+ describe ( "Switch.for" , ( ) => {
9+ it ( "should create an instance of Switch" , ( ) => {
10+ expect ( Switch . for ( "" ) ) . toBeInstanceOf ( Switch ) ;
11+ } ) ;
12+ } ) ;
13+
14+ describe ( "case/default" , ( ) => {
15+ it ( "should defer execution until default is called" , ( ) => {
16+ expect ( match ( "asdf" ) . case ( "" , ( ) => 123 ) ) . toBeInstanceOf ( Switch ) ;
17+ } ) ;
18+
19+ it ( "should return value if matched by equation" , ( ) => {
20+ expect (
21+ match ( "" )
22+ . case ( "" , 123 )
23+ . default ( 345 ) ,
24+ ) . toEqual ( 123 ) ;
25+ } ) ;
26+
27+ it ( "should return value if matched by predicate function" , ( ) => {
28+ expect (
29+ match ( "asdf" )
30+ . case ( x => x == "asdf" , 123 )
31+ . default ( 345 ) ,
32+ ) . toEqual ( 123 ) ;
33+ } ) ;
34+
35+ it ( "should return default value if not matched" , ( ) => {
36+ expect (
37+ match ( "asdf" )
38+ . case ( "" , 123 )
39+ . default ( 234 ) ,
40+ ) . toEqual ( 234 ) ;
41+ } ) ;
42+
43+ it ( "should preserve the first match and its value" , ( ) => {
44+ expect (
45+ match ( "asdf" )
46+ . case ( "asdf" , 123 )
47+ . case ( "asdf" , 234 )
48+ . default ( 345 ) ,
49+ ) . toEqual ( 123 ) ;
50+ } ) ;
51+ } ) ;
52+ } ) ;
You can’t perform that action at this time.
0 commit comments