From 856dd493d0f3ca79074fda2c9b191a9773cecd25 Mon Sep 17 00:00:00 2001 From: Richard Tingstad Date: Fri, 24 Oct 2025 13:44:40 +0200 Subject: [PATCH] add ,unicode --- bin/,unicode | 15 +++++++++++++++ test/test.sh | 1 + test/test_bin.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100755 bin/,unicode create mode 100755 test/test_bin.sh diff --git a/bin/,unicode b/bin/,unicode new file mode 100755 index 0000000..849a4a7 --- /dev/null +++ b/bin/,unicode @@ -0,0 +1,15 @@ +#!/bin/sh +set -e + +[ $# -eq 0 ] || data="$*" + +set -- \ +node -e 'for (let c of require("fs").readFileSync(0, "utf-8")) + console.log(c.codePointAt(0).toString(16), c);' + +if [ -z "$data" ]; then + "$@" +else + printf %s "$data" | "$@" +fi + diff --git a/test/test.sh b/test/test.sh index b5c3341..e480575 100755 --- a/test/test.sh +++ b/test/test.sh @@ -14,6 +14,7 @@ bash "$DIR/photosort/photosort-test.sh" source "$DIR/test_add_aliases.sh" source "$DIR/test_link_dotfiles.sh" source "$DIR/test_gitlog.sh" +source "$DIR/test_bin.sh" testCapture() { assertEquals 'hello, world!' \ diff --git a/test/test_bin.sh b/test/test_bin.sh new file mode 100755 index 0000000..c460b51 --- /dev/null +++ b/test/test_bin.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +set -o errexit + +TESTMODE="on" + +if [ -z "$DIR" ]; then + src=$(echo "${BASH_SOURCE[0]}" | grep . || echo "$0") + DIR=$(dirname -- "$src") + DIR=$(cd -- "$DIR"; pwd) +fi + +bin=$(cd -- "$DIR"; cd ../bin/; pwd) +export PATH="$PATH:$bin" + +testUnicode() { + assertEquals \ +'2190 ← +2192 →' \ + "$(,unicode ←→)" + + expected=$(printf '1f1e6\n1f1f4') # A O + assertEquals "$expected" \ + "$(printf %s '🇦🇴' | ,unicode | awk '{ print $1 }')" +} + +return 2>/dev/null || true + +set +o errexit +source "$DIR/shunit2.sh" +