PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/src/tests/Parser/ValueListAttributeParsingFixture.cs

https://github.com/sflanker/commandline
C# | 111 lines | 71 code | 14 blank | 26 comment | 1 complexity | 75be261788a732a115714d3b563b683d MD5 | raw file
Possible License(s): Apache-2.0
  1. #region License
  2. //
  3. // Command Line Library: ValueListParsingFixture.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 System;
  31. using System.Collections.Generic;
  32. using Xunit;
  33. using FluentAssertions;
  34. using CommandLine.Tests.Mocks;
  35. #endregion
  36. namespace CommandLine.Tests
  37. {
  38. public class ValueListAttributeParsingFixture : ParserBaseFixture
  39. {
  40. [Fact]
  41. public void Value_list_attribute_isolates_non_option_values()
  42. {
  43. var options = new SimpleOptionsWithValueList();
  44. var parser = new Parser();
  45. var result = parser.ParseArguments(
  46. new string[] { "--switch", "file1.ext", "file2.ext", "file3.ext", "-s", "out.ext" }, options);
  47. result.Should().BeTrue();
  48. options.Items[0].Should().Be("file1.ext");
  49. options.Items[1].Should().Be("file2.ext");
  50. options.Items[2].Should().Be("file3.ext");
  51. options.StringValue.Should().Be("out.ext");
  52. options.BooleanValue.Should().BeTrue();
  53. Console.WriteLine(options);
  54. }
  55. [Fact]
  56. public void Value_list_with_max_elem_inside_bounds()
  57. {
  58. var options = new OptionsWithValueListMaximumThree();
  59. var parser = new Parser();
  60. var result = parser.ParseArguments(new string[] { "file.a", "file.b", "file.c" }, options);
  61. result.Should().BeTrue();
  62. options.InputFilenames[0].Should().Be("file.a");
  63. options.InputFilenames[1].Should().Be("file.b");
  64. options.InputFilenames[2].Should().Be("file.c");
  65. options.OutputFile.Should().BeNull();
  66. options.Overwrite.Should().BeFalse();
  67. Console.WriteLine(options);
  68. }
  69. [Fact]
  70. public void Value_list_with_max_elem_outside_bounds()
  71. {
  72. var options = new OptionsWithValueListMaximumThree();
  73. var parser = new Parser();
  74. var result = parser.ParseArguments(
  75. new string[] { "file.a", "file.b", "file.c", "file.d" }, options);
  76. result.Should().BeFalse();
  77. }
  78. [Fact]
  79. public void Value_list_with_max_elem_set_to_zero_succeeds()
  80. {
  81. var options = new OptionsWithValueListMaximumZero();
  82. var parser = new Parser();
  83. var result = parser.ParseArguments(new string[] { }, options);
  84. result.Should().BeTrue();
  85. options.Junk.Should().HaveCount(n => n == 0);
  86. Console.WriteLine(options);
  87. }
  88. [Fact]
  89. public void Value_list_with_max_elem_set_to_zero_failes()
  90. {
  91. var options = new OptionsWithValueListMaximumZero();
  92. var parser = new Parser();
  93. var result = parser.ParseArguments(new string[] { "some", "value" }, options);
  94. result.Should().BeFalse();
  95. }
  96. }
  97. }