diff options
| author | DanielGavin <danielgavin5@hotmail.com> | 2021-05-03 23:52:45 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-03 23:52:45 +0200 |
| commit | e123d0024da473808263371e32cf23f0c29c726e (patch) | |
| tree | 4892be264d82a8864fb9c0285fbd28eb62fd73ad /src/testing | |
| parent | 934b6c81106774d09f07804f881e6db219d15bf8 (diff) | |
| parent | ea0457da00f49fb758337e8456a3fe3965e2d2fa (diff) | |
Merge pull request #35 from DanielGavin/new-symbols
Refractor symbols to support correct procedure overloading.
Diffstat (limited to 'src/testing')
| -rw-r--r-- | src/testing/testing.odin | 108 |
1 files changed, 99 insertions, 9 deletions
diff --git a/src/testing/testing.odin b/src/testing/testing.odin index aaba07b..e74fb0e 100644 --- a/src/testing/testing.odin +++ b/src/testing/testing.odin @@ -4,19 +4,22 @@ import "core:testing" import "core:mem" import "core:fmt" import "core:strings" +import "core:path/filepath" +import "core:odin/parser" +import "core:odin/ast" import "shared:server" import "shared:index" import "shared:common" -Package_Source :: struct { - pkg_name: string, +Package :: struct { + pkg: string, source: string, } Source :: struct { main: string, - source_packages: Package_Source, + packages: [] Package, document: ^server.Document, collections: map[string]string, config: common.Config, @@ -35,7 +38,7 @@ setup :: proc(src: ^Source) { src.document.allocator = new(common.Scratch_Allocator); src.document.package_name = "test"; - common.scratch_allocator_init(src.document.allocator, mem.kilobytes(5), context.temp_allocator); + common.scratch_allocator_init(src.document.allocator, mem.kilobytes(20), context.temp_allocator); server.document_refresh(src.document, &src.config, nil); @@ -66,6 +69,49 @@ setup :: proc(src: ^Source) { last = current; } + /* + There is a lot code here that is used in the real code, then i'd like to see. + */ + + index.indexer.dynamic_index = index.make_memory_index(index.make_symbol_collection(context.allocator, &common.config)); + + for src_pkg in src.packages { + uri := common.create_uri(fmt.aprintf("test/%v/package.odin", src_pkg.pkg), context.temp_allocator); + + fullpath := uri.path; + + p := parser.Parser { + err = index.log_error_handler, + warn = index.log_warning_handler, + }; + + dir := filepath.base(filepath.dir(fullpath, context.temp_allocator)); + + pkg := new(ast.Package); + pkg.kind = .Normal; + pkg.fullpath = fullpath; + pkg.name = dir; + + if dir == "runtime" { + pkg.kind = .Runtime; + } + + file := ast.File { + fullpath = fullpath, + src = transmute([]u8)src_pkg.source, + pkg = pkg, + }; + + ok := parser.parse_file(&p, &file); + + if !ok { + return; + } + + if ret := index.collect_symbols(&index.indexer.dynamic_index.collection, file, uri.uri); ret != .None { + return; + } + } } expect_signature_labels :: proc(t: ^testing.T, src: ^Source, expect_labels: []string) { @@ -74,7 +120,7 @@ expect_signature_labels :: proc(t: ^testing.T, src: ^Source, expect_labels: []st help, ok := server.get_signature_information(src.document, src.position); if !ok { - testing.errorf(t, "Failed get_signature_information"); + testing.error(t, "Failed get_signature_information"); } if len(expect_labels) == 0 && len(help.signatures) > 0 { @@ -83,9 +129,9 @@ expect_signature_labels :: proc(t: ^testing.T, src: ^Source, expect_labels: []st flags := make([]int, len(expect_labels)); - for expect_signature, i in expect_labels { + for expect_label, i in expect_labels { for signature, j in help.signatures { - if expect_signature == signature.label { + if expect_label == signature.label { flags[i] += 1; } } @@ -99,12 +145,56 @@ expect_signature_labels :: proc(t: ^testing.T, src: ^Source, expect_labels: []st } -expect_completion :: proc(t: ^testing.T, src: ^Source, dot: bool, expect_completions: []string) { +expect_completion_details :: proc(t: ^testing.T, src: ^Source, trigger_character: string, expect_details: []string) { setup(src); + completion_context := server.CompletionContext { + triggerCharacter = trigger_character, + }; + + completion_list, ok := server.get_completion_list(src.document, src.position, completion_context); + + if !ok { + testing.error(t, "Failed get_completion_list"); + } + + if len(expect_details) == 0 && len(completion_list.items) > 0 { + testing.errorf(t, "Expected empty completion label, but received %v", completion_list.items); + } + + flags := make([]int, len(expect_details)); + + for expect_detail, i in expect_details { + for completion, j in completion_list.items { + if expect_detail == completion.detail { + flags[i] += 1; + } + } + } + + for flag, i in flags { + if flag != 1 { + testing.errorf(t, "Expected completion label %v, but received %v", expect_details[i], completion_list.items); + } + } + } -expect_hover :: proc(t: ^testing.T, src: ^Source, expect_hover_info: string) { +expect_hover :: proc(t: ^testing.T, src: ^Source, expect_hover_string: string) { setup(src); + hover, ok := server.get_hover_information(src.document, src.position); + + if !ok { + testing.error(t, "Failed get_hover_information"); + } + + if expect_hover_string == "" && hover.contents.value != "" { + testing.errorf(t, "Expected empty hover string, but received %v", hover.contents.value); + } + + if strings.contains(expect_hover_string, hover.contents.value) { + testing.errorf(t, "Expected hover string %v, but received %v", expect_hover_string, hover.contents.value); + } + } |