aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/autotest/catch/catchcodeparser.h
blob: 39f9b8aa27bfc7f5aafafb002d26ca9ff17c4c63 (plain)
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
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#pragma once

#include "catchtreeitem.h"

#include <cplusplus/SimpleLexer.h>

#include <QByteArray>

namespace Autotest {
namespace Internal {

class CatchCodeParser
{
public:
    CatchCodeParser(const QByteArray &source, const CPlusPlus::LanguageFeatures &features);
    virtual ~CatchCodeParser() = default;
    CatchTestCodeLocationList findTests();
private:
    void handleIdentifier();
    void handleTestCase(bool isScenario);
    void handleParameterizedTestCase(bool isFixture);
    void handleFixtureOrRegisteredTestCase(bool isFixture);

    QString getStringLiteral(CPlusPlus::Kind &stoppedAtKind);
    bool skipCommentsUntil(CPlusPlus::Kind nextExpectedKind);   // moves currentIndex if succeeds
    CPlusPlus::Kind skipUntilCorrespondingRParen();             // moves currentIndex
    bool skipFixtureParameter();
    bool skipFunctionParameter();

    const QByteArray &m_source;
    const CPlusPlus::LanguageFeatures &m_features;
    CPlusPlus::Tokens m_tokens;
    int m_currentIndex = 0;
    CatchTestCodeLocationList m_testCases;
};

} // namespace Internal
} // namespace Autotest