|
| 1 | +"""Tests for the CMake schema""" |
| 2 | + |
| 3 | +from cppython.plugins.cmake.schema import CacheVariable, VariableType |
| 4 | + |
| 5 | + |
| 6 | +class TestCacheVariable: |
| 7 | + """Tests for the CacheVariable class""" |
| 8 | + |
| 9 | + @staticmethod |
| 10 | + def test_cache_variable_bool() -> None: |
| 11 | + """Tests the CacheVariable class with a boolean value""" |
| 12 | + var = CacheVariable(type=VariableType.BOOL, value=True) |
| 13 | + assert var.type == VariableType.BOOL |
| 14 | + assert var.value is True |
| 15 | + |
| 16 | + @staticmethod |
| 17 | + def test_cache_variable_string() -> None: |
| 18 | + """Tests the CacheVariable class with a string value""" |
| 19 | + var = CacheVariable(type=VariableType.STRING, value='SomeValue') |
| 20 | + assert var.type == VariableType.STRING |
| 21 | + assert var.value == 'SomeValue' |
| 22 | + |
| 23 | + @staticmethod |
| 24 | + def test_cache_variable_null_type() -> None: |
| 25 | + """Tests the CacheVariable class with a null type""" |
| 26 | + var = CacheVariable(type=None, value='Unset') |
| 27 | + assert var.type is None |
| 28 | + assert var.value == 'Unset' |
| 29 | + |
| 30 | + @staticmethod |
| 31 | + def test_cache_variable_type_enum_values() -> None: |
| 32 | + """Tests the CacheVariable class with enum values""" |
| 33 | + # Ensure all CMake types are present |
| 34 | + expected = {'BOOL', 'PATH', 'FILEPATH', 'STRING', 'INTERNAL', 'STATIC', 'UNINITIALIZED'} |
| 35 | + actual = {v.value for v in VariableType} |
| 36 | + assert expected == actual |
| 37 | + |
| 38 | + @staticmethod |
| 39 | + def test_cache_variable_bool_value_as_string() -> None: |
| 40 | + """Tests the CacheVariable class with a boolean value as a string""" |
| 41 | + # CMake allows bool as "TRUE"/"FALSE" as well |
| 42 | + var = CacheVariable(type=VariableType.BOOL, value='TRUE') |
| 43 | + assert var.value == 'TRUE' |
| 44 | + |
| 45 | + @staticmethod |
| 46 | + def test_cache_variable_type_optional() -> None: |
| 47 | + """Tests the CacheVariable class with an optional type""" |
| 48 | + # type is optional |
| 49 | + var = CacheVariable(value='SomeValue') |
| 50 | + assert var.type is None |
| 51 | + assert var.value == 'SomeValue' |
0 commit comments