xaizek / zograscope (License: AGPLv3 only) (since 2018-12-07)
Mainly a syntax-aware diff that also provides a number of additional tools.
<root> / tests / Printer.cpp (4ad7b5f550a515c2c8f99e50bf6cd6f9bbf659f2) (23KiB) (mode 100644) [raw]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
// Copyright (C) 2017 xaizek <xaizek@posteo.net>
//
// This file is part of zograscope.
//
// zograscope is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU Affero General Public License as
// published by the Free Software Foundation.
//
// zograscope 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 zograscope.  If not, see <http://www.gnu.org/licenses/>.

#include "Catch/catch.hpp"

#include <iostream>
#include <sstream>
#include <string>

#include "utils/strings.hpp"
#include "utils/time.hpp"
#include "Printer.hpp"
#include "compare.hpp"
#include "tree.hpp"

#include "tests.hpp"

TEST_CASE("Width of titles is considered on determining width", "[printer]")
{
    Tree oldTree = parseC("");
    Tree newTree = parseC("");

    TimeReport tr;
    compare(oldTree, newTree, tr, true, true);

    std::ostringstream oss;
    Printer printer(*oldTree.getRoot(), *newTree.getRoot(),
                    *oldTree.getLanguage(), oss);
    std::string expected;

    SECTION("e1/e2")
    {
        printer.addHeader({ "e1", "e2" });
        expected = normalizeText(R"(
            ~~~~~~~!~~~~~~~
             -  e1 !  +  e2
            ~~~~~~~!~~~~~~~
        )");
    }

    SECTION("left/right")
    {
        printer.addHeader({ "left", "right" });
        expected = normalizeText(R"(
            ~~~~~~~~~!~~~~~~~~~~
             -  left !  +  right
            ~~~~~~~~~!~~~~~~~~~~
        )");
    }

    printer.print(tr);

    REQUIRE(normalizeText(oss.str()) == expected);
}

TEST_CASE("Comment contents is compared", "[printer]")
{
    std::string printed = compareAndPrint(parseC("// This is that comment.\n"),
                                          parseC("// This is this comment.\n"),
                                          true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1  // This is {-that-} comment. {#~#}  1  // This is {+this+} comment.
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("String literal contents is compared", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        char str[] = "this is
        a
        string";
    )"), parseC(R"(
        char str[] = "this is
        the
        string";
    )"), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1                                |  1
         2          char str[] = "this is {#~#}  2          char str[] = "this is
         3          {-a-}                 {#~#}  3          {+the+}
         4          string";              {#~#}  4          string";
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Inner diffing does not mess up column tracking", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        format_str("...%s", str);
    )", true), parseC(R"(
        format_str("%s%s", ell, str);
    )", true));

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1                                |  1
         2  format_str("{-...-}%s", str); {#~#}  2  format_str("%s{+%s+}"{+,+}{+ +}{+ell+}, str);
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Comment contents is marked as moved on move", "[printer]")
{
    std::string printed = compareAndPrint(parseC(
R"(void f() {
    /* This is bad. */
}
    )", true), parseC(
R"(void f() {
    {
        /* Failure is bad. */
    }
}
    )", true), false);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1  void f() {                         |  1  void f() {
         -                                     {+++}  2      {+{+}
         2      {:/* :}{-This-}{: is bad. */:} {#~#}  3          {:/* :}{+Failure+}{: is bad. */:}
         -                                     {+++}  4      {+}+}
         3  }                                  |  5  }
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Lines with moves aren't folded", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        void f() {
        }

        void g()
        {
            movedStuff;
            movedStuff;
            movedStuff;
            movedStuff;
        }

        void h() {
        }
    )", true), parseC(R"(
        void h() {
        }

        void g()
        {
            movedStuff;
            movedStuff;
            movedStuff;
            movedStuff;
        }

        void f() {
        }
    )", true), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          1                                         |   1
          2  {:void:}{: :}{:f:}{:(:}{:):}{: :}{:{:} {---}   -
          3  {:}:}                                  {---}   -
          -                                         {+++}   2  void h() {
          -                                         {+++}   3  }
          4                                         |   4
          5  {:void:}{: :}{:g:}{:(:}{:):}           {#~#}   5  {:void:}{: :}{:g:}{:(:}{:):}
          6  {:{:}                                  {#~#}   6  {:{:}
          7      {:movedStuff:}{:;:}                {#~#}   7      {:movedStuff:}{:;:}
          8      {:movedStuff:}{:;:}                {#~#}   8      {:movedStuff:}{:;:}
          9      {:movedStuff:}{:;:}                {#~#}   9      {:movedStuff:}{:;:}
         10      {:movedStuff:}{:;:}                {#~#}  10      {:movedStuff:}{:;:}
         11  {:}:}                                  {#~#}  11  {:}:}
         12                                         |  12
         13  void h() {                             {---}  --
         14  }                                      {---}  --
         --                                         {+++}  13  {:void:}{: :}{:f:}{:(:}{:):}{: :}{:{:}
         --                                         {+++}  14  {:}:}
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Lines with additions/deletions aren't folded", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        int array[] = {
            somethingOldThatWontMatch,
            somethingOldThatWontMatch,
            somethingOldThatWontMatch,

            somethingCommon,
            somethingCommon,
            somethingCommon,
            somethingCommon,
            somethingCommon,
            somethingCommon,

            somethingOldThatWontMatch,
            somethingOldThatWontMatch,
            somethingOldThatWontMatch,
        };
    )", true), parseC(R"(
        int array[] = {
            aNewThingThatHasNothingInCommonWithTheOldOne,
            aNewThingThatHasNothingInCommonWithTheOldOne,
            aNewThingThatHasNothingInCommonWithTheOldOne,

            somethingCommon,
            somethingCommon,
            somethingCommon,
            somethingCommon,
            somethingCommon,
            somethingCommon,

            aNewThingThatHasNothingInCommonWithTheOldOne,
            aNewThingThatHasNothingInCommonWithTheOldOne,
            aNewThingThatHasNothingInCommonWithTheOldOne,
        };
    )", true), true);

    std::string expected = normalizeText(R"(
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           1                                         |   1
           2  int array[] = {-{-}                    {#~#}   2  int array[] = {+{+}
           3      {-somethingOldThatWontMatch-}{-,-} {---}   -
           4      {-somethingOldThatWontMatch-}{-,-} {---}   -
           5      {-somethingOldThatWontMatch-}{-,-} {---}   -
           -                                         {+++}   3      {+aNewThingThatHasNothingInCommonWithTheOldOne+}{+,+}
           -                                         {+++}   4      {+aNewThingThatHasNothingInCommonWithTheOldOne+}{+,+}
           -                                         {+++}   5      {+aNewThingThatHasNothingInCommonWithTheOldOne+}{+,+}
           6                                         |   6
           7      {-somethingCommon-}{-,-}           {#~#}   7      {+somethingCommon+}{+,+}
           8      {-somethingCommon-}{-,-}           {#~#}   8      {+somethingCommon+}{+,+}
           9      {-somethingCommon-}{-,-}           {#~#}   9      {+somethingCommon+}{+,+}
          10      {-somethingCommon-}{-,-}           {#~#}  10      {+somethingCommon+}{+,+}
          11      {-somethingCommon-}{-,-}           {#~#}  11      {+somethingCommon+}{+,+}
          12      {-somethingCommon-}{-,-}           {#~#}  12      {+somethingCommon+}{+,+}
          13                                         |  13
          14      {-somethingOldThatWontMatch-}{-,-} {---}  --
          15      {-somethingOldThatWontMatch-}{-,-} {---}  --
          16      {-somethingOldThatWontMatch-}{-,-} {---}  --
          --                                         {+++}  14      {+aNewThingThatHasNothingInCommonWithTheOldOne+}{+,+}
          --                                         {+++}  15      {+aNewThingThatHasNothingInCommonWithTheOldOne+}{+,+}
          --                                         {+++}  16      {+aNewThingThatHasNothingInCommonWithTheOldOne+}{+,+}
          17  {-}-};                                 {#~#}  17  {+}+};
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Highlighting skips leading whitespace", "[printer]")
{
    std::string printed = compareAndPrint(parseC(""), parseC(R"(
        /* This
         * is
         * a
         * comment */
    )"), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~
        {+++}  1
        {+++}  2          {+/* This+}
        {+++}  3           {+* is+}
        {+++}  4           {+* a+}
        {+++}  5           {+* comment */+}
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Highlighting fills background in a meaningful way", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        void func_proto(int a);
        int a;
        int b;
    )", true), parseC(R"(
        int a;
        int b;
        void func_prototype(int a);
    )", true), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1                                                              |  1
         2  {:void:}{: :}{#func_proto#}{:(:}{:int:}{: :}{:a:}{:):}{:;:} {---}  -
         3  int a;                                                      |  2  int a;
         4  int b;                                                      |  3  int b;
         -                                                              {+++}  4  {:void:}{: :}{#func_prototype#}{:(:}{:int:}{: :}{:a:}{:):}{:;:}
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Highlighting doesn't fill background where shouldn't 1", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        void f() {
            some_function(argument);
        }
    )", true), parseC(R"(
        void f() {
            some_function(argument + 1);
        }
    )", true), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1                                   |  1
         2  void f() {                       |  2  void f() {
         3      some_function({:argument:}); {#~#}  3      some_function({:argument:} {+++}{+ +}{+1+});
         4  }                                |  4  }
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Highlighting doesn't fill background where shouldn't 2", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        void f() {
            if (*p == 'T') {
                cfg.trunc_normal_sb_msgs = 1;
            } else if (*p == 'p') {
                cfg.shorten_title_paths = 1;
            }
        }
    )", true), parseC(R"(
        void f() {
            if (*p == 'M') {
                cfg.short_term_mux_titles = 1;
            } else if (*p == 'T') {
                cfg.trunc_normal_sb_msgs = 1;
            } else if (*p == 'p') {
                cfg.shorten_title_paths = 1;
            }
        }
    )", true), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1                                                                                              |   1
         2  void f() {                                                                                  |   2  void f() {
         -                                                                                              {+++}   3      {+if+}{+ +}{+(+}{+*+}{+p+}{+ +}{+==+}{+ +}{+'M'+}{+)+}{+ +}{+{+}
         -                                                                                              {+++}   4          {+cfg+}{+.+}{+short_term_mux_titles+}{+ +}{+=+}{+ +}{+1+}{+;+}
         3      {:if:}{: :}{:(:}{:*:}{:p:}{: :}{:==:}{: :}{:'T':}{:):}{: :}{:{:}                        {#~#}   5      {+}+}{+ +}{+else+} {:if:}{: :}{:(:}{:*:}{:p:}{: :}{:==:}{: :}{:'T':}{:):}{: :}{:{:}
         4          {:cfg:}{:.:}{:trunc_normal_sb_msgs:}{: :}{:=:}{: :}{:1:}{:;:}                       {#~#}   6          {:cfg:}{:.:}{:trunc_normal_sb_msgs:}{: :}{:=:}{: :}{:1:}{:;:}
         5      {:}:}{: :}{:else:}{: :}{:if:}{: :}{:(:}{:*:}{:p:}{: :}{:==:}{: :}{:'p':}{:):}{: :}{:{:} {#~#}   7      {:}:}{: :}{:else:}{: :}{:if:}{: :}{:(:}{:*:}{:p:}{: :}{:==:}{: :}{:'p':}{:):}{: :}{:{:}
         6          {:cfg:}{:.:}{:shorten_title_paths:}{: :}{:=:}{: :}{:1:}{:;:}                        {#~#}   8          {:cfg:}{:.:}{:shorten_title_paths:}{: :}{:=:}{: :}{:1:}{:;:}
         7      {:}:}                                                                                   {#~#}   9      {:}:}
         8  }                                                                                           |  10  }
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Widths is adjusted correctly on long headers", "[printer]")
{
    Tree oldTree = parseC("");
    Tree newTree = parseC("int a;");

    TimeReport tr;
    compare(oldTree, newTree, tr, true, true);

    std::ostringstream oss;
    Printer printer(*oldTree.getRoot(), *newTree.getRoot(),
                    *oldTree.getLanguage(), oss);

    std::string expected;

    oss.str({});
    printer.addHeader({ "left", "right" });
    printer.print(tr);
    expected = normalizeText(R"(
        ~~~~~~~~~~~~!~~~~~~~~~~~~~~~
         -  left    !  +  right
        ~~~~~~~~~~~~!~~~~~~~~~~~~~~~
        {+++}  1  {+int+}{+ +}{+a+}{+;+}
    )");
    CHECK(normalizeText(oss.str()) == expected);

    oss.str({});
    printer.addHeader({ "longleft", "right" });
    printer.print(tr);
    expected = normalizeText(R"(
        ~~~~~~~~~~~~~!~~~~~~~~~~~~~~
         -  left     !  +  right
         -  longleft !  +  right
        ~~~~~~~~~~~~~!~~~~~~~~~~~~~~
        {+++}  1  {+int+}{+ +}{+a+}{+;+}
    )");
    CHECK(normalizeText(oss.str()) == expected);

    oss.str({});
    printer.addHeader({ "left", "verylongright" });
    printer.print(tr);
    expected = normalizeText(R"(
        ~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~
         -  left     !  +  right
         -  longleft !  +  right
         -  left     !  +  verylongright
        ~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~
        {+++}  1  {+int+}{+ +}{+a+}{+;+}
    )");
    CHECK(normalizeText(oss.str()) == expected);
}

TEST_CASE("Deletions only leave only one side", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        /* This
         * is
         * a
         * comment */
    )"), parseC(""), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~
         1                            {---}
         2          {-/* This-}       {---}
         3           {-* is-}         {---}
         4           {-* a-}          {---}
         5           {-* comment */-} {---}
    )");

    CHECK(printed == expected);
}

TEST_CASE("Single side view doesn't contain blanks", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        struct Args {
            bool noRefine;
            bool gitDiff;
            bool gitRename;
            bool gitRenameOnly;
        };
    )"), parseC(R"(
        struct Args {
            bool noRefine;      // Don't run TED on updated nodes.
            bool gitDiff;       // Invoked by git and file was changed.
            bool gitRename;     // File was renamed and possibly changed too.
            bool gitRenameOnly; // File was renamed without changing it.
        };
    )"), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        |  1
        |  2  struct Args {
        {#~#}  3      bool noRefine;      {+// Don't run TED on updated nodes.+}
        {#~#}  4      bool gitDiff;       {+// Invoked by git and file was changed.+}
        {#~#}  5      bool gitRename;     {+// File was renamed and possibly changed too.+}
        {#~#}  6      bool gitRenameOnly; {+// File was renamed without changing it.+}
        |  7  };
    )");

    CHECK(printed == expected);
}

TEST_CASE("Adjacent updates aren't merged with background", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        void f() {
            if (someLongVariableName == 0) {
            }
        }
    )"), parseC(R"(
        void f() {
            if (someLongVariableName != 1) {
            }
        }
    )"), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1                                               |  1
         2  void f() {                                   |  2  void f() {
         3      if (someLongVariableName {#==#} {#0#}) { {#~#}  3      if (someLongVariableName {#!=#} {#1#}) {
         4      }                                        |  4      }
         5  }                                            |  5  }
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Separators in diffable tokens are handled separately", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        void f() {
            something("Destination doesn't exist");
        }
    )"), parseC(R"(
        void f() {
            something("Destination doesn't exist or not a directory");
        }
    )"), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1                                              |  1
         2  void f() {                                  |  2  void f() {
         3      something("Destination doesn't exist"); {#~#}  3      something("Destination doesn't exist{+ or not a directory+}");
         4  }                                           |  4  }
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Diffable identifiers are surrounded with brackets", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        void f() {
            cmd_group_open(undo_msg);
        }
    )"), parseC(R"(
        void f() {
            un_group_open(undo_msg);
        }
    )"), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1                                        |  1
         2  void f() {                            |  2  void f() {
         3      {-cmd-}{~_group_open~}(undo_msg); {#~#}  3      {+un+}{~_group_open~}(undo_msg);
         4  }                                     |  4  }
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Diffable identifiers that are too different aren't detailed",
          "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        void f() {
            cmd_group_begin(undo_msg);
        }
    )"), parseC(R"(
        void f() {
            un_group_open(undo_msg);
        }
    )"), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1                                     |  1
         2  void f() {                         |  2  void f() {
         3      {#cmd_group_begin#}(undo_msg); {#~#}  3      {#un_group_open#}(undo_msg);
         4  }                                  |  4  }
    )");

    REQUIRE(printed == expected);
}

TEST_CASE("Diffing by characters", "[printer]")
{
    std::string printed = compareAndPrint(parseC(R"(
        void f() {
            cmdGroupBegin(undo_msg);
        }
    )"), parseC(R"(
        void f() {
            unGroupOpen(undo_msg);
        }
    )"), true);

    std::string expected = normalizeText(R"(
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         1                                                       |  1
         2  void f() {                                           |  2  void f() {
         3      {-cmd-}{~Group~}{-B-}{~e~}{-gi-}{~n~}(undo_msg); {#~#}  3      {+un+}{~Group~}{+Op+}{~en~}(undo_msg);
         4  }                                                    |  4  }
    )");

    REQUIRE(printed == expected);
}
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/zograscope

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/zograscope

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master