HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/pwa.sports-crowd.com/node_modules/encode-utf8/test.js
/* eslint-env mocha */

'use strict'

const assert = require('assert')
const encodeUtf8 = require('./')

const testCases = [
  '゚・✿ヾ╲(。◕‿◕。)╱✿・゚',
  '𝌆',
  '🐵 🙈 🙉 🙊',
  '💩',
  'åß∂ƒ©˙∆˚¬…æ',
  'Hello, World!',
  'Powerلُلُصّبُلُلصّبُررً ॣ ॣh ॣ ॣ冗',
  '𝕿𝖍𝖊 𝖖𝖚𝖎𝖈𝖐 𝖇𝖗𝖔𝖜𝖓 𝖋𝖔𝖝 𝖏𝖚𝖒𝖕𝖘 𝖔𝖛𝖊𝖗 𝖙𝖍𝖊 𝖑𝖆𝖟𝖞 𝖉𝖔𝖌',
  '사회과학원 어학연구소'
]

const badStrings = [
  {
    input: 'abc123',
    expected: [0x61, 0x62, 0x63, 0x31, 0x32, 0x33],
    name: 'Sanity check'
  },
  {
    input: '\uD800',
    expected: [0xef, 0xbf, 0xbd],
    name: 'Surrogate half (low)'
  },
  {
    input: '\uDC00',
    expected: [0xef, 0xbf, 0xbd],
    name: 'Surrogate half (high)'
  },
  {
    input: 'abc\uD800123',
    expected: [0x61, 0x62, 0x63, 0xef, 0xbf, 0xbd, 0x31, 0x32, 0x33],
    name: 'Surrogate half (low), in a string'
  },
  {
    input: 'abc\uDC00123',
    expected: [0x61, 0x62, 0x63, 0xef, 0xbf, 0xbd, 0x31, 0x32, 0x33],
    name: 'Surrogate half (high), in a string'
  },
  {
    input: '\uDC00\uD800',
    expected: [0xef, 0xbf, 0xbd, 0xef, 0xbf, 0xbd],
    name: 'Wrong order'
  }
]

describe('encode-utf8', () => {
  describe('test strings', () => {
    for (const input of testCases) {
      it(`should encode "${input}"`, () => {
        const actual = Buffer.from(encodeUtf8(input))
        const expected = Buffer.from(input, 'utf8')

        assert.ok(actual.equals(expected))
      })
    }
  })

  describe('web platform test', () => {
    for (const testCase of badStrings) {
      it(testCase.name, () => {
        const actual = Array.from(new Uint8Array(encodeUtf8(testCase.input)))

        assert.deepStrictEqual(actual, testCase.expected)
      })
    }
  })
})