Module: test-editor-manager-common Synopsis: Environment-Editor Interface Test -- platform-independent part Author: Hugh Greene Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND /// Two test kinds of editor. // First, a specialised kind of . define function test-exe-editor-commands-init () => (commands :: ) // Make the table. let test-exe-editor-commands = make(
); editor-add-command-factory! (test-exe-editor-commands, *test-string-based-command-factory*); test-exe-editor-commands end function; define variable *test-exe-editor-factory* = #f; // Second, a custom editor class define function test-custom-editor-commands-init () => (commands ::
) // Make the table. let test-custom-editor-commands = make(
); editor-add-command-factory! (test-custom-editor-commands, *test-table-based-command-factory*); test-custom-editor-commands end function; define class () inherited slot editor-name = #"test-custom-editor"; inherited slot editor-title = "A test editor direct subclass of "; inherited slot editor-commands, init-function: test-custom-editor-commands-init; // The following slot is for checking that init-keywords supplied to // factories are passed on to the editors they create. slot test-extra-slot :: , required-init-keyword: test-extra-slot:; end class; define method editor-call-main (editor :: , command :: , #rest args, #key fail-main?, #all-keys) => (#rest objects) if ( fail-main? ) signal(make(, other-values: "Oops!")) else command.editor-command-variable-table end if; end method; define method editor-call-finalize (editor :: , command :: false-or(), #key fail-finalize?, #all-keys) => () if ( fail-finalize? ) error(make(, other-values: "Oops again!")); else editor-uncache-instances(#"test-custom-editor"); next-method() end if end method; define variable *test-custom-editor-factory* = #f; /// Test editors. define variable *previous-editor-default-factory-name* = #f; define test test-editors (description: "Test editors.") check-true ("editors: making a specialised factory", *test-exe-editor-factory* := make(, editor-class: , editor-name: #"test-exe-editor", editor-title: "A test editor specialised from ", editor-commands: test-exe-editor-commands-init(), editor-image: "echo \"You shouldn't USE this editor!\"")); check-equal ("editors: editor-supported-command-names on test ", editor-supported-command-names (*test-exe-editor-factory*.make-instance()), #[#"test-string-based-command"]); check-true ("editors: initialisation of factory for test custom editor class", *test-custom-editor-factory* := make(, editor-class: , test-extra-slot: 1046)); check-equal ("editors: factory of origin for test custom editor class", *test-custom-editor-factory*.make-instance().editor-factory-of-origin, *test-custom-editor-factory*); // Register our factory, then make it the default, remembering the // previous default so we can reset it later. editor-register-factory(*test-custom-editor-factory*); *previous-editor-default-factory-name* := editor-default-factory-name(); editor-default-factory-name() := #"test-custom-editor"; check-equal ("editors: getting default factory name", editor-default-factory-name(), #"test-custom-editor"); check-equal ("editors: getting default factory", editor-default-factory(), *test-custom-editor-factory*); // Ensure that the editor instance cache does NOT contain an instance // of the test editor (which might happen if, say, the test suite is // re-run after a crash part-way through). editor-uncache-instances(#"test-custom-editor"); // The first call will have to create a new instance but the second // should return the same instance. check-equal ("editors: editor-get-instance cacheing", editor-default-instance(), editor-default-instance()); end test;