2015-12-12 04:24:49 +01:00
|
|
|
// Copyright © 2015 Daniele Tricoli <eriol@mornie.org>.
|
|
|
|
// All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-11-22 18:37:44 +01:00
|
|
|
package format // import "eriol.xyz/piken/format"
|
2015-12-11 03:43:36 +01:00
|
|
|
|
2015-11-22 18:37:44 +01:00
|
|
|
import (
|
2015-11-22 19:27:23 +01:00
|
|
|
"strconv"
|
2015-11-22 18:37:44 +01:00
|
|
|
"testing"
|
|
|
|
|
2015-12-08 00:42:12 +01:00
|
|
|
"eriol.xyz/piken/sql"
|
|
|
|
|
2015-11-22 18:37:44 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCodePointToGlyph(t *testing.T) {
|
|
|
|
glyph, err := CodePointToGlyph("1F602")
|
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, glyph, "😂")
|
|
|
|
|
|
|
|
glyph, err = CodePointToGlyph("1000000000")
|
|
|
|
assert.Equal(t, glyph, "")
|
2015-11-22 19:27:23 +01:00
|
|
|
if assert.Error(t, err) {
|
|
|
|
assert.Equal(t, err.(*strconv.NumError).Err, strconv.ErrRange)
|
|
|
|
}
|
2015-11-22 18:37:44 +01:00
|
|
|
}
|
2015-12-08 00:42:12 +01:00
|
|
|
|
|
|
|
func TestFormat(t *testing.T) {
|
|
|
|
|
|
|
|
s := sql.UnicodeData{CodePoint: "1F602",
|
|
|
|
Name: "FACE WITH TEARS OF JOY"}
|
|
|
|
|
|
|
|
formatter := NewTextFormatter(
|
|
|
|
[]string{"CodePoint", "Name"}, " -- ", true)
|
|
|
|
b, _ := formatter.Format(&s)
|
|
|
|
assert.Equal(t, b, "1F602 -- FACE WITH TEARS OF JOY -- 😂")
|
|
|
|
|
|
|
|
formatter = NewTextFormatter(
|
|
|
|
[]string{"CodePoint", "Name"}, " ## ", true)
|
|
|
|
b, _ = formatter.Format(&s)
|
|
|
|
assert.Equal(t, b, "1F602 ## FACE WITH TEARS OF JOY ## 😂")
|
|
|
|
|
|
|
|
formatter = NewTextFormatter(
|
|
|
|
[]string{"Name"}, " -- ", true)
|
|
|
|
b, _ = formatter.Format(&s)
|
|
|
|
assert.Equal(t, b, "FACE WITH TEARS OF JOY -- 😂")
|
|
|
|
|
|
|
|
formatter = NewTextFormatter(
|
|
|
|
[]string{"Name"}, " -- ", false)
|
|
|
|
b, _ = formatter.Format(&s)
|
|
|
|
assert.Equal(t, b, "FACE WITH TEARS OF JOY")
|
|
|
|
}
|