###############################################################################
#
# Tests for XlsxWriter.
#
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c), 2013-2025, John McNamara, jmcnamara@cpan.org
#

from xlsxwriter.workbook import Workbook

from ..excel_comparison_test import ExcelComparisonTest


class TestCompareXLSXFiles(ExcelComparisonTest):
    """
    Test file created by XlsxWriter against a file created by Excel.

    """

    def setUp(self):
        self.set_filename("protect05.xlsx")

    def test_create_file(self):
        """Test the a simple XlsxWriter file with worksheet protection."""

        workbook = Workbook(self.got_filename)

        worksheet = workbook.add_worksheet()

        unlocked = workbook.add_format({"locked": 0, "hidden": 0})
        hidden = workbook.add_format({"locked": 0, "hidden": 1})

        worksheet.protect()

        worksheet.unprotect_range("=A1")
        worksheet.unprotect_range("$C$1:$C$3")
        worksheet.unprotect_range("G4:I6", "MyRange")
        worksheet.unprotect_range("K7")

        worksheet.write("A1", 1)
        worksheet.write("A2", 2, unlocked)
        worksheet.write("A3", 3, hidden)

        workbook.close()

        self.assertExcelEqual()
