diff options
| author | Shulhan <ms@kilabit.info> | 2025-01-22 23:16:24 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-01-23 00:00:30 +0700 |
| commit | 8ad0d7cc01c08f60402d3d18df5dea13bfd94ece (patch) | |
| tree | 89657439f55005f135180f2a894c37331114de4e /lib/bytes/bytes_example_test.go | |
| parent | 536ff758c77cefe8d8c5c3ccdba67087128684ef (diff) | |
| download | pakakeh.go-8ad0d7cc01c08f60402d3d18df5dea13bfd94ece.tar.xz | |
all: replace "lib/bytes.AppendXxx" with standard library
Since Go 1.19, package "encoding/binary.BigEndian" support appending
byte order.
Diffstat (limited to 'lib/bytes/bytes_example_test.go')
| -rw-r--r-- | lib/bytes/bytes_example_test.go | 119 |
1 files changed, 0 insertions, 119 deletions
diff --git a/lib/bytes/bytes_example_test.go b/lib/bytes/bytes_example_test.go index e8c18d9b..5ca7a1ea 100644 --- a/lib/bytes/bytes_example_test.go +++ b/lib/bytes/bytes_example_test.go @@ -6,130 +6,11 @@ package bytes_test import ( "fmt" - "math" "git.sr.ht/~shulhan/pakakeh.go/lib/ascii" libbytes "git.sr.ht/~shulhan/pakakeh.go/lib/bytes" ) -func ExampleAppendInt16() { - for _, v := range []int16{math.MinInt16, 0xab, 0xabc, math.MaxInt16} { - out := libbytes.AppendInt16([]byte{}, v) - fmt.Printf("%6d => %#04x => %#02v\n", v, v, out) - } - // Output: - // -32768 => -0x8000 => []byte{0x80, 0x00} - // 171 => 0x00ab => []byte{0x00, 0xab} - // 2748 => 0x0abc => []byte{0x0a, 0xbc} - // 32767 => 0x7fff => []byte{0x7f, 0xff} -} - -func ExampleAppendInt32() { - for _, v := range []int32{math.MinInt32, 0xab, 0xabc, math.MaxInt32} { - out := libbytes.AppendInt32([]byte{}, v) - fmt.Printf("%11d => %#x => %#v\n", v, v, out) - } - // Output: - // -2147483648 => -0x80000000 => []byte{0x80, 0x0, 0x0, 0x0} - // 171 => 0xab => []byte{0x0, 0x0, 0x0, 0xab} - // 2748 => 0xabc => []byte{0x0, 0x0, 0xa, 0xbc} - // 2147483647 => 0x7fffffff => []byte{0x7f, 0xff, 0xff, 0xff} -} - -func ExampleAppendInt64() { - var listInt64 = []int64{ - math.MaxInt64, - 1000, - math.MinInt64, - } - - var ( - v int64 - out []byte - ) - for _, v = range listInt64 { - out = libbytes.AppendInt64(nil, v) - fmt.Printf("%d\n=> %#x\n=> %#v\n", v, v, out) - } - // Output: - // 9223372036854775807 - // => 0x7fffffffffffffff - // => []byte{0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} - // 1000 - // => 0x3e8 - // => []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0xe8} - // -9223372036854775808 - // => -0x8000000000000000 - // => []byte{0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} -} - -func ExampleAppendUint16() { - inputs := []uint16{0, 0xab, 0xabc, math.MaxInt16, math.MaxUint16} - for _, v := range inputs { - out := libbytes.AppendUint16([]byte{}, v) - fmt.Printf("%5d => %#04x => %#02v\n", v, v, out) - } - - v := inputs[4] + 1 // MaxUint16 + 1 - out := libbytes.AppendUint16([]byte{}, v) - fmt.Printf("%5d => %#04x => %#02v\n", v, v, out) - - // Output: - // 0 => 0x0000 => []byte{0x00, 0x00} - // 171 => 0x00ab => []byte{0x00, 0xab} - // 2748 => 0x0abc => []byte{0x0a, 0xbc} - // 32767 => 0x7fff => []byte{0x7f, 0xff} - // 65535 => 0xffff => []byte{0xff, 0xff} - // 0 => 0x0000 => []byte{0x00, 0x00} -} - -func ExampleAppendUint32() { - inputs := []uint32{0, 0xab, 0xabc, math.MaxInt32, math.MaxUint32} - for _, v := range inputs { - out := libbytes.AppendUint32([]byte{}, v) - fmt.Printf("%11d => %#x => %#v\n", v, v, out) - } - - v := inputs[4] + 2 // MaxUint32 + 2 - out := libbytes.AppendUint32([]byte{}, v) - fmt.Printf("%11d => %#x => %#v\n", v, v, out) - - // Output: - // 0 => 0x0 => []byte{0x0, 0x0, 0x0, 0x0} - // 171 => 0xab => []byte{0x0, 0x0, 0x0, 0xab} - // 2748 => 0xabc => []byte{0x0, 0x0, 0xa, 0xbc} - // 2147483647 => 0x7fffffff => []byte{0x7f, 0xff, 0xff, 0xff} - // 4294967295 => 0xffffffff => []byte{0xff, 0xff, 0xff, 0xff} - // 1 => 0x1 => []byte{0x0, 0x0, 0x0, 0x1} -} - -func ExampleAppendUint64() { - var listUint64 = []uint64{ - math.MaxUint64, - math.MaxInt64, - 1000, - } - - var ( - v uint64 - out []byte - ) - for _, v = range listUint64 { - out = libbytes.AppendUint64(nil, v) - fmt.Printf("%d\n=> %#x\n=> %#v\n", v, v, out) - } - // Output: - // 18446744073709551615 - // => 0xffffffffffffffff - // => []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} - // 9223372036854775807 - // => 0x7fffffffffffffff - // => []byte{0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} - // 1000 - // => 0x3e8 - // => []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0xe8} -} - func ExampleCutUntilToken() { text := []byte(`\\abc \def \deg`) |
