Add missing .clang-format, and fix some spaces that slipped through.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4856 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-02-17 19:22:02 +00:00
parent 1958623a7a
commit d0e11bc68b
23 changed files with 583 additions and 597 deletions

View File

@ -61,24 +61,24 @@ static void _test_nop(const tf_test_options_t* options)
static void _test_sandbox(const tf_test_options_t* options)
{
_write_file("out/test.js",
"var task = new Task();\n"
"task.onExit = function(code, signal) {\n"
" print('child exited', code, signal);\n"
" if (code === 0 && signal === 0) {\n"
" exit(1);\n"
" }\n"
"};\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
" print('child started');\n"
" });\n"
"});");
"var task = new Task();\n"
"task.onExit = function(code, signal) {\n"
" print('child exited', code, signal);\n"
" if (code === 0 && signal === 0) {\n"
" exit(1);\n"
" }\n"
"};\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
" print('child started');\n"
" });\n"
"});");
_write_file("out/child.js",
"print('Poking the sandbox. This should fail.');\n"
"let r = pokeSandbox();\n"
"exit(r);\n");
"print('Poking the sandbox. This should fail.');\n"
"let r = pokeSandbox();\n"
"exit(r);\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -95,21 +95,21 @@ static void _test_sandbox(const tf_test_options_t* options)
static void _test_child(const tf_test_options_t* options)
{
_write_file("out/test.js",
"var task = new Task();\n"
"task.onExit = function(code, signal) {\n"
" print('child exited', code, signal);\n"
" exit(code || signal);\n"
"};\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
" print('child started');\n"
" });\n"
"});");
"var task = new Task();\n"
"task.onExit = function(code, signal) {\n"
" print('child exited', code, signal);\n"
" exit(code || signal);\n"
"};\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
" print('child started');\n"
" });\n"
"});");
_write_file("out/child.js",
"print('I am the child process.');\n"
"exit(0);\n");
"print('I am the child process.');\n"
"exit(0);\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -126,28 +126,28 @@ static void _test_child(const tf_test_options_t* options)
static void _test_promise(const tf_test_options_t* options)
{
_write_file("out/test.js",
"var task = new Task();\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
" task.getExports().then(function(exports) {\n"
" return exports.add(1, 1);\n"
" }).then(function(sum) {\n"
" if (sum == 2) {\n"
" exit(0);\n"
" } else {\n"
" exit(1);\n"
" }\n"
" });\n"
" });\n"
"});\n");
"var task = new Task();\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
" task.getExports().then(function(exports) {\n"
" return exports.add(1, 1);\n"
" }).then(function(sum) {\n"
" if (sum == 2) {\n"
" exit(0);\n"
" } else {\n"
" exit(1);\n"
" }\n"
" });\n"
" });\n"
"});\n");
_write_file("out/child.js",
"exports = {\n"
" add: function(left, right) {\n"
" return left + right;\n"
" }\n"
"}\n");
"exports = {\n"
" add: function(left, right) {\n"
" return left + right;\n"
" }\n"
"}\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -164,32 +164,32 @@ static void _test_promise(const tf_test_options_t* options)
static void _test_promise_remote_throw(const tf_test_options_t* options)
{
_write_file("out/test.js",
"var task = new Task();\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
" task.getExports().then(function(exp) {\n"
" return exp.add(1, 1);\n"
" }).then(function(sum) {\n"
" exit(1);\n"
" }).catch(function(error) {\n"
" print('Caught: ' + error.message);\n"
" if (error.stack) {\n"
" print('stack: ' + error.stack);\n"
" }\n"
" exit(0);\n"
" });\n"
" }).catch(function(e) {\n"
" print('caught', e.message);\n"
" });\n"
"});\n");
"var task = new Task();\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
" task.getExports().then(function(exp) {\n"
" return exp.add(1, 1);\n"
" }).then(function(sum) {\n"
" exit(1);\n"
" }).catch(function(error) {\n"
" print('Caught: ' + error.message);\n"
" if (error.stack) {\n"
" print('stack: ' + error.stack);\n"
" }\n"
" exit(0);\n"
" });\n"
" }).catch(function(e) {\n"
" print('caught', e.message);\n"
" });\n"
"});\n");
_write_file("out/child.js",
"exports = {\n"
" add: function(left, right) {\n"
" throw new Error('fail');\n"
" }\n"
"}\n");
"exports = {\n"
" add: function(left, right) {\n"
" throw new Error('fail');\n"
" }\n"
"}\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -206,34 +206,34 @@ static void _test_promise_remote_throw(const tf_test_options_t* options)
static void _test_promise_remote_reject(const tf_test_options_t* options)
{
_write_file("out/test.js",
"var task = new Task();\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
" task.getExports().then(function(exp) {\n"
" return exp.add(1, 1);\n"
" }).then(function(sum) {\n"
" exit(1);\n"
" }).catch(function(error) {\n"
" print('Caught: ' + error.message);\n"
" if (error.stack) {\n"
" print('stack: ' + error.stack);\n"
" }\n"
" exit(0);\n"
" });\n"
" }).catch(function(e) {\n"
" print('caught', e.message);\n"
" });\n"
"});\n");
"var task = new Task();\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
" task.getExports().then(function(exp) {\n"
" return exp.add(1, 1);\n"
" }).then(function(sum) {\n"
" exit(1);\n"
" }).catch(function(error) {\n"
" print('Caught: ' + error.message);\n"
" if (error.stack) {\n"
" print('stack: ' + error.stack);\n"
" }\n"
" exit(0);\n"
" });\n"
" }).catch(function(e) {\n"
" print('caught', e.message);\n"
" });\n"
"});\n");
_write_file("out/child.js",
"exports = {\n"
" add: function(left, right) {\n"
" return new Promise(function(resolve, reject) {\n"
" reject(new Error('oops'));\n"
" });\n"
" }\n"
"}\n");
"exports = {\n"
" add: function(left, right) {\n"
" return new Promise(function(resolve, reject) {\n"
" reject(new Error('oops'));\n"
" });\n"
" }\n"
"}\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -250,32 +250,32 @@ static void _test_promise_remote_reject(const tf_test_options_t* options)
static void _test_database(const tf_test_options_t* options)
{
_write_file("out/test.js",
"var db = new Database('testdb');\n"
"if (db.get('a')) {\n"
" exit(1);\n"
"}\n"
"db.set('a', 1);\n"
"if (db.get('a') != 1) {\n"
" exit(2);\n"
"}\n"
"db.set('b', 2);\n"
"db.set('c', 3);\n"
"\n"
"var expected = ['a', 'b', 'c'];\n"
"var have = db.getAll();\n"
"for (var i = 0; i < have.length; i++) {\n"
" var item = have[i];\n"
" if (expected.indexOf(item) == -1) {\n"
" print('Did not find ' + item + ' in db.');\n"
" exit(3);\n"
" } else {\n"
" expected.splice(expected.indexOf(item), 1);\n"
" }\n"
"}\n"
"if (expected.length) {\n"
" print('Expected but did not find: ' + JSON.stringify(expected));\n"
" exit(4);\n"
"}\n");
"var db = new Database('testdb');\n"
"if (db.get('a')) {\n"
" exit(1);\n"
"}\n"
"db.set('a', 1);\n"
"if (db.get('a') != 1) {\n"
" exit(2);\n"
"}\n"
"db.set('b', 2);\n"
"db.set('c', 3);\n"
"\n"
"var expected = ['a', 'b', 'c'];\n"
"var have = db.getAll();\n"
"for (var i = 0; i < have.length; i++) {\n"
" var item = have[i];\n"
" if (expected.indexOf(item) == -1) {\n"
" print('Did not find ' + item + ' in db.');\n"
" exit(3);\n"
" } else {\n"
" expected.splice(expected.indexOf(item), 1);\n"
" }\n"
"}\n"
"if (expected.length) {\n"
" print('Expected but did not find: ' + JSON.stringify(expected));\n"
" exit(4);\n"
"}\n");
char command[256];
unlink("out/test_db0.sqlite");
@ -293,9 +293,9 @@ static void _test_database(const tf_test_options_t* options)
static void _test_this(const tf_test_options_t* options)
{
_write_file("out/test.js",
"var task = new Task();\n"
"task.activate.bind(null).apply();\n"
"exit(0);\n");
"var task = new Task();\n"
"task.activate.bind(null).apply();\n"
"exit(0);\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -311,21 +311,21 @@ static void _test_this(const tf_test_options_t* options)
static void _test_await(const tf_test_options_t* options)
{
_write_file("out/test.js",
"print('hi');\n"
"function foobar() {\n"
" return new Promise(function(resolve, reject) {\n"
" resolve(10);\n"
" });\n"
"}\n"
"\n"
"async function huh() {\n"
" let v = await foobar();\n"
" print('v => ' + v);\n"
" if (v != 10) {\n"
" throw new Error('nope');\n"
" }\n"
"}\n"
"\n");
"print('hi');\n"
"function foobar() {\n"
" return new Promise(function(resolve, reject) {\n"
" resolve(10);\n"
" });\n"
"}\n"
"\n"
"async function huh() {\n"
" let v = await foobar();\n"
" print('v => ' + v);\n"
" if (v != 10) {\n"
" throw new Error('nope');\n"
" }\n"
"}\n"
"\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -341,21 +341,21 @@ static void _test_await(const tf_test_options_t* options)
static void _test_import(const tf_test_options_t* options)
{
_write_file("out/test.js",
"import * as req from './required.js';\n"
"if (req.foo() != 12345) {\n"
" exit(1);\n"
"}\n");
"import * as req from './required.js';\n"
"if (req.foo() != 12345) {\n"
" exit(1);\n"
"}\n");
_write_file("out/required.js",
"export function foo() {\n"
" return 12345;\n"
"}\n");
"export function foo() {\n"
" return 12345;\n"
"}\n");
_write_file("out/bad.js",
"import * as req from './missing.js';\n"
"if (req.foo() != 12345) {\n"
" exit(1);\n"
"}\n");
"import * as req from './missing.js';\n"
"if (req.foo() != 12345) {\n"
" exit(1);\n"
"}\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -397,8 +397,8 @@ static void _test_exit(const tf_test_options_t* options)
static void _test_icu(const tf_test_options_t* options)
{
_write_file("out/test.js",
"print('Hi');\n"
"print(parseInt('3').toLocaleString());\n");
"print('Hi');\n"
"print(parseInt('3').toLocaleString());\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -414,39 +414,39 @@ static void _test_icu(const tf_test_options_t* options)
static void _test_uint8array(const tf_test_options_t* options)
{
_write_file("out/test.js",
"var task = new Task();\n"
"task.onExit = function() {\n"
" print('child exited');\n"
"};\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(async function() {\n"
" print('child started');\n"
" var input = new Uint8Array(10);\n"
" for (var i = 0; i < 10; i++) {\n"
" input[i] = i;\n"
" }\n"
" var test = (await task.getExports()).test;\n"
" var output = new Uint8Array(await test(input));\n"
" print('input', input, input.length, input.byteLength);\n"
" print('output', output, output.length, output.byteLength);\n"
" for (var i = 0; i < 10; i++) {\n"
" print(output[i]);\n"
" if (output[i] != i) {\n"
" print('output[' + i + '] == ' + output[i]);\n"
" exit(1);\n"
" }\n"
" }\n"
" exit(0);\n"
" })\n"
"})\n");
"var task = new Task();\n"
"task.onExit = function() {\n"
" print('child exited');\n"
"};\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(async function() {\n"
" print('child started');\n"
" var input = new Uint8Array(10);\n"
" for (var i = 0; i < 10; i++) {\n"
" input[i] = i;\n"
" }\n"
" var test = (await task.getExports()).test;\n"
" var output = new Uint8Array(await test(input));\n"
" print('input', input, input.length, input.byteLength);\n"
" print('output', output, output.length, output.byteLength);\n"
" for (var i = 0; i < 10; i++) {\n"
" print(output[i]);\n"
" if (output[i] != i) {\n"
" print('output[' + i + '] == ' + output[i]);\n"
" exit(1);\n"
" }\n"
" }\n"
" exit(0);\n"
" })\n"
"})\n");
_write_file("out/child.js",
"exports = {\n"
" test: function(data) {\n"
" return data;\n"
" }\n"
"}\n");
"exports = {\n"
" test: function(data) {\n"
" return data;\n"
" }\n"
"}\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -463,31 +463,31 @@ static void _test_uint8array(const tf_test_options_t* options)
static void _test_float(const tf_test_options_t* options)
{
_write_file("out/test.js",
"var task = new Task();\n"
"task.onExit = function() {\n"
" print('child exited');\n"
"};\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(async function() {\n"
" print('get exports');\n"
" let test = (await task.getExports()).test;\n"
" print('calling export');\n"
" let result = await test(1.2);\n"
" print(result);\n"
" exit(result == 1.2 ? 0 : 1);\n"
" });\n"
"});");
"var task = new Task();\n"
"task.onExit = function() {\n"
" print('child exited');\n"
"};\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(async function() {\n"
" print('get exports');\n"
" let test = (await task.getExports()).test;\n"
" print('calling export');\n"
" let result = await test(1.2);\n"
" print(result);\n"
" exit(result == 1.2 ? 0 : 1);\n"
" });\n"
"});");
_write_file("out/child.js",
"print(\"child\");\n"
"exports = {\n"
" test: function(value) {\n"
" print(value);\n"
" return value;\n"
" }\n"
"};\n"
"print(\"child ready\");\n");
"print(\"child\");\n"
"exports = {\n"
" test: function(value) {\n"
" print(value);\n"
" return value;\n"
" }\n"
"};\n"
"print(\"child ready\");\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -504,77 +504,77 @@ static void _test_float(const tf_test_options_t* options)
static void _test_socket(const tf_test_options_t* options)
{
_write_file("out/test.js",
"'use strict';\n"
"\n"
"var s = new Socket();\n"
"print('connecting');\n"
"print('before connect', s.isConnected);\n"
"s.onError(function(e) {\n"
" print(e);\n"
"});\n"
"print('noDelay', s.noDelay);\n"
"s.noDelay = true;\n"
"s.connect('www.unprompted.com', 80).then(function() {\n"
" print('connected', 'www.unprompted.com', 80, s.isConnected);\n"
" print(s.peerName);\n"
" s.read(function(data) {\n"
" print('read', data ? data.length : null);\n"
" });\n"
" s.write('GET / HTTP/1.0\\r\\n\\r\\n');\n"
"}).then(function(e) {\n"
" print('closed 1');\n"
"});\n"
"\n"
"var s2 = new Socket();\n"
"print('connecting');\n"
"print('before connect', s2.isConnected);\n"
"s2.onError(function(e) {\n"
" print('error');\n"
" print(e);\n"
"});\n"
"print('noDelay', s2.noDelay);\n"
"s2.noDelay = true;\n"
"s2.connect('www.unprompted.com', 443).then(function() {\n"
" print('connected', 'www.unprompted.com', 443);\n"
" s2.read(function(data) {\n"
" print('read', data ? data.length : null);\n"
" });\n"
" return s2.startTls();\n"
"}).then(function() {\n"
" print('ready');\n"
" print(s2.peerName);\n"
" s2.write('GET / HTTP/1.0\\r\\nConnection: close\\r\\n\\r\\n').then(function() {\n"
" s2.shutdown();\n"
" });\n"
"}).catch(function(e) {\n"
" print('caught');\n"
" print(e);\n"
"});\n"
"var s3 = new Socket();\n"
"print('connecting s3');\n"
"print('before connect', s3.isConnected);\n"
"s3.onError(function(e) {\n"
" print('error');\n"
" print(e);\n"
"});\n"
"print('noDelay', s3.noDelay);\n"
"s3.noDelay = true;\n"
"s3.connect('0.0.0.0', 443).then(function() {\n"
" print('connected', '0.0.0.0', 443);\n"
" s3.read(function(data) {\n"
" print('read', data ? data.length : null);\n"
" });\n"
" return s3.startTls();\n"
"}).then(function() {\n"
" print('ready');\n"
" print(s3.peerName);\n"
" s3.write('GET / HTTP/1.0\\r\\nConnection: close\\r\\n\\r\\n').then(function() {\n"
" s3.shutdown();\n"
" });\n"
"}).catch(function(e) {\n"
" print('caught');\n"
" print(e);\n"
"});\n");
"'use strict';\n"
"\n"
"var s = new Socket();\n"
"print('connecting');\n"
"print('before connect', s.isConnected);\n"
"s.onError(function(e) {\n"
" print(e);\n"
"});\n"
"print('noDelay', s.noDelay);\n"
"s.noDelay = true;\n"
"s.connect('www.unprompted.com', 80).then(function() {\n"
" print('connected', 'www.unprompted.com', 80, s.isConnected);\n"
" print(s.peerName);\n"
" s.read(function(data) {\n"
" print('read', data ? data.length : null);\n"
" });\n"
" s.write('GET / HTTP/1.0\\r\\n\\r\\n');\n"
"}).then(function(e) {\n"
" print('closed 1');\n"
"});\n"
"\n"
"var s2 = new Socket();\n"
"print('connecting');\n"
"print('before connect', s2.isConnected);\n"
"s2.onError(function(e) {\n"
" print('error');\n"
" print(e);\n"
"});\n"
"print('noDelay', s2.noDelay);\n"
"s2.noDelay = true;\n"
"s2.connect('www.unprompted.com', 443).then(function() {\n"
" print('connected', 'www.unprompted.com', 443);\n"
" s2.read(function(data) {\n"
" print('read', data ? data.length : null);\n"
" });\n"
" return s2.startTls();\n"
"}).then(function() {\n"
" print('ready');\n"
" print(s2.peerName);\n"
" s2.write('GET / HTTP/1.0\\r\\nConnection: close\\r\\n\\r\\n').then(function() {\n"
" s2.shutdown();\n"
" });\n"
"}).catch(function(e) {\n"
" print('caught');\n"
" print(e);\n"
"});\n"
"var s3 = new Socket();\n"
"print('connecting s3');\n"
"print('before connect', s3.isConnected);\n"
"s3.onError(function(e) {\n"
" print('error');\n"
" print(e);\n"
"});\n"
"print('noDelay', s3.noDelay);\n"
"s3.noDelay = true;\n"
"s3.connect('0.0.0.0', 443).then(function() {\n"
" print('connected', '0.0.0.0', 443);\n"
" s3.read(function(data) {\n"
" print('read', data ? data.length : null);\n"
" });\n"
" return s3.startTls();\n"
"}).then(function() {\n"
" print('ready');\n"
" print(s3.peerName);\n"
" s3.write('GET / HTTP/1.0\\r\\nConnection: close\\r\\n\\r\\n').then(function() {\n"
" s3.shutdown();\n"
" });\n"
"}).catch(function(e) {\n"
" print('caught');\n"
" print(e);\n"
"});\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -590,18 +590,18 @@ static void _test_socket(const tf_test_options_t* options)
static void _test_file(const tf_test_options_t* options)
{
_write_file("out/test.js",
"'use strict';\n"
"File.readFile('out/test.js').then(function(data) {\n"
"}).catch(function(error) {\n"
" print('ERROR', error);\n"
" exit(1);\n"
"});\n"
"File.readFile('out/missing.txt').then(function(data) {\n"
" print('READ', utf8Decode(data));\n"
" exit(1);\n"
"}).catch(function(error) {\n"
" print('expected error', error);\n"
"});\n");
"'use strict';\n"
"File.readFile('out/test.js').then(function(data) {\n"
"}).catch(function(error) {\n"
" print('ERROR', error);\n"
" exit(1);\n"
"});\n"
"File.readFile('out/missing.txt').then(function(data) {\n"
" print('READ', utf8Decode(data));\n"
" exit(1);\n"
"}).catch(function(error) {\n"
" print('expected error', error);\n"
"});\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -617,20 +617,20 @@ static void _test_file(const tf_test_options_t* options)
static void _test_sign(const tf_test_options_t* options)
{
_write_file("out/test.js",
"'use strict';\n"
"let id = ssb.createIdentity('test');\n"
"print(id);\n"
"let sig = ssb.hmacsha256sign('hello', 'test', id);\n"
"print(sig);\n"
"if (!ssb.hmacsha256verify(id, 'hello', sig)) {\n"
" exit(1);\n"
"}\n"
"if (ssb.hmacsha256verify(id, 'world', sig)) {\n"
" exit(1);\n"
"}\n"
"if (ssb.hmacsha256verify(id, 'hello1', sig)) {\n"
" exit(1);\n"
"}\n");
"'use strict';\n"
"let id = ssb.createIdentity('test');\n"
"print(id);\n"
"let sig = ssb.hmacsha256sign('hello', 'test', id);\n"
"print(sig);\n"
"if (!ssb.hmacsha256verify(id, 'hello', sig)) {\n"
" exit(1);\n"
"}\n"
"if (ssb.hmacsha256verify(id, 'world', sig)) {\n"
" exit(1);\n"
"}\n"
"if (ssb.hmacsha256verify(id, 'hello1', sig)) {\n"
" exit(1);\n"
"}\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -646,13 +646,13 @@ static void _test_sign(const tf_test_options_t* options)
static void _test_b64(const tf_test_options_t* options)
{
_write_file("out/test.js",
"'use strict';\n"
"print(base64Encode('hello'));\n"
"let x = utf8Decode(base64Decode(base64Encode('hello')));\n"
"if (x !== 'hello') {\n"
" print(x);\n"
" exit(1);\n"
"}\n");
"'use strict';\n"
"print(base64Encode('hello'));\n"
"let x = utf8Decode(base64Decode(base64Encode('hello')));\n"
"if (x !== 'hello') {\n"
" print(x);\n"
" exit(1);\n"
"}\n");
char command[256];
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
@ -667,7 +667,7 @@ static void _test_b64(const tf_test_options_t* options)
static const char* k_bip39_test_key_base64 = "GO0Lv5BvcuuJJdHrokHoo0PmCDC/XjO/SZ6H+ddq4UvWd/VPW1RJrjd1aCUIfPIojFXrWMb8R54vVerU2TwjdQ==.ed25519";
static const char* k_bip32_test_key_words =
"body hair useful camp warm into cause riot two bamboo kick educate dinosaur advice seed type crisp where guilt avocado output rely lunch goddess";
"body hair useful camp warm into cause riot two bamboo kick educate dinosaur advice seed type crisp where guilt avocado output rely lunch goddess";
static void _test_bip39(const tf_test_options_t* options)
{