Exemplo n.º 1
0
        public void GetNext_Test()
        {
            var target = new MapSequence <int, int>(
                new ListSequence <int>(
                    new[] { 1, 2, 3 },
                    0
                    ),
                x => x * 2
                );

            target.GetNext().Should().Be(2);
            target.GetNext().Should().Be(4);
            target.GetNext().Should().Be(6);
            target.GetNext().Should().Be(0);
        }
Exemplo n.º 2
0
        public void Location_Test()
        {
            var target = new MapSequence <int, int>(
                new ListSequence <int>(
                    new[] { 1, 2, 3 },
                    0
                    ),
                x => x
                );

            target.GetNext().Should().Be(1);
            target.CurrentLocation.Column.Should().Be(1);
            target.GetNext().Should().Be(2);
            target.CurrentLocation.Column.Should().Be(2);
            target.GetNext().Should().Be(3);
            target.CurrentLocation.Column.Should().Be(3);
            target.GetNext().Should().Be(0);
            target.CurrentLocation.Column.Should().Be(3);
        }
Exemplo n.º 3
0
        public void Checkpoint_Test()
        {
            var target = new MapSequence <int, int>(
                new ListSequence <int>(
                    new[] { 1, 2, 3 },
                    0
                    ),
                x => x * 2
                );

            target.GetNext().Should().Be(2);
            var cp = target.Checkpoint();

            target.GetNext().Should().Be(4);
            target.GetNext().Should().Be(6);
            target.GetNext().Should().Be(0);
            cp.Rewind();
            target.GetNext().Should().Be(4);
            target.GetNext().Should().Be(6);
            target.GetNext().Should().Be(0);
        }
Exemplo n.º 4
0
        private static ITarget LoadTarget(XElement element)
        {
            if (element.Name == "seq")
            {
                var target = new MapSequence();
                target.Action = LoadAction(element);
                foreach (var sub in element.Elements())
                {
                    var minCnt   = 1;
                    var maxCnt   = 1;
                    var handle   = true;
                    var maximize = false;

                    foreach (var attr in sub.Attributes())
                    {
                        var name = attr.Name.LocalName;
                        if (name.StartsWith("s-"))
                        {
                            name = name.Substring(2);
                            if (name == "min")
                            {
                                minCnt = int.Parse(attr.Value);
                            }
                            else if (name == "max")
                            {
                                maxCnt = int.Parse(attr.Value);
                            }
                            else if (name == "handle")
                            {
                                handle = bool.Parse(attr.Value);
                            }
                            else if (name == "maximize")
                            {
                                maximize = bool.Parse(attr.Value);
                            }
                        }
                    }

                    var subTarget = LoadTarget(sub);

                    target.Sequence.Add(new MapSequence.SequenceToken
                    {
                        MinCount       = minCnt,
                        MaxCount       = maxCnt,
                        ActionHandling = handle,
                        Target         = subTarget,
                        Maximize       = maximize
                    });
                }
                return(target);
            }
            else
            {
                var target = new MapTarget();
                target.Action = LoadAction(element);
                foreach (var attr in element.Attributes())
                {
                    var name = attr.Name.LocalName;
                    if (!name.Contains("-") && name != "h")
                    {
                        target.TagFilter[name] = StringFilter.Parse(attr.Value);
                    }
                }
                return(target);
            }
            throw new Exception("Unknown target");
        }