BadScript 2
Loading...
Searching...
No Matches
KeyValuePairHelperTests.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.Collections.Generic;
4using System.Linq;
5using Xunit;
7
9{
11 {
12 [Fact]
14 {
15 var expected = new KeyValuePair<string, IEnumerable<string>>[] { };
16
17 var result = KeyValuePairHelper.ForSequence(new Token[] { });
18
19 AssertEqual(expected, result);
20 }
21
22 [Fact]
24 {
25 var expected = new[]
26 {
27 new KeyValuePair<string, IEnumerable<string>>("seq", new[] {"seq0", "seq1", "seq2"})
28 };
29
30 var result = KeyValuePairHelper.ForSequence(new []
31 {
32 Token.Name("seq"), Token.Value("seq0"), Token.Value("seq1"), Token.Value("seq2")
33 }).ToArray();
34
35 AssertEqual(expected, result);
36 }
37
38 [Fact]
40 {
41 var expected = new[]
42 {
43 new KeyValuePair<string, IEnumerable<string>>("seq1", new[] {"seq10", "seq11", "seq12"}),
44 new KeyValuePair<string, IEnumerable<string>>("seq2", new[] {"seq20", "seq21"})
45 };
46
47 var result = KeyValuePairHelper.ForSequence(new[]
48 {
49 Token.Name("seq1"), Token.Value("seq10"), Token.Value("seq11"), Token.Value("seq12"),
50 Token.Name("seq2"), Token.Value("seq20"), Token.Value("seq21")
51 });
52
53 AssertEqual(expected, result);
54 }
55
56 private static void AssertEqual(IEnumerable<KeyValuePair<string, IEnumerable<string>>> expected, IEnumerable<KeyValuePair<string, IEnumerable<string>>> result)
57 {
58 Assert.Equal(expected.Count(), result.Count());
59 foreach (var value in expected.Zip(result, (e, r) => new { Expected = e, Result = r }))
60 {
61 Assert.Equal(value.Expected.Key, value.Result.Key);
62 Assert.Equal(value.Expected.Value, value.Result.Value);
63 }
64 }
65 }
66}
static IEnumerable< KeyValuePair< string, IEnumerable< string > > > ForSequence(IEnumerable< Token > tokens)
static Token Value(string text)
Definition Token.cs:30
static Token Name(string text)
Definition Token.cs:25
static void AssertEqual(IEnumerable< KeyValuePair< string, IEnumerable< string > > > expected, IEnumerable< KeyValuePair< string, IEnumerable< string > > > result)