summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-06-11 21:30:58 +0200
committerRyan Dahl <ry@tinyclouds.org>2018-06-11 21:33:58 +0200
commit314f08672157a0977d7c3eeb72010eb0f717d889 (patch)
tree3af048bc57343712a3037c84a6a47d499f1cf985
parent56c3ac464eb5f9287b9bae0dad4dfabfb3534a1c (diff)
Better function names in mock_runtime.js
-rw-r--r--deno2/js/mock_runtime.js31
-rw-r--r--deno2/mock_runtime_test.cc13
2 files changed, 26 insertions, 18 deletions
diff --git a/deno2/js/mock_runtime.js b/deno2/js/mock_runtime.js
index 97688a08d..538174f79 100644
--- a/deno2/js/mock_runtime.js
+++ b/deno2/js/mock_runtime.js
@@ -1,27 +1,34 @@
// A simple runtime that doesn't involve typescript or protobufs to test
-// libdeno.
+// libdeno. Invoked by mock_runtime_test.cc
const window = eval("this");
-window["foo"] = () => {
- deno_print("Hello world from foo");
- return "foo";
-};
function assert(cond) {
if (!cond) throw Error("mock_runtime.js assert failed");
}
-function subabc() {
+function typedArrayToArrayBuffer(ta) {
+ return ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength);
+}
+
+function CanCallFunction() {
+ deno_print("Hello world from foo");
+ return "foo";
+}
+
+function PubSuccess() {
deno_sub(msg => {
- assert(msg instanceof ArrayBuffer);
- assert(msg.byteLength === 3);
+ deno_print("PubSuccess: ok");
});
}
-function typedArrayToArrayBuffer(ta) {
- return ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength);
+function PubByteLength() {
+ deno_sub(msg => {
+ assert(msg instanceof ArrayBuffer);
+ assert(msg.byteLength === 3);
+ });
}
-function pubReturnEmpty() {
+function SubReturnEmpty() {
const ui8 = new Uint8Array("abc".split("").map(c => c.charCodeAt(0)));
const ab = typedArrayToArrayBuffer(ui8);
let r = deno_pub(ab);
@@ -30,7 +37,7 @@ function pubReturnEmpty() {
assert(r == null);
}
-function pubReturnBar() {
+function SubReturnBar() {
const ui8 = new Uint8Array("abc".split("").map(c => c.charCodeAt(0)));
const ab = typedArrayToArrayBuffer(ui8);
const r = deno_pub(ab);
diff --git a/deno2/mock_runtime_test.cc b/deno2/mock_runtime_test.cc
index 0b2966b69..14f78f6e8 100644
--- a/deno2/mock_runtime_test.cc
+++ b/deno2/mock_runtime_test.cc
@@ -10,9 +10,10 @@ TEST(MockRuntimeTest, InitializesCorrectly) {
deno_dispose(d);
}
-TEST(MockRuntimeTest, CanCallFoo) {
+TEST(MockRuntimeTest, CanCallFunction) {
Deno* d = deno_new(NULL, NULL);
- EXPECT_TRUE(deno_execute(d, "a.js", "if (foo() != 'foo') throw Error();"));
+ EXPECT_TRUE(deno_execute(d, "a.js",
+ "if (CanCallFunction() != 'foo') throw Error();"));
deno_dispose(d);
}
@@ -29,14 +30,14 @@ deno_buf strbuf(const char* str) {
TEST(MockRuntimeTest, PubSuccess) {
Deno* d = deno_new(NULL, NULL);
- EXPECT_TRUE(deno_execute(d, "a.js", "subabc();"));
+ EXPECT_TRUE(deno_execute(d, "a.js", "PubSuccess()"));
EXPECT_TRUE(deno_pub(d, strbuf("abc")));
deno_dispose(d);
}
TEST(MockRuntimeTest, PubByteLength) {
Deno* d = deno_new(NULL, NULL);
- EXPECT_TRUE(deno_execute(d, "a.js", "subabc();"));
+ EXPECT_TRUE(deno_execute(d, "a.js", "PubByteLength()"));
// We pub the wrong sized message, it should throw.
EXPECT_FALSE(deno_pub(d, strbuf("abcd")));
deno_dispose(d);
@@ -61,7 +62,7 @@ TEST(MockRuntimeTest, SubReturnEmpty) {
EXPECT_EQ(data[2], 'c');
return deno_buf{nullptr, 0};
});
- EXPECT_TRUE(deno_execute(d, "a.js", "pubReturnEmpty()"));
+ EXPECT_TRUE(deno_execute(d, "a.js", "SubReturnEmpty()"));
EXPECT_EQ(count, 2);
deno_dispose(d);
}
@@ -78,7 +79,7 @@ TEST(MockRuntimeTest, SubReturnBar) {
EXPECT_EQ(data[2], 'c');
return strbuf("bar");
});
- EXPECT_TRUE(deno_execute(d, "a.js", "pubReturnBar()"));
+ EXPECT_TRUE(deno_execute(d, "a.js", "SubReturnBar()"));
EXPECT_EQ(count, 1);
deno_dispose(d);
}