Skip to content

Unit tests to cover error conditions for variables #47

@SapphireBrand

Description

@SapphireBrand

Here are two unit tests that I added to TypeScript Lizzie to cover validateThatSymbolIsUndefined in the Binder. This is called from the Var function in Functions.cs, so I added this to my Functions test.

    it('CannotDefineNonSymbol', () => {
        var lambda = LambdaCompiler.compileNoContext(`var(3, 17)`);

        var success = true;
        try {
            lambda();
            success = false;
        } catch (e) {
            expect(e.error).toMatch(/A valid symbol must be specified, but the non-string value '3' was given./i);
        }
        expect(success).toBe(true);
    });

    it('CannotRedefineSymbol', () => {
        var lambda = LambdaCompiler.compileNoContext(`var(@x, 17) var(@x, 17)`);

        var success = true;
        try {
            lambda();
            success = false;
        } catch (e) {
            expect(e.error).toMatch(/The symbol 'x' has already been declared in the scope of where you are trying to declare it using the 'var' keyword./i);
        }
        expect(success).toBe(true);
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions