1+ /*---------------------------------------------------------------------------------------------
2+ * Copyright (c) Microsoft Corporation. All rights reserved.
3+ * Licensed under the MIT License. See License.txt in the project root for license information.
4+ *--------------------------------------------------------------------------------------------*/
5+ 'use strict' ;
6+
7+ import * as assert from 'assert' ;
8+ import { hash } from 'vs/base/common/hash' ;
9+
10+ suite ( 'Hash' , ( ) => {
11+ test ( 'string' , ( ) => {
12+ assert . equal ( hash ( 'hello' ) , hash ( 'hello' ) ) ;
13+ assert . notEqual ( hash ( 'hello' ) , hash ( 'world' ) ) ;
14+ assert . notEqual ( hash ( 'hello' ) , hash ( 'olleh' ) ) ;
15+ assert . notEqual ( hash ( 'hello' ) , hash ( 'Hello' ) ) ;
16+ assert . notEqual ( hash ( 'hello' ) , hash ( 'Hello ' ) ) ;
17+ assert . notEqual ( hash ( 'h' ) , hash ( 'H' ) ) ;
18+ assert . notEqual ( hash ( '-' ) , hash ( '_' ) ) ;
19+ } ) ;
20+
21+ test ( 'number' , ( ) => {
22+ assert . equal ( hash ( 1 ) , hash ( 1.0 ) ) ;
23+ assert . notEqual ( hash ( 0 ) , hash ( 1 ) ) ;
24+ assert . notEqual ( hash ( 1 ) , hash ( - 1 ) ) ;
25+ assert . notEqual ( hash ( 0x12345678 ) , hash ( 0x123456789 ) ) ;
26+ } ) ;
27+
28+ test ( 'boolean' , ( ) => {
29+ assert . equal ( hash ( true ) , hash ( true ) ) ;
30+ assert . notEqual ( hash ( true ) , hash ( false ) ) ;
31+ } ) ;
32+
33+ test ( 'array' , ( ) => {
34+ assert . equal ( hash ( [ 1 , 2 , 3 ] ) , hash ( [ 1 , 2 , 3 ] ) ) ;
35+ assert . equal ( hash ( [ 'foo' , 'bar' ] ) , hash ( [ 'foo' , 'bar' ] ) ) ;
36+ assert . equal ( hash ( [ ] ) , hash ( [ ] ) ) ;
37+ assert . notEqual ( hash ( [ 'foo' , 'bar' ] ) , hash ( [ 'bar' , 'foo' ] ) ) ;
38+ assert . notEqual ( hash ( [ 'foo' , 'bar' ] ) , hash ( [ 'bar' , 'foo' , null ] ) ) ;
39+ } ) ;
40+
41+ test ( 'object' , ( ) => {
42+ assert . equal ( hash ( { } ) , hash ( { } ) ) ;
43+ assert . equal ( hash ( { 'foo' : 'bar' } ) , hash ( { 'foo' : 'bar' } ) ) ;
44+ assert . equal ( hash ( { 'foo' : 'bar' , 'foo2' : void 0 } ) , hash ( { 'foo2' : void 0 , 'foo' : 'bar' } ) ) ;
45+ assert . notEqual ( hash ( { 'foo' : 'bar' } ) , hash ( { 'foo' : 'bar2' } ) ) ;
46+ assert . notEqual ( hash ( { } ) , hash ( [ ] ) ) ;
47+ } ) ;
48+ } ) ;
0 commit comments