# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
# 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.
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========

from mirage.commands.builtin.generic.crossmount.fanout.exit import \
    combined_exit


def testcombined_exit_grep_match_wins_over_no_match():
    assert combined_exit("grep", [0, 1]) == 0
    assert combined_exit("grep", [1, 1]) == 1
    assert combined_exit("grep", [2, 0]) == 2
    assert combined_exit("rm", [0, 1]) == 1
    assert combined_exit("md5", [0, 0]) == 0


def testcombined_exit_grep_failed_operand_forces_1():
    assert combined_exit("grep", [0, 1], [False, True]) == 1
    assert combined_exit("rg", [0, 1], [False, True]) == 1
    assert combined_exit("grep", [0, 1], [False, False]) == 0


def testcombined_exit_grep_quiet_match_wins_over_error():
    assert combined_exit("grep", [0, 1], [False, True], quiet=True) == 0
    assert combined_exit("grep", [1, 1], [False, True], quiet=True) == 1
