mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3910 Unit test for table formatter and split text
This commit is contained in:
parent
708f24943b
commit
4e5925808a
@ -77,6 +77,14 @@ QString RifEclipseDataTableFormatter::tableRowPrependText() const
|
|||||||
return m_tableRowPrependText;
|
return m_tableRowPrependText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QString RifEclipseDataTableFormatter::tableRowAppendText() const
|
||||||
|
{
|
||||||
|
return m_tableRowAppendText;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -93,6 +101,14 @@ void RifEclipseDataTableFormatter::setTableRowLineAppendText(const QString& text
|
|||||||
m_tableRowAppendText = text;
|
m_tableRowAppendText = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QString RifEclipseDataTableFormatter::commentPrefix() const
|
||||||
|
{
|
||||||
|
return m_commentPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -456,12 +472,13 @@ int RifEclipseDataTableFormatter::measure(size_t num)
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
int RifEclipseDataTableFormatter::tableWidth() const
|
int RifEclipseDataTableFormatter::tableWidth() const
|
||||||
{
|
{
|
||||||
int characterCount = 0;
|
int characterCount = m_tableRowPrependText.length();
|
||||||
|
|
||||||
for (size_t i = 0u; i < m_columns.size(); ++i)
|
for (size_t i = 0u; i < m_columns.size(); ++i)
|
||||||
{
|
{
|
||||||
characterCount += formatColumn(" ", i).size();
|
characterCount += formatColumn(" ", i).size();
|
||||||
}
|
}
|
||||||
|
characterCount += m_tableRowAppendText.length();
|
||||||
|
|
||||||
return characterCount;
|
return characterCount;
|
||||||
}
|
}
|
||||||
|
@ -114,8 +114,10 @@ public:
|
|||||||
int columnSpacing() const;
|
int columnSpacing() const;
|
||||||
void setColumnSpacing(int spacing);
|
void setColumnSpacing(int spacing);
|
||||||
QString tableRowPrependText() const;
|
QString tableRowPrependText() const;
|
||||||
|
QString tableRowAppendText() const;
|
||||||
void setTableRowPrependText(const QString& text);
|
void setTableRowPrependText(const QString& text);
|
||||||
void setTableRowLineAppendText(const QString& text);
|
void setTableRowLineAppendText(const QString& text);
|
||||||
|
QString commentPrefix() const;
|
||||||
void setCommentPrefix(const QString& commentPrefix);
|
void setCommentPrefix(const QString& commentPrefix);
|
||||||
|
|
||||||
RifEclipseDataTableFormatter& keyword(const QString& keyword);
|
RifEclipseDataTableFormatter& keyword(const QString& keyword);
|
||||||
@ -135,6 +137,8 @@ public:
|
|||||||
|
|
||||||
static void addValueTable(QTextStream& stream, const QString& keyword, size_t columns, const std::vector<double>& values);
|
static void addValueTable(QTextStream& stream, const QString& keyword, size_t columns, const std::vector<double>& values);
|
||||||
|
|
||||||
|
int tableWidth() const;
|
||||||
|
static int maxEclipseRowWidth();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int measure(const QString str);
|
int measure(const QString str);
|
||||||
@ -142,9 +146,6 @@ private:
|
|||||||
int measure(int num);
|
int measure(int num);
|
||||||
int measure(size_t num);
|
int measure(size_t num);
|
||||||
|
|
||||||
int tableWidth() const;
|
|
||||||
static int maxEclipseRowWidth();
|
|
||||||
|
|
||||||
QString format(double num, RifEclipseOutputTableDoubleFormatting doubleFormat);
|
QString format(double num, RifEclipseOutputTableDoubleFormatting doubleFormat);
|
||||||
QString format(int num);
|
QString format(int num);
|
||||||
QString format(size_t num);
|
QString format(size_t num);
|
||||||
|
@ -73,3 +73,48 @@ TEST(RifEclipseDataTableFormatter, NoPrefix)
|
|||||||
std::cout << tableText.toStdString();
|
std::cout << tableText.toStdString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(RifEclipseDataTableFormatter, LongLine)
|
||||||
|
{
|
||||||
|
QString tableText;
|
||||||
|
QTextStream stream(&tableText);
|
||||||
|
RifEclipseDataTableFormatter formatter(stream);
|
||||||
|
|
||||||
|
std::vector<RifEclipseOutputTableColumn> header = {
|
||||||
|
RifEclipseOutputTableColumn("50 Character Well Name"),
|
||||||
|
RifEclipseOutputTableColumn("10 Int #1", RifEclipseOutputTableDoubleFormatting(), RIGHT),
|
||||||
|
RifEclipseOutputTableColumn("10 Int #2", RifEclipseOutputTableDoubleFormatting(), RIGHT),
|
||||||
|
RifEclipseOutputTableColumn("10 Int #3", RifEclipseOutputTableDoubleFormatting(), RIGHT),
|
||||||
|
RifEclipseOutputTableColumn("10 Int #4", RifEclipseOutputTableDoubleFormatting(), RIGHT),
|
||||||
|
RifEclipseOutputTableColumn("10 Int #5", RifEclipseOutputTableDoubleFormatting(), RIGHT),
|
||||||
|
RifEclipseOutputTableColumn("10 Int #6", RifEclipseOutputTableDoubleFormatting(), RIGHT),
|
||||||
|
RifEclipseOutputTableColumn("10 Int #7", RifEclipseOutputTableDoubleFormatting(), RIGHT),
|
||||||
|
RifEclipseOutputTableColumn("10 Int #8", RifEclipseOutputTableDoubleFormatting(), RIGHT),
|
||||||
|
};
|
||||||
|
|
||||||
|
formatter.header(header);
|
||||||
|
QString fiftyCharacterWellName = "01234567890123456789012345678901234567890123456789";
|
||||||
|
formatter.add(fiftyCharacterWellName);
|
||||||
|
for (int i = 0; i < 8; ++i)
|
||||||
|
{
|
||||||
|
formatter.add(std::numeric_limits<int>::max()); // 10 characters
|
||||||
|
}
|
||||||
|
int fullLineLength = formatter.tableRowPrependText().length() + 9 * formatter.columnSpacing() +
|
||||||
|
50 + 8 * 10 + formatter.tableRowAppendText().length();
|
||||||
|
int tableWidth = formatter.tableWidth();
|
||||||
|
EXPECT_EQ(tableWidth, fullLineLength);
|
||||||
|
EXPECT_GT(tableWidth, RifEclipseDataTableFormatter::maxEclipseRowWidth());
|
||||||
|
|
||||||
|
formatter.rowCompleted();
|
||||||
|
formatter.tableCompleted();
|
||||||
|
std::cout << tableText.toStdString() << std::endl;
|
||||||
|
|
||||||
|
QStringList tableLines = tableText.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);
|
||||||
|
for (QString line : tableLines)
|
||||||
|
{
|
||||||
|
if (!line.startsWith(formatter.commentPrefix()))
|
||||||
|
{
|
||||||
|
EXPECT_LE(line.length(), RifEclipseDataTableFormatter::maxEclipseRowWidth());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user