From 505a4d38ce301a0db0fd3a67de7b42d256d5a478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20C=C3=A9sar=20Batista?= Date: Wed, 16 Nov 2022 14:58:06 -0300 Subject: [PATCH] Add test for edge column index --- d2compiler/compile_test.go | 26 + .../TestCompile/edge_column_index.exp.json | 559 ++++++++++++++++++ 2 files changed, 585 insertions(+) create mode 100644 testdata/d2compiler/TestCompile/edge_column_index.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 54f59d64c..34e262e69 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1474,6 +1474,32 @@ b`, g.Objects[0].Attributes.Label.Value) SVP1.style.3d: true`, expErr: `d2/testdata/d2compiler/TestCompile/3d_oval.d2:2:1: key "3d" can only be applied to squares and rectangles `, + }, { + name: "edge_column_index", + text: `src: { + shape: sql_table + id: int + dst_id: int +} + +dst: { + shape: sql_table + id: int + name: string +} + +dst.id <-> src.dst_id +`, + assertions: func(t *testing.T, g *d2graph.Graph) { + fromIndex := g.Edges[0].FromTableColumnIndex + if fromIndex == nil || *fromIndex != 0 { + t.Fatalf("Expected FromTableColumnIndex to be 0, got %v", fromIndex) + } + toIndex := g.Edges[0].ToTableColumnIndex + if toIndex == nil || *toIndex != 1 { + t.Fatalf("Expected ToTableColumnIndex to be 1, got %v", toIndex) + } + }, }, } diff --git a/testdata/d2compiler/TestCompile/edge_column_index.exp.json b/testdata/d2compiler/TestCompile/edge_column_index.exp.json new file mode 100644 index 000000000..74cf487cd --- /dev/null +++ b/testdata/d2compiler/TestCompile/edge_column_index.exp.json @@ -0,0 +1,559 @@ +{ + "graph": { + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,0:0:0-13:0:123", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,0:0:0-4:1:48", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,0:0:0-0:3:3", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,0:0:0-0:3:3", + "value": [ + { + "string": "src", + "raw_string": "src" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,0:5:5-4:0:47", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,1:1:8-1:17:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,1:1:8-1:6:13", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,1:1:8-1:6:13", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,1:8:15-1:17:24", + "value": [ + { + "string": "sql_table", + "raw_string": "sql_table" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,2:1:26-2:8:33", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,2:1:26-2:3:28", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,2:1:26-2:3:28", + "value": [ + { + "string": "id", + "raw_string": "id" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,2:5:30-2:8:33", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,3:1:35-3:12:46", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,3:1:35-3:7:41", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,3:1:35-3:7:41", + "value": [ + { + "string": "dst_id", + "raw_string": "dst_id" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,3:9:43-3:12:46", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,6:0:50-10:1:99", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,6:0:50-6:3:53", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,6:0:50-6:3:53", + "value": [ + { + "string": "dst", + "raw_string": "dst" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,6:5:55-10:0:98", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,7:1:58-7:17:74", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,7:1:58-7:6:63", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,7:1:58-7:6:63", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,7:8:65-7:17:74", + "value": [ + { + "string": "sql_table", + "raw_string": "sql_table" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,8:1:76-8:8:83", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,8:1:76-8:3:78", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,8:1:76-8:3:78", + "value": [ + { + "string": "id", + "raw_string": "id" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,8:5:80-8:8:83", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,9:1:85-9:13:97", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,9:1:85-9:5:89", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,9:1:85-9:5:89", + "value": [ + { + "string": "name", + "raw_string": "name" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,9:7:91-9:13:97", + "value": [ + { + "string": "string", + "raw_string": "string" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:0:101-12:21:122", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:0:101-12:21:122", + "src": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:0:101-12:7:108", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:0:101-12:3:104", + "value": [ + { + "string": "dst", + "raw_string": "dst" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:4:105-12:6:107", + "value": [ + { + "string": "id", + "raw_string": "id" + } + ] + } + } + ] + }, + "src_arrow": "<", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:10:111-12:21:122", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:11:112-12:14:115", + "value": [ + { + "string": "src", + "raw_string": "src" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:15:116-12:21:122", + "value": [ + { + "string": "dst_id", + "raw_string": "dst_id" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + } + } + }, + "edges": [ + { + "index": 0, + "minWidth": 0, + "minHeight": 0, + "fromTableColumnIndex": 0, + "toTableColumnIndex": 1, + "label_dimensions": { + "width": 0, + "height": 0 + }, + "isCurve": false, + "src_arrow": true, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + } + } + } + ], + "objects": [ + { + "id": "src", + "id_val": "src", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,0:0:0-0:3:3", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,0:0:0-0:3:3", + "value": [ + { + "string": "src", + "raw_string": "src" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:10:111-12:21:122", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:11:112-12:14:115", + "value": [ + { + "string": "src", + "raw_string": "src" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:15:116-12:21:122", + "value": [ + { + "string": "dst_id", + "raw_string": "dst_id" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "sql_table": { + "columns": [ + { + "name": "id", + "type": "int", + "constraint": "", + "reference": "" + }, + { + "name": "dst_id", + "type": "int", + "constraint": "", + "reference": "" + } + ] + }, + "attributes": { + "label": { + "value": "src" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "sql_table" + } + } + }, + { + "id": "dst", + "id_val": "dst", + "label_dimensions": { + "width": 0, + "height": 0 + }, + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,6:0:50-6:3:53", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,6:0:50-6:3:53", + "value": [ + { + "string": "dst", + "raw_string": "dst" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:0:101-12:7:108", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:0:101-12:3:104", + "value": [ + { + "string": "dst", + "raw_string": "dst" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,12:4:105-12:6:107", + "value": [ + { + "string": "id", + "raw_string": "id" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "sql_table": { + "columns": [ + { + "name": "id", + "type": "int", + "constraint": "", + "reference": "src.dst_id" + }, + { + "name": "name", + "type": "string", + "constraint": "", + "reference": "" + } + ] + }, + "attributes": { + "label": { + "value": "dst" + }, + "style": {}, + "near_key": null, + "shape": { + "value": "sql_table" + } + } + } + ] + }, + "err": null +}