PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/tests/Parser/MutuallyExclusiveParsingFixture.cs

https://github.com/sflanker/commandline
C# | 118 lines | 77 code | 15 blank | 26 comment | 0 complexity | 050d9e6eba5328656745fda1bd555de8 MD5 | raw file
Possible License(s): Apache-2.0
  1. #region License
  2. //
  3. // Command Line Library: MutuallyExclusiveParsingFixture.cs
  4. //
  5. // Author:
  6. // Giacomo Stelluti Scala (gsscoder@gmail.com)
  7. //
  8. // Copyright (C) 2005 - 2013 Giacomo Stelluti Scala
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining a copy
  11. // of this software and associated documentation files (the "Software"), to deal
  12. // in the Software without restriction, including without limitation the rights
  13. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. // copies of the Software, and to permit persons to whom the Software is
  15. // furnished to do so, subject to the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be included in
  18. // all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. // THE SOFTWARE.
  27. //
  28. #endregion
  29. #region Using Directives
  30. using Xunit;
  31. using FluentAssertions;
  32. using CommandLine.Tests.Mocks;
  33. #endregion
  34. namespace CommandLine.Tests
  35. {
  36. public class MutuallyExclusiveParsingFixture : ParserBaseFixture
  37. {
  38. [Fact]
  39. public void Parsing_one_mutually_exclusive_option_succeeds()
  40. {
  41. var options = new OptionsWithDefaultSet();
  42. var parser = new Parser(new ParserSettings {MutuallyExclusive = true});
  43. var result = parser.ParseArguments(new string[] { "--file=mystuff.xml" }, options);
  44. result.Should().BeTrue();
  45. options.FileName.Should().Be("mystuff.xml");
  46. }
  47. [Fact]
  48. public void Parsing_two_mutually_exclusive_options_fails()
  49. {
  50. var parser = new Parser(new ParserSettings { MutuallyExclusive = true });
  51. var options = new OptionsWithDefaultSet();
  52. var result = parser.ParseArguments(new string[] { "-i", "1", "--file=mystuff.xml" }, options);
  53. result.Should().BeFalse();
  54. }
  55. [Fact]
  56. public void Parsing_one_mutually_exclusive_option_with_another_option_succeeds()
  57. {
  58. var options = new OptionsWithDefaultSet();
  59. var parser = new Parser(new ParserSettings { MutuallyExclusive = true });
  60. var result = parser.ParseArguments(new string[] { "--file=mystuff.xml", "-v" }, options);
  61. result.Should().BeTrue();
  62. options.FileName.Should().Be("mystuff.xml");
  63. options.Verbose.Should().Be(true);
  64. }
  65. [Fact]
  66. public void Parsing_two_mutually_exclusive_options_in_two_set_succeeds()
  67. {
  68. var options = new OptionsWithMultipleSet();
  69. var parser = new Parser(new ParserSettings { MutuallyExclusive = true });
  70. var result = parser.ParseArguments(new string[] { "-g167", "--hue", "205" }, options);
  71. result.Should().BeTrue();
  72. options.Green.Should().Be((byte)167);
  73. options.Hue.Should().Be((short)205);
  74. }
  75. [Fact]
  76. public void Parsing_three_mutually_exclusive_options_in_two_set_fails()
  77. {
  78. var parser = new Parser(new ParserSettings {MutuallyExclusive = true});
  79. var options = new OptionsWithMultipleSet();
  80. var result = parser.ParseArguments(new string[] { "-g167", "--hue", "205", "--saturation=37" }, options);
  81. result.Should().BeFalse();
  82. }
  83. [Fact]
  84. public void Parsing_mutually_exclusive_options_and_required_option_fails()
  85. {
  86. var options = new OptionsWithMultipleSetAndOneOption();
  87. var parser = new Parser(new ParserSettings { MutuallyExclusive = true });
  88. var result = parser.ParseArguments(new string[] { "-g167", "--hue", "205" }, options);
  89. result.Should().BeFalse();
  90. }
  91. [Fact]
  92. public void Parsing_mutually_exclusive_options_and_required_option_succeeds()
  93. {
  94. var options = new OptionsWithMultipleSetAndOneOption();
  95. var parser = new Parser(new ParserSettings { MutuallyExclusive = true });
  96. var result = parser.ParseArguments(new string[] { "-g100", "-h200", "-cRgbColorSet" }, options);
  97. result.Should().BeTrue();
  98. options.Green.Should().Be((byte)100);
  99. options.Hue.Should().Be((short)200);
  100. options.DefaultColorSet.Should().Be(ColorSet.RgbColorSet);
  101. }
  102. }
  103. }