mirror of
https://github.com/NixOS/nix
synced 2025-07-07 06:01:48 +02:00
Split tests, organize more string functions
The test split matches PR #8920, so the utility files and tests files are once again to 1-1. The string changes continues what was started in PR #11093.
This commit is contained in:
parent
1fce591cbc
commit
9d2d4d11e6
13 changed files with 959 additions and 766 deletions
60
tests/unit/libutil/terminal.cc
Normal file
60
tests/unit/libutil/terminal.cc
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include "util.hh"
|
||||
#include "types.hh"
|
||||
#include "terminal.hh"
|
||||
#include "strings.hh"
|
||||
|
||||
#include <limits.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <numeric>
|
||||
|
||||
namespace nix {
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* filterANSIEscapes
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(filterANSIEscapes, emptyString)
|
||||
{
|
||||
auto s = "";
|
||||
auto expected = "";
|
||||
|
||||
ASSERT_EQ(filterANSIEscapes(s), expected);
|
||||
}
|
||||
|
||||
TEST(filterANSIEscapes, doesntChangePrintableChars)
|
||||
{
|
||||
auto s = "09 2q304ruyhr slk2-19024 kjsadh sar f";
|
||||
|
||||
ASSERT_EQ(filterANSIEscapes(s), s);
|
||||
}
|
||||
|
||||
TEST(filterANSIEscapes, filtersColorCodes)
|
||||
{
|
||||
auto s = "\u001b[30m A \u001b[31m B \u001b[32m C \u001b[33m D \u001b[0m";
|
||||
|
||||
ASSERT_EQ(filterANSIEscapes(s, true, 2), " A");
|
||||
ASSERT_EQ(filterANSIEscapes(s, true, 3), " A ");
|
||||
ASSERT_EQ(filterANSIEscapes(s, true, 4), " A ");
|
||||
ASSERT_EQ(filterANSIEscapes(s, true, 5), " A B");
|
||||
ASSERT_EQ(filterANSIEscapes(s, true, 8), " A B C");
|
||||
}
|
||||
|
||||
TEST(filterANSIEscapes, expandsTabs)
|
||||
{
|
||||
auto s = "foo\tbar\tbaz";
|
||||
|
||||
ASSERT_EQ(filterANSIEscapes(s, true), "foo bar baz");
|
||||
}
|
||||
|
||||
TEST(filterANSIEscapes, utf8)
|
||||
{
|
||||
ASSERT_EQ(filterANSIEscapes("foobar", true, 5), "fooba");
|
||||
ASSERT_EQ(filterANSIEscapes("fóóbär", true, 6), "fóóbär");
|
||||
ASSERT_EQ(filterANSIEscapes("fóóbär", true, 5), "fóóbä");
|
||||
ASSERT_EQ(filterANSIEscapes("fóóbär", true, 3), "fóó");
|
||||
ASSERT_EQ(filterANSIEscapes("f€€bär", true, 4), "f€€b");
|
||||
ASSERT_EQ(filterANSIEscapes("f𐍈𐍈bär", true, 4), "f𐍈𐍈b");
|
||||
}
|
||||
|
||||
} // namespace nix
|
Loading…
Add table
Add a link
Reference in a new issue