forked from gsscoder/commandline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptionMapperTests.cs
49 lines (44 loc) · 1.99 KB
/
OptionMapperTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using CommandLine.Core;
using CommandLine.Tests.Fakes;
using Xunit;
using CSharpx;
using RailwaySharp.ErrorHandling;
namespace CommandLine.Tests.Unit.Core
{
public class OptionMapperTests
{
[Fact]
public void Map_boolean_switch_creates_boolean_value()
{
// Fixture setup
var tokenPartitions = new[]
{
new KeyValuePair<string, IEnumerable<string>>("x", new [] { "true" })
};
var specProps = new[]
{
SpecificationProperty.Create(
new OptionSpecification("x", string.Empty, false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '\0', Maybe.Nothing<object>(), string.Empty, string.Empty, new List<string>(), typeof(bool), TargetType.Switch),
typeof(Simple_Options).GetProperties().Single(p => p.Name.Equals("BoolValue", StringComparison.Ordinal)),
Maybe.Nothing<object>())
};
// Exercize system
var result = OptionMapper.MapValues(
specProps.Where(pt => pt.Specification.IsOption()),
tokenPartitions,
(vals, type, isScalar) => TypeConverter.ChangeType(vals, type, isScalar, CultureInfo.InvariantCulture, false),
StringComparer.InvariantCulture);
// Verify outcome
Assert.NotNull(((Ok<IEnumerable<SpecificationProperty>, Error>)result).Success.Single(
a => a.Specification.IsOption()
&& ((OptionSpecification)a.Specification).ShortName.Equals("x")
&& (bool)((Just<object>)a.Value).Value));
// Teardown
}
}
}