Ejemplo n.º 1
0
        public async Task <bool> RunAsync()
        {
            bool result = true;

            {
                byte[] buffer = Encoding.UTF8.GetBytes("hello world");

                MemoryStream memory_stream = new MemoryStream();
                IInputStream input_stream  = new InputStream();
                memory_stream.Write(buffer, 0, buffer.Count());

                input_stream.Initialize(memory_stream);
                ICharacterStream cStream = new CharacterStream();
                cStream.Initialize(input_stream);

                ICharacter c1 = await cStream.Get();

                result = result && (null != c1); // ICharacterStream never returns null

                ICharacter ch = null;
                // verify that Get uses a pushed character
                cStream.Push(c1);
                ch = await cStream.Get();

                result = result && (c1.Info == ch.Info);

                while (ch.Kind != CharKind.NULL)
                {
                    ch = await cStream.Get();
                }
                ch = await cStream.Get(); // verify that Get() continues to get the NULL

                result = result && (ch.Kind == CharKind.NULL);
                memory_stream.Dispose();
            }
            {
                byte[]       buffer        = Encoding.UTF8.GetBytes("\n");
                MemoryStream memory_stream = new MemoryStream();
                IInputStream input_stream  = new InputStream();
                memory_stream.Write(buffer, 0, buffer.Count());

                input_stream.Initialize(memory_stream);
                ICharacterStream cStream = new CharacterStream();
                cStream.Initialize(input_stream);
                ICharacter ch = await cStream.Get();

                result = result && (ch.Kind == CharKind.CARRAGERETURN);
                ch     = await cStream.Get();

                result = result && (ch.Kind == CharKind.NULL);
                memory_stream.Dispose();
            }
            return(result);
        }
        public async Task <bool> RunAsync()
        {
            bool result = true;

            byte[]       buffer        = Encoding.UTF8.GetBytes(" 2,9.0-77.4");
            MemoryStream memory_stream = new MemoryStream();

            IInputStream input_stream = new InputStream();

            memory_stream.Write(buffer, 0, buffer.Count());
            input_stream.Initialize(memory_stream);

            ICharacterStream cStream = new CharacterStream();

            cStream.Initialize(input_stream);

            IStream <IToken> tokenStream = new Stream <IToken>();
            Queue <char>     word        = new Queue <char>();

            ITokenizer tokenizer = new Tokenizer();

            tokenizer.Initialize();
            await tokenizer.Tokenize(tokenStream, cStream, "filename", 0, 0);

            IToken token = tokenStream.Get();

            result = result && (token.Kind == TokenKind.OneOrMoreSpace);

            token  = tokenStream.Get();
            result = result && ((token.Kind == TokenKind.LiteralInteger) && (token.Info == "2"));

            token  = tokenStream.Get();
            result = result && ((token.Kind == TokenKind.Comma) && (token.Info == ","));

            token  = tokenStream.Get();
            result = result && ((token.Kind == TokenKind.LiteralFloat) && (token.Info == "9.0"));

            token  = tokenStream.Get();
            result = result && ((token.Kind == TokenKind.LiteralFloat) && (token.Info == "-77.4"));

            memory_stream.Dispose();
            return(result);
        }