File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -31,10 +31,10 @@ module.exports = {
31
31
* Adds a dummy node to the graph and return v.
32
32
*/
33
33
function addDummyNode ( g , type , attrs , name ) {
34
- let v ;
35
- do {
34
+ var v = name ;
35
+ while ( g . hasNode ( v ) ) {
36
36
v = uniqueId ( name ) ;
37
- } while ( g . hasNode ( v ) ) ;
37
+ }
38
38
39
39
attrs . dummy = type ;
40
40
g . setNode ( v , attrs ) ;
@@ -278,7 +278,7 @@ function notime(name, fn) {
278
278
let idCounter = 0 ;
279
279
function uniqueId ( prefix ) {
280
280
var id = ++ idCounter ;
281
- return toString ( prefix ) + id ;
281
+ return prefix + ( "" + id ) ;
282
282
}
283
283
284
284
function range ( start , limit , step = 1 ) {
Original file line number Diff line number Diff line change
1
+ var expect = require ( "./chai" ) . expect ;
2
+ var util = require ( "../lib/util.js" ) ;
3
+
4
+ describe ( "Given a function to generate unique identifiers" , function ( ) {
5
+ it ( "uniqueId(name) generates a valid identifier" , function ( ) {
6
+ // This test guards against a bug #477, where the call to toString(prefix) inside
7
+ // uniqueId() produced [object undefined].
8
+ var id = util . uniqueId ( "_root" ) ;
9
+ expect ( id ) . not . to . include ( '[object undefined]' ) ;
10
+ expect ( id ) . match ( / _ r o o t \d + / ) ;
11
+ } ) ;
12
+
13
+ it ( "Calling uniqueId(name) multiple times generate distinct values" , function ( ) {
14
+ var first = util . uniqueId ( "name" ) ;
15
+ var second = util . uniqueId ( "name" ) ;
16
+ var third = util . uniqueId ( "name" ) ;
17
+ expect ( first ) . not . equals ( second ) ;
18
+ expect ( second ) . not . equals ( third ) ;
19
+ } ) ;
20
+
21
+ it ( "Calling uniqueId(number) with a number creates a valid identifier string" , function ( ) {
22
+ var id = util . uniqueId ( 99 ) ;
23
+ expect ( id ) . to . be . a ( 'string' ) ;
24
+ expect ( id ) . not . to . be . a ( 'number' ) ;
25
+
26
+ expect ( id ) . to . match ( / 9 9 \d + / ) ;
27
+ } ) ;
28
+ } ) ;
You can’t perform that action at this time.
0 commit comments