aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2024-10-03 19:24:17 +0200
committerDanielGavin <danielgavin5@hotmail.com>2024-10-03 19:24:17 +0200
commit28982c543bf43eb3378cc47b7aa33c405f7bc6b2 (patch)
treef1364500555b6fa6b259c9c2d612d6b99731bc17 /src/testing
parent0c2c02a3ee5018f757b92209add22042e0b1f00a (diff)
Make sure not to return $ for identifiers.
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/testing.odin195
1 files changed, 58 insertions, 137 deletions
diff --git a/src/testing/testing.odin b/src/testing/testing.odin
index 3cd62ec..303f577 100644
--- a/src/testing/testing.odin
+++ b/src/testing/testing.odin
@@ -30,24 +30,14 @@ Source :: struct {
setup :: proc(src: ^Source) {
src.main = strings.clone(src.main, context.temp_allocator)
src.document = new(server.Document, context.temp_allocator)
- src.document.uri = common.create_uri(
- "test/test.odin",
- 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,
- context.temp_allocator,
- )
+ src.document.allocator = new(common.Scratch_Allocator, context.temp_allocator)
src.document.package_name = "test"
- common.scratch_allocator_init(
- src.document.allocator,
- mem.Kilobyte * 2000,
- context.temp_allocator,
- )
+ common.scratch_allocator_init(src.document.allocator, mem.Kilobyte * 2000, context.temp_allocator)
//no unicode in tests currently
current, last: u8
@@ -62,8 +52,7 @@ setup :: proc(src: ^Source) {
} else if current == '\n' {
current_line += 1
current_character = 0
- } else if len(src.main) > current_index + 3 &&
- src.main[current_index:current_index + 3] == "{*}" {
+ } else if len(src.main) > current_index + 3 && src.main[current_index:current_index + 3] == "{*}" {
dst_slice := transmute([]u8)src.main[current_index:]
src_slice := transmute([]u8)src.main[current_index + 3:]
copy(dst_slice, src_slice)
@@ -86,10 +75,7 @@ setup :: proc(src: ^Source) {
for src_pkg in src.packages {
context.allocator = common.scratch_allocator(src.document.allocator)
- uri := common.create_uri(
- fmt.aprintf("test/%v/package.odin", src_pkg.pkg),
- context.temp_allocator,
- )
+ uri := common.create_uri(fmt.aprintf("test/%v/package.odin", src_pkg.pkg), context.temp_allocator)
fullpath := uri.path
@@ -123,11 +109,7 @@ setup :: proc(src: ^Source) {
panic("Parser error in test package source")
}
- if ret := server.collect_symbols(
- &server.indexer.index.collection,
- file,
- uri.uri,
- ); ret != .None {
+ if ret := server.collect_symbols(&server.indexer.index.collection, file, uri.uri); ret != .None {
return
}
}
@@ -151,11 +133,7 @@ teardown :: proc(src: ^Source) {
common.scratch_allocator_destroy(src.document.allocator)
}
-expect_signature_labels :: proc(
- t: ^testing.T,
- src: ^Source,
- expect_labels: []string,
-) {
+expect_signature_labels :: proc(t: ^testing.T, src: ^Source, expect_labels: []string) {
setup(src)
defer teardown(src)
@@ -166,10 +144,7 @@ expect_signature_labels :: proc(
}
if len(expect_labels) == 0 && len(help.signatures) > 0 {
- log.errorf(
- "Expected empty signature label, but received %v",
- help.signatures,
- )
+ log.errorf("Expected empty signature label, but received %v", help.signatures)
}
flags := make([]int, len(expect_labels), context.temp_allocator)
@@ -184,41 +159,24 @@ expect_signature_labels :: proc(
for flag, i in flags {
if flag != 1 {
- log.errorf(
- "Expected signature label %v, but received %v",
- expect_labels[i],
- help.signatures,
- )
+ log.errorf("Expected signature label %v, but received %v", expect_labels[i], help.signatures)
}
}
}
-expect_signature_parameter_position :: proc(
- t: ^testing.T,
- src: ^Source,
- position: int,
-) {
+expect_signature_parameter_position :: proc(t: ^testing.T, src: ^Source, position: int) {
setup(src)
defer teardown(src)
help, ok := server.get_signature_information(src.document, src.position)
if help.activeParameter != position {
- log.errorf(
- "expected parameter position %v, but received %v",
- position,
- help.activeParameter,
- )
+ log.errorf("expected parameter position %v, but received %v", position, help.activeParameter)
}
}
-expect_completion_labels :: proc(
- t: ^testing.T,
- src: ^Source,
- trigger_character: string,
- expect_labels: []string,
-) {
+expect_completion_labels :: proc(t: ^testing.T, src: ^Source, trigger_character: string, expect_labels: []string) {
setup(src)
defer teardown(src)
@@ -226,21 +184,14 @@ expect_completion_labels :: proc(
triggerCharacter = trigger_character,
}
- completion_list, ok := server.get_completion_list(
- src.document,
- src.position,
- completion_context,
- )
+ completion_list, ok := server.get_completion_list(src.document, src.position, completion_context)
if !ok {
log.error("Failed get_completion_list")
}
if len(expect_labels) == 0 && len(completion_list.items) > 0 {
- log.errorf(
- "Expected empty completion label, but received %v",
- completion_list.items,
- )
+ log.errorf("Expected empty completion label, but received %v", completion_list.items)
}
flags := make([]int, len(expect_labels), context.temp_allocator)
@@ -255,21 +206,12 @@ expect_completion_labels :: proc(
for flag, i in flags {
if flag != 1 {
- log.errorf(
- "Expected completion detail %v, but received %v",
- expect_labels[i],
- completion_list.items,
- )
+ log.errorf("Expected completion detail %v, but received %v", expect_labels[i], completion_list.items)
}
}
}
-expect_completion_details :: proc(
- t: ^testing.T,
- src: ^Source,
- trigger_character: string,
- expect_details: []string,
-) {
+expect_completion_details :: proc(t: ^testing.T, src: ^Source, trigger_character: string, expect_details: []string) {
setup(src)
defer teardown(src)
@@ -277,21 +219,14 @@ expect_completion_details :: proc(
triggerCharacter = trigger_character,
}
- completion_list, ok := server.get_completion_list(
- src.document,
- src.position,
- completion_context,
- )
+ completion_list, ok := server.get_completion_list(src.document, src.position, completion_context)
if !ok {
log.error("Failed get_completion_list")
}
if len(expect_details) == 0 && len(completion_list.items) > 0 {
- log.errorf(
- "Expected empty completion label, but received %v",
- completion_list.items,
- )
+ log.errorf("Expected empty completion label, but received %v", completion_list.items)
}
flags := make([]int, len(expect_details), context.temp_allocator)
@@ -306,50 +241,35 @@ expect_completion_details :: proc(
for flag, i in flags {
if flag != 1 {
- log.errorf(
- "Expected completion label %v, but received %v",
- expect_details[i],
- completion_list.items,
- )
+ log.errorf("Expected completion label %v, but received %v", expect_details[i], completion_list.items)
}
}
}
-expect_hover :: proc(
- t: ^testing.T,
- src: ^Source,
- expect_hover_string: string,
-) {
+expect_hover :: proc(t: ^testing.T, src: ^Source, expect_hover_string: string) {
setup(src)
defer teardown(src)
- hover, _, ok := server.get_hover_information(src.document, src.position)
+ hover, valid, ok := server.get_hover_information(src.document, src.position)
if !ok {
log.error(t, "Failed get_hover_information")
+ return
+ }
+
+ if !valid {
+ log.error(t, "Failed get_hover_information")
+ return
}
- /*
- ```odin\n
- content\n
- ```
- */
- content_without_markdown := hover.contents.value[8:len(hover.contents.value)-5]
+ content_without_markdown := hover.contents.value[8:len(hover.contents.value) - 5]
if content_without_markdown != expect_hover_string {
- log.errorf(
- "Expected hover string:\n%q, but received:\n%q",
- expect_hover_string,
- content_without_markdown,
- )
+ log.errorf("Expected hover string:\n%q, but received:\n%q", expect_hover_string, content_without_markdown)
}
}
-expect_definition_locations :: proc(
- t: ^testing.T,
- src: ^Source,
- expect_locations: []common.Location,
-) {
+expect_definition_locations :: proc(t: ^testing.T, src: ^Source, expect_locations: []common.Location) {
setup(src)
defer teardown(src)
@@ -375,20 +295,12 @@ expect_definition_locations :: proc(
for flag, i in flags {
if flag != 1 {
- log.errorf(
- "Expected location %v, but received %v",
- expect_locations[i].range,
- locations,
- )
+ log.errorf("Expected location %v, but received %v", expect_locations[i].range, locations)
}
}
}
-expect_reference_locations :: proc(
- t: ^testing.T,
- src: ^Source,
- expect_locations: []common.Location,
-) {
+expect_reference_locations :: proc(t: ^testing.T, src: ^Source, expect_locations: []common.Location) {
setup(src)
defer teardown(src)
@@ -415,35 +327,44 @@ expect_reference_locations :: proc(
}
}
-expect_semantic_tokens :: proc(
- t: ^testing.T,
- src: ^Source,
- expected: []server.SemanticToken,
-) {
+expect_semantic_tokens :: proc(t: ^testing.T, src: ^Source, expected: []server.SemanticToken) {
setup(src)
defer teardown(src)
-
+
resolve_flag: server.ResolveReferenceFlag
- symbols_and_nodes := server.resolve_entire_file(
- src.document,
- resolve_flag,
- context.temp_allocator,
- )
+ symbols_and_nodes := server.resolve_entire_file(src.document, resolve_flag, context.temp_allocator)
- range := common.Range{end = {line = 9000000}} //should be enough
+ range := common.Range {
+ end = {line = 9000000},
+ } //should be enough
tokens := server.get_semantic_tokens(src.document, range, symbols_and_nodes)
- testing.expectf(t, len(expected) == len(tokens), "\nExpected %d tokens, but received %d", len(expected), len(tokens))
+ testing.expectf(
+ t,
+ len(expected) == len(tokens),
+ "\nExpected %d tokens, but received %d",
+ len(expected),
+ len(tokens),
+ )
- for i in 0..<min(len(expected), len(tokens)) {
+ for i in 0 ..< min(len(expected), len(tokens)) {
e, a := expected[i], tokens[i]
- testing.expectf(t,
+ testing.expectf(
+ t,
e == a,
"\n[%d]: Expected \n(%d, %d, %d, %v, %w)\nbut received\n(%d, %d, %d, %v, %w)",
i,
- e.delta_line, e.delta_char, e.len, e.type, e.modifiers,
- a.delta_line, a.delta_char, a.len, a.type, a.modifiers,
+ e.delta_line,
+ e.delta_char,
+ e.len,
+ e.type,
+ e.modifiers,
+ a.delta_line,
+ a.delta_char,
+ a.len,
+ a.type,
+ a.modifiers,
)
}
}