/* * Copyright (c) 2021-present Fabien Potencier * * This file is part of Symfony CLI project * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ package terminal import ( . "gopkg.in/check.v1" ) type OutputBlockSuite struct{} var _ = Suite(&OutputBlockSuite{}) func (ts *OutputBlockSuite) TestSplitsBlockLines(c *C) { lines, maxLen := splitsBlockLines("Foo Bazz", 3) c.Assert(lines, DeepEquals, []string{"Foo", " Ba", "zz"}) c.Assert(maxLen, Equals, 3) lines, maxLen = splitsBlockLines("Foo", 3) c.Assert(lines, DeepEquals, []string{"Foo"}) c.Assert(maxLen, Equals, 3) lines, maxLen = splitsBlockLines("FooBar", 3) c.Assert(lines, DeepEquals, []string{"Foo", "Bar"}) c.Assert(maxLen, Equals, 3) lines, maxLen = splitsBlockLines("Foo BarBaz", 3) c.Assert(lines, DeepEquals, []string{"Foo Bar", "Baz"}) c.Assert(maxLen, Equals, 3) } func (ts *OutputBlockSuite) TestEnclosedWithQuotes(c *C) { lines, maxLen := splitsBlockLines(`The "foo bar" file has moved to "a very long path". Please consider it.`, 40) c.Assert(lines, DeepEquals, []string{`The "foo bar" file has moved to `, `"a very long path". Please consider it.`}) c.Assert(maxLen, Equals, 38) lines, maxLen = splitsBlockLines(`The "foo bar" file has moved to "a very very very very very very very very very unterminated long path.`, 40) c.Assert(lines, DeepEquals, []string{`The "foo bar" file has moved to `, `"a very very very very very very very ver`, `y very unterminated long path.`}) c.Assert(maxLen, Equals, 40) lines, maxLen = splitsBlockLines(`This is an example of a message about a "/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/long/path" that needs to be moved to "/another/very/very/very/very/very/very/very/long/path"`, 107) c.Assert(lines, DeepEquals, []string{`This is an example of a message about a `, `"/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/very/long/path" that needs`, ` to be moved to "/another/very/very/very/very/very/very/very/long/path"`}) c.Assert(maxLen, Equals, 107) } func (ts *OutputBlockSuite) TestSplitsBlockLinesDonotPanic(c *C) { lines, maxLen := splitsBlockLines("Foo Baz<", 4) c.Assert(lines, DeepEquals, []string{"Foo ", "Baz<"}) c.Assert(maxLen, Equals, 4) }