diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2021-04-26 16:24:50 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2021-04-26 16:24:50 +0200 |
| commit | c751160c558eb6a81637238375604ca8ad2c2c0d (patch) | |
| tree | 7a9a950194df2e53990d309a2f28e38e449ff156 /src/testing | |
| parent | e9dfb0b598b8cee0ca296a7edb92475aac37a5ae (diff) | |
add tests for signatures
Diffstat (limited to 'src/testing')
| -rw-r--r-- | src/testing/testing.odin | 135 |
1 files changed, 110 insertions, 25 deletions
diff --git a/src/testing/testing.odin b/src/testing/testing.odin index 7b47f90..aaba07b 100644 --- a/src/testing/testing.odin +++ b/src/testing/testing.odin @@ -1,25 +1,110 @@ -package ols_testing
-
-import "core:testing"
-
-Package_Source :: struct {
- pkg_name: string,
- source: string,
-}
-
-Source :: struct {
- main: string,
- source_packages: Package_Source,
-}
-
-expect_signature :: proc(t: ^testing.T, src: Source, expect_arg: []string) {
-
-}
-
-expect_completion :: proc(t: ^testing.T, src: Source, completions: []string) {
-
-}
-
-expect_hover :: proc(t: ^testing.T, src: Source, hover_info: string) {
-
-}
\ No newline at end of file +package ols_testing + +import "core:testing" +import "core:mem" +import "core:fmt" +import "core:strings" + +import "shared:server" +import "shared:index" +import "shared:common" + +Package_Source :: struct { + pkg_name: string, + source: string, +} + +Source :: struct { + main: string, + source_packages: Package_Source, + document: ^server.Document, + collections: map[string]string, + config: common.Config, + position: common.Position, +} + +@(private) +setup :: proc(src: ^Source) { + + src.main = strings.clone(src.main); + src.document = new(server.Document, context.temp_allocator); + src.document.uri = common.create_uri("test/test.odin", context.temp_allocator); + src.document.client_owned = true; + src.document.text = transmute([]u8)src.main; + src.document.used_text = len(src.document.text); + 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); + + server.document_refresh(src.document, &src.config, nil); + + //no unicode in tests currently + current, last: u8; + current_line, current_character: int; + + for current_index := 0; current_index < len(src.main); current_index += 1 { + current = src.main[current_index]; + + if last == '\r' { + current_line += 1; + current_character = 0; + } else if current == '\n' { + current_line += 1; + current_character = 0; + } else if current == '*' { + dst_slice := transmute([]u8)src.main[current_index:]; + src_slice := transmute([]u8)src.main[current_index + 1:]; + copy(dst_slice, src_slice); + src.position.character = current_character; + src.position.line = current_line; + break; + } else { + current_character += 1; + } + + last = current; + } + +} + +expect_signature_labels :: proc(t: ^testing.T, src: ^Source, expect_labels: []string) { + setup(src); + + help, ok := server.get_signature_information(src.document, src.position); + + if !ok { + testing.errorf(t, "Failed get_signature_information"); + } + + if len(expect_labels) == 0 && len(help.signatures) > 0 { + testing.errorf(t, "Expected empty signature label, but received %v", help.signatures); + } + + flags := make([]int, len(expect_labels)); + + for expect_signature, i in expect_labels { + for signature, j in help.signatures { + if expect_signature == signature.label { + flags[i] += 1; + } + } + } + + for flag, i in flags { + if flag != 1 { + testing.errorf(t, "Expected signature label %v, but received %v", expect_labels[i], help.signatures); + } + } + +} + +expect_completion :: proc(t: ^testing.T, src: ^Source, dot: bool, expect_completions: []string) { + setup(src); + +} + +expect_hover :: proc(t: ^testing.T, src: ^Source, expect_hover_info: string) { + setup(src); + +} |