github.com/maruel/nin@v0.0.0-20220112143044-f35891e3ce7e/cmd/nin/main_test.go (about) 1 // Copyright 2011 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package main 16 17 import "testing" 18 19 func TestStripAnsiEscapeCodes_EscapeAtEnd(t *testing.T) { 20 stripped := stripAnsiEscapeCodes("foo\x1B") 21 if "foo" != stripped { 22 t.Fatalf("%+q", stripped) 23 } 24 25 stripped = stripAnsiEscapeCodes("foo\x1B[") 26 if "foo" != stripped { 27 t.Fatalf("%+q", stripped) 28 } 29 } 30 31 func TestStripAnsiEscapeCodes_StripColors(t *testing.T) { 32 // An actual clang warning. 33 input := "\x1B[1maffixmgr.cxx:286:15: \x1B[0m\x1B[0;1;35mwarning: \x1B[0m\x1B[1musing the result... [-Wparentheses]\x1B[0m" 34 stripped := stripAnsiEscapeCodes(input) 35 if "affixmgr.cxx:286:15: warning: using the result... [-Wparentheses]" != stripped { 36 t.Fatalf("%+q", stripped) 37 } 38 }