From 37a63debdc21e372d99e1808cdd31aecf75018c3 Mon Sep 17 00:00:00 2001 From: antonovvk Date: Thu, 10 Feb 2022 16:47:51 +0300 Subject: Restoring authorship annotation for . Commit 1 of 2. --- library/cpp/diff/diff_ut.cpp | 338 +++++++++++++++++++++---------------------- 1 file changed, 169 insertions(+), 169 deletions(-) (limited to 'library/cpp/diff/diff_ut.cpp') diff --git a/library/cpp/diff/diff_ut.cpp b/library/cpp/diff/diff_ut.cpp index b82a7b000ee..99b8167f44a 100644 --- a/library/cpp/diff/diff_ut.cpp +++ b/library/cpp/diff/diff_ut.cpp @@ -1,41 +1,41 @@ -#include "diff.h" - +#include "diff.h" + #include - -using namespace NDiff; - -struct TDiffTester { - TStringStream Res; + +using namespace NDiff; + +struct TDiffTester { + TStringStream Res; TVector> Chunks; - - TStringBuf Special(const TStringBuf& str) const { - return str; - } - - TStringBuf Common(const TConstArrayRef& str) const { - return TStringBuf(str.begin(), str.end()); - } - - TStringBuf Left(const TConstArrayRef& str) const { - return TStringBuf(str.begin(), str.end()); - } - - TStringBuf Right(const TConstArrayRef& str) const { - return TStringBuf(str.begin(), str.end()); - } - + + TStringBuf Special(const TStringBuf& str) const { + return str; + } + + TStringBuf Common(const TConstArrayRef& str) const { + return TStringBuf(str.begin(), str.end()); + } + + TStringBuf Left(const TConstArrayRef& str) const { + return TStringBuf(str.begin(), str.end()); + } + + TStringBuf Right(const TConstArrayRef& str) const { + return TStringBuf(str.begin(), str.end()); + } + void Test(const TStringBuf& a, const TStringBuf& b, const TString& delims = " \t\n") { - Chunks.clear(); - InlineDiff(Chunks, a, b, delims); - Res.clear(); - PrintChunks(Res, *this, Chunks); - } - + Chunks.clear(); + InlineDiff(Chunks, a, b, delims); + Res.clear(); + PrintChunks(Res, *this, Chunks); + } + const TString& Result() const { - return Res.Str(); - } -}; - + return Res.Str(); + } +}; + Y_UNIT_TEST_SUITE(DiffTokens) { Y_UNIT_TEST(ReturnValue) { TVector> res; @@ -50,148 +50,148 @@ Y_UNIT_TEST_SUITE(DiffTokens) { } Y_UNIT_TEST(EqualStringsOneToken) { - TDiffTester tester; - - tester.Test("aaa", "aaa"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa"); - } - + TDiffTester tester; + + tester.Test("aaa", "aaa"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa"); + } + Y_UNIT_TEST(NonCrossingStringsOneToken) { - TDiffTester tester; - - tester.Test("aaa", "bbb"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|bbb)"); - - tester.Test("aaa", "bbbb"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|bbbb)"); - } - + TDiffTester tester; + + tester.Test("aaa", "bbb"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|bbb)"); + + tester.Test("aaa", "bbbb"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|bbbb)"); + } + Y_UNIT_TEST(Simple) { - TDiffTester tester; - - tester.Test("aaa", "abb", ""); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "a(aa|bb)"); - - tester.Test("aac", "abc", ""); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "a(a|b)c"); - - tester.Test("123", "133", ""); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "1(2|3)3"); - - tester.Test("[1, 2, 3]", "[1, 3, 3]", ""); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "[1, (2|3), 3]"); - } - + TDiffTester tester; + + tester.Test("aaa", "abb", ""); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "a(aa|bb)"); + + tester.Test("aac", "abc", ""); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "a(a|b)c"); + + tester.Test("123", "133", ""); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "1(2|3)3"); + + tester.Test("[1, 2, 3]", "[1, 3, 3]", ""); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "[1, (2|3), 3]"); + } + Y_UNIT_TEST(CommonCharOneToken) { - TDiffTester tester; - - tester.Test("abcde", "accfg"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(abcde|accfg)"); - } - + TDiffTester tester; + + tester.Test("abcde", "accfg"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(abcde|accfg)"); + } + Y_UNIT_TEST(EqualStringsTwoTokens) { - TDiffTester tester; - - TStringBuf str("aaa bbb"); - tester.Test(str, str); - - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa bbb"); - } - + TDiffTester tester; + + TStringBuf str("aaa bbb"); + tester.Test(str, str); + + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa bbb"); + } + Y_UNIT_TEST(NonCrossingStringsTwoTokens) { - TDiffTester tester; - - tester.Test("aaa bbb", "ccc ddd"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|ccc) (bbb|ddd)"); - - tester.Test("aaa bbb", "c d"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|c) (bbb|d)"); - } - + TDiffTester tester; + + tester.Test("aaa bbb", "ccc ddd"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|ccc) (bbb|ddd)"); + + tester.Test("aaa bbb", "c d"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|c) (bbb|d)"); + } + Y_UNIT_TEST(SimpleTwoTokens) { - TDiffTester tester; - - tester.Test("aaa ccd", "abb cce"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|abb) (ccd|cce)"); - - tester.Test("aac cbb", "aa bb"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aac|aa) (cbb|bb)"); - } - + TDiffTester tester; + + tester.Test("aaa ccd", "abb cce"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|abb) (ccd|cce)"); + + tester.Test("aac cbb", "aa bb"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aac|aa) (cbb|bb)"); + } + Y_UNIT_TEST(MixedTwoTokens) { - TDiffTester tester; - - tester.Test("aaa bbb", "bbb aaa"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(|bbb )aaa( bbb|)"); - - tester.Test("aaa bbb", " bbb aaa"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|) bbb(| aaa)"); - - tester.Test(" aaa bbb ", " bbb aaa "); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(| bbb) aaa (bbb |)"); - - tester.Test("aaa bb", " bbb aa"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|) (bb|bbb aa)"); - } - + TDiffTester tester; + + tester.Test("aaa bbb", "bbb aaa"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(|bbb )aaa( bbb|)"); + + tester.Test("aaa bbb", " bbb aaa"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|) bbb(| aaa)"); + + tester.Test(" aaa bbb ", " bbb aaa "); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(| bbb) aaa (bbb |)"); + + tester.Test("aaa bb", " bbb aa"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|) (bb|bbb aa)"); + } + Y_UNIT_TEST(TwoTokensInOneString) { - TDiffTester tester; - - tester.Test("aaa bbb", "aaa"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa( bbb|)"); - - tester.Test("aaa bbb", "aaa "); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa (bbb|)"); - - tester.Test("aaa bbb", " bbb"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|) bbb"); - - tester.Test("aaa bbb", "bbb"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa |)bbb"); - } - + TDiffTester tester; + + tester.Test("aaa bbb", "aaa"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa( bbb|)"); + + tester.Test("aaa bbb", "aaa "); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa (bbb|)"); + + tester.Test("aaa bbb", " bbb"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa|) bbb"); + + tester.Test("aaa bbb", "bbb"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "(aaa |)bbb"); + } + Y_UNIT_TEST(Multiline) { - TDiffTester tester; - - tester.Test("aaa\nabc\nbbb", "aaa\nacc\nbbb"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa\n(abc|acc)\nbbb"); - - tester.Test("aaa\nabc\nbbb", "aaa\nac\nbbb"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa\n(abc|ac)\nbbb"); - } - + TDiffTester tester; + + tester.Test("aaa\nabc\nbbb", "aaa\nacc\nbbb"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa\n(abc|acc)\nbbb"); + + tester.Test("aaa\nabc\nbbb", "aaa\nac\nbbb"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa\n(abc|ac)\nbbb"); + } + Y_UNIT_TEST(DifferentDelimiters) { - TDiffTester tester; - - tester.Test("aaa bbb", "aaa\tbbb"); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa( |\t)bbb"); - - tester.Test(" aaa\tbbb\n", "\taaa\nbbb "); - //~ Cerr << tester.Result() << Endl; - UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "( |\t)aaa(\t|\n)bbb(\n| )"); - } -} + TDiffTester tester; + + tester.Test("aaa bbb", "aaa\tbbb"); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "aaa( |\t)bbb"); + + tester.Test(" aaa\tbbb\n", "\taaa\nbbb "); + //~ Cerr << tester.Result() << Endl; + UNIT_ASSERT_VALUES_EQUAL(tester.Result(), "( |\t)aaa(\t|\n)bbb(\n| )"); + } +} -- cgit v1.3