Esempio n. 1
0
        private void ResetState()
        {
            Vim.MarkMap.Clear();

            Vim.VimData.SearchHistory.Reset();
            Vim.VimData.CommandHistory.Reset();
            Vim.VimData.LastCommand       = FSharpOption <StoredCommand> .None;
            Vim.VimData.LastCommandLine   = "";
            Vim.VimData.LastShellCommand  = FSharpOption <string> .None;
            Vim.VimData.LastTextInsert    = FSharpOption <string> .None;
            Vim.VimData.AutoCommands      = FSharpList <AutoCommand> .Empty;
            Vim.VimData.AutoCommandGroups = FSharpList <AutoCommandGroup> .Empty;

            Vim.KeyMap.ClearAll();
            Vim.KeyMap.IsZeroMappingEnabled = true;

            Vim.CloseAllVimBuffers();
            Vim.IsDisabled = false;

            // The majority of tests run without a VimRc file but a few do customize it for specific
            // test reasons.  Make sure it's consistent
            VimRcState = VimRcState.None;

            // Reset all of the global settings back to their default values.   Adds quite
            // a bit of sanity to the test bed
            foreach (var setting in Vim.GlobalSettings.Settings)
            {
                if (!setting.IsValueDefault && !setting.IsValueCalculated)
                {
                    Vim.GlobalSettings.TrySetValue(setting.Name, setting.DefaultValue);
                }
            }

            // Reset all of the register values to empty
            foreach (var name in Vim.RegisterMap.RegisterNames)
            {
                Vim.RegisterMap.GetRegister(name).UpdateValue("");
            }

            // Don't let recording persist across tests
            if (Vim.MacroRecorder.IsRecording)
            {
                Vim.MacroRecorder.StopRecording();
            }

            if (Vim.VimHost is MockVimHost vimHost)
            {
                vimHost.ShouldCreateVimBufferImpl = false;
                vimHost.Clear();
            }

            VariableMap.Clear();
            VimErrorDetector.Clear();
            TestableSynchronizationContext?.Dispose();
            TestableSynchronizationContext = null;
        }
Esempio n. 2
0
        public virtual void Dispose()
        {
            Vim.MarkMap.Clear();

            if (VimErrorDetector.HasErrors())
            {
                var msg = String.Format("Extension Exception: {0}", VimErrorDetector.GetErrors().First().Message);

                // Need to clear before we throw or every subsequent test will fail with the same error
                VimErrorDetector.Clear();

                throw new Exception(msg);
            }
            VimErrorDetector.Clear();

            Vim.VimData.SearchHistory.Reset();
            Vim.VimData.CommandHistory.Reset();
            Vim.VimData.LastCommand       = FSharpOption <StoredCommand> .None;
            Vim.VimData.LastCommandLine   = "";
            Vim.VimData.LastShellCommand  = FSharpOption <string> .None;
            Vim.VimData.AutoCommands      = FSharpList <AutoCommand> .Empty;
            Vim.VimData.AutoCommandGroups = FSharpList <AutoCommandGroup> .Empty;

            Vim.KeyMap.ClearAll();
            Vim.KeyMap.IsZeroMappingEnabled = true;

            Vim.CloseAllVimBuffers();
            Vim.IsDisabled = false;

            // The majority of tests run without a VimRc file but a few do customize it for specific
            // test reasons.  Make sure it's consistent
            VimRcState = VimRcState.None;

            // Reset all of the global settings back to their default values.   Adds quite
            // a bit of sanity to the test bed
            foreach (var setting in Vim.GlobalSettings.AllSettings)
            {
                if (!setting.IsValueDefault && !setting.IsValueCalculated)
                {
                    Vim.GlobalSettings.TrySetValue(setting.Name, setting.DefaultValue);
                }
            }

            // Reset all of the register values to empty
            foreach (var name in Vim.RegisterMap.RegisterNames)
            {
                Vim.RegisterMap.GetRegister(name).UpdateValue("");
            }

            // Don't let recording persist across tests
            if (Vim.MacroRecorder.IsRecording)
            {
                Vim.MacroRecorder.StopRecording();
            }

            var vimHost = Vim.VimHost as MockVimHost;

            if (vimHost != null)
            {
                vimHost.ShouldCreateVimBufferImpl = false;
                vimHost.Clear();
            }

            VariableMap.Clear();
        }