aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Gavin <danielgavin5@hotmail.com>2021-12-07 16:39:50 +0100
committerDaniel Gavin <danielgavin5@hotmail.com>2021-12-07 16:39:50 +0100
commitca0bc6739213a2ef38aa79efc53b20793b00e1a1 (patch)
tree0ccef266ef6effad14bd866052abecd4631322ad /src
parentb37fc717c7ecc9a62e052c94a373fddde66352ad (diff)
More tests
Diffstat (limited to 'src')
-rw-r--r--src/analysis/analysis.odin11
-rw-r--r--src/odin/printer/visit.odin2
-rw-r--r--src/testing/testing.odin30
3 files changed, 41 insertions, 2 deletions
diff --git a/src/analysis/analysis.odin b/src/analysis/analysis.odin
index ce94c4f..11e3e58 100644
--- a/src/analysis/analysis.odin
+++ b/src/analysis/analysis.odin
@@ -779,6 +779,7 @@ resolve_basic_lit :: proc(ast_context: ^AstContext, basic_lit: ast.Basic_Lit) ->
value.type = .String;
}
+ symbol.pkg = ast_context.current_package
symbol.value = value;
return symbol, true;
@@ -792,7 +793,7 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i
using ast;
- switch v in node.derived {
+ switch v in &node.derived {
case Array_Type:
return make_symbol_array_from_ast(ast_context, v), true;
case Dynamic_Array_Type:
@@ -801,6 +802,8 @@ resolve_type_expression :: proc(ast_context: ^AstContext, node: ^ast.Expr) -> (i
return make_symbol_map_from_ast(ast_context, v), true;
case Proc_Type:
return make_symbol_procedure_from_ast(ast_context, node, v, ast_context.field_name), true;
+ case Binary_Expr:
+ return resolve_first_symbol_from_binary_expression(ast_context, &v);
case Ident:
return resolve_type_identifier(ast_context, v);
case Basic_Lit:
@@ -2316,6 +2319,12 @@ get_signature :: proc(ast_context: ^AstContext, ident: ast.Ident, symbol: index.
case SymbolPackageValue:
return "package";
case SymbolUntypedValue:
+ switch v.type {
+ case .Float: return "float"
+ case .String: return "string"
+ case .Bool: return "bool"
+ case .Integer: return "int"
+ }
}
return "";
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin
index ba7c61c..19353e8 100644
--- a/src/odin/printer/visit.odin
+++ b/src/odin/printer/visit.odin
@@ -838,7 +838,7 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) -> ^
case Undef:
return text("---")
case Auto_Cast:
- return cons(text_token(p, v.op), visit_expr(p, v.expr))
+ return cons_with_nopl(text_token(p, v.op), visit_expr(p, v.expr))
case Ternary_If_Expr:
document := visit_expr(p, v.cond)
document = cons_with_opl(document, text_token(p, v.op1))
diff --git a/src/testing/testing.odin b/src/testing/testing.odin
index 4720497..d02695c 100644
--- a/src/testing/testing.odin
+++ b/src/testing/testing.odin
@@ -211,3 +211,33 @@ expect_hover :: proc(t: ^testing.T, src: ^Source, expect_hover_string: string) {
}
}
+
+expect_definition_locations :: proc(t: ^testing.T, src: ^Source, expect_locations: []common.Location) {
+ setup(src);
+
+ locations, ok := server.get_definition_location(src.document, src.position);
+
+ if !ok {
+ testing.error(t, "Failed get_definition_location");
+ }
+
+ if len(expect_locations) == 0 && len(locations) > 0 {
+ testing.errorf(t, "Expected empty locations, but received %v", locations);
+ }
+
+ flags := make([]int, len(expect_locations));
+
+ for expect_location, i in expect_locations {
+ for location, j in locations {
+ if location == expect_location {
+ flags[i] += 1;
+ }
+ }
+ }
+
+ for flag, i in flags {
+ if flag != 1 {
+ testing.errorf(t, "Expected location %v, but received %v", expect_locations[i], locations);
+ }
+ }
+} \ No newline at end of file