File: functions_test.go

package info (click to toggle)
golang-github-influxdata-go-syslog 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 964 kB
  • sloc: makefile: 84
file content (32 lines) | stat: -rw-r--r-- 762 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package common

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestSimpleUTF8DecimalConversion(t *testing.T) {
	slice := []uint8{49, 48, 49}
	res := UnsafeUTF8DecimalCodePointsToInt(slice)
	assert.Equal(t, 101, res)
}

func TestNumberStartingWithZero(t *testing.T) {
	slice := []uint8{48, 48, 50}
	res := UnsafeUTF8DecimalCodePointsToInt(slice)
	assert.Equal(t, 2, res)
}

func TestCharsNotInRange(t *testing.T) {
	point := 10
	slice := []uint8{uint8(point)} // Line Feed (LF)
	res := UnsafeUTF8DecimalCodePointsToInt(slice)
	assert.Equal(t, res, -(48 - point))
}

func TestAllDigits(t *testing.T) {
	slice := []uint8{49, 50, 51, 52, 53, 54, 55, 56, 57, 48}
	res := UnsafeUTF8DecimalCodePointsToInt(slice)
	assert.Equal(t, 1234567890, res)
}