BadScript 2
Loading...
Searching...
No Matches
ScalarTests.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.Linq;
4using Xunit;
5using FluentAssertions;
6using CSharpx;
8
10{
11 public class ScalarTests
12 {
13 [Fact]
15 {
16 var expected = new Token[] { };
17
19 new Token[] { },
20 name =>
21 new[] { "str", "int" }.Contains(name)
22 ? Maybe.Just(TypeDescriptor.Create(TargetType.Scalar, Maybe.Nothing<int>()))
23 : Maybe.Nothing<TypeDescriptor>());
24 var result = tokens.Item2; // Switch, *Scalar*, Sequence, NonOption
25
26 expected.Should().BeEquivalentTo(result);
27 }
28
29 [Fact]
31 {
32 var expected = new [] { Token.Name("str"), Token.Value("strvalue") };
33
35 new []
36 {
37 Token.Name("str"), Token.Value("strvalue"), Token.Value("freevalue"),
38 Token.Name("x"), Token.Value("freevalue2")
39 },
40 name =>
41 new[] { "str", "int" }.Contains(name)
42 ? Maybe.Just(TypeDescriptor.Create(TargetType.Scalar, Maybe.Nothing<int>()))
43 : Maybe.Nothing<TypeDescriptor>());
44 var result = tokens.Item2; // Switch, *Scalar*, Sequence, NonOption
45
46 expected.Should().BeEquivalentTo(result);
47 }
48 }
49}
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< Token >, IEnumerable< Token >, IEnumerable< Token >, IEnumerable< Token > > PartitionTokensByType(IEnumerable< Token > tokens, Func< string, Maybe< TypeDescriptor > > typeLookup)
static TypeDescriptor Create(TargetType tag, Maybe< int > maximumItems, TypeDescriptor next=default)