BadScript 2
Loading...
Searching...
No Matches
TokenPartitionerTests.cs
Go to the documentation of this file.
1// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
2
3using System;
4using System.Collections.Generic;
5using System.Linq;
6using Xunit;
7using CSharpx;
9
11{
13 {
14 [Fact]
16 {
17 // Fixture setup
18 var expectedSequence = new[]
19 {
20 new KeyValuePair<string, IEnumerable<string>>("i", new[] {"10", "20", "30", "40"})
21 };
22 var specs = new[]
23 {
24 new OptionSpecification(string.Empty, "stringvalue", false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '\0', null, string.Empty, string.Empty, new List<string>(), typeof(string), TargetType.Scalar, string.Empty),
25 new OptionSpecification("i", string.Empty, false, string.Empty, Maybe.Just(3), Maybe.Just(4), '\0', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<int>), TargetType.Sequence, string.Empty)
26 };
27
28 // Exercize system
29 var result = TokenPartitioner.Partition(
30 new[] { Token.Name("i"), Token.Value("10"), Token.Value("20"), Token.Value("30"), Token.Value("40") },
31 name => TypeLookup.FindTypeDescriptorAndSibling(name, specs, StringComparer.Ordinal)
32 );
33
34 // Verify outcome
35 var options = result.Item1;
36 Assert.True(expectedSequence.All(a => options.Any(r => a.Key.Equals(r.Key) && a.Value.SequenceEqual(r.Value))));
37
38 // Teardown
39 }
40
41 [Fact]
43 {
44 // Fixture setup
45 var expectedSequence = new[]
46 {
47 new KeyValuePair<string, IEnumerable<string>>("i", new[] {"10", "10", "30", "40"})
48 };
49 var specs = new[]
50 {
51 new OptionSpecification(string.Empty, "stringvalue", false, string.Empty, Maybe.Nothing<int>(), Maybe.Nothing<int>(), '\0', null, string.Empty, string.Empty, new List<string>(), typeof(string), TargetType.Scalar, string.Empty),
52 new OptionSpecification("i", string.Empty, false, string.Empty, Maybe.Just(3), Maybe.Just(4), '\0', null, string.Empty, string.Empty, new List<string>(), typeof(IEnumerable<int>), TargetType.Sequence, string.Empty)
53 };
54
55 // Exercize system
56 var result = TokenPartitioner.Partition(
57 new[] { Token.Name("i"), Token.Value("10"), Token.Value("10"), Token.Value("30"), Token.Value("40") },
58 name => TypeLookup.FindTypeDescriptorAndSibling(name, specs, StringComparer.Ordinal)
59 );
60
61 // Verify outcome
62 var options = result.Item1;
63 Assert.True(expectedSequence.All(a => options.Any(r => a.Key.Equals(r.Key) && a.Value.SequenceEqual(r.Value))));
64
65 // Teardown
66 }
67 }
68}
The Maybe type models an optional value. A value of type Maybe a either contains a value of type a (r...
Definition Maybe.cs:33
static Token Value(string text)
Definition Token.cs:30
static Token Name(string text)
Definition Token.cs:25
static Tuple< IEnumerable< KeyValuePair< string, IEnumerable< string > > >, IEnumerable< string >, IEnumerable< Token > > Partition(IEnumerable< Token > tokens, Func< string, Maybe< TypeDescriptor > > typeLookup)
static Maybe< TypeDescriptor > FindTypeDescriptorAndSibling(string name, IEnumerable< OptionSpecification > specifications, StringComparer comparer)
Definition TypeLookup.cs:13