github.com/richardwilkes/toolbox@v1.121.0/txt/wrap_test.go (about) 1 // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved. 2 // 3 // This Source Code Form is subject to the terms of the Mozilla Public 4 // License, version 2.0. If a copy of the MPL was not distributed with 5 // this file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 // 7 // This Source Code Form is "Incompatible With Secondary Licenses", as 8 // defined by the Mozilla Public License, version 2.0. 9 10 package txt_test 11 12 import ( 13 "testing" 14 15 "github.com/richardwilkes/toolbox/check" 16 "github.com/richardwilkes/toolbox/txt" 17 ) 18 19 func TestWrap(t *testing.T) { 20 table := []struct { 21 Prefix string 22 Text string 23 Out string 24 Max int 25 }{ 26 {Prefix: "// ", Text: "short", Max: 78, Out: "// short"}, 27 {Prefix: "// ", Text: "some text that is longer", Max: 12, Out: "// some text\n// that is\n// longer"}, 28 {Prefix: "// ", Text: "some text\nwith embedded line feeds", Max: 16, Out: "// some text\n// with embedded\n// line feeds"}, 29 {Prefix: "", Text: "some text that is longer", Max: 12, Out: "some text\nthat is\nlonger"}, 30 {Prefix: "", Text: "some text that is longer", Max: 4, Out: "some\ntext\nthat\nis\nlonger"}, 31 {Prefix: "", Text: "some text that is longer, yep", Max: 4, Out: "some\ntext\nthat\nis\nlonger,\nyep"}, 32 {Prefix: "", Text: "some text\nwith embedded line feeds", Max: 16, Out: "some text\nwith embedded\nline feeds"}, 33 } 34 for i, one := range table { 35 check.Equal(t, one.Out, txt.Wrap(one.Prefix, one.Text, one.Max), "#%d", i) 36 } 37 }