From f2b7d3bd95a70c57026d7a61d23305166482f9cc Mon Sep 17 00:00:00 2001 From: James Westman Date: Wed, 24 Nov 2021 14:39:35 -0600 Subject: [PATCH] Fix uint properties --- gtkblueprinttool/ast.py | 8 ++++++++ tests/sample_errors/uint.blp | 5 +++++ tests/sample_errors/uint.err | 1 + tests/samples/uint.blp | 5 +++++ tests/samples/uint.ui | 7 +++++++ tests/test_samples.py | 2 ++ 6 files changed, 28 insertions(+) create mode 100644 tests/sample_errors/uint.blp create mode 100644 tests/sample_errors/uint.err create mode 100644 tests/samples/uint.blp create mode 100644 tests/samples/uint.ui diff --git a/gtkblueprinttool/ast.py b/gtkblueprinttool/ast.py index 5120139..4b93cd3 100644 --- a/gtkblueprinttool/ast.py +++ b/gtkblueprinttool/ast.py @@ -377,6 +377,14 @@ class LiteralValue(Value): except: raise CompileError(f"Cannot convert {self.tokens['value']} to integer") + elif isinstance(type, gir.UIntType): + try: + int(self.tokens["value"]) + if int(self.tokens["value"]) < 0: + raise Exception() + except: + raise CompileError(f"Cannot convert {self.tokens['value']} to unsigned integer") + elif isinstance(type, gir.FloatType): try: float(self.tokens["value"]) diff --git a/tests/sample_errors/uint.blp b/tests/sample_errors/uint.blp new file mode 100644 index 0000000..f4c20f2 --- /dev/null +++ b/tests/sample_errors/uint.blp @@ -0,0 +1,5 @@ +using Gtk 4.0; + +FlowBox { + column-spacing: -2; +} diff --git a/tests/sample_errors/uint.err b/tests/sample_errors/uint.err new file mode 100644 index 0000000..259e0e2 --- /dev/null +++ b/tests/sample_errors/uint.err @@ -0,0 +1 @@ +4,19,2,Cannot convert -2 to unsigned integer diff --git a/tests/samples/uint.blp b/tests/samples/uint.blp new file mode 100644 index 0000000..c0befe4 --- /dev/null +++ b/tests/samples/uint.blp @@ -0,0 +1,5 @@ +using Gtk 4.0; + +FlowBox { + column-spacing: 2; +} diff --git a/tests/samples/uint.ui b/tests/samples/uint.ui new file mode 100644 index 0000000..d64f298 --- /dev/null +++ b/tests/samples/uint.ui @@ -0,0 +1,7 @@ + + + + + 2 + + diff --git a/tests/test_samples.py b/tests/test_samples.py index 0b06257..5ae3e0b 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -110,6 +110,7 @@ class TestSamples(unittest.TestCase): self.assert_sample("style") self.assert_sample("template") self.assert_sample("translated") + self.assert_sample("uint") self.assert_sample("using") @@ -136,5 +137,6 @@ class TestSamples(unittest.TestCase): self.assert_sample_error("size_group_obj_dne") self.assert_sample_error("styles_in_non_widget") self.assert_sample_error("two_templates") + self.assert_sample_error("uint") self.assert_sample_error("using_invalid_namespace") self.assert_sample_error("widgets_in_non_size_group")