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 {
2
2
constructor ( ) {
3
3
this . keys = [ ] ;
4
4
this . values = [ ] ;
5
5
}
6
6
7
+ get size ( ) {
8
+ return this . keys . length ;
9
+ }
10
+
7
11
get ( key ) {
8
12
const index = this . keys . indexOf ( key ) ;
9
13
@@ -17,3 +21,7 @@ export default class SimpleMap {
17
21
return value ;
18
22
}
19
23
}
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