ronantakizawa/codereview-bench huggingface dataset:
Repository: nuttyartist/notes
File: src/mainwindow.cpp (C++)

Code before:
    if(m_currentSelectedNoteProxy.isValid()){

        m_noteView->scrollToTop();

        // move the current selected note to the top
        QModelIndex sourceIndex = m_proxyModel->mapToSource(m_currentSelectedNoteProxy);
        QModelIndex destinationIndex = m_noteModel->index(0);
        m_noteModel->moveRow(sourceIndex, sourceIndex.row(), destinationIndex, 0);

        // update the current item
        m_currentSelectedNoteProxy = m_proxyModel->mapFromSource(destinationIndex);
        m_noteView->setCurrentIndex(m_currentSelectedNoteProxy);
    }else{
        qDebug() << "MainWindow::moveNoteTop : m_currentSelectedNoteProxy not valid";
    }
}

/*!
 * \brief MainWindow::clearSearch
 */
void MainWindow::clearSearch()
{
    m_noteView->setFocusPolicy(Qt::StrongFocus);

    m_searchEdit->blockSignals(true);
    m_searchEdit->clear();
    m_searchEdit->blockSignals(false);

    m_textEdit->blockSignals(true);
    m_textEdit->clear();
    m_textEdit->clearFocus();
    m_editorDateLabel->clear();
    m_textEdit->blockSignals(false);

    m_proxyModel->setFilterFixedString(QString());

    m_clearButton->hide();
    m_searchEdit->setFocus();
}

/*!
 * \brief MainWindow::findNotesContain
 * \param keyword
 */
void MainWindow::findNotesContain(const QString& keyword)
{
    m_proxyModel->setFilterFixedString(keyword);
    m_clearButton->show();

    m_textEdit->blockSignals(true);
    m_textEdit->clear();

Review comment (bug):
why ?
also QLatin1String could be used : `QDebug &QDebug::operator<<(QLatin1String t)`

Code after:
    event->accept();
}
#endif

/*!
 * \brief MainWindow::moveNoteToTop
 * moves the current note Widget to the top of the layout
 */
void MainWindow::moveNoteToTop()
{
    // check if the current note is note on the top of the list
    // if true move the note to the top
    if(m_currentSelectedNoteProxy.isValid()){

        m_noteView->scrollToTop();

        // move the current selected note to the top
        QModelIndex sourceIndex = m_proxyModel->mapToSource(m_currentSelectedNoteProxy);
        QModelIndex destinationIndex = m_noteModel->index(0);
        m_noteModel->moveRow(sourceIndex, sourceIndex.row(), destinationIndex, 0);

        // update the current item
        m_currentSelectedNoteProxy = m_proxyModel->mapFromSource(destinationIndex);
        m_noteView->setCurrentIndex(m_currentSelectedNoteProxy);
    }else{
        qDebug() << "MainWindow::moveNoteTop : m_currentSelectedNoteProxy not valid";
    }
}

/*!
 * \brief MainWindow::clearSearch
 */
void MainWindow::clearSearch()
{
    m_noteView->setFocusPolicy(Qt::StrongFocus);

    m_searchEdit->blockSignals(true);
    m_searchEdit->clear();
    m_searchEdit->blockSignals(false);

    m_textEdit->blockSignals(true);
    m_textEdit->clear();
    m_textEdit->clearFocus();
    m_editorDateLabel->clear();
    m_textEdit->blockSignals(false);

    m_proxyModel->setFilterFixedString(QString());

    m_clearButton->hide();
    m_searchEdit->setFocus();
}
Repository: nuttyartist/notes
File: src/mainwindow.cpp (C++)

Code before:
    }


    QRect zone(topLeft, bottomRight);
    radialGradient = QRadialGradient(center, resizedShadowWidth, center);

    linearGradient.setStart(shadowStart);
    linearGradient.setFinalStop(shadowStop);

    switch (type) {
    case ShadowType::Radial :
        fillRectWithGradient(painter, zone, radialGradient);
        break;
    case ShadowType::Linear :
        fillRectWithGradient(painter, zone, linearGradient);
        break;
    }
}

/*!
 * \brief MainWindow::fillRectWithGradient
 * \param painter
 * \param rect
 * \param gradient
 */
void MainWindow::fillRectWithGradient(QPainter& painter, const QRect& rect, QGradient& gradient)
{
    double variance = 0.2;
    double xMax = 1.10;
    double q = 70/gaussianDist(0, 0, sqrt(variance));
    double nPt = 100.0;

    for(int i=0; i<=nPt; i++){
        double v = gaussianDist(i*xMax/nPt, 0, sqrt(variance));

        QColor c(168, 168, 168, int(q*v));
        gradient.setColorAt(i/nPt, c);
    }

    painter.fillRect(rect, gradient);
}

/*!
 * \brief MainWindow::gaussianDist
 * \param x
 * \param center
 * \param sigma
 * \return
 */
double MainWindow::gaussianDist(double x, const double center, double sigma) const
{

Review comment (suggestion):
I feel like this better stay `const QRect &` since [`QPainter::fillRect`](https://doc.qt.io/qt-5/qpainter.html#fillRect-13) also takes a const reference (and I think Qt API does this in general). But I don't really care so if it's easier to pass by value it's fine with me.

Code after:
    }


    QRect zone(topLeft, bottomRight);
    radialGradient = QRadialGradient(center, resizedShadowWidth, center);

    linearGradient.setStart(shadowStart);
    linearGradient.setFinalStop(shadowStop);

    switch (type) {
    case ShadowType::Radial :
        fillRectWithGradient(painter, zone, radialGradient);
        break;
    case ShadowType::Linear :
        fillRectWithGradient(painter, zone, linearGradient);
        break;
    }
}

/*!
 * \brief MainWindow::fillRectWithGradient
 * \param painter
 * \param rect
 * \param gradient
 */
void MainWindow::fillRectWithGradient(QPainter& painter, QRect rect, QGradient& gradient)
{
    double variance = 0.2;
    double xMax = 1.10;
    double q = 70/gaussianDist(0, 0, sqrt(variance));
    double nPt = 100.0;

    for(int i=0; i<=nPt; i++){
        double v = gaussianDist(i*xMax/nPt, 0, sqrt(variance));

        QColor c(168, 168, 168, int(q*v));
        gradient.setColorAt(i/nPt, c);
    }

    painter.fillRect(rect, gradient);
}

/*!
 * \brief MainWindow::gaussianDist
 * \param x
 * \param center
 * \param sigma
 * \return
 */
double MainWindow::gaussianDist(double x, const double center, double sigma) const
{
Repository: nuttyartist/notes
File: src/mainwindow.cpp (C++)

Code before:
}

/*!
 * \brief MainWindow::minimizeWindow
 * Minimize the window
 */
void MainWindow::minimizeWindow()
{
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
    //    QMargins margins(m_layoutMargin,m_layoutMargin,m_layoutMargin,m_layoutMargin);
    //    setMargins(margins);
#endif

    // BUG : QTBUG-57902 minimize doesn't store the window state before minimizing
    showMinimized();
}

/*!
 * \brief MainWindow::QuitApplication
 * Exit the application
 * If a new note created but wasn't edited, delete it from the database
 */
void MainWindow::QuitApplication()
{
    m_noteEditorLogic->closeEditor();
    qApp->quit();
}

/*!
 * \brief MainWindow::checkForUpdates
 * Called when the "Check for Updates" menu item is clicked, this function
 * instructs the updater window to check if there are any updates available
 */
void MainWindow::checkForUpdates()
{
    m_updater.checkForUpdates(true);
}

/*!
 * \brief MainWindow::importNotesFile
 * Called when the "Import Notes" menu button is clicked. this function will
 * prompt the user to select a file, attempt to load the file, and update the DB
 * if valid.
 * The user is presented with a dialog box if the upload/import fails for any reason.
 */
void MainWindow::importNotesFile()
{
    executeImport(false);
}

/*!

Review comment (suggestion):
Since this is a static method, I'd suggest:
```suggestion
    QCoreApplication::quit();
```

Code after:

    } else {
        setWindowState(windowState() | Qt::WindowMaximized);
        //        setMargins(QMargins(0,0,0,0));
    }
#elif _WIN32
    if (isMaximized()) {
        setWindowState(windowState() & ~Qt::WindowMaximized);
        setWindowState(windowState() & ~Qt::WindowFullScreen);
    } else if (isFullScreen()) {
        setWindowState((windowState() | Qt::WindowMaximized) & ~Qt::WindowFullScreen);
        setGeometry(qApp->primaryScreen()->availableGeometry());
    } else {
        setWindowState(windowState() | Qt::WindowMaximized);
        setGeometry(qApp->primaryScreen()->availableGeometry());
    }
#endif
}

/*!
 * \brief MainWindow::minimizeWindow
 * Minimize the window
 */
void MainWindow::minimizeWindow()
{
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
    //    QMargins margins(m_layoutMargin,m_layoutMargin,m_layoutMargin,m_layoutMargin);
    //    setMargins(margins);
#endif

    // BUG : QTBUG-57902 minimize doesn't store the window state before minimizing
    showMinimized();
}

/*!
 * \brief MainWindow::QuitApplication
 * Exit the application
 * If a new note created but wasn't edited, delete it from the database
 */
void MainWindow::QuitApplication()
{
    if (windowState() != Qt::WindowFullScreen) {
        m_settingsDatabase->setValue(QStringLiteral("windowGeometry"), saveGeometry());
        if (m_styleEditorWindow.windowState() != Qt::WindowFullScreen)
            m_settingsDatabase->setValue(QStringLiteral("editorSettingsWindowGeometry"),
                                         m_styleEditorWindow.saveGeometry());
    }

    m_noteEditorLogic->saveNoteToDB();

#if defined(UPDATE_CHECKER)
Repository: nuttyartist/notes
File: src/customapplicationstyle.cpp (C++)

Code before:
#include <QStyleOption>

void CustomApplicationStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
                                           QPainter *painter, const QWidget *widget) const
{
    if (element == QStyle::PE_IndicatorItemViewItemDrop) {
        painter->setRenderHint(QPainter::Antialiasing, true);

        QColor c;
        //        if (m_theme == Theme::Dark) {
        //            c = QColor(15, 45, 90);
        //        } else {
        c = QColor(207, 207, 207);
        //        }
        QPen pen(c);
        pen.setWidth(2);
        c.setAlpha(50);
        QBrush brush(c);

        painter->setPen(pen);
        painter->setBrush(brush);
        if (option->rect.height() == 0) {
            painter->drawLine(option->rect.topLeft(), option->rect.topRight());
        } else {
            c.setAlpha(200);
            brush.setColor(c);
            painter->fillRect(option->rect, brush);
        }
    } else {
        QProxyStyle::drawPrimitive(element, option, painter, widget);
    }
}

void CustomApplicationStyle::setTheme(Theme newTheme)
{
    m_theme = newTheme;
}

CustomApplicationStyle::CustomApplicationStyle() : m_theme(Theme::Light) { }


Review comment (suggestion):
Here I would get rid of both `brush` variables instead. You can pass the `c` directly to `setBrush` or `fillRect` since colors implicitly convert to a solid brush.

Code after:
#include <QStyleOption>

void CustomApplicationStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
                                           QPainter *painter, const QWidget *widget) const
{
    if (element == QStyle::PE_IndicatorItemViewItemDrop) {
        painter->setRenderHint(QPainter::Antialiasing, true);

        QColor color(207, 207, 207);
        QPen pen(color);
        pen.setWidth(2);
        painter->setPen(pen);

        if (option->rect.height() == 0) {
            color.setAlpha(50);
            painter->setBrush(color);
            painter->drawLine(option->rect.topLeft(), option->rect.topRight());
        } else {
            color.setAlpha(200);
            painter->fillRect(option->rect, color);
        }
    } else {
        QProxyStyle::drawPrimitive(element, option, painter, widget);
    }
}

void CustomApplicationStyle::setTheme(Theme newTheme)
{
    m_theme = newTheme;
}

CustomApplicationStyle::CustomApplicationStyle() : m_theme(Theme::Light) { }
Repository: nuttyartist/notes
File: src/mainwindow.cpp (C++)

Code before:
 * \param event
 */
void MainWindow::mouseDoubleClickEvent(QMouseEvent *event)
{
    if (m_useNativeWindowFrame) {
        MainWindowBase::mouseDoubleClickEvent(event);
        return;
    }

#ifndef __APPLE__
    maximizeWindow();
#else
    this->maximizeWindowMac();
#endif
    event->accept();
}

/*!
 * \brief MainWindow::leaveEvent
 */
void MainWindow::leaveEvent(QEvent *)
{
    this->unsetCursor();
}

/*!
 * \brief MainWindow::changeEvent
 */
void MainWindow::changeEvent(QEvent *event)
{
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
    if (!event->spontaneous() || m_useNativeWindowFrame)
        return;

    if (isMaximized())
        setMargins(QMargins());
    else
        setMargins(QMargins(m_layoutMargin, m_layoutMargin, m_layoutMargin, m_layoutMargin));
#endif
}

/*!
 * \brief MainWindow::setVisibilityOfFrameRightNonEditor
 * Either show or hide all widgets which are not m_textEdit
 */
void MainWindow::setVisibilityOfFrameRightNonEditor(bool isVisible)
{
    m_isFrameRightTopWidgetsVisible = isVisible;

    if (isVisible) {
        m_areNonEditorWidgetsVisible = true;

Review comment (suggestion):
When overriding virtual functions, we should generally not assume that the superclass doesn't need their implementation to be called, so I think we should add `MainWindowBase::changeEvent(event);`.

Code after:
    if (m_useNativeWindowFrame) {
        MainWindowBase::mouseDoubleClickEvent(event);
        return;
    }

#ifndef __APPLE__
    maximizeWindow();
#else
    this->maximizeWindowMac();
#endif
    event->accept();
}

/*!
 * \brief MainWindow::leaveEvent
 */
void MainWindow::leaveEvent(QEvent *)
{
    this->unsetCursor();
}

/*!
 * \brief MainWindow::changeEvent
 */
void MainWindow::changeEvent(QEvent *event)
{
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
    if (event->type() == QEvent::WindowStateChange && !m_useNativeWindowFrame) {
        if (isMaximized())
            setMargins(QMargins());
        else
            setMargins(QMargins(m_layoutMargin, m_layoutMargin, m_layoutMargin, m_layoutMargin));
    }
#endif
    MainWindowBase::changeEvent(event);
}

/*!
 * \brief MainWindow::setVisibilityOfFrameRightNonEditor
 * Either show or hide all widgets which are not m_textEdit
 */
void MainWindow::setVisibilityOfFrameRightNonEditor(bool isVisible)
{
    m_isFrameRightTopWidgetsVisible = isVisible;

    if (isVisible) {
        m_areNonEditorWidgetsVisible = true;
        m_editorDateLabel->setVisible(true);
        m_trashButton->setVisible(true);
        m_dotsButton->setVisible(true);
        m_styleEditorButton->setVisible(true);
Repository: nuttyartist/notes
File: src/mainwindow.cpp (C++)

Code before:
    if (m_searchEdit->text().isEmpty())
        return;

    QString searchText = m_searchEdit->text();
    QTextDocument *doc = m_textEdit->document();
    // get current cursor
    QTextCursor from = m_textEdit->textCursor();
    // search
    QTextCursor found = doc->find(searchText, from);
    m_textEdit->setTextCursor(found);
}

/*!
 * \brief MainWindow::setMargins
 * \param margins
 */
void MainWindow::setMargins(QMargins margins)
{
    if (m_useNativeWindowFrame)
        return;

    ui->centralWidget->layout()->setContentsMargins(margins);
    m_trafficLightLayout.setGeometry(QRect(4 + margins.left(), 4 + margins.top(), 56, 16));
}

bool MainWindow::isTitleBar(const int &x, const int &y)
{
    if (m_useNativeWindowFrame)
        return false;

    // The width of the title bar is essentially the width of the main window.
    int titleBarWidth = width();
    int titleBarHeight = ui->verticalSpacer_upTreeView->height();

    int adjustedX = x;
    int adjustedY = y;

    if (!isMaximized() && !isFullScreen()) {
        titleBarWidth -= m_layoutMargin * 2;
        adjustedX -= m_layoutMargin;
        adjustedY -= m_layoutMargin;
    }

    return (adjustedX >= 0 && adjustedX <= titleBarWidth && adjustedY >= 0
            && adjustedY <= titleBarHeight);
}

Review comment (performance):
Just two things:

* Please don't pass an `int` (4-byte value) as `const int &` (8-byte reference to that value). It's just more typing and makes things needlessly more expensive. :-)
* This function should be `const`.

Code after:
    if (m_searchEdit->text().isEmpty())
        return;

    QString searchText = m_searchEdit->text();
    QTextDocument *doc = m_textEdit->document();
    // get current cursor
    QTextCursor from = m_textEdit->textCursor();
    // search
    QTextCursor found = doc->find(searchText, from);
    m_textEdit->setTextCursor(found);
}

/*!
 * \brief MainWindow::setMargins
 * \param margins
 */
void MainWindow::setMargins(QMargins margins)
{
    if (m_useNativeWindowFrame)
        return;

    ui->centralWidget->layout()->setContentsMargins(margins);
    m_trafficLightLayout.setGeometry(QRect(4 + margins.left(), 4 + margins.top(), 56, 16));
}

bool MainWindow::isTitleBar(int x, int y) const
{
    if (m_useNativeWindowFrame)
        return false;

    // The width of the title bar is essentially the width of the main window.
    int titleBarWidth = width();
    int titleBarHeight = ui->verticalSpacer_upTreeView->height();

    int adjustedX = x;
    int adjustedY = y;

    if (!isMaximized() && !isFullScreen()) {
        titleBarWidth -= m_layoutMargin * 2;
        adjustedX -= m_layoutMargin;
        adjustedY -= m_layoutMargin;
    }

    return (adjustedX >= 0 && adjustedX <= titleBarWidth && adjustedY >= 0
            && adjustedY <= titleBarHeight);
}
Repository: nuttyartist/notes
File: src/elidedlabel.cpp (C++)

Code before:
#include "elidedlabel.h"

#include <QResizeEvent>
#include <QTimer>

ElidedLabel::ElidedLabel(QWidget *parent, Qt::WindowFlags f) : ElidedLabel("", parent, f) { }

ElidedLabel::ElidedLabel(const QString &text, QWidget *parent, Qt::WindowFlags f)
    : QLabel(text, parent, f), defaultType(Qt::ElideRight), eliding(false), original("")
{
    setText(text);
}

void ElidedLabel::setType(const Qt::TextElideMode type)
{
    defaultType = type;
    elide();
}

QString ElidedLabel::text() const
{
    return original;
}

void ElidedLabel::resizeEvent(QResizeEvent *event)
{
    Q_UNUSED(event);

    QTimer::singleShot(50, this, SLOT(elide()));
}

void ElidedLabel::setText(const QString &text)
{
    original = text;

Review comment (suggestion):
Can you fix the warning?

```
In file included from /src/src/elidedlabel.cpp:1:
/src/src/elidedlabel.h: In constructor 'ElidedLabel::ElidedLabel(const QString&, QWidget*, Qt::WindowFlags)':
/src/src/elidedlabel.h:26:10: warning: 'ElidedLabel::eliding' will be initialized after [-Wreorder]
   26 |     bool eliding;
      |          ^~~~~~~
/src/src/elidedlabel.h:24:13: warning:   'QString ElidedLabel::original' [-Wreorder]
   24 |     QString original;
      |             ^~~~~~~~
/src/src/elidedlabel.cpp:8:1: warning:   when initialized here [-Wreorder]
    8 | ElidedLabel::ElidedLabel(const QString &text, QWidget *parent, Qt::WindowFlags f)
      | ^~~~~~~~~~~
```

Code after:
#include "elidedlabel.h"

#include <QResizeEvent>
#include <QTimer>

ElidedLabel::ElidedLabel(QWidget *parent, Qt::WindowFlags f) : ElidedLabel("", parent, f) { }

ElidedLabel::ElidedLabel(const QString &text, QWidget *parent, Qt::WindowFlags f)
    : QLabel(text, parent, f), original(""), defaultType(Qt::ElideRight), eliding(false)
{
    setText(text);
}

void ElidedLabel::setType(const Qt::TextElideMode type)
{
    defaultType = type;
    elide();
}

QString ElidedLabel::text() const
{
    return original;
}

void ElidedLabel::resizeEvent(QResizeEvent *event)
{
    Q_UNUSED(event);

    QTimer::singleShot(50, this, SLOT(elide()));
}

void ElidedLabel::setText(const QString &text)
{
    original = text;
Repository: nvbn/thefuck
File: thefuck/rules/whois.py (Python)

Code before:
from six.moves.urllib.parse import urlparse


def match(command, settings):
    """
    What the `whois` command returns depends on the 'Whois server' it contacted
    and is not consistent through different servers. But there can be only two
    types of errors I can think of with `whois`:
        - `whois https://en.wikipedia.org/` -> `whois en.wikipedia.org`;
        - `whois en.wikipedia.org` -> `whois wikipedia.org`.
    So we match any `whois` command and then:
        - if there is a slash: keep only the FQDN;
        - if there is no slash but there is a point: removes the left-most
          subdomain.

    We cannot either remove all subdomains because we cannot know which part is
    the subdomains and which is the domain, consider:
        - www.google.fr -> subdomain: www, domain: 'google.fr';
        - google.co.uk -> subdomain: None, domain; 'google.co.uk'.
    """
    return 'whois' in command.script


def get_new_command(command, settings):
    url = command.script.split()[1]

    if '/' in command.script:
        return 'whois ' + urlparse(url).netloc
    elif '.' in command.script:
        return 'whois ' + '.'.join(urlparse(url).path.split('.')[1:])


Review comment (suggestion):
I still prefer adding an encoding line at the top of the file, like this:

``` python
# -*- encoding: utf-8 -*-
from six.moves.urllib.parse import urlparse

...
```


Code after:
# -*- encoding: utf-8 -*-
from six.moves.urllib.parse import urlparse


def match(command, settings):
    """
    What the `whois` command returns depends on the 'Whois server' it contacted
    and is not consistent through different servers. But there can be only two
    types of errors I can think of with `whois`:
        - `whois https://en.wikipedia.org/` → `whois en.wikipedia.org`;
        - `whois en.wikipedia.org` → `whois wikipedia.org`.
    So we match any `whois` command and then:
        - if there is a slash: keep only the FQDN;
        - if there is no slash but there is a point: removes the left-most
          subdomain.

    We cannot either remove all subdomains because we cannot know which part is
    the subdomains and which is the domain, consider:
        - www.google.fr → subdomain: www, domain: 'google.fr';
        - google.co.uk → subdomain: None, domain; 'google.co.uk'.
    """
    return 'whois' in command.script


def get_new_command(command, settings):
    url = command.script.split()[1]

    if '/' in command.script:
        return 'whois ' + urlparse(url).netloc
    elif '.' in command.script:
        return 'whois ' + '.'.join(urlparse(url).path.split('.')[1:])
Repository: nvbn/thefuck
File: tests/rules/test_ag_literal.py (Python)

Code before:
import pytest
from thefuck.rules.ag_literal import match, get_new_command
from tests.utils import Command

stderr = ('ERR: Bad regex! pcre_compile() failed at position 1: missing )\n'
          'If you meant to search for a literal string, run ag with -Q\n')

matching_command = Command(script='ag \\(', stderr=stderr)

@pytest.mark.parametrize('command', [
    matching_command])
def test_match(command):
    assert match(matching_command)


@pytest.mark.parametrize('command', [
    Command(script='ag foo', stderr='')])
def test_not_match(command):
    assert not match(command)


@pytest.mark.parametrize('command, new_command', [
    (matching_command, 'ag -Q \\(')])
def test_get_new_command(command, new_command):
    assert get_new_command(command) == new_command


Review comment (bug):
I'd recommend refactoring the test as the following:

``` python
import pytest
from thefuck.rules.ag_literal import get_new_command, match
from tests.utils import Command


@pytest.fixture
def stderr():
    return ('ERR: Bad regex! pcre_compile() failed at position 1: missing )\n'
            'If you meant to search for a literal string, run ag with -Q\n')


@pytest.mark.parametrize('script', ['ag \('])
def test_match(script, stderr):
    assert match(Command(script=script, stderr=stderr))


@pytest.mark.parametrize('script', ['ag foo'])
def test_not_match(script):
    assert not match(Command(script=script))


@pytest.mark.parametrize('script, new_cmd', [
    ('ag \(', 'ag -Q \(')])
def test_get_new_command(script, new_cmd, stderr):
    assert get_new_command((Command(script=script, stderr=stderr))) == new_cmd
```


Code after:
import pytest
from thefuck.rules.ag_literal import get_new_command, match
from tests.utils import Command


@pytest.fixture
def stderr():
    return ('ERR: Bad regex! pcre_compile() failed at position 1: missing )\n'
            'If you meant to search for a literal string, run ag with -Q\n')


@pytest.mark.parametrize('script', ['ag \('])
def test_match(script, stderr):
    assert match(Command(script=script, stderr=stderr))


@pytest.mark.parametrize('script', ['ag foo'])
def test_not_match(script):
    assert not match(Command(script=script))


@pytest.mark.parametrize('script, new_cmd', [
    ('ag \(', 'ag -Q \(')])
def test_get_new_command(script, new_cmd, stderr):
    assert get_new_command((Command(script=script, stderr=stderr))) == new_cmd