public void VerifyOperationTrieFindsTokenAfterStart()
        {
            OperationTrie trie = OperationTrie.Create(new IOperation[]
            {
                new MockOperation("Test1", null, true, TokenConfig.LiteralToken(new byte[] { 5, 2, 3, 4 })),
                new MockOperation("Test2", null, true, TokenConfig.LiteralToken(new byte[] { 4, 6 }), TokenConfig.LiteralToken(new byte[] { 2, 3 }))
            });

            byte[]     buffer = { 1, 2, 3, 4, 5 };
            int        currentBufferPosition = 0;
            IOperation match = trie.GetOperation(buffer, buffer.Length, ref currentBufferPosition, out int token);

            Assert.Null(match);
            Assert.Equal(0, currentBufferPosition);
            currentBufferPosition = 1;
            match = trie.GetOperation(buffer, buffer.Length, ref currentBufferPosition, out token);

            Assert.NotNull(match);
            Assert.Equal("Test2", match.Id);
            Assert.Equal(1, token);
            Assert.Equal(3, currentBufferPosition);
        }
Exemplo n.º 2
0
        public void VerifyOperationTrieFindsTokenAtEnd()
        {
            OperationTrie trie = OperationTrie.Create(new IOperation[]
            {
                new MockOperation("Test1", null, new byte[] { 5, 2, 3, 4 }),
                new MockOperation("Test2", null, new byte[] { 4, 5 }, new byte[] { 2, 3 })
            });

            byte[]     buffer = { 1, 2, 3, 4, 5 };
            int        currentBufferPosition = 3;
            IOperation match = trie.GetOperation(buffer, buffer.Length, ref currentBufferPosition, out int token);

            Assert.NotNull(match);
            Assert.Equal("Test2", match.Id);
            Assert.Equal(0, token);
            Assert.Equal(buffer.Length, currentBufferPosition);
        }
        public void VerifyLastInWinsForIdenticalMatching()
        {
            OperationTrie trie = OperationTrie.Create(new IOperation[]
            {
                new MockOperation("TestOp1", null, true, TokenConfig.LiteralToken(new byte[] { 5, 5, 5 })),
                new MockOperation("TestOp2", null, true, TokenConfig.LiteralToken(new byte[] { 2, 3, 4, 5 })),
                new MockOperation("TestOp3", null, true, TokenConfig.LiteralToken(new byte[] { 7, 7, 7 })),
                new MockOperation("TestOp4", null, true, TokenConfig.LiteralToken(new byte[] { 9, 9, 9, 9 }), TokenConfig.LiteralToken(new byte[] { 2, 3, 4, 5 })),
            });

            byte[]     buffer = { 9, 8, 9, 8, 7, 2, 3, 4, 5 };
            int        currentBufferPosition = 0;
            IOperation match = trie.GetOperation(buffer, buffer.Length, ref currentBufferPosition, out int token);

            Assert.NotNull(match);
            Assert.Equal("TestOp4", match.Id);
            Assert.Equal(1, token);
            Assert.Equal(buffer.Length, currentBufferPosition);
        }