File: wrap_test.go

package info (click to toggle)
golang-github-olekukonko-tablewriter 0.0~git20151029.0.a5eefc2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 148 kB
  • ctags: 101
  • sloc: makefile: 5
file content (44 lines) | stat: -rw-r--r-- 1,019 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
// Copyright 2014 Oleku Konko All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.

// This module is a Table Writer  API for the Go Programming Language.
// The protocols were written in pure Go and works on windows and unix systems

package tablewriter

import (
	"strings"
	"testing"
)

var text = "The quick brown fox jumps over the lazy dog."

func TestWrap(t *testing.T) {
	exp := []string{
		"The", "quick", "brown", "fox",
		"jumps", "over", "the", "lazy", "dog."}

	got, _ := WrapString(text, 6)
	if len(exp) != len(got) {
		t.Fail()
	}
}

func TestWrapOneLine(t *testing.T) {
	exp := "The quick brown fox jumps over the lazy dog."
	words, _ := WrapString(text, 500)
	got := strings.Join(words, string(sp))
	if exp != got {
		t.Fail()
	}
}

func TestUnicode(t *testing.T) {
	input := "Česká řeřicha"
	wordsUnicode, _ := WrapString(input, 13)
	// input contains 13 runes, so it fits on one line.
	if len(wordsUnicode) != 1 {
		t.Fail()
	}
}