stlib arraylist
This commit is contained in:
@@ -6990,6 +6990,71 @@ comptime_type_params_compile_and_run :: proc(t: ^testing.T) {
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
type_factories_compile_and_run :: proc(t: ^testing.T) {
|
||||
output := "/tmp/brolang-test-type-factory"
|
||||
defer _ = os.remove(output)
|
||||
status := compiler_core.compile_package("examples/programs/type_factory", output)
|
||||
testing.expect_value(t, status, 0)
|
||||
state := run_executable(output)
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
arraylist_compiles_and_runs :: proc(t: ^testing.T) {
|
||||
output := "/tmp/brolang-test-arraylist"
|
||||
defer _ = os.remove(output)
|
||||
status := compiler_core.compile_package("examples/programs/arraylist", output, nil, target.DEFAULT, cimport.Options{}, ".")
|
||||
testing.expect_value(t, status, 0)
|
||||
state := run_executable(output)
|
||||
testing.expect_value(t, state.exit_code, 0)
|
||||
}
|
||||
|
||||
@(test)
|
||||
type_factory_rejects_runtime_parameters_and_recursion :: proc(t: ^testing.T) {
|
||||
texts := []string{
|
||||
`Bad func($T type, n usize) type {
|
||||
return struct { value [n]T }
|
||||
}
|
||||
main func() void { value Bad(i32, 4) = undefined; _ = &value }
|
||||
`,
|
||||
`Loop func($T type) type {
|
||||
return struct { next @Loop(T) }
|
||||
}
|
||||
main func() void { value Loop(i32) = undefined; _ = &value }
|
||||
`,
|
||||
`Box func($T type) type {
|
||||
return struct { value T }
|
||||
}
|
||||
main func() void { _ = Box(i32) }
|
||||
`,
|
||||
`Bad func($T type) type {
|
||||
return 1
|
||||
}
|
||||
main func() void { value Bad(i32) = undefined; _ = &value }
|
||||
`,
|
||||
}
|
||||
wanted := []string{"must be comptime", "recursive type-factory specialization", "only valid in type position", "cannot implicitly convert"}
|
||||
for text, index in texts {
|
||||
source_file := source.Source{path="test.bro", text=text}
|
||||
diagnostics := source.init_diagnostics(&source_file)
|
||||
symbols := symbol.init_table()
|
||||
stream := lexer.lex(&source_file, &diagnostics, &symbols)
|
||||
ast_module := parser.parse(&stream, &source_file, &diagnostics)
|
||||
hir_module := checker.check(&ast_module, &diagnostics, &symbols)
|
||||
found := false
|
||||
for diagnostic in diagnostics.items {
|
||||
found = found || strings.contains(diagnostic.message, wanted[index])
|
||||
}
|
||||
testing.expect(t, found)
|
||||
hir.destroy_module(&hir_module)
|
||||
ast.destroy_module(&ast_module)
|
||||
delete(stream.items)
|
||||
symbol.destroy_table(&symbols)
|
||||
source.destroy_diagnostics(&diagnostics)
|
||||
}
|
||||
}
|
||||
|
||||
@(test)
|
||||
comptime_eval_compile_and_run :: proc(t: ^testing.T) {
|
||||
output := "/tmp/brolang-test-comptime-eval"
|
||||
|
||||
Reference in New Issue
Block a user