public void VerifyOperationTrieFindsTokenAtEnd()
        {
            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, 5 }), TokenConfig.LiteralToken(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);
        }
 public MockOperation(string id, MatchHandler onMatch, bool initialState, params byte[][] tokens)
     : this(id, onMatch, initialState, tokens.Select(token => TokenConfig.LiteralToken(token)).ToArray())
 {
 }
Beispiel #4
0
 public void AddToken(byte[] literalToken, int index)
 {
     AddToken(TokenConfig.LiteralToken(literalToken), index);
 }
Beispiel #5
0
 public int AddToken(byte[] literalToken)
 {
     return(AddToken(TokenConfig.LiteralToken(literalToken)));
 }