Exemple #1
0
        public void CommandLine_ProjectArgument_GetsPassedToHandler()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();
            var handlerWasCalled = false;

            sut.Handler = CommandHandler.Create(new TestCommandHandlerDelegate(TestCommandHandler));

            void TestCommandHandler(
                string workspace,
                bool folder,
                string verbosity,
                bool check,
                string[] include,
                string[] exclude,
                string report,
                bool includeGenerated)
            {
                handlerWasCalled = true;
                Assert.Equal("workspaceValue", workspace);
                Assert.Equal("detailed", verbosity);
            };

            // Act
            var result = sut.Invoke(new[] { "--verbosity", "detailed", "workspace" });

            // Assert
            Assert.True(handlerWasCalled);
        }
        public void CommandLine_OptionsAreParsedCorrectly()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] {
                "--folder", "folder",
                "--workspace", "workspace",
                "--include", "include1", "include2",
                "--exclude", "exclude1", "exclude2",
                "--check",
                "--report", "report",
                "--verbosity", "verbosity",
                "--include-generated"
            });

            // Assert
            Assert.Equal(1, result.Errors.Count); // folder and workspace can not be combined
            Assert.Equal(0, result.UnmatchedTokens.Count);
            Assert.Equal(0, result.UnparsedTokens.Count);
            Assert.Equal("folder", result.ValueForOption("folder"));
            Assert.Equal("workspace", result.ValueForOption("workspace"));
            Assert.Collection(result.ValueForOption <IEnumerable <string> >("include"),
                              i0 => Assert.Equal("include1", i0),
                              i1 => Assert.Equal("include2", i1));
            Assert.Collection(result.ValueForOption <IEnumerable <string> >("exclude"),
                              i0 => Assert.Equal("exclude1", i0),
                              i1 => Assert.Equal("exclude2", i1));
            Assert.True(result.ValueForOption <bool>("check"));
            Assert.Equal("report", result.ValueForOption("report"));
            Assert.Equal("verbosity", result.ValueForOption("verbosity"));
            Assert.True(result.ValueForOption <bool>("include-generated"));
        }
Exemple #3
0
 public static int Execute(string[] args, IConfiguration config)
 => Parser.Default.ParseArguments <RunOptions, AssembleOptions, DisassembleOptions, FormatOptions>(args).MapResult(
     (RunOptions opts) => RunCommand.Run(opts, _fileReader, _outputWriter, config),
     (AssembleOptions opts) => AssembleCommand.Run(opts, _fileReader, _fileWriter, config),
     (DisassembleOptions opts) => DisassembleCommand.Run(opts, _fileReader, _fileWriter, config),
     (FormatOptions opts) => FormatCommand.Run(opts, _fileReader, _fileWriter, config),
     errs => 1);
        private static void VerifyArguments(string arguments, string expected)
        {
            var app          = new FormatCommand().FromArgs(arguments.Split(" "));
            var expectedArgs = expected.Split(" ").ToList();

            app.Arugments.Skip(1).ToArray() // We skip the project/solution argument as its path will change
            .ShouldAllBeEquivalentTo(expectedArgs.ToArray());
        }
Exemple #5
0
        public void FormatCommand_Verify_1()
        {
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            FormatCommand           command
                = new FormatCommand(connection);

            Assert.IsFalse(command.Verify(false));
        }
Exemple #6
0
        public void FormatCommand_Construciton_1()
        {
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            FormatCommand           command
                = new FormatCommand(connection);

            Assert.AreSame(connection, command.Connection);
        }
        public async Task InitializeCommandsAsync(AsyncPackage aAsyncPackage)
        {
            if (CompileCommand.Instance == null)
            {
                await CompileCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kCompileId);

                await CompileCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kCompileToolbarId);
            }

            if (TidyCommand.Instance == null)
            {
                await TidyCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kTidyId);

                await TidyCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kTidyToolbarId);

                await TidyCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kTidyFixId);

                await TidyCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kTidyFixToolbarId);
            }

            if (FormatCommand.Instance == null)
            {
                await FormatCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kClangFormat);

                await FormatCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kClangFormatToolbarId);
            }

            if (IgnoreFormatCommand.Instance == null)
            {
                await IgnoreFormatCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kIgnoreFormatId);
            }

            if (IgnoreCompileCommand.Instance == null)
            {
                await IgnoreCompileCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kIgnoreCompileId);
            }

            if (StopCommand.Instance == null)
            {
                await StopCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kStopClang);
            }

            if (SettingsCommand.Instance == null)
            {
                await SettingsCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kSettingsId);
            }

            if (TidyConfigCommand.Instance == null)
            {
                await TidyConfigCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kITidyExportConfigId);
            }

            if (Logout.Instance == null)
            {
                await Logout.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kLogoutId);
            }
        }
 public void WithHelpOption(string arguments)
 {
     try
     {
         var app = new FormatCommand().FromArgs(arguments.Split(" "));
     }
     catch (HelpException helpException)
     {
         helpException.Message.ShouldAllBeEquivalentTo("");
     }
 }
Exemple #9
0
        public void CommandLine_BinaryLog_FailsIfFolderIsSpecified()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "--folder", "--binarylog" });

            // Assert
            Assert.Equal(1, result.Errors.Count);
        }
        public void WithoutAnyAdditionalArguments()
        {
            var app = new FormatCommand().FromArgs(Array.Empty <string>());

            app.Arugments.Skip(1).ToArray() // We skip the project/solution argument as its path will change
            .ShouldAllBeEquivalentTo(new string[] {
                "--fix-whitespace",
                "--fix-style",
                "--fix-analyzers"
            });
        }
Exemple #11
0
        public void CommandLine_Diagnostics_FailsIfDiagnosticNoSpecified()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "--diagnostics" });

            // Assert
            Assert.Equal(1, result.Errors.Count);
        }
        public void CommandLine_InvalidArgumentsDontCrashTheValidators()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "--workspace", "workspace1", "--workspace", "workspace2" });

            // Assert
            Assert.Equal(2, result.Errors.Count);
        }
        public void CommandLine_ProjectArgumentAndFolderCanNotBeCombined1()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "projectValue", "--folder", "folder" });

            // Assert
            Assert.Equal(1, result.Errors.Count);
        }
        public void CommandLine_ProjectWorkspaceAndFolderCanNotBeCombined2()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "--workspace", "workspace", "--folder", "folder" });

            // Assert
            Assert.Equal(1, result.Errors.Count);
        }
Exemple #15
0
        public void CommandLine_AnalyzerOptions_CanSpecifyBothWithDefaults()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "--fix-analyzers", "--fix-style" });

            // Assert
            Assert.Equal(0, result.Errors.Count);
        }
Exemple #16
0
        public void CommandLine_Diagnostics_DoesNotFailIfMultipleDiagnosticAreSpecified()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "--diagnostics", "RS0016", "RS0017", "RS0018" });

            // Assert
            Assert.Equal(0, result.Errors.Count);
        }
Exemple #17
0
        public void CommandLine_FolderValidation_FailsIfFixStyleSpecified()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "--folder", "--fix-style" });

            // Assert
            Assert.Equal(1, result.Errors.Count);
        }
Exemple #18
0
        private void InsertShape(Agilix.Ink.ShapeElement shape)
        {
            FormatCommand format = new FormatCommand();

            fScribble.Scribble.GetCommandStatus(format);
            if (format.State.ColorValid)
            {
                shape.LineColor = format.State.Color;
            }
            fScribble.StylusMode = new InsertShapeMode(shape);
        }
        public void CommandLine_ProjectArgument_FailesIfSpecifiedTwice()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "projectValue1", "projectValue2" });

            // Assert
            Assert.Equal(1, result.Errors.Count);
        }
Exemple #20
0
        public void CommandLine_BinaryLog_DoesNotFailIfPathIsSpecified()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "--binarylog", "log" });

            // Assert
            Assert.Equal(0, result.Errors.Count);
            Assert.True(result.WasOptionUsed("--binarylog"));
        }
Exemple #21
0
        public void CommandLine_ProjectArgument_Simple()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "workspaceValue" });

            // Assert
            Assert.Equal(0, result.Errors.Count);
            Assert.Equal("workspaceValue", result.ValueForArgument("workspace"));
        }
        public void CommandLine_ProjectArgument_Simple()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "projectValue" });

            // Assert
            Assert.Equal(0, result.Errors.Count);
            Assert.Equal("projectValue", result.CommandResult.GetArgumentValueOrDefault("project"));
        }
Exemple #23
0
        public async Task InitializeCommandsAsync(AsyncPackage aAsyncPackage)
        {
            if (CompileCommand.Instance == null)
            {
                await CompileCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kCompileId);

                await CompileCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kCompileToolbarId);
            }

            if (TidyCommand.Instance == null)
            {
                await TidyCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kTidyId);

                await TidyCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kTidyToolbarId);

                await TidyCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kTidyFixId);

                await TidyCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kTidyFixToolbarId);
            }

            if (FormatCommand.Instance == null)
            {
                await FormatCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kClangFormat);

                await FormatCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kClangFormatToolbarId);
            }

            if (IgnoreFormatCommand.Instance == null)
            {
                await IgnoreFormatCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kIgnoreFormatId);
            }

            if (IgnoreCompileCommand.Instance == null)
            {
                await IgnoreCompileCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kIgnoreCompileId);
            }

            if (StopCommand.Instance == null)
            {
                await StopCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kStopClang);
            }

            if (JsonCompilationDatabaseCommand.Instance == null)
            {
                await JsonCompilationDatabaseCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kJsonCompilationDatabase);
            }

            if (SettingsCommand.Instance == null)
            {
                await SettingsCommand.InitializeAsync(this, aAsyncPackage, mCommandSet, CommandIds.kSettingsId);
            }
        }
        public void CommandLine_ProjectArgument_WithOption_AfterArgument()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "projectValue", "--verbosity", "verbosity" });

            // Assert
            Assert.Equal(0, result.Errors.Count);
            Assert.Equal("projectValue", result.CommandResult.GetArgumentValueOrDefault("project"));
            Assert.Equal("verbosity", result.ValueForOption("verbosity"));
        }
Exemple #25
0
        public void CommandLine_ProjectArgument_WithOption_BeforeArgument()
        {
            // Arrange
            var sut = FormatCommand.CreateCommandLineOptions();

            // Act
            var result = sut.Parse(new[] { "--verbosity", "detailed", "workspaceValue" });

            // Assert
            Assert.Equal(0, result.Errors.Count);
            Assert.Equal("workspaceValue", result.CommandResult.GetArgumentValueOrDefault("workspace"));
            Assert.Equal("detailed", result.ValueForOption("verbosity"));
        }
Exemple #26
0
        public void ParseArgumentsSetsFormatAndDefaultCultureWithInvalidCulture()
        {
            FormatCommand cmd = new FormatCommand();

            cmd.ArgumentsString = @"""##,#"", ""aa-aa""";
            Document         doc     = new Document();
            var              slide   = new SlideElement(doc);
            ShapeElementBase element = (ShapeElementBase)(ShapeElementBaseTest.Create());

            cmd.TargetElement = element;
            cmd.ParseArguments();
            Assert.AreEqual("##,#", cmd.FormatString);
            Assert.AreEqual(CultureInfo.CurrentUICulture.Name, cmd.Culture.Name);
        }
Exemple #27
0
        public void ParseArgumentsSetsFormatAndCultureWithCulture()
        {
            FormatCommand cmd = new FormatCommand();

            cmd.ArgumentsString = @"""##,#"", ""de-DE""";
            Document         doc     = new Document();
            var              slide   = new SlideElement(doc);
            ShapeElementBase element = (ShapeElementBase)(ShapeElementBaseTest.Create());

            cmd.TargetElement = element;
            cmd.ParseArguments();
            Assert.AreEqual("##,#", cmd.FormatString);
            Assert.AreEqual((new CultureInfo("de-DE")).Name, cmd.Culture.Name);
        }
        private static void VerifyArgumentsWithDefault(string arguments, string expected)
        {
            var app          = new FormatCommand().FromArgs(arguments.Split(" "));
            var expectedArgs = expected.Split(" ").ToList();

            expectedArgs.AddRange(
                new string[] {
                "--fix-whitespace",
                "--fix-style",
                "--fix-analyzers"
            });
            app.Arugments.Skip(1).ToArray() // We skip the project/solution argument as its path will change
            .ShouldAllBeEquivalentTo(expectedArgs.ToArray());
        }
        public void WithExcludeOption(string files)
        {
            var app          = new FormatCommand().FromArgs(new string[] { "--exclude", files });
            var expectedArgs = new string[]
            {
                "--exclude",
                files,
                "--fix-whitespace",
                "--fix-style",
                "--fix-analyzers",
            };

            app.Arugments.Skip(1).ToArray() // We skip the project/solution argument as its path will change
            .ShouldAllBeEquivalentTo(expectedArgs.ToArray());
        }
Exemple #30
0
        private ServerResponse ExecuteFormatCommand
        (
            [NotNull] FormatCommand command,
            bool emptyRecords
        )
        {
            IIrbisConnection connection = command.Connection;
            List <int>       list       = command.MfnList;
            int count = list.Count;

            command.FormatResult = new string[count];
            for (int i = 0; i < count; i++)
            {
                MarcRecord record = new MarcRecord
                {
                    Database = connection.Database,
                    Mfn      = list[i],
                    Version  = 1,
                    Status   = RecordStatus.Last
                };
                if (!emptyRecords)
                {
                    record.Fields.Add(RecordField.Parse(100, "Field100"));
                    record.Fields.Add(RecordField.Parse(300, "Field200"));
                    record.Fields.Add(RecordField.Parse(300, "Field300"));
                }
                string line = EncodeRecord(record);
                command.FormatResult[i] = line;
            }

            byte[]         rawAnswer  = new byte[0];
            byte[]         rawRequest = new byte[0];
            ServerResponse response   = new ServerResponse
                                        (
                connection,
                rawAnswer,
                rawRequest,
                true
                                        );

            return(response);
        }
Exemple #31
0
		private void InsertShape(Agilix.Ink.ShapeElement shape)
		{
			FormatCommand format = new FormatCommand();
			fScribble.Scribble.GetCommandStatus(format);
			if (format.State.ColorValid)
			{
				shape.LineColor = format.State.Color;
			}
			fScribble.StylusMode = new InsertShapeMode(shape);
		}