File: helpers_test.go

package info (click to toggle)
go-sendxmpp 0.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 332 kB
  • sloc: makefile: 11
file content (56 lines) | stat: -rw-r--r-- 1,447 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main

import (
	"fmt"
	"testing"
)

func TestValidUTF8(t *testing.T) {
	invalidCodePoints := [...]rune{
		0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
		0x08, 0x0B, 0x0C, 0x0E, 0x0F, 0x10, 0x11, 0x12,
		0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A,
		0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
	}
	for _, icp := range invalidCodePoints {
		teststring := fmt.Sprintf("bla%cbla", icp)
		cleanstring := validUTF8(teststring)
		if cleanstring != "bla�bla" {
			t.Errorf("Expected 'bla�bla', got '%s'", cleanstring)
		}
	}
}

func TestGetRpad(t *testing.T) {
	rpad := getRpad(10)
	if len(rpad) != 90 {
		t.Errorf("Expected a rpad length of 90, got length of %d", len(rpad))
	}
	rpad = getRpad(99)
	if len(rpad) != 1 {
		t.Errorf("Expected a rpad length of 1, got length of %d", len(rpad))
	}
	rpad = getRpad(100)
	if len(rpad) != 100 {
		t.Errorf("Expected a rpad length of 100, got length of %d", len(rpad))
	}
	rpad = getRpad(101)
	if len(rpad) != 99 {
		t.Errorf("Expected a rpad length of 99, got length of %d", len(rpad))
	}
	rpad = getRpad(199)
	if len(rpad) != 1 {
		t.Errorf("Expected a rpad length of 1, got length of %d", len(rpad))
	}
	rpad = getRpad(201)
	if len(rpad) != 99 {
		t.Errorf("Expected a rpad length of 99, got length of %d", len(rpad))
	}
}

func TestFsFriendlyJid(t *testing.T) {
	jid := fsFriendlyJid("user@example.org")
	if jid != "user_at_example_org" {
		t.Errorf("Expected 'user_at_example_org', got '%s'", jid)
	}
}