Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ardublockly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ardublockly
Commits
d702808f
Commit
d702808f
authored
Nov 19, 2015
by
Neil Fraser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add UUID generator.
parent
00ba0acf
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
73 deletions
+122
-73
core/utils.js
core/utils.js
+22
-0
tests/jsunit/blockly_test.js
tests/jsunit/blockly_test.js
+4
-73
tests/jsunit/connection_test.js
tests/jsunit/connection_test.js
+95
-0
tests/jsunit/index.html
tests/jsunit/index.html
+1
-0
No files found.
core/utils.js
View file @
d702808f
...
...
@@ -551,3 +551,25 @@ Blockly.tokenizeInterpolation = function(message) {
}
return
tokens
;
};
/**
* Legal characters for the unique ID.
* Should be all on a US keyboard. No XML special characters or control codes.
* @private
*/
Blockly
.
CHARACTER_SOUP_
=
'
!#$%()*+,-./:;=?@[]^_`{|}~
'
+
'
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
'
;
/**
* Generate a unique ID. This should be globally unique.
* 88 characters ^ 20 length ≈ 129 bits (one bit better than a UUID).
* @return {string}
*/
Blockly
.
genUid
=
function
()
{
var
id
=
[];
for
(
var
i
=
0
;
i
<
20
;
i
++
)
{
id
[
i
]
=
Blockly
.
CHARACTER_SOUP_
.
charAt
(
Math
.
random
()
*
Blockly
.
CHARACTER_SOUP_
.
length
);
}
return
id
.
join
(
''
);
};
tests/jsunit/blockly_test.js
View file @
d702808f
...
...
@@ -19,79 +19,10 @@
*/
'
use strict
'
;
function
verify_DB_
(
msg
,
expected
,
db
)
{
var
equal
=
(
expected
.
length
==
db
.
length
);
if
(
equal
)
{
for
(
var
x
=
0
;
x
<
expected
.
length
;
x
++
)
{
if
(
expected
[
x
]
!=
db
[
x
])
{
equal
=
false
;
break
;
}
}
}
if
(
equal
)
{
assertTrue
(
msg
,
true
);
}
else
{
assertEquals
(
msg
,
expected
,
db
);
}
}
function
test_DB_addConnection
()
{
var
db
=
new
Blockly
.
ConnectionDB
();
var
o2
=
{
y_
:
2
,
sourceBlock_
:
{}};
db
.
addConnection_
(
o2
);
verify_DB_
(
'
Adding connection #2
'
,
[
o2
],
db
);
var
o4
=
{
y_
:
4
,
sourceBlock_
:
{}};
db
.
addConnection_
(
o4
);
verify_DB_
(
'
Adding connection #4
'
,
[
o2
,
o4
],
db
);
var
o1
=
{
y_
:
1
,
sourceBlock_
:
{}};
db
.
addConnection_
(
o1
);
verify_DB_
(
'
Adding connection #1
'
,
[
o1
,
o2
,
o4
],
db
);
var
o3a
=
{
y_
:
3
,
sourceBlock_
:
{}};
db
.
addConnection_
(
o3a
);
verify_DB_
(
'
Adding connection #3a
'
,
[
o1
,
o2
,
o3a
,
o4
],
db
);
var
o3b
=
{
y_
:
3
,
sourceBlock_
:
{}};
db
.
addConnection_
(
o3b
);
verify_DB_
(
'
Adding connection #3b
'
,
[
o1
,
o2
,
o3b
,
o3a
,
o4
],
db
);
}
function
test_DB_removeConnection
()
{
var
db
=
new
Blockly
.
ConnectionDB
();
var
o1
=
{
y_
:
1
,
sourceBlock_
:
{}};
var
o2
=
{
y_
:
2
,
sourceBlock_
:
{}};
var
o3a
=
{
y_
:
3
,
sourceBlock_
:
{}};
var
o3b
=
{
y_
:
3
,
sourceBlock_
:
{}};
var
o3c
=
{
y_
:
3
,
sourceBlock_
:
{}};
var
o4
=
{
y_
:
4
,
sourceBlock_
:
{}};
db
.
addConnection_
(
o1
);
db
.
addConnection_
(
o2
);
db
.
addConnection_
(
o3c
);
db
.
addConnection_
(
o3b
);
db
.
addConnection_
(
o3a
);
db
.
addConnection_
(
o4
);
verify_DB_
(
'
Adding connections 1-4
'
,
[
o1
,
o2
,
o3a
,
o3b
,
o3c
,
o4
],
db
);
db
.
removeConnection_
(
o2
);
verify_DB_
(
'
Removing connection #2
'
,
[
o1
,
o3a
,
o3b
,
o3c
,
o4
],
db
);
db
.
removeConnection_
(
o4
);
verify_DB_
(
'
Removing connection #4
'
,
[
o1
,
o3a
,
o3b
,
o3c
],
db
);
db
.
removeConnection_
(
o1
);
verify_DB_
(
'
Removing connection #1
'
,
[
o3a
,
o3b
,
o3c
],
db
);
db
.
removeConnection_
(
o3a
);
verify_DB_
(
'
Removing connection #3a
'
,
[
o3b
,
o3c
],
db
);
db
.
removeConnection_
(
o3c
);
verify_DB_
(
'
Removing connection #3c
'
,
[
o3b
],
db
);
db
.
removeConnection_
(
o3b
);
verify_DB_
(
'
Removing connection #3b
'
,
[],
db
);
function
test_genUid
()
{
var
a
=
Blockly
.
genUid
();
var
b
=
Blockly
.
genUid
();
assertFalse
(
'
UUID different
'
,
a
==
b
);
}
function
test_addClass
()
{
...
...
tests/jsunit/connection_test.js
0 → 100644
View file @
d702808f
/**
* @license
* Blockly Tests
*
* Copyright 2015 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'
use strict
'
;
function
verify_DB_
(
msg
,
expected
,
db
)
{
var
equal
=
(
expected
.
length
==
db
.
length
);
if
(
equal
)
{
for
(
var
x
=
0
;
x
<
expected
.
length
;
x
++
)
{
if
(
expected
[
x
]
!=
db
[
x
])
{
equal
=
false
;
break
;
}
}
}
if
(
equal
)
{
assertTrue
(
msg
,
true
);
}
else
{
assertEquals
(
msg
,
expected
,
db
);
}
}
function
test_DB_addConnection
()
{
var
db
=
new
Blockly
.
ConnectionDB
();
var
o2
=
{
y_
:
2
,
sourceBlock_
:
{}};
db
.
addConnection_
(
o2
);
verify_DB_
(
'
Adding connection #2
'
,
[
o2
],
db
);
var
o4
=
{
y_
:
4
,
sourceBlock_
:
{}};
db
.
addConnection_
(
o4
);
verify_DB_
(
'
Adding connection #4
'
,
[
o2
,
o4
],
db
);
var
o1
=
{
y_
:
1
,
sourceBlock_
:
{}};
db
.
addConnection_
(
o1
);
verify_DB_
(
'
Adding connection #1
'
,
[
o1
,
o2
,
o4
],
db
);
var
o3a
=
{
y_
:
3
,
sourceBlock_
:
{}};
db
.
addConnection_
(
o3a
);
verify_DB_
(
'
Adding connection #3a
'
,
[
o1
,
o2
,
o3a
,
o4
],
db
);
var
o3b
=
{
y_
:
3
,
sourceBlock_
:
{}};
db
.
addConnection_
(
o3b
);
verify_DB_
(
'
Adding connection #3b
'
,
[
o1
,
o2
,
o3b
,
o3a
,
o4
],
db
);
}
function
test_DB_removeConnection
()
{
var
db
=
new
Blockly
.
ConnectionDB
();
var
o1
=
{
y_
:
1
,
sourceBlock_
:
{}};
var
o2
=
{
y_
:
2
,
sourceBlock_
:
{}};
var
o3a
=
{
y_
:
3
,
sourceBlock_
:
{}};
var
o3b
=
{
y_
:
3
,
sourceBlock_
:
{}};
var
o3c
=
{
y_
:
3
,
sourceBlock_
:
{}};
var
o4
=
{
y_
:
4
,
sourceBlock_
:
{}};
db
.
addConnection_
(
o1
);
db
.
addConnection_
(
o2
);
db
.
addConnection_
(
o3c
);
db
.
addConnection_
(
o3b
);
db
.
addConnection_
(
o3a
);
db
.
addConnection_
(
o4
);
verify_DB_
(
'
Adding connections 1-4
'
,
[
o1
,
o2
,
o3a
,
o3b
,
o3c
,
o4
],
db
);
db
.
removeConnection_
(
o2
);
verify_DB_
(
'
Removing connection #2
'
,
[
o1
,
o3a
,
o3b
,
o3c
,
o4
],
db
);
db
.
removeConnection_
(
o4
);
verify_DB_
(
'
Removing connection #4
'
,
[
o1
,
o3a
,
o3b
,
o3c
],
db
);
db
.
removeConnection_
(
o1
);
verify_DB_
(
'
Removing connection #1
'
,
[
o3a
,
o3b
,
o3c
],
db
);
db
.
removeConnection_
(
o3a
);
verify_DB_
(
'
Removing connection #3a
'
,
[
o3b
,
o3c
],
db
);
db
.
removeConnection_
(
o3c
);
verify_DB_
(
'
Removing connection #3c
'
,
[
o3b
],
db
);
db
.
removeConnection_
(
o3b
);
verify_DB_
(
'
Removing connection #3b
'
,
[],
db
);
}
tests/jsunit/index.html
View file @
d702808f
...
...
@@ -8,6 +8,7 @@
</head>
<body>
<script
src=
"blockly_test.js"
></script>
<script
src=
"connection_test.js"
></script>
<script
src=
"generator_test.js"
></script>
<script
src=
"names_test.js"
></script>
<script
src=
"workspace_test.js"
></script>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment