public void GetReader_MoveIntoStreamCreateNewReaderAndCheckPosition()
        {
            // Setup tests data
            string testInput = _codeSnippets[CodeType.SevenLinesOfAssignemtStatements];

            // Count the code lines
            Regex           RE         = new Regex("\n", RegexOptions.Multiline);
            MatchCollection theMatches = RE.Matches(testInput);
            int             lines      = theMatches.Count + 1;

            // Create script source
            ScriptSource source = _testEng.CreateScriptSourceFromString(testInput,
                                                                        SourceCodeKind.Statements);
            // Create first reader
            SourceCodeReader srcFirstUnitReader = source.GetReader();

            // This could be a little fragile. Might be better just to hard code
            // expected value. - Save first line with first reader.
            Assert.IsTrue(srcFirstUnitReader.SeekLine(1));
            string expValue = srcFirstUnitReader.ReadLine();

            // Move to the middle of the stream (approximately).
            Assert.IsTrue(srcFirstUnitReader.SeekLine(lines / 2));

            // Create second unit reader
            SourceCodeReader srcSecondUnitReader = source.GetReader();

            Assert.AreEqual(srcSecondUnitReader.ReadLine(), expValue);
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a Lexer instance with the given source of text.
 /// </summary>
 /// <param name="source"> The source of javascript code. </param>
 public Lexer(ScriptSource source)
 {
     if (source == null)
     {
         throw new ArgumentNullException(nameof(source));
     }
     this.source       = source;
     this.reader       = source.GetReader();
     this.lineNumber   = 1;
     this.columnNumber = 1;
 }
Esempio n. 3
0
 /// <summary>
 /// Creates a Lexer instance with the given source of text.
 /// </summary>
 /// <param name="engine"> The associated script engine. </param>
 /// <param name="source"> The source of javascript code. </param>
 public Lexer(ScriptEngine engine, ScriptSource source)
 {
     if (engine == null)
         throw new ArgumentNullException("engine");
     if (source == null)
         throw new ArgumentNullException("source");
     this.engine = engine;
     this.source = source;
     this.reader = source.GetReader();
     this.lineNumber = 1;
     this.columnNumber = 1;
 }
        public void GetReader_TwoIndependentReadersAccessingSameData()
        {
            string        testInput = _codeSnippets[CodeType.SevenLinesOfAssignemtStatements];
            StringBuilder strBuffer = new StringBuilder();

            //Get the aprox midpoint length of codinput.
            int codeMidPoint = testInput.Length / 2;

            ScriptSource source = _testEng.CreateScriptSourceFromString(testInput,
                                                                        SourceCodeKind.Statements);
            // Create the Readers
            SourceCodeReader srcFirstUnitReader  = source.GetReader();
            SourceCodeReader srcSecondUnitReader = source.GetReader();

            int chrnbr = 0;
            int cnt    = 0;

            // Read first half of stream with first stream reader
            while (((chrnbr = srcFirstUnitReader.Read()) > 0) && (cnt < codeMidPoint))
            {
                strBuffer.Append((char)chrnbr);
                cnt++; // inc cnt
                // Increment Second Reader
                srcSecondUnitReader.Read();
            }

            // Now get the second half of the input stream with second reader
            while ((chrnbr = srcSecondUnitReader.Read()) > 0)
            {
                strBuffer.Append((char)chrnbr);
                cnt++;
            }

            Assert.AreEqual(cnt, testInput.Length);
            Assert.AreEqual(testInput, strBuffer.ToString());
        }
Esempio n. 5
0
 /// <summary>
 /// Creates a Lexer instance with the given source of text.
 /// </summary>
 /// <param name="engine"> The associated script engine. </param>
 /// <param name="source"> The source of javascript code. </param>
 public Lexer(ScriptEngine engine, ScriptSource source)
 {
     if (engine == null)
     {
         throw new ArgumentNullException("engine");
     }
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     this.engine       = engine;
     this.source       = source;
     this.reader       = source.GetReader();
     this.lineNumber   = 1;
     this.columnNumber = 1;
 }
        public void GetReader_CreateMultipleDifferentInstances()
        {
            string       testInput = _codeSnippets[CodeType.SevenLinesOfAssignemtStatements];
            ScriptSource source    = _testEng.CreateScriptSourceFromString(testInput,
                                                                           SourceCodeKind.Statements);
            // Storage for readers to test
            SourceCodeReader prevStream = null, tmpStream = null;

            for (int i = 0; i < 10; i++)
            {
                if (i > 0)
                {
                    prevStream = tmpStream;
                }
                tmpStream = source.GetReader();
                Assert.AreNotEqual(prevStream, tmpStream);
            }
        }