github.com/blend/go-sdk@v1.20220411.3/stringutil/compress_space_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package stringutil
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/blend/go-sdk/assert"
    14  )
    15  
    16  func TestCompressSpace(t *testing.T) {
    17  	assert := assert.New(t)
    18  
    19  	assert.Equal("", CompressSpace(""))
    20  	assert.Equal("", CompressSpace(" "))
    21  	assert.Equal("", CompressSpace("\n"))
    22  	assert.Equal("", CompressSpace("\t"))
    23  
    24  	assert.Equal("foo", CompressSpace(" foo"))
    25  	assert.Equal("foo", CompressSpace("foo "))
    26  	assert.Equal("foo", CompressSpace("foo\n"))
    27  
    28  	assert.Equal("foo bar", CompressSpace("foo bar"))
    29  	assert.Equal("foo bar", CompressSpace("foo\tbar"))
    30  	assert.Equal("foo bar", CompressSpace("foo\nbar"))
    31  
    32  	assert.Equal("foo bar", CompressSpace("foo  bar"))
    33  	assert.Equal("foo bar", CompressSpace("foo\t\tbar"))
    34  	assert.Equal("foo bar", CompressSpace("foo\n\nbar"))
    35  
    36  	assert.Equal("foo bar baz", CompressSpace("foo  bar   baz"))
    37  	assert.Equal("foo bar baz", CompressSpace("foo\t\t\tbar baz\n"))
    38  	assert.Equal("foo bar baz", CompressSpace("foo\n\n\nbar\tbaz"))
    39  }