<commit_before>assert = require "assert"
_ = require "underscore"

compile = require "./compile-for-testing"

describe = global.describe
it = global.it
SyntaxError = global.SyntaxError

compiles = [ prgm |
    assert.doesNotThrow [
        compile prgm
    ]
]

doesNotCompile = [ prgm |
    assert.throws [
        compile prgm
    ] SyntaxError
]

describe "type checking" [|
    describe "basic assignment" [|
        it "should work for nested tables" [|
            assert.doesNotThrow [
                compile {
                    "f = global.console.log"
                }
            ]
        ]
    ]

    describe "undeclared variables" [|
        it "use of an undeclared variable should throw a type error" [|
            assert.throws [
                compile {
                    "a = b"
                }
            ] SyntaxError
        ]

        it "use of a declared variable should not throw a type error" [|
            assert.doesNotThrow [
                compile {
                    "b = 6"
                    "a = b"
                }
            ]
        ]
    ]

    describe "shadowing" [|
        it "should not allow shadowing at the same scope" [|
            assert.throws [
                compile {
                    "a = 1"
                    "a = 2"
                }
            ] SyntaxError
        ]

        it "should not allow shadowing at an inner scope" [|
            assert.throws [
                compile {
                    "a = 1"
                    "if false ["
                    "    a = 2"
                    "]"
                }
            ] SyntaxError
        ]
<commit_msg>failing hoisting test<commit_after>assert = require "assert"
_ = require "underscore"

compile = require "./compile-for-testing"

describe = global.describe
it = global.it
SyntaxError = global.SyntaxError

compiles = [ prgm |
    assert.doesNotThrow [
        compile prgm
    ]
]

doesNotCompile = [ prgm |
    assert.throws [
        compile prgm
    ] SyntaxError
]

describe "type checking" [|
    describe "basic assignment" [|
        it "should work for nested tables" [|
            assert.doesNotThrow [
                compile {
                    "f = global.console.log"
                }
            ]
        ]
    ]

    describe "undeclared variables" [|
        it "use of an undeclared variable should throw a type error" [|
            assert.throws [
                compile {
                    "a = b"
                }
            ] SyntaxError
        ]

        it "use of a declared variable should not throw a type error" [|
            assert.doesNotThrow [
                compile {
                    "b = 6"
                    "a = b"
                }
            ]
        ]
    ]

    describe "variable ~hoisting" [|
        it "compiles without hoisting" [|
            compiles {
                "mutable a = 0"
                "f = ["
                "    mutate a = a + 1"
                "]"
                "f()"
            }
        ]
        it "compiles with hoisting" [|
            compiles {
                "f = ["
                "    mutate a = a + 1"
                "]"
                "mutable a = 0"
                "f()"
            }
        ]
    ]

    describe "shadowing" [|
        it "should not allow shadowing at the same scope" [|
            assert.throws [
                compile {
                    "a = 1"
                    "a = 2"
                }
            ] SyntaxError
        ]

        it "should not allow shadowing at an inner scope" [|
            assert.throws [
                compile {
                    "a = 1"
                    "if false ["
                    "    a = 2"
                    "]"
                }
            ] SyntaxError
        ]

{'fraction_non_alphanumeric': 0.08624769918485406, 'fraction_numerical': 0.0036813042334998686, 'mean_word_length': 0.9477726574500768, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5071112', 'n_tokens_mistral': 1066, 'n_tokens_neox': 968, 'n_words': 261}