2019-05-20 18:34:30 +02:00
|
|
|
// Copyright (c) 2019 Shivaram Lingamneni <slingamn@cs.stanford.edu>
|
|
|
|
// released under the MIT license
|
|
|
|
|
|
|
|
package utils
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2020-05-30 17:45:43 +02:00
|
|
|
func TestArgsToStrings(t *testing.T) {
|
|
|
|
val := ArgsToStrings(512, []string{"a", "b", "c"}, ",")
|
|
|
|
assertEqual(val, []string{"a,b,c"}, t)
|
|
|
|
|
|
|
|
val = ArgsToStrings(10, []string{"abcd", "efgh", "ijkl"}, ",")
|
|
|
|
assertEqual(val, []string{"abcd,efgh", "ijkl"}, t)
|
|
|
|
}
|
|
|
|
|
2019-05-20 18:34:30 +02:00
|
|
|
func TestStringToBool(t *testing.T) {
|
|
|
|
val, err := StringToBool("on")
|
|
|
|
assertEqual(val, true, t)
|
|
|
|
assertEqual(err, nil, t)
|
|
|
|
|
|
|
|
val, err = StringToBool("n")
|
|
|
|
assertEqual(val, false, t)
|
|
|
|
assertEqual(err, nil, t)
|
|
|
|
|
|
|
|
val, err = StringToBool("OFF")
|
|
|
|
assertEqual(val, false, t)
|
|
|
|
assertEqual(err, nil, t)
|
|
|
|
|
|
|
|
val, err = StringToBool("default")
|
|
|
|
assertEqual(err, ErrInvalidParams, t)
|
|
|
|
}
|
2019-12-03 03:13:09 +01:00
|
|
|
|
|
|
|
func TestSafeErrorParam(t *testing.T) {
|
|
|
|
assertEqual(SafeErrorParam("hi"), "hi", t)
|
|
|
|
assertEqual(SafeErrorParam("#hi"), "#hi", t)
|
|
|
|
assertEqual(SafeErrorParam("#hi there"), "*", t)
|
|
|
|
assertEqual(SafeErrorParam(":"), "*", t)
|
|
|
|
assertEqual(SafeErrorParam("#hi:there"), "#hi:there", t)
|
|
|
|
assertEqual(SafeErrorParam(""), "*", t)
|
|
|
|
}
|