Forbid blankspaces in 'New package...' dialogs

Adapt existing test to cover that case.

For eng/ide/gnatstudio#228
This commit is contained in:
Anthony Leonardo Gracio
2024-01-25 15:07:58 +00:00
parent cbff43887e
commit dc027b7a2e
2 changed files with 34 additions and 12 deletions

View File

@@ -355,6 +355,13 @@ package body Language_Handlers.Assistants is
("You should specify the unit name, not the filename (e.g: "
& " for an Ada main, enter ""Main"" and not ""main.adb"".");
return False;
elsif Unbounded_String_Array'
(GNATCOLL.Utils.Split (Text, On => ' '))'Length > 1
then
Error_Msg := To_Unbounded_String
("Unit names can't contain blankspaces.");
return False;
end if;
return True;
@@ -570,11 +577,11 @@ package body Language_Handlers.Assistants is
declare
Impl_Cursor : Integer;
Impl_Expanded_Text : constant String :=
Expand_Alias_With_Values
(Alias => Command.File_Template.Impl_Alias,
Kernel => Kernel,
Params_Substitutions => Params_Substitutions,
Cursor => Impl_Cursor);
Expand_Alias_With_Values
(Alias => Command.File_Template.Impl_Alias,
Kernel => Kernel,
Params_Substitutions => Params_Substitutions,
Cursor => Impl_Cursor);
begin
Impl_File := Create_File_From_Expanded_Template
(Part => Unit_Body,

View File

@@ -18,28 +18,43 @@ def run_test():
# Verify that the 'Ok' button is insensitive
ok_button = get_button_from_label("OK", dialog)
gps_assert(ok_button.get_sensitive(), False,
"The OK button should not be clickable")
gps_assert(
ok_button.get_sensitive(),
False,
"The OK button should not be clickable when specifying filenames",
)
# Try to enter a unit name containing blank spaces
name_ent = get_widgets_by_type(Gtk.Entry, dialog)[0]
name_ent.set_text("main adb")
# Verify that the 'Ok' button is insensitive
ok_button = get_button_from_label("OK", dialog)
gps_assert(
ok_button.get_sensitive(),
False,
"The OK button should not be clickable when there are blankspaces",
)
# Now enter a valid unit name
name_ent.set_text("Main")
# Verify that the 'Ok' button is now sensitive
gps_assert(ok_button.get_sensitive(), True,
"The OK button should now be clickable")
gps_assert(
ok_button.get_sensitive(), True, "The OK button should now be clickable"
)
# Cancel the dialog
cancel_button = get_stock_button(dialog, Gtk.STOCK_CANCEL)
cancel_button.clicked()
# Click in the 'src' directory in the Project view
GPS.MDI.get("Project").raise_window()
explorer = get_widget_by_name("Project Explorer Tree")
select_in_tree(explorer, column=1, key='.')
select_in_tree(explorer, column=1, key=".")
# try to create a new Ada main unit from there
before_dialog(on_create_main_unit_dialog)
GPS.execute_action('new ada main unit')
GPS.execute_action("new ada main unit")
yield wait_tasks(other_than=known_tasks)