OTest2
A C++ testing framework
testmarkdiffprinter.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Ondrej Starek
3  *
4  * This file is part of OTest2.
5  *
6  * OTest2 is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License,
9  * or (at your option) any later version.
10  *
11  * OTest2 is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include <testmarkdiffprinter.h>
20 
21 #include <iostream>
22 
23 #include <testmarkformatter.h>
24 #include <testmarkprinter.h>
25 
26 namespace OTest2 {
27 
29  TestMarkFormatter& formatter_,
30  const std::vector<TestMark::LinearizedRecord>& left_,
31  const std::vector<TestMark::LinearizedRecord>& right_,
32  const DiffLogBlocks& diff_log_,
33  int context_) {
34  int left_line_(0);
35  int right_line_(0);
36  TestMarkPrinter left_printer_(&left_, left_line_);
37  TestMarkPrinter right_printer_(&right_, right_line_);
38  bool trailing_context_(false);
39 
40  for(const auto& diff_ : diff_log_) {
41  /* -- trailing context of previous change */
42  if(trailing_context_) {
43  for(int beg_(left_line_);
44  left_line_ < beg_ + context_ && left_line_ < diff_.left_begin;
45  )
46  left_printer_.printLine(formatter_);
47  }
48  else
49  trailing_context_ = true;
50 
51  /* -- skip unchanged lines */
52  if(left_line_ < diff_.left_begin - context_)
53  formatter_.printSeparator();
54  while(left_line_ < diff_.left_begin - context_)
55  left_printer_.skipLine(formatter_);
56  while(right_line_ < diff_.right_begin)
57  right_printer_.skipLine(formatter_);
58 
59  /* -- print the context lines */
60  while(left_line_ < diff_.left_begin)
61  left_printer_.printLine(formatter_);
62 
63  /* -- print the changes */
64  while(right_line_ < diff_.right_end)
65  right_printer_.printDeleted(formatter_);
66  while(left_line_ < diff_.left_end)
67  left_printer_.printAdded(formatter_);
68  }
69 
70  /* -- print trailing context */
71  if(trailing_context_) {
72  bool gap_mark_(true);
73  for(int beg_(left_line_); left_line_ < beg_ + context_;) {
74  if(!left_printer_.printLine(formatter_)) {
75  gap_mark_ = false;
76  break;
77  }
78  }
79  if(gap_mark_)
80  formatter_.printSeparator();
81  }
82 }
83 
84 } /* namespace OTest2 */
OTest2::TestMarkPrinter::skipLine
bool skipLine(TestMarkFormatter &os_)
Skip current line.
Definition: testmarkprinter.cpp:160
OTest2::printTestMarkDiff
void printTestMarkDiff(TestMarkFormatter &formatter_, const std::vector< TestMark::LinearizedRecord > &left_, const std::vector< TestMark::LinearizedRecord > &right_, const DiffLogBlocks &diff_log_, int context_)
Print difference of two testmarks.
Definition: testmarkdiffprinter.cpp:28
testmarkdiffprinter.h
testmarkformatter.h
OTest2::DiffLogBlocks
std::vector< DiffBlock > DiffLogBlocks
Ordered (indexes into the sequences) list of diff changes.
Definition: difflogblock.h:42
OTest2::TestMarkPrinter
Printer of testmarks.
Definition: testmarkprinter.h:35
OTest2
Definition: assertbean.h:25
OTest2::TestMarkFormatter::printSeparator
virtual void printSeparator()=0
Print separator (used for unchanged blocks)
testmarkprinter.h
OTest2::TestMarkPrinter::printAdded
bool printAdded(TestMarkFormatter &formatter_)
Print added line.
Definition: testmarkprinter.cpp:154
OTest2::TestMarkPrinter::printLine
bool printLine(TestMarkFormatter &formatter_)
Print current line into a stream.
Definition: testmarkprinter.cpp:142
OTest2::TestMarkPrinter::printDeleted
bool printDeleted(TestMarkFormatter &formatter_)
Print deleted line.
Definition: testmarkprinter.cpp:148
OTest2::TestMarkFormatter
Generic interface of the testmark formatter.
Definition: testmarkformatter.h:32