File: Operand_test.py

package info (click to toggle)
spirv-tools 2025.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,588 kB
  • sloc: cpp: 470,407; javascript: 5,893; python: 3,326; ansic: 488; sh: 450; ruby: 88; makefile: 18; lisp: 9
file content (105 lines) | stat: -rwxr-xr-x 3,720 bytes parent folder | download | duplicates (11)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python3
# Copyright 2025 Google LLC

# 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.

import unittest
from . Operand import *

class TestOperand(unittest.TestCase):
    def test_enumerant(self) -> None:
        x = Operand({'enumerant': 'abc'});
        self.assertEqual(x.enumerant, 'abc');

    def test_value_decimal(self) -> None:
        x = Operand({'value': 123});
        self.assertEqual(x.value, 123);

    def test_value_str_hex(self) -> None:
        x = Operand({'value': "0x0101"});
        self.assertEqual(x.value, 257);

    def test_value_str_dec(self) -> None:
        x = Operand({'value': "0101"});
        self.assertEqual(x.value, 101);

    def test_value_str_invalid_dec(self) -> None:
        x = Operand({'value': "01ab"});
        self.assertRaises(Exception, lambda y: x.value, 0);

    def test_value_str_invalid_hex(self) -> None:
        x = Operand({'value': "0x010j"});
        self.assertRaises(Exception, lambda y: x.value, 0);

    def test_capabilities_absent(self) -> None:
        x = Operand({});
        self.assertEqual(x.capabilities, []);

    def test_capabilities_present(self) -> None:
        x = Operand({'capabilities': ['abc', 'def']});
        self.assertEqual(x.capabilities, ['abc', 'def']);

    def test_extensions_absent(self) -> None:
        x = Operand({});
        self.assertEqual(x.extensions, []);

    def test_extensions_present(self) -> None:
        x = Operand({'extensions': ['abc', 'def']});
        self.assertEqual(x.extensions, ['abc', 'def']);

    def test_aliases_absent(self) -> None:
        x = Operand({});
        self.assertEqual(x.aliases, []);

    def test_aliases_present(self) -> None:
        x = Operand({'aliases': ['abc', 'def']});
        self.assertEqual(x.aliases, ['abc', 'def']);

    def test_parameters_absent(self) -> None:
        x = Operand({});
        self.assertEqual(x.parameters, []);

    def test_parameters_present(self) -> None:
        x = Operand({'parameters': ['abc', 'def']});
        self.assertEqual(x.parameters, ['abc', 'def']);

    def test_version_absent(self) -> None:
        x = Operand({});
        self.assertEqual(x.version, None);

    def test_version_present(self) -> None:
        x = Operand({'version': '1.0'});
        self.assertEqual(x.version, '1.0');

    def test_lastVersion_absent(self) -> None:
        x = Operand({});
        self.assertEqual(x.lastVersion, None);

    def test_lastVersion_present(self) -> None:
        x = Operand({'lastVersion': '1.3'});
        self.assertEqual(x.lastVersion, '1.3');

    def test_all_propertites(self) -> None:
        x = Operand({'enumerant': 'Foobar',
                         'value': 12,
                         'capabilities': ["yes"],
                         'extensions': ["SPV_FOOBAR_baz_bat"],
                         'version': "1.0",
                         'lastVersion': "1.3",
                         });
        self.assertEqual(x.enumerant, 'Foobar');
        self.assertEqual(x.value, 12);
        self.assertEqual(x.capabilities, ["yes"]);
        self.assertEqual(x.extensions, ["SPV_FOOBAR_baz_bat"]);
        self.assertEqual(x.version, '1.0');
        self.assertEqual(x.lastVersion, '1.3');