Esempio n. 1
0
        protected void CheckTokens(string input, string[] errors, string[] tokens)
        {
            var sfm     = new LexicalStackMachine();
            var results = sfm.Parse(input);

            Assert.IsTrue(results != null, "State machine results cannot be null");
            Assert.IsTrue(results.Tokens != null, "Tokens collection cannot be null");

            if (tokens != null)
            {
                Assert.IsTrue(results.Tokens.Count == tokens.Length, "Invalid number of tokens is returned. Returned:" + results.Tokens.Count + ". Expected:" + tokens.Length);
                for (int i = 0; i < results.Tokens.Count; i++)
                {
                    var returned = results.Tokens[i].Value;
                    var expected = tokens[i];

                    Assert.IsTrue(returned == expected, "Unexpected token is returned:" + returned + ". Expected:" + expected + ". Index:" + i);
                }
            }

            // We expect some errors. So check them.
            if (errors != null)
            {
                Assert.IsTrue(results.HasErrors == true, "No errors are returned by sfm");
                var currentErrors = results.Errors;

                for (int i = 0; i < currentErrors.Count; i++)
                {
                    var returned = currentErrors[i].Value;
                    var expected = errors[i];

                    Assert.IsTrue(returned == expected, "Error is missing:" + returned + ". Expected:" + expected + ". Index:" + i);
                }
            }
        }
Esempio n. 2
0
        private async void OnTextChanged(object sender, TextChangedEventArgs e)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            this.tbLoading.Visibility = Visibility.Visible;
            var input  = this.tbInput.Text;
            var tokens = await Task.Run <List <LexicalToken> >(() =>
            {
                var sfm     = new LexicalStackMachine();
                var results = sfm.Parse(input);
                return(results.Tokens);
            });

            // Stop timing.
            stopwatch.Stop();

            lbTokens.ItemsSource = tokens;
            this.tbLoading.Text  = "Time elapsed: " + stopwatch.Elapsed;
        }