Ejemplo n.º 1
0
        public object TestCategorizer(ScriptEngine engine, object state, string /*!*/ src, SourceLocation initial, params TokenInfo[] /*!*/ expected)
        {
            TokenCategorizer categorizer = engine.GetService <TokenCategorizer>();

            categorizer.Initialize(state, engine.CreateScriptSourceFromString(src), initial);
            IEnumerable <TokenInfo> actual = categorizer.ReadTokens(Int32.MaxValue);

            int i = 0;

            foreach (TokenInfo info in actual)
            {
                Assert(i < expected.Length);
                if (!info.Equals(expected[i]))
                {
                    Assert(false);
                }
                i++;
            }
            Assert(i == expected.Length);

            TokenInfo      t   = categorizer.ReadToken();
            SourceLocation end = expected[expected.Length - 1].SourceSpan.End;

            Assert(t.Equals(new TokenInfo(new SourceSpan(end, end), TokenCategory.EndOfStream, TokenTriggers.None)));

            return(categorizer.CurrentState);
        }
Ejemplo n.º 2
0
        public void TestCategorizer(ScriptEngine engine, string src, int charCount, params TokenInfo[] expected)
        {
            if (charCount == -1)
            {
                charCount = src.Length;
            }

            TokenCategorizer categorizer = engine.GetService <TokenCategorizer>();

            categorizer.Initialize(null, engine.CreateScriptSourceFromString(src), SourceLocation.MinValue);
            IEnumerable <TokenInfo> actual = categorizer.ReadTokens(charCount);

            int i = 0;

            foreach (TokenInfo info in actual)
            {
                Assert(i < expected.Length);
                if (!info.Equals(expected[i]))
                {
#if DEBUG
                    Console.WriteLine("");      // TODO: Fix Ruby
#endif
                    Assert(false);
                }
                i++;
            }
            Assert(i == expected.Length);
        }
Ejemplo n.º 3
0
        internal DlrClassifier(DlrClassifierProvider provider, ScriptEngine engine, ITextBuffer buffer)
        {
            buffer.Changed            += BufferChanged;
            buffer.ContentTypeChanged += BufferContentTypeChanged;

            _tokenCache  = new TokenCache();
            _categorizer = engine.GetService <TokenCategorizer>();
            _engine      = engine;
            _provider    = provider;
            _buffer      = buffer;
        }