mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
decompiler: Add more decompilable tags
Add more tags to the list of things the decompiler can handle. This required some changes to track the containing object class in the DecompileCtx, since some objects use the same tag names. The improved support means we can test the decompiler on most of the test suite. Any new test samples will by default be tested to ensure the decompiler produces the original blueprint file. Also, updated the decompiler to always use double quotes.
This commit is contained in:
parent
ea4c7245be
commit
c1a82a034b
49 changed files with 396 additions and 151 deletions
|
@ -7,5 +7,5 @@ Gtk.Box {
|
|||
checked: true;
|
||||
}
|
||||
}
|
||||
Gtk.Label my_label {}
|
||||
|
||||
Gtk.Label my_label {}
|
||||
|
|
|
@ -2,7 +2,7 @@ using Gtk 4.0;
|
|||
|
||||
Box {
|
||||
accessibility {
|
||||
label: _('Hello, world!');
|
||||
label: _("Hello, world!");
|
||||
labelled-by: my_label;
|
||||
checked: true;
|
||||
}
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Dialog {
|
||||
[action response=cancel]
|
||||
Button cancel_button {
|
||||
label: _("Cancel");
|
||||
}
|
||||
[action response=cancel]
|
||||
Button cancel_button {
|
||||
label: _("Cancel");
|
||||
}
|
||||
|
||||
[action response=9]
|
||||
Button custom_response_button {
|
||||
label: _("Reinstall Windows");
|
||||
}
|
||||
[action response=9]
|
||||
Button custom_response_button {
|
||||
label: _("Reinstall Windows");
|
||||
}
|
||||
|
||||
[action response=ok default]
|
||||
Button ok_button {
|
||||
label: _("Ok");
|
||||
}
|
||||
[action response=ok default]
|
||||
Button ok_button {
|
||||
label: _("Ok");
|
||||
}
|
||||
}
|
||||
|
||||
InfoBar {
|
||||
[action response=ok]
|
||||
Button ok_info_button {
|
||||
label: _("Ok");
|
||||
}
|
||||
[action response=ok]
|
||||
Button ok_info_button {
|
||||
label: _("Ok");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ using Adw 1;
|
|||
|
||||
Adw.AlertDialog {
|
||||
responses [
|
||||
cancel: _('Cancel'),
|
||||
discard: _('Discard') destructive,
|
||||
save: 'Save' suggested disabled,
|
||||
cancel: _("Cancel"),
|
||||
discard: _("Discard") destructive,
|
||||
save: "Save" suggested disabled,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ using Adw 1;
|
|||
|
||||
Adw.MessageDialog {
|
||||
responses [
|
||||
cancel: _('Cancel'),
|
||||
discard: _('Discard') destructive,
|
||||
save: 'Save' suggested disabled,
|
||||
cancel: _("Cancel"),
|
||||
discard: _("Discard") destructive,
|
||||
save: "Save" suggested disabled,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,4 +2,4 @@ using Gtk 4.0;
|
|||
|
||||
Label my-label {
|
||||
label: bind ($my-closure(my-label.margin-bottom)) as <string>;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Label {
|
||||
label: bind $my-closure (true, 10, "Hello") as <string>;
|
||||
}
|
||||
label: bind $my-closure(true, 10, "Hello") as <string>;
|
||||
}
|
||||
|
|
5
tests/samples/expr_closure_dec.blp
Normal file
5
tests/samples/expr_closure_dec.blp
Normal file
|
@ -0,0 +1,5 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Label my-label {
|
||||
label: bind $my-closure(my-label.margin-bottom) as <string>;
|
||||
}
|
|
@ -5,5 +5,5 @@ Overlay {
|
|||
}
|
||||
|
||||
Label {
|
||||
label: bind (label.parent) as <Overlay>.child as <Label>.label;
|
||||
label: bind label.parent as <Overlay>.child as <Label>.label;
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
FileFilter {
|
||||
name: 'File Filter Name';
|
||||
name: "File Filter Name";
|
||||
|
||||
mime-types [
|
||||
'text/plain',
|
||||
'image/ *',
|
||||
"text/plain",
|
||||
"image/ *",
|
||||
]
|
||||
|
||||
patterns [
|
||||
'*.txt',
|
||||
"*.txt",
|
||||
]
|
||||
|
||||
suffixes [
|
||||
'png',
|
||||
"png",
|
||||
]
|
||||
}
|
||||
|
|
|
@ -2,4 +2,4 @@ using Gtk 4.0;
|
|||
|
||||
Adjustment {
|
||||
value: bind 1.0 as <double>;
|
||||
}
|
||||
}
|
||||
|
|
5
tests/samples/issue_119_dec.blp
Normal file
5
tests/samples/issue_119_dec.blp
Normal file
|
@ -0,0 +1,5 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Adjustment {
|
||||
value: bind 1;
|
||||
}
|
|
@ -3,8 +3,8 @@ using Gtk 4.0;
|
|||
Grid {
|
||||
Label {
|
||||
layout {
|
||||
column: '0';
|
||||
row: '1';
|
||||
column: "0";
|
||||
row: "1";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Gtk.ListView {
|
||||
factory: Gtk.BuilderListItemFactory list_item_factory {
|
||||
template ListItem {
|
||||
child: Label {
|
||||
label: bind template.item as <$MyObject>.name;
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
factory: Gtk.BuilderListItemFactory list_item_factory {
|
||||
template ListItem {
|
||||
child: Label {
|
||||
label: bind template.item as <$MyObject>.name;
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,26 +3,26 @@ using Gtk 4.0;
|
|||
menu my-menu {
|
||||
submenu {
|
||||
section {
|
||||
label: 'test section';
|
||||
label: "test section";
|
||||
}
|
||||
|
||||
item {
|
||||
label: C_('context', 'test translated item');
|
||||
label: C_("context", "test translated item");
|
||||
}
|
||||
|
||||
item {
|
||||
label: 'test item shorthand 1';
|
||||
label: "test item shorthand 1";
|
||||
}
|
||||
|
||||
item {
|
||||
label: 'test item shorthand 2';
|
||||
action: 'app.test-action';
|
||||
label: "test item shorthand 2";
|
||||
action: "app.test-action";
|
||||
}
|
||||
|
||||
item {
|
||||
label: 'test item shorthand 3';
|
||||
action: 'app.test-action';
|
||||
icon: 'test-symbolic';
|
||||
label: "test item shorthand 3";
|
||||
action: "app.test-action";
|
||||
icon: "test-symbolic";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
5
tests/samples/multiline_string_dec.blp
Normal file
5
tests/samples/multiline_string_dec.blp
Normal file
|
@ -0,0 +1,5 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Label {
|
||||
label: "Hello,\nworld!";
|
||||
}
|
8
tests/samples/numbers_dec.blp
Normal file
8
tests/samples/numbers_dec.blp
Normal file
|
@ -0,0 +1,8 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Label {
|
||||
xalign: 0.5;
|
||||
yalign: 0;
|
||||
height-request: 1000000;
|
||||
margin-top: 48;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Gtk.Shortcut {
|
||||
Shortcut {
|
||||
trigger: "Escape";
|
||||
}
|
||||
|
||||
|
@ -10,4 +10,4 @@ Picture {
|
|||
|
||||
ColorButton {
|
||||
rgba: "rgb(0, 0, 0)";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ using Gtk 4.0;
|
|||
Scale {
|
||||
marks [
|
||||
mark (-1, bottom),
|
||||
mark (0, top, _('Hello, world!')),
|
||||
mark (0, top, _("Hello, world!")),
|
||||
mark (2),
|
||||
]
|
||||
}
|
||||
|
|
|
@ -2,8 +2,13 @@ using Gtk 4.0;
|
|||
|
||||
SizeGroup {
|
||||
mode: horizontal;
|
||||
widgets [label, button]
|
||||
|
||||
widgets [
|
||||
label,
|
||||
button,
|
||||
]
|
||||
}
|
||||
|
||||
Label label {}
|
||||
|
||||
Button button {}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
AboutDialog about {
|
||||
valign: center;
|
||||
authors: ["Jane doe <jane-doe@email.com>", "Jhonny D <jd@email.com>"];
|
||||
valign: center;
|
||||
|
||||
authors: [
|
||||
"Jane doe <jane-doe@email.com>",
|
||||
"Jhonny D <jd@email.com>"
|
||||
];
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ StringList greetings {
|
|||
]
|
||||
}
|
||||
|
||||
Gtk.DropDown {
|
||||
DropDown {
|
||||
model: greetings;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Label {
|
||||
label: '\\\\\'Test 1 2 3\n & 4 "5\' 6 \t';
|
||||
label: "\\\\'Test 1 2 3\n & 4 \"5' 6 \t";
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Label {
|
||||
styles ["class-1", "class-2"]
|
||||
styles [
|
||||
"class-1",
|
||||
"class-2"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -6,4 +6,4 @@ Gtk.BuilderListItemFactory {
|
|||
}
|
||||
}
|
||||
|
||||
Gtk.Label label {}
|
||||
Gtk.Label label {}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template $TestTemplate: ApplicationWindow {
|
||||
test-property: 'Hello, world';
|
||||
test-property: "Hello, world";
|
||||
test-signal => $on_test_signal();
|
||||
}
|
||||
|
||||
Dialog {
|
||||
transient-for: template;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,4 +2,4 @@ using Gtk 4.0;
|
|||
|
||||
template $MyTemplate {
|
||||
object: bind template.object2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template $MyTemplate : Box {
|
||||
template $MyTemplate: Box {
|
||||
prop1: bind template.prop2 as <$MyObject>.prop3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template $MyTemplate : $MyParentClass {
|
||||
template $MyTemplate: $MyParentClass {
|
||||
prop1: bind template.prop2 as <$MyObject>.prop3;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template $MyTemplate : Gtk.Button {
|
||||
template $MyTemplate: Gtk.Button {
|
||||
/* this makes no actual sense, but it tests what I want to test */
|
||||
child: template;
|
||||
}
|
||||
}
|
||||
|
|
5
tests/samples/template_id_dec.blp
Normal file
5
tests/samples/template_id_dec.blp
Normal file
|
@ -0,0 +1,5 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template $MyTemplate: Button {
|
||||
child: template;
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template Gtk.ListItem {}
|
||||
template ListItem {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
template $TestTemplate {
|
||||
test-property: 'Hello, world';
|
||||
test-property: "Hello, world";
|
||||
}
|
|
@ -2,4 +2,4 @@ using Gtk 4.0;
|
|||
|
||||
template $MyTemplate {
|
||||
prop: bind template.prop2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
Label {
|
||||
label: _('Hello, world!');
|
||||
label: _("Hello, world!");
|
||||
}
|
||||
|
||||
Label {
|
||||
label: C_('translation context', 'Hello');
|
||||
label: C_("translation context", "Hello");
|
||||
}
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
translation-domain "blueprint-tests";
|
||||
|
|
|
@ -8,4 +8,4 @@ Gio.ListStore {
|
|||
|
||||
Gio.ListStore {
|
||||
item-type: typeof<$MyObject>;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@ using Gtk 4.0;
|
|||
|
||||
$MyComponent component {
|
||||
$MyComponent2 {
|
||||
flags-value: 'a|b';
|
||||
flags-value: "a|b";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
|
||||
import os
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
@ -36,7 +37,6 @@ from blueprintcompiler.errors import (
|
|||
)
|
||||
from blueprintcompiler.lsp import LanguageServer
|
||||
from blueprintcompiler.outputs.xml import XmlOutput
|
||||
from blueprintcompiler.tokenizer import Token, TokenType, tokenize
|
||||
|
||||
|
||||
class TestSamples(unittest.TestCase):
|
||||
|
@ -150,17 +150,27 @@ class TestSamples(unittest.TestCase):
|
|||
def assert_decompile(self, name):
|
||||
print(f'assert_decompile("{name}")')
|
||||
try:
|
||||
with open((Path(__file__).parent / f"samples/{name}.blp").resolve()) as f:
|
||||
expected = f.read()
|
||||
if os.path.exists(
|
||||
(Path(__file__).parent / f"samples/{name}_dec.blp").resolve()
|
||||
):
|
||||
with open(
|
||||
(Path(__file__).parent / f"samples/{name}_dec.blp").resolve()
|
||||
) as f:
|
||||
expected = f.read().strip()
|
||||
else:
|
||||
with open(
|
||||
(Path(__file__).parent / f"samples/{name}.blp").resolve()
|
||||
) as f:
|
||||
expected = f.read().strip()
|
||||
|
||||
name = name.removesuffix("_dec")
|
||||
ui_path = (Path(__file__).parent / f"samples/{name}.ui").resolve()
|
||||
|
||||
actual = decompiler.decompile(ui_path)
|
||||
actual = decompiler.decompile(ui_path).strip()
|
||||
|
||||
self.assertEqual(actual.strip(), expected.strip())
|
||||
self.assertEqual(actual, expected)
|
||||
except PrintableError as e: # pragma: no cover
|
||||
e.pretty_print(name + ".blp", blueprint)
|
||||
e.pretty_print(name + ".blp", expected)
|
||||
raise AssertionError()
|
||||
|
||||
def test_samples(self):
|
||||
|
@ -173,7 +183,10 @@ class TestSamples(unittest.TestCase):
|
|||
samples.sort()
|
||||
for sample in samples:
|
||||
REQUIRE_ADW_1_4 = ["adw_breakpoint"]
|
||||
REQUIRE_ADW_1_5 = ["adw_alertdialog_responses"]
|
||||
REQUIRE_ADW_1_5 = [
|
||||
"adw_alertdialog_responses",
|
||||
"adw_alert_dialog_duplicate_flags",
|
||||
]
|
||||
|
||||
SKIP_RUN = [
|
||||
"adw_breakpoint_template",
|
||||
|
@ -193,6 +206,23 @@ class TestSamples(unittest.TestCase):
|
|||
"unchecked_class",
|
||||
]
|
||||
|
||||
SKIP_DECOMPILE = [
|
||||
# Not implemented yet
|
||||
"action_widgets",
|
||||
# Not implemented yet
|
||||
"adw_breakpoint",
|
||||
# Not implemented yet
|
||||
"adw_breakpoint_template",
|
||||
# Not implemented yet
|
||||
"gtkcolumnview",
|
||||
# Comments are not preserved in either direction
|
||||
"comments",
|
||||
# Not implemented yet
|
||||
"list_factory",
|
||||
# Not implemented yet
|
||||
"subscope",
|
||||
]
|
||||
|
||||
if sample in REQUIRE_ADW_1_4 and not self.have_adw_1_4:
|
||||
continue
|
||||
if sample in REQUIRE_ADW_1_5 and not self.have_adw_1_5:
|
||||
|
@ -201,15 +231,16 @@ class TestSamples(unittest.TestCase):
|
|||
with self.subTest(sample):
|
||||
self.assert_sample(sample, skip_run=sample in SKIP_RUN)
|
||||
|
||||
with self.subTest("decompile/" + sample):
|
||||
if sample not in SKIP_DECOMPILE:
|
||||
self.assert_decompile(sample)
|
||||
|
||||
# list the sample_errors directory
|
||||
sample_errors = [
|
||||
f.stem for f in Path(__file__).parent.glob("sample_errors/*.blp")
|
||||
]
|
||||
sample_errors.sort()
|
||||
for sample_error in sample_errors:
|
||||
REQUIRE_ADW_1_4 = ["adw_breakpoint"]
|
||||
REQUIRE_ADW_1_5 = ["adw_alert_dialog_duplicate_flags"]
|
||||
|
||||
if sample_error in REQUIRE_ADW_1_4 and not self.have_adw_1_4:
|
||||
continue
|
||||
if sample_error in REQUIRE_ADW_1_5 and not self.have_adw_1_5:
|
||||
|
@ -217,27 +248,3 @@ class TestSamples(unittest.TestCase):
|
|||
|
||||
with self.subTest(sample_error):
|
||||
self.assert_sample_error(sample_error)
|
||||
|
||||
def test_decompiler(self):
|
||||
self.assert_decompile("accessibility_dec")
|
||||
if self.have_adw_1_5:
|
||||
self.assert_decompile("adw_alertdialog_responses")
|
||||
self.assert_decompile("adw_messagedialog_responses")
|
||||
self.assert_decompile("child_type")
|
||||
self.assert_decompile("file_filter")
|
||||
self.assert_decompile("flags")
|
||||
self.assert_decompile("id_prop")
|
||||
self.assert_decompile("layout_dec")
|
||||
self.assert_decompile("menu_dec")
|
||||
self.assert_decompile("property")
|
||||
self.assert_decompile("property_binding_dec")
|
||||
self.assert_decompile("placeholder_dec")
|
||||
self.assert_decompile("scale_marks")
|
||||
self.assert_decompile("signal")
|
||||
self.assert_decompile("strings_dec")
|
||||
self.assert_decompile("style_dec")
|
||||
self.assert_decompile("template")
|
||||
self.assert_decompile("template_orphan")
|
||||
self.assert_decompile("translated")
|
||||
self.assert_decompile("using")
|
||||
self.assert_decompile("unchecked_class_dec")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue