-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Test Types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<head> | ||
<link rel="stylesheet" href="../sketch.css" /> | ||
</head> | ||
</head> | ||
<body> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.0.0/p5.min.js"></script> | ||
|
||
<script src="/dist/p5.party.js"></script> | ||
|
||
<script src="index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
let shared; | ||
|
||
function preload() { | ||
partyConnect( | ||
"wss://deepstream-server-1.herokuapp.com", | ||
"identity_test", | ||
"main" | ||
); | ||
shared = partyLoadShared("shared"); | ||
} | ||
|
||
function setup() { | ||
createCanvas(400, 400); | ||
|
||
if (partyIsHost()) { | ||
// supported types | ||
shared.null = null; | ||
shared.boolean = true; | ||
shared.number = 1; | ||
shared.string = "hello"; | ||
shared.array = [1, 2, 3]; | ||
shared.object = { | ||
x: 1, | ||
y: 1, | ||
}; | ||
|
||
// tricky types | ||
shared.date = new Date("January 1, 2001 01:00:00"); | ||
shared.color = color("red").toString(); | ||
shared.set = new Set([1, 2, 3]); | ||
shared.undefined = "temp"; | ||
shared.undefined = undefined; | ||
|
||
// unsupported types | ||
shared.function = () => { | ||
console.log("hello"); | ||
}; | ||
|
||
shared.symbol = Symbol("hello"); | ||
|
||
shared.infinity = Infinity; // -> null | ||
shared.nan = NaN; // -> null | ||
} | ||
console.log("A", shared); | ||
|
||
console.log(""); | ||
console.log("SUPPORTED"); | ||
test("null", shared.null, null); | ||
test("boolean", shared.boolean, true); | ||
test("number", shared.number, 1); | ||
test("string", shared.string, "hello"); | ||
test("array", shared.array, [1, 2, 3]); | ||
test("object", shared.object, { x: 1, y: 1 }); | ||
|
||
console.log(""); | ||
console.log("TRICKY"); | ||
test( | ||
"date are stringified", | ||
new Date(shared.date), | ||
new Date("January 1, 2001 01:00:00") | ||
); | ||
|
||
console.log( | ||
"colors need to be wrapped `shared.color color('red').toString()` and `color(shared.color)`" | ||
); | ||
console.log(shared.color); | ||
const c = color(shared.color); | ||
test("color", red(c), red(color("red"))); | ||
test("color", green(c), green(color("red"))); | ||
test("color", blue(c), blue(color("red"))); | ||
|
||
test("undefineds are stripped", shared.undefined, undefined); | ||
|
||
console.log(""); | ||
console.log("UNSUPPORTED"); | ||
test("functions are stripped", undefined); | ||
test("symbols are stripped", shared.symbol, undefined); | ||
test("infinity becomes null", shared.infinity, null); | ||
test("nan becomes null", shared.nan, null); | ||
} | ||
|
||
function test(name, value, expected) { | ||
if (same(value, expected)) { | ||
console.log(`%c${name} passed`, "color: green", value, expected); | ||
} else { | ||
console.log(`%c${name} failed`, "color: red", value, expected); | ||
} | ||
} | ||
|
||
function same(value, expected) { | ||
if (value === expected) { | ||
return true; | ||
} | ||
if (typeof value === "object" && typeof expected === "object") { | ||
if (Object.keys(expected).length !== Object.keys(value).length) { | ||
return false; | ||
} | ||
return Object.entries(expected).every(([k, v]) => v === value[k]); | ||
} | ||
return false; | ||
} | ||
|
||
function draw() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters