예제 #1
0
    /// Invoques the specified command with the given args.
    /// (It dies if the command doesn't exists).
    /// Returns true if the command success, false otherwise.
    bool DispatchCmd(Form f, Stack <Action> asserts, PreCondErrors errors,
                     bool quiet, string cmd, params string[] args)
    {
        DieIf(f == null, "Target form can't be null.");
        DieIf(IsNullOrEmpty(cmd), "Cmd is required.");

        if (cmd.StartsWith(";"))         //<= Comment
        {
            return(true);
        }

        cmd = cmd.ToLower();
        switch (cmd)
        {
        case "move:":
            Move(f, asserts);
            break;

        case "focus:":
            DieIf(args.Length == 0, "[Focus] Name is required.");
            Focus(f, args[0]);
            break;

        case "change:":
            Change(f, args.Length > 0 ? args[0] : null);
            break;

        case "end:":
            End();
            break;

        case "start:":
            if (!Start(f, errors, quiet))                     // Can't start due to preconds errors.
            {
                return(false);
            }
            else
            {
                return(Start(f, errors, quiet));
            }

        case "ensure:":
            DieIf(args.Length == 0, "[Ensure] name is required.");
            DieIf(args.Length == 1, "[Ensure] value is required.");
            Ensure(f, args[0], args[1], errors);
            break;

        case "assert:":
            DieIf(args.Length == 0, "[Assert] name is required.");
            DieIf(args.Length == 1, "[Assert] value is required.");
            DieIf(asserts == null, "[Assert] asserts is required.");
            Assert(f, args[0], args[1], asserts);
            break;

        default:
            Die($"Unknown cmd => {cmd}");
            break;
        }
        return(true);
    }
예제 #2
0
    public bool Start(Form f, PreCondErrors errors, bool quiet)
    {
        WriteLine($"Start errors count: {errors.Count}");

        if (errors.Count == 0)
        {
            return(true);
        }

        int fixes = 0;

        for (int i = 0; i < errors.Count; ++i)
        {
            var err = errors.At(i);
            if (quiet || AutoFix(err))
            {
                Fix(f, err.InputName, err.Expected?.ToString());
                ++fixes;
            }
        }

        if (fixes == errors.Count)
        {
            errors.Clear();
            return(Start(f, errors, quiet));
        }
        return(false);
    }
예제 #3
0
    /// Parses and executes a replay script.
    /// It dies on syntax errors.
    public void Eval(string script, Form target, bool quiet)
    {
        DieIf(IsNullOrEmpty(script), "Script can't be null or empty.");

        script = CleanScript(script);
        var    reader  = new StringReader(script);
        var    asserts = new Stack <Action>();
        var    errors  = new PreCondErrors();
        string line    = null;

        while ((line = reader.ReadLine()) != null)
        {
            if (!Dispatch(line, target, asserts, errors, quiet))
            {
                break;
            }
        }
    }
예제 #4
0
    /// Executes a line of the script.
    bool Dispatch(string line, Form target, Stack <Action> asserts,
                  PreCondErrors errors, bool quiet)
    {
        var delim = new [] { ' ' };
        var words = line.Split(delim, RemoveEmptyEntries);

        if (words.Length == 0)
        {
            return(true);            //<= Empty line.
        }
        if (words.Length == 1)
        {
            return(DispatchCmd(target, asserts, errors, quiet, words[0]));
        }
        else
        {
            var args = new string[words.Length - 1];
            Array.Copy(words, 1, args, 0, args.Length);
            return(DispatchCmd(target, asserts, errors, quiet, words[0], args));
        }
    }