<commit_before>/*
Copyright libCellML Contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "test_utils.h"

#include "gtest/gtest.h"

#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>

#include "test_resources.h"

#define TEST_UTILS
#include "../src/commonutils.cpp"
#undef TEST_UTILS

std::string resourcePath(const std::string &resourceRelativePath)
{
    return TESTS_RESOURCE_LOCATION + "/" + resourceRelativePath;
}

std::string fileContents(const std::string &fileName)
{
    std::ifstream file(resourcePath(fileName));
    std::stringstream buffer;

    buffer << file.rdbuf();

    return buffer.str();
}

std::chrono::steady_clock::time_point timeNow()
{
    return std::chrono::steady_clock::now();
}

int elapsedTime(const std::chrono::steady_clock::time_point &startTime)
{
    return std::chrono::duration_cast<std::chrono::milliseconds>(timeNow() - startTime).count();
}

void printIssues(const libcellml::LoggerPtr &l, bool headings, bool cellmlElementTypes, bool rule)
{
    int width = int(floor(log10(l->errorCount())));
    for (size_t i = 0; i < l->issueCount(); ++i) {
        switch (l->issue(i)->level()) {
        case libcellml::Issue::Level::ERROR:
            std::cout << "Error " << std::setw(width) << i + 1 << ": ";
            break;
        case libcellml::Issue::Level::WARNING:
            std::cout << "Warning " << std::setw(width) << i + 1 << ": ";
            break;
        case libcellml::Issue::Level::HINT:
            std::cout << "Hint " << std::setw(width) << i + 1 << ": ";
            break;
        case libcellml::Issue::Level::MESSAGE:
            std::cout << "Message " << std::setw(width) << i + 1 << ": ";
            break;
        default:
            break;
        }

        if (headings) {
            std::cout << ", " << l->issue(i)->referenceHeading();
        }<commit_msg>Tests: make MSVC happy.<commit_after>/*
Copyright libCellML Contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "test_utils.h"

#include "gtest/gtest.h"

#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>

#include "test_resources.h"

#define TEST_UTILS
#include "../src/commonutils.cpp"
#undef TEST_UTILS

std::string resourcePath(const std::string &resourceRelativePath)
{
    return TESTS_RESOURCE_LOCATION + "/" + resourceRelativePath;
}

std::string fileContents(const std::string &fileName)
{
    std::ifstream file(resourcePath(fileName));
    std::stringstream buffer;

    buffer << file.rdbuf();

    return buffer.str();
}

std::chrono::steady_clock::time_point timeNow()
{
    return std::chrono::steady_clock::now();
}

int elapsedTime(const std::chrono::steady_clock::time_point &startTime)
{
    return int(std::chrono::duration_cast<std::chrono::milliseconds>(timeNow() - startTime).count());
}

void printIssues(const libcellml::LoggerPtr &l, bool headings, bool cellmlElementTypes, bool rule)
{
    int width = int(floor(log10(l->errorCount())));
    for (size_t i = 0; i < l->issueCount(); ++i) {
        switch (l->issue(i)->level()) {
        case libcellml::Issue::Level::ERROR:
            std::cout << "Error " << std::setw(width) << i + 1 << ": ";
            break;
        case libcellml::Issue::Level::WARNING:
            std::cout << "Warning " << std::setw(width) << i + 1 << ": ";
            break;
        case libcellml::Issue::Level::HINT:
            std::cout << "Hint " << std::setw(width) << i + 1 << ": ";
            break;
        case libcellml::Issue::Level::MESSAGE:
            std::cout << "Message " << std::setw(width) << i + 1 << ": ";
            break;
        default:
            break;
        }

        if (headings) {
            std::cout << ", " << l->issue(i)->referenceHeading();
        }
{'fraction_non_alphanumeric': 0.14665828619316992, 'fraction_numerical': 0.004609260423213911, 'mean_word_length': 3.4492078285181735, 'pattern_counts': {'":': 8, '<': 93, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4783580', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1452, 'n_words': 391}