Skip to content

Commit

Permalink
more string utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adrums86 committed Jan 24, 2023
1 parent e92f776 commit da67712
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/utils.string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ QUnit.test('Converts a uint8 array into a C string from start of array until fir
assert.equal(secondString, 'value.bar\0', 'converts uint8 data to a c string');
assert.equal(secondString.length, 10, 'string has the correct length');
});

QUnit.test('Converts a uint8 array with no null char into a C string', function(assert) {
var uint8String = new Uint8Array([0x66, 0x6F, 0x6F, 0x2E, 0x62, 0x61, 0x72]); // foo.bar
var firstString = string.uint8ToCString(uint8String);
assert.equal(firstString, 'foo.bar\0', 'converts uint8 data to a c string');
assert.equal(firstString.length, 8, 'string has the correct length');
});

QUnit.test('Returns a null char from a uint8 array starting with a null char', function(assert) {
var uint8String = new Uint8Array([0x00, 0x66, 0x6F, 0x6F, 0x2E, 0x62, 0x61, 0x72]); // \0foo.bar
var firstString = string.uint8ToCString(uint8String);
assert.equal(firstString, '\0', 'converts uint8 data to a c string');
assert.equal(firstString.length, 1, 'string has the correct length');
});

0 comments on commit da67712

Please sign in to comment.