<commit_before>﻿// Copyright 2005-2015 <NAME> & Contributors. All rights reserved. See doc/License.md in the project root for license information.

using System;
using System.Globalization;
using System.Linq;
using CommandLine.Core;
using CommandLine.Tests.Fakes;
using FluentAssertions;
using Xunit;

namespace CommandLine.Tests.Unit.Core
{
    public class InstanceChooserTests
    {        
        [Fact]
        public void Parse_empty_array_returns_NullInstance()
        {
            // Fixture setup
            var expectedErrors = new[] { new NoVerbSelectedError() };

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions) },
                new string[] { },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            //Assert.IsType<NullInstance>(result.Value);
            Assert.True(expectedErrors.SequenceEqual(((NotParsed<object>)result).Errors));
            // Teardown
        }

        [Fact]
        public void Explicit_help_request_generates_HelpVerbRequestedError()
        {
            // Fixture setup
            var expectedErrors = new[] { new HelpVerbRequestedError(null, null, false) };

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions) },
                new[] { "help" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            //Assert.IsType<NullInstance>(result.Value);
            Assert.True(expectedErrors.SequenceEqual(((NotParsed<object>)result).Errors));
            // Teardown
        }

        [Fact]
        public void Explicit_help_request_for_a_valid_verb_generates_HelpVerbRequestedError_with_appropriate_data()
        {
            // Fixture setup
            var expectedErrors = new[] { new HelpVerbRequestedError("commit", typeof(CommitOptions), true) };

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions) },
                new[] { "help", "commit" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            //Assert.IsType<NullInstance>(result.Value);
            Assert.True(expectedErrors.SequenceEqual(((NotParsed<object>)result).Errors));
            // Teardown
        }

        [Fact]
        public void Explicit_help_request_for_an_invalid_verb_generates_HelpVerbRequestedError_with_Matched_set_to_false()
        {
            // Fixture setup
            var expectedErrors = new[] { new HelpVerbRequestedError(null, null, false) };

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions) },
                new[] { "help", "earthunderalienattack" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            //Assert.IsType<NullInstance>(result.Value);
            Assert.True(expectedErrors.SequenceEqual(((NotParsed<object>)result).Errors));
            // Teardown
        }

        [Fact]
        public void Parse_existing_verb_returns_verb_instance()
        {
            // Fixture setup
            var expected = new AddOptions { Patch = true, FileName = "dummy.bin"};

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions) },
                new[] { "add", "--patch", "dummy.bin" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            Assert.IsType<AddOptions>(((Parsed<object>)result).Value);
            expected.ShouldBeEquivalentTo(((Parsed<object>)result).Value);
            // Teardown
        }

        [Fact]
        public void Parse_existing_verb_returns_verb_immutable_instance()
        {
            // Fixture setup
            var expected = new ImmutableAddOptions(true, default(bool), "dummy.bin");

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(ImmutableAddOptions), typeof(ImmutableCommitOptions), typeof(ImmutableCloneOptions) },
                new[] { "add", "--patch", "dummy.bin" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            Assert.IsType<ImmutableAddOptions>(((Parsed<object>)result).Value);
            expected.ShouldBeEquivalentTo(((Parsed<object>)result).Value);
            // Teardown
        }
    
        [Fact]
        public void Parse_sequence_verb_returns_verb_instance()
        {
            // Fixture setup
            var expected = new SequenceOptions { LongSequence = new long[] { }, StringSequence = new[] { "aa", "b" } };

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions), typeof(SequenceOptions) },
                new[] { "sequence", "-s", "aa", "b" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            Assert.IsType<SequenceOptions>(((Parsed<object>)result).Value);
            expected.ShouldBeEquivalentTo(((Parsed<object>)result).Value);
            // Teardown
        }

        [Theory]
        [InlineData(new[] { "sequence", "-s", "here-one-elem-but-no-sep" }, new[] { "here-one-elem-but-no-sep" })]
        [InlineData(new[] { "sequence", "-shere-one-elem-but-no-sep" }, new[] { "here-one-elem-but-no-sep" })]
        [InlineData(new[] { "sequence", "-s", "<EMAIL>,<EMAIL>,<EMAIL>" }, new[] { "<EMAIL>", "<EMAIL>", "<EMAIL>" })]
        [InlineData(new[] { "sequence", "-s<EMAIL>,<EMAIL>,<EMAIL>,another,the-last-one" }, new[] { "<EMAIL>", "<EMAIL>", "<EMAIL>", "another", "the-last-one" })]
        public void Parse_sequence_verb_with_separator_returns_verb_instance(string[] arguments, string[] expectedString)
        {
            // Fixture setup
            var expected = new SequenceOptions { LongSequence = new long[] { }, StringSequence = expectedString };

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions), typeof(SequenceOptions) },
                arguments,
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            Assert.IsType<SequenceOptions>(((Parsed<object>)result).Value);
            expected.ShouldBeEquivalentTo(((Parsed<object>)result).Value);
            // Teardown
        }
    }
}
<commit_msg>Using Should() when possible (2)<commit_after>﻿// Copyright 2005-2015 <NAME> & Contributors. All rights reserved. See doc/License.md in the project root for license information.

using System;
using System.Globalization;
using System.Linq;
using CommandLine.Core;
using CommandLine.Tests.Fakes;
using FluentAssertions;
using Xunit;

namespace CommandLine.Tests.Unit.Core
{
    public class InstanceChooserTests
    {        
        [Fact]
        public void Parse_empty_array_returns_NullInstance()
        {
            // Fixture setup
            var expectedErrors = new[] { new NoVerbSelectedError() };

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions) },
                new string[] { },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            ((NotParsed<object>)result).Errors.ShouldBeEquivalentTo(expectedErrors);

            // Teardown
        }

        [Fact]
        public void Explicit_help_request_generates_HelpVerbRequestedError()
        {
            // Fixture setup
            var expectedErrors = new[] { new HelpVerbRequestedError(null, null, false) };

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions) },
                new[] { "help" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            ((NotParsed<object>)result).Errors.ShouldBeEquivalentTo(expectedErrors);

            // Teardown
        }

        [Fact]
        public void Explicit_help_request_for_a_valid_verb_generates_HelpVerbRequestedError_with_appropriate_data()
        {
            // Fixture setup
            var expectedErrors = new[] { new HelpVerbRequestedError("commit", typeof(CommitOptions), true) };

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions) },
                new[] { "help", "commit" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            ((NotParsed<object>)result).Errors.ShouldBeEquivalentTo(expectedErrors);

            // Teardown
        }

        [Fact]
        public void Explicit_help_request_for_an_invalid_verb_generates_HelpVerbRequestedError_with_Matched_set_to_false()
        {
            // Fixture setup
            var expectedErrors = new[] { new HelpVerbRequestedError(null, null, false) };

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions) },
                new[] { "help", "earthunderalienattack" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            ((NotParsed<object>)result).Errors.ShouldBeEquivalentTo(expectedErrors);

            // Teardown
        }

        [Fact]
        public void Parse_existing_verb_returns_verb_instance()
        {
            // Fixture setup
            var expected = new AddOptions { Patch = true, FileName = "dummy.bin"};

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions) },
                new[] { "add", "--patch", "dummy.bin" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            Assert.IsType<AddOptions>(((Parsed<object>)result).Value);
            expected.ShouldBeEquivalentTo(((Parsed<object>)result).Value);
            // Teardown
        }

        [Fact]
        public void Parse_existing_verb_returns_verb_immutable_instance()
        {
            // Fixture setup
            var expected = new ImmutableAddOptions(true, default(bool), "dummy.bin");

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(ImmutableAddOptions), typeof(ImmutableCommitOptions), typeof(ImmutableCloneOptions) },
                new[] { "add", "--patch", "dummy.bin" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            Assert.IsType<ImmutableAddOptions>(((Parsed<object>)result).Value);
            expected.ShouldBeEquivalentTo(((Parsed<object>)result).Value);
            // Teardown
        }
    
        [Fact]
        public void Parse_sequence_verb_returns_verb_instance()
        {
            // Fixture setup
            var expected = new SequenceOptions { LongSequence = new long[] { }, StringSequence = new[] { "aa", "b" } };

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions), typeof(SequenceOptions) },
                new[] { "sequence", "-s", "aa", "b" },
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            Assert.IsType<SequenceOptions>(((Parsed<object>)result).Value);
            expected.ShouldBeEquivalentTo(((Parsed<object>)result).Value);
            // Teardown
        }

        [Theory]
        [InlineData(new[] { "sequence", "-s", "here-one-elem-but-no-sep" }, new[] { "here-one-elem-but-no-sep" })]
        [InlineData(new[] { "sequence", "-shere-one-elem-but-no-sep" }, new[] { "here-one-elem-but-no-sep" })]
        [InlineData(new[] { "sequence", "-s", "<EMAIL>,<EMAIL>,<EMAIL>" }, new[] { "<EMAIL>", "<EMAIL>", "<EMAIL>" })]
        [InlineData(new[] { "sequence", "-s<EMAIL>,<EMAIL>,<EMAIL>,another,the-last-one" }, new[] { "<EMAIL>", "<EMAIL>", "<EMAIL>", "another", "the-last-one" })]
        public void Parse_sequence_verb_with_separator_returns_verb_instance(string[] arguments, string[] expectedString)
        {
            // Fixture setup
            var expected = new SequenceOptions { LongSequence = new long[] { }, StringSequence = expectedString };

            // Exercize system 
            var result = InstanceChooser.Choose(
                new[] { typeof(AddOptions), typeof(CommitOptions), typeof(CloneOptions), typeof(SequenceOptions) },
                arguments,
                StringComparer.Ordinal,
                CultureInfo.InvariantCulture);

            // Verify outcome
            Assert.IsType<SequenceOptions>(((Parsed<object>)result).Value);
            expected.ShouldBeEquivalentTo(((Parsed<object>)result).Value);
            // Teardown
        }
    }
}

{'fraction_non_alphanumeric': 0.11631006664328306, 'fraction_numerical': 0.0011925640126271484, 'mean_word_length': 1.9472813727517055, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3431666', 'n_tokens_mistral': 3862, 'n_tokens_neox': 3661, 'n_words': 658}