Add tests, remove unused code, fix bugs

- Added tests for more error messages
- Test the "go to reference" feature at every character index of every
test case
- Delete unused code and imports
- Fix some bugs I found along the way
This commit is contained in:
James Westman 2024-12-22 18:00:39 -06:00
parent 5b0f662478
commit 9b9fab832b
No known key found for this signature in database
GPG key ID: CE2DBA0ADB654EA6
47 changed files with 140 additions and 190 deletions

View file

@ -4,7 +4,6 @@ from .adw_breakpoint import (
AdwBreakpointSetters,
)
from .adw_response_dialog import ExtAdwResponseDialog
from .attributes import BaseAttribute
from .binding import Binding
from .common import *
from .contexts import ScopeCtx, ValueTypeCtx
@ -20,7 +19,7 @@ from .expression import (
from .gobject_object import Object, ObjectContent
from .gobject_property import Property
from .gobject_signal import Signal
from .gtk_a11y import ExtAccessibility
from .gtk_a11y import A11yProperty, ExtAccessibility
from .gtk_combo_box_text import ExtComboBoxItems
from .gtk_file_filter import (
Filters,

View file

@ -20,7 +20,6 @@
from ..decompiler import decompile_translatable, truthy
from .common import *
from .contexts import ValueTypeCtx
from .gobject_object import ObjectContent, validate_parent_type
from .values import StringValue
@ -94,10 +93,6 @@ class ExtAdwResponseDialogResponse(AstNode):
self.value.range.text,
)
@context(ValueTypeCtx)
def value_type(self) -> ValueTypeCtx:
return ValueTypeCtx(StringType())
@validate("id")
def unique_in_parent(self):
self.validate_unique_in_parent(

View file

@ -1,32 +0,0 @@
# attributes.py
#
# Copyright 2022 James Westman <james@jwestman.net>
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# This file is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: LGPL-3.0-or-later
from .common import *
class BaseAttribute(AstNode):
"""A helper class for attribute syntax of the form `name: literal_value;`"""
tag_name: str = ""
attr_name: str = "name"
@property
def name(self):
return self.tokens["name"]

View file

@ -38,10 +38,6 @@ class ExprBase(AstNode):
def type(self) -> T.Optional[GirType]:
raise NotImplementedError()
@property
def type_complete(self) -> bool:
return True
@property
def rhs(self) -> T.Optional["ExprBase"]:
if isinstance(self.parent, Expression):
@ -65,10 +61,6 @@ class Expression(ExprBase):
def type(self) -> T.Optional[GirType]:
return self.last.type
@property
def type_complete(self) -> bool:
return self.last.type_complete
class InfixExpr(ExprBase):
@property
@ -99,15 +91,6 @@ class LiteralExpr(ExprBase):
def type(self) -> T.Optional[GirType]:
return self.literal.value.type
@property
def type_complete(self) -> bool:
from .values import IdentLiteral
if isinstance(self.literal.value, IdentLiteral):
if object := self.context[ScopeCtx].objects.get(self.literal.value.ident):
return not object.gir_class.incomplete
return True
class LookupOp(InfixExpr):
grammar = [".", UseIdent("property")]
@ -211,10 +194,6 @@ class CastExpr(InfixExpr):
def type(self) -> T.Optional[GirType]:
return self.children[TypeName][0].gir_type
@property
def type_complete(self) -> bool:
return True
@validate()
def cast_makes_sense(self):
if self.type is None or self.lhs.type is None:

View file

@ -51,7 +51,7 @@ class Property(AstNode):
@property
def document_symbol(self) -> DocumentSymbol:
if isinstance(self.value, ObjectValue):
if isinstance(self.value, ObjectValue) or self.value is None:
detail = None
else:
detail = self.value.range.text

View file

@ -122,7 +122,7 @@ class Signal(AstNode):
)
def get_reference(self, idx: int) -> T.Optional[LocationLink]:
if idx in self.group.tokens["object"].range:
if self.object_id is not None and idx in self.group.tokens["object"].range:
obj = self.context[ScopeCtx].objects.get(self.object_id)
if obj is not None:
return LocationLink(

View file

@ -19,8 +19,6 @@
import typing as T
from ..decompiler import escape_quote
from .attributes import BaseAttribute
from .common import *
from .contexts import ValueTypeCtx
from .gobject_object import ObjectContent, validate_parent_type
@ -119,7 +117,7 @@ def _get_docs(gir, name):
return gir_type.doc
class A11yProperty(BaseAttribute):
class A11yProperty(AstNode):
grammar = Statement(
UseIdent("name"),
":",

View file

@ -19,7 +19,6 @@
from .common import *
from .contexts import ValueTypeCtx
from .gobject_object import ObjectContent, validate_parent_type
from .values import StringValue

View file

@ -50,7 +50,7 @@ class ExtListItemFactory(AstNode):
else:
return self.root.gir.get_type("ListItem", "Gtk")
@validate("template")
@validate("id")
def container_is_builder_list(self):
validate_parent_type(
self,
@ -59,7 +59,7 @@ class ExtListItemFactory(AstNode):
"sub-templates",
)
@validate("template")
@validate("id")
def unique_in_parent(self):
self.validate_unique_in_parent("Duplicate template block")
@ -76,7 +76,7 @@ class ExtListItemFactory(AstNode):
f"Only Gtk.ListItem, Gtk.ListHeader, Gtk.ColumnViewRow, or Gtk.ColumnViewCell is allowed as a type here"
)
@validate("template")
@validate("id")
def type_name_upgrade(self):
if self.type_name is None:
raise UpgradeWarning(
@ -103,10 +103,7 @@ class ExtListItemFactory(AstNode):
@property
def action_widgets(self):
"""
The sub-template shouldn't have it`s own actions this is
just hear to satisfy XmlOutput._emit_object_or_template
"""
# The sub-template shouldn't have its own actions, this is just here to satisfy XmlOutput._emit_object_or_template
return None
@docs("id")

View file

@ -59,14 +59,8 @@ class GtkDirective(AstNode):
@property
def gir_namespace(self):
# validate the GTK version first to make sure the more specific error
# message is emitted
self.gtk_version()
if self.tokens["version"] is not None:
return gir.get_namespace("Gtk", self.tokens["version"])
else:
# For better error handling, just assume it's 4.0
return gir.get_namespace("Gtk", "4.0")
# For better error handling, just assume it's 4.0
return gir.get_namespace("Gtk", "4.0")
@docs()
def ref_docs(self):
@ -90,7 +84,7 @@ class Import(AstNode):
@validate("namespace", "version")
def namespace_exists(self):
gir.get_namespace(self.tokens["namespace"], self.tokens["version"])
gir.get_namespace(self.namespace, self.version)
@validate()
def unused(self):
@ -106,7 +100,7 @@ class Import(AstNode):
@property
def gir_namespace(self):
try:
return gir.get_namespace(self.tokens["namespace"], self.tokens["version"])
return gir.get_namespace(self.namespace, self.version)
except CompileError:
return None