Пример #1
0
 public ParseState(ISequence <TInput> input, Action <string> logCallback, IMemoryCache cache)
 {
     Input        = input;
     _store       = new CascadingKeyValueStore();
     _logCallback = logCallback;
     Cache        = new MemoryCacheResultsCache(cache);
 }
Пример #2
0
        public void Method_Parse_MultiOutput()
        {
            var parser = Cache(ProduceMulti(() => new[] { "abc" }));
            var input  = new StringCharacterSequence("TEST");
            var start  = input.Checkpoint();
            var cache  = new MemoryCacheResultsCache();
            var state  = new ParseState <char>(input, _ => { }, cache);

            // First attempt, we parse the string for the first time. There's nothing in cache
            var result = parser.Parse(state);

            result.Success.Should().BeTrue();
            result.Results[0].Value.Should().Be("abc");
            var stats = cache.GetStatistics();

            stats.Attempts.Should().Be(1);
            stats.Misses.Should().Be(1);
            stats.Hits.Should().Be(0);

            // Second attempt, we start from the beginning again, but now the value is in cache
            // already. We keep the same statistics from last time (1 attempt, 1 miss) and append
            // the new hit
            start.Rewind();
            result = parser.Parse(state);
            result.Success.Should().BeTrue();
            result.Results[0].Value.Should().Be("abc");
            stats = cache.GetStatistics();
            stats.Attempts.Should().Be(2);
            stats.Misses.Should().Be(1);
            stats.Hits.Should().Be(1);
        }