File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change 1- export default class SimpleMap {
1+ export class SimpleMap {
22 constructor ( ) {
33 this . keys = [ ] ;
44 this . values = [ ] ;
55 }
66
7+ get size ( ) {
8+ return this . keys . length ;
9+ }
10+
711 get ( key ) {
812 const index = this . keys . indexOf ( key ) ;
913
@@ -17,3 +21,7 @@ export default class SimpleMap {
1721 return value ;
1822 }
1923}
24+
25+ const exportedMap = typeof Map === 'undefined' ? SimpleMap : Map ;
26+
27+ export default exportedMap ;
Original file line number Diff line number Diff line change 1+ import {
2+ expect
3+ } from 'chai' ;
4+ import { SimpleMap } from './../src/simple-map' ;
5+
6+ const getTests = ( map ) => {
7+ return ( ) => {
8+ const values = [
9+ [ 1 , 'something' ] ,
10+ [ '1' , 'somethingElse' ] ,
11+ [ { } , [ ] ] ,
12+ [ null , null ]
13+ ] ;
14+
15+ it ( 'should set' , ( ) => {
16+ values . forEach ( ( [ key , value ] ) => {
17+ map . set ( key , value ) ;
18+ } ) ;
19+ expect ( map . size ) . to . equal ( values . length ) ;
20+ } ) ;
21+
22+ it ( 'should get' , ( ) => {
23+ values . forEach ( ( [ key , value ] ) => {
24+ expect ( map . get ( key ) ) . to . equal ( value ) ;
25+ } ) ;
26+ } ) ;
27+ } ;
28+ } ;
29+
30+ describe ( 'SimpleMap' , ( ) => {
31+ context ( 'simple map with primitive or object as keys' , getTests ( new SimpleMap ( ) ) ) ;
32+ if ( typeof Map !== 'undefined' ) {
33+ context ( 'sanity - running tests against native Map' , getTests ( new Map ( ) ) ) ;
34+ }
35+ } ) ;
You can’t perform that action at this time.
0 commit comments