11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciconst b = Buffer.alloc(1, 'a');
71cb0ef41Sopenharmony_ciconst c = Buffer.alloc(1, 'c');
81cb0ef41Sopenharmony_ciconst d = Buffer.alloc(2, 'aa');
91cb0ef41Sopenharmony_ciconst e = new Uint8Array([ 0x61, 0x61 ]); // ASCII 'aa', same as d
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciassert.strictEqual(b.compare(c), -1);
121cb0ef41Sopenharmony_ciassert.strictEqual(c.compare(d), 1);
131cb0ef41Sopenharmony_ciassert.strictEqual(d.compare(b), 1);
141cb0ef41Sopenharmony_ciassert.strictEqual(d.compare(e), 0);
151cb0ef41Sopenharmony_ciassert.strictEqual(b.compare(d), -1);
161cb0ef41Sopenharmony_ciassert.strictEqual(b.compare(b), 0);
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciassert.strictEqual(Buffer.compare(b, c), -1);
191cb0ef41Sopenharmony_ciassert.strictEqual(Buffer.compare(c, d), 1);
201cb0ef41Sopenharmony_ciassert.strictEqual(Buffer.compare(d, b), 1);
211cb0ef41Sopenharmony_ciassert.strictEqual(Buffer.compare(b, d), -1);
221cb0ef41Sopenharmony_ciassert.strictEqual(Buffer.compare(c, c), 0);
231cb0ef41Sopenharmony_ciassert.strictEqual(Buffer.compare(e, e), 0);
241cb0ef41Sopenharmony_ciassert.strictEqual(Buffer.compare(d, e), 0);
251cb0ef41Sopenharmony_ciassert.strictEqual(Buffer.compare(d, b), 1);
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ciassert.strictEqual(Buffer.compare(Buffer.alloc(0), Buffer.alloc(0)), 0);
281cb0ef41Sopenharmony_ciassert.strictEqual(Buffer.compare(Buffer.alloc(0), Buffer.alloc(1)), -1);
291cb0ef41Sopenharmony_ciassert.strictEqual(Buffer.compare(Buffer.alloc(1), Buffer.alloc(0)), 1);
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciassert.throws(() => Buffer.compare(Buffer.alloc(1), 'abc'), {
321cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_ARG_TYPE',
331cb0ef41Sopenharmony_ci  message: 'The "buf2" argument must be an instance of Buffer or Uint8Array. ' +
341cb0ef41Sopenharmony_ci           "Received type string ('abc')"
351cb0ef41Sopenharmony_ci});
361cb0ef41Sopenharmony_ciassert.throws(() => Buffer.compare('abc', Buffer.alloc(1)), {
371cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_ARG_TYPE',
381cb0ef41Sopenharmony_ci  message: 'The "buf1" argument must be an instance of Buffer or Uint8Array. ' +
391cb0ef41Sopenharmony_ci           "Received type string ('abc')"
401cb0ef41Sopenharmony_ci});
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ciassert.throws(() => Buffer.alloc(1).compare('abc'), {
431cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_ARG_TYPE',
441cb0ef41Sopenharmony_ci  name: 'TypeError',
451cb0ef41Sopenharmony_ci  message: 'The "target" argument must be an instance of ' +
461cb0ef41Sopenharmony_ci           "Buffer or Uint8Array. Received type string ('abc')"
471cb0ef41Sopenharmony_ci});
48