@malloydata/malloy-tests 0.0.135 → 0.0.136-dev240326234246

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/api.spec.d.ts +1 -0
  2. package/dist/api.spec.js +113 -0
  3. package/dist/api.spec.js.map +1 -0
  4. package/dist/databases/all/db_index.spec.d.ts +1 -0
  5. package/dist/databases/all/db_index.spec.js +126 -0
  6. package/dist/databases/all/db_index.spec.js.map +1 -0
  7. package/dist/databases/all/expr.spec.d.ts +1 -0
  8. package/dist/databases/all/expr.spec.js +652 -0
  9. package/dist/databases/all/expr.spec.js.map +1 -0
  10. package/dist/databases/all/functions.spec.d.ts +1 -0
  11. package/dist/databases/all/functions.spec.js +1180 -0
  12. package/dist/databases/all/functions.spec.js.map +1 -0
  13. package/dist/databases/all/join.spec.d.ts +1 -0
  14. package/dist/databases/all/join.spec.js +255 -0
  15. package/dist/databases/all/join.spec.js.map +1 -0
  16. package/dist/databases/all/lenses.spec.d.ts +1 -0
  17. package/dist/databases/all/lenses.spec.js +374 -0
  18. package/dist/databases/all/lenses.spec.js.map +1 -0
  19. package/dist/databases/all/nomodel.spec.d.ts +1 -0
  20. package/dist/databases/all/nomodel.spec.js +1070 -0
  21. package/dist/databases/all/nomodel.spec.js.map +1 -0
  22. package/dist/databases/all/orderby.spec.d.ts +1 -0
  23. package/dist/databases/all/orderby.spec.js +170 -0
  24. package/dist/databases/all/orderby.spec.js.map +1 -0
  25. package/dist/databases/all/problems.spec.d.ts +1 -0
  26. package/dist/databases/all/problems.spec.js +106 -0
  27. package/dist/databases/all/problems.spec.js.map +1 -0
  28. package/dist/databases/all/sql_expressions.spec.d.ts +1 -0
  29. package/dist/databases/all/sql_expressions.spec.js +73 -0
  30. package/dist/databases/all/sql_expressions.spec.js.map +1 -0
  31. package/dist/databases/all/time.spec.d.ts +1 -0
  32. package/dist/databases/all/time.spec.js +602 -0
  33. package/dist/databases/all/time.spec.js.map +1 -0
  34. package/dist/databases/bigquery/double_truncation.spec.d.ts +1 -0
  35. package/dist/databases/bigquery/double_truncation.spec.js +50 -0
  36. package/dist/databases/bigquery/double_truncation.spec.js.map +1 -0
  37. package/dist/databases/bigquery/handexpr.spec.d.ts +1 -0
  38. package/dist/databases/bigquery/handexpr.spec.js +723 -0
  39. package/dist/databases/bigquery/handexpr.spec.js.map +1 -0
  40. package/dist/databases/bigquery/injestion_time_partitioning.spec.d.ts +1 -0
  41. package/dist/databases/bigquery/injestion_time_partitioning.spec.js +235 -0
  42. package/dist/databases/bigquery/injestion_time_partitioning.spec.js.map +1 -0
  43. package/dist/databases/bigquery/joined_filters.spec.d.ts +1 -0
  44. package/dist/databases/bigquery/joined_filters.spec.js +72 -0
  45. package/dist/databases/bigquery/joined_filters.spec.js.map +1 -0
  46. package/dist/databases/bigquery/json.spec.d.ts +1 -0
  47. package/dist/databases/bigquery/json.spec.js +66 -0
  48. package/dist/databases/bigquery/json.spec.js.map +1 -0
  49. package/dist/databases/bigquery/malloy_query.spec.d.ts +1 -0
  50. package/dist/databases/bigquery/malloy_query.spec.js +840 -0
  51. package/dist/databases/bigquery/malloy_query.spec.js.map +1 -0
  52. package/dist/databases/bigquery/performance.skipped.spec.d.ts +1 -0
  53. package/dist/databases/bigquery/performance.skipped.spec.js +70 -0
  54. package/dist/databases/bigquery/performance.skipped.spec.js.map +1 -0
  55. package/dist/databases/bigquery/time.spec.d.ts +1 -0
  56. package/dist/databases/bigquery/time.spec.js +52 -0
  57. package/dist/databases/bigquery/time.spec.js.map +1 -0
  58. package/dist/databases/bigquery/wildcard_table_names.spec.d.ts +1 -0
  59. package/dist/databases/bigquery/wildcard_table_names.spec.js +212 -0
  60. package/dist/databases/bigquery/wildcard_table_names.spec.js.map +1 -0
  61. package/dist/databases/bigquery-duckdb/nested_source_table.spec.d.ts +1 -0
  62. package/dist/databases/bigquery-duckdb/nested_source_table.spec.js +213 -0
  63. package/dist/databases/bigquery-duckdb/nested_source_table.spec.js.map +1 -0
  64. package/dist/databases/duckdb/duckdb.spec.d.ts +1 -0
  65. package/dist/databases/duckdb/duckdb.spec.js +124 -0
  66. package/dist/databases/duckdb/duckdb.spec.js.map +1 -0
  67. package/dist/databases/duckdb/streaming.spec.d.ts +1 -0
  68. package/dist/databases/duckdb/streaming.spec.js +142 -0
  69. package/dist/databases/duckdb/streaming.spec.js.map +1 -0
  70. package/dist/databases/multi-connection/multi_connection.spec.d.ts +1 -0
  71. package/dist/databases/multi-connection/multi_connection.spec.js +120 -0
  72. package/dist/databases/multi-connection/multi_connection.spec.js.map +1 -0
  73. package/dist/databases/postgres/postgres.spec.d.ts +1 -0
  74. package/dist/databases/postgres/postgres.spec.js +140 -0
  75. package/dist/databases/postgres/postgres.spec.js.map +1 -0
  76. package/dist/databases/shared/test_list.d.ts +3 -0
  77. package/dist/databases/shared/test_list.js +5 -0
  78. package/dist/databases/shared/test_list.js.map +1 -0
  79. package/dist/databases/streaming/streaming.spec.d.ts +1 -0
  80. package/dist/databases/streaming/streaming.spec.js +93 -0
  81. package/dist/databases/streaming/streaming.spec.js.map +1 -0
  82. package/dist/dependencies.spec.d.ts +1 -0
  83. package/dist/dependencies.spec.js +63 -0
  84. package/dist/dependencies.spec.js.map +1 -0
  85. package/dist/index.d.ts +4 -0
  86. package/dist/index.js +49 -0
  87. package/dist/index.js.map +1 -0
  88. package/dist/jestMatcher.spec.d.ts +1 -0
  89. package/dist/jestMatcher.spec.js +81 -0
  90. package/dist/jestMatcher.spec.js.map +1 -0
  91. package/dist/model/sql_source.spec.d.ts +1 -0
  92. package/dist/model/sql_source.spec.js +47 -0
  93. package/dist/model/sql_source.spec.js.map +1 -0
  94. package/dist/models/faa_model.d.ts +5 -0
  95. package/dist/models/faa_model.js +997 -0
  96. package/dist/models/faa_model.js.map +1 -0
  97. package/dist/models/medicare_model.d.ts +4 -0
  98. package/dist/models/medicare_model.js +259 -0
  99. package/dist/models/medicare_model.js.map +1 -0
  100. package/dist/render/drill.spec.d.ts +1 -0
  101. package/dist/render/drill.spec.js +107 -0
  102. package/dist/render/drill.spec.js.map +1 -0
  103. package/dist/render/render.spec.d.ts +1 -0
  104. package/dist/render/render.spec.js +548 -0
  105. package/dist/render/render.spec.js.map +1 -0
  106. package/dist/runtimes.d.ts +35 -0
  107. package/dist/runtimes.js +180 -0
  108. package/dist/runtimes.js.map +1 -0
  109. package/dist/tags.spec.d.ts +8 -0
  110. package/dist/tags.spec.js +490 -0
  111. package/dist/tags.spec.js.map +1 -0
  112. package/dist/util/db-jest-matchers.d.ts +30 -0
  113. package/dist/util/db-jest-matchers.js +157 -0
  114. package/dist/util/db-jest-matchers.js.map +1 -0
  115. package/dist/util/index.d.ts +15 -0
  116. package/dist/util/index.js +182 -0
  117. package/dist/util/index.js.map +1 -0
  118. package/package.json +8 -8
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.RuntimeList = exports.allDatabases = exports.testRuntimeFor = exports.runtimeFor = exports.rows = exports.DuckDBWASMTestConnection = exports.DuckDBTestConnection = exports.PostgresTestConnection = exports.BigQueryTestConnection = exports.SnowflakeTestConnection = void 0;
26
+ const malloy_1 = require("@malloydata/malloy");
27
+ const db_bigquery_1 = require("@malloydata/db-bigquery");
28
+ const db_duckdb_1 = require("@malloydata/db-duckdb");
29
+ const wasm_1 = require("@malloydata/db-duckdb/wasm");
30
+ const db_snowflake_1 = require("@malloydata/db-snowflake");
31
+ const db_postgres_1 = require("@malloydata/db-postgres");
32
+ const db_trino_1 = require("@malloydata/db-trino");
33
+ const snowflake_executor_1 = require("@malloydata/db-snowflake/src/snowflake_executor");
34
+ class SnowflakeTestConnection extends db_snowflake_1.SnowflakeConnection {
35
+ async runSQL(sqlCommand, options) {
36
+ try {
37
+ return await super.runSQL(sqlCommand, options);
38
+ }
39
+ catch (e) {
40
+ // eslint-disable-next-line no-console
41
+ console.log(`Error in SQL:\n ${sqlCommand}`);
42
+ throw e;
43
+ }
44
+ }
45
+ }
46
+ exports.SnowflakeTestConnection = SnowflakeTestConnection;
47
+ class BigQueryTestConnection extends db_bigquery_1.BigQueryConnection {
48
+ // we probably need a better way to do this.
49
+ async runSQL(sqlCommand, options) {
50
+ try {
51
+ return await super.runSQL(sqlCommand, options);
52
+ }
53
+ catch (e) {
54
+ // eslint-disable-next-line no-console
55
+ console.log(`Error in SQL:\n ${sqlCommand}`);
56
+ throw e;
57
+ }
58
+ }
59
+ }
60
+ exports.BigQueryTestConnection = BigQueryTestConnection;
61
+ class PostgresTestConnection extends db_postgres_1.PooledPostgresConnection {
62
+ // we probably need a better way to do this.
63
+ async runSQL(sqlCommand, options) {
64
+ try {
65
+ return await super.runSQL(sqlCommand, options);
66
+ }
67
+ catch (e) {
68
+ // eslint-disable-next-line no-console
69
+ console.log(`Error in SQL:\n ${sqlCommand}`);
70
+ throw e;
71
+ }
72
+ }
73
+ }
74
+ exports.PostgresTestConnection = PostgresTestConnection;
75
+ class DuckDBTestConnection extends db_duckdb_1.DuckDBConnection {
76
+ // we probably need a better way to do this.
77
+ async runSQL(sqlCommand, options) {
78
+ try {
79
+ return await super.runSQL(sqlCommand, options);
80
+ }
81
+ catch (e) {
82
+ // eslint-disable-next-line no-console
83
+ console.log(`Error in SQL:\n ${sqlCommand}`);
84
+ throw e;
85
+ }
86
+ }
87
+ }
88
+ exports.DuckDBTestConnection = DuckDBTestConnection;
89
+ class DuckDBWASMTestConnection extends wasm_1.DuckDBWASMConnection {
90
+ // we probably need a better way to do this.
91
+ async runSQL(sqlCommand, options) {
92
+ try {
93
+ return await super.runSQL(sqlCommand, options);
94
+ }
95
+ catch (e) {
96
+ // eslint-disable-next-line no-console
97
+ console.log(`Error in SQL:\n ${sqlCommand}`);
98
+ throw e;
99
+ }
100
+ }
101
+ }
102
+ exports.DuckDBWASMTestConnection = DuckDBWASMTestConnection;
103
+ const files = new malloy_1.EmptyURLReader();
104
+ function rows(qr) {
105
+ return qr.data.value;
106
+ }
107
+ exports.rows = rows;
108
+ function runtimeFor(dbName) {
109
+ let connection;
110
+ try {
111
+ switch (dbName) {
112
+ case 'bigquery':
113
+ connection = new BigQueryTestConnection(dbName, {}, { projectId: 'malloy-data' });
114
+ break;
115
+ case 'postgres':
116
+ connection = new PostgresTestConnection(dbName);
117
+ break;
118
+ case 'duckdb':
119
+ connection = new DuckDBTestConnection(dbName, 'test/data/duckdb/duckdb_test.db');
120
+ break;
121
+ case 'duckdb_wasm':
122
+ connection = new DuckDBWASMTestConnection(dbName, 'test/data/duckdb/duckdb_test.db');
123
+ break;
124
+ case 'motherduck':
125
+ connection = new DuckDBTestConnection(dbName, 'md:my_db');
126
+ break;
127
+ case 'snowflake':
128
+ {
129
+ const connOptions = snowflake_executor_1.SnowflakeExecutor.getConnectionOptionsFromEnv();
130
+ connection = new SnowflakeTestConnection(dbName, { connOptions });
131
+ }
132
+ break;
133
+ case 'trino':
134
+ connection = new db_trino_1.TrinoConnection(dbName, {}, db_trino_1.TrinoExecutor.getConnectionOptionsFromEnv());
135
+ break;
136
+ default:
137
+ throw new Error(`Unknown runtime "${dbName}`);
138
+ }
139
+ return testRuntimeFor(connection);
140
+ }
141
+ catch (error) {
142
+ throw new Error(`Failed to create connection \`${dbName}\`: ${error.message}`);
143
+ }
144
+ }
145
+ exports.runtimeFor = runtimeFor;
146
+ function testRuntimeFor(connection) {
147
+ return new malloy_1.SingleConnectionRuntime(files, connection);
148
+ }
149
+ exports.testRuntimeFor = testRuntimeFor;
150
+ exports.allDatabases = [
151
+ 'postgres',
152
+ 'bigquery',
153
+ 'duckdb',
154
+ 'duckdb_wasm',
155
+ 'snowflake',
156
+ ];
157
+ class RuntimeList {
158
+ constructor(...args) {
159
+ this.runtimeMap = new Map();
160
+ this.runtimeList = [];
161
+ const databases = args.length > 0 && args[0] !== undefined ? args[0] : exports.allDatabases;
162
+ for (const database of databases) {
163
+ const rt = database instanceof malloy_1.SingleConnectionRuntime
164
+ ? database
165
+ : runtimeFor(database);
166
+ this.runtimeMap.set(rt.connection.name, rt);
167
+ this.runtimeList.push([rt.connection.name, rt]);
168
+ }
169
+ }
170
+ async closeAll() {
171
+ for (const [_key, runtime] of this.runtimeMap) {
172
+ await runtime.connection.close();
173
+ }
174
+ // Unfortunate hack to avoid slow to die background threads tripping
175
+ // up jest
176
+ await new Promise(resolve => setTimeout(resolve, 10000));
177
+ }
178
+ }
179
+ exports.RuntimeList = RuntimeList;
180
+ //# sourceMappingURL=runtimes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtimes.js","sourceRoot":"","sources":["../src/runtimes.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAEH,+CAQ4B;AAC5B,yDAA2D;AAC3D,qDAAuD;AACvD,qDAAgE;AAChE,2DAA6D;AAC7D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AAuB;gBACzC,CAAC,CAAC,QAAQ;gBACV,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;YAC3B,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC5C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;SACjD;IACH,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE;YAC7C,MAAM,OAAO,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;SAClC;QACD,oEAAoE;QACpE,UAAU;QACV,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF;AA9BD,kCA8BC"}
@@ -0,0 +1,8 @@
1
+ import { TagDict } from '@malloydata/malloy';
2
+ declare global {
3
+ namespace jest {
4
+ interface Matchers<R> {
5
+ tagsAre(t: TagDict): R;
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,490 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2023 Google LLC
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files
7
+ * (the "Software"), to deal in the Software without restriction,
8
+ * including without limitation the rights to use, copy, modify, merge,
9
+ * publish, distribute, sublicense, and/or sell copies of the Software,
10
+ * and to permit persons to whom the Software is furnished to do so,
11
+ * subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be
14
+ * included in all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+ */
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ const malloy_1 = require("@malloydata/malloy");
26
+ const runtimes_1 = require("./runtimes");
27
+ expect.extend({
28
+ tagsAre(src, result) {
29
+ if (typeof src === 'string') {
30
+ const { tag, log } = malloy_1.Tag.fromTagline(src, undefined);
31
+ const errs = log.map(e => e.message);
32
+ if (log.length > 0) {
33
+ return {
34
+ pass: false,
35
+ message: () => `${src}: Tag Parsing Error(s)\n${errs.join('\n')}`,
36
+ };
37
+ }
38
+ src = tag;
39
+ }
40
+ const got = src.properties;
41
+ if (this.equals(got, result)) {
42
+ return {
43
+ pass: true,
44
+ message: () => 'Parse returned expected object',
45
+ };
46
+ }
47
+ const expected = this.utils.printExpected(result);
48
+ const received = this.utils.printReceived(got);
49
+ return {
50
+ pass: false,
51
+ message: () => `Expected: ${expected}\nReceived: ${received}`,
52
+ };
53
+ },
54
+ });
55
+ const runtime = (0, runtimes_1.runtimeFor)('duckdb');
56
+ describe('tagParse to Tag', () => {
57
+ const tagTests = [
58
+ ['just_name', { just_name: {} }],
59
+ ['name=bare_string', { name: { eq: 'bare_string' } }],
60
+ ['name="quoted_string"', { name: { eq: 'quoted_string' } }],
61
+ ['name {prop1}', { name: { properties: { prop1: {} } } }],
62
+ [
63
+ 'name {prop1 prop2=value}',
64
+ {
65
+ name: {
66
+ properties: {
67
+ prop1: {},
68
+ prop2: { eq: 'value' },
69
+ },
70
+ },
71
+ },
72
+ ],
73
+ ['name.prop', { name: { properties: { prop: {} } } }],
74
+ ['name.prop=value', { name: { properties: { prop: { eq: 'value' } } } }],
75
+ [
76
+ 'name.prop.sub=value',
77
+ { name: { properties: { prop: { properties: { sub: { eq: 'value' } } } } } },
78
+ ],
79
+ [
80
+ 'name{first3=[a, b, c]}',
81
+ { name: { properties: { first3: { eq: [{ eq: 'a' }, { eq: 'b' }, { eq: 'c' }] } } } },
82
+ ],
83
+ ['name{first1=[a,]}', { name: { properties: { first1: { eq: [{ eq: 'a' }] } } } }],
84
+ [
85
+ 'name{first=[a {A}]}',
86
+ { name: { properties: { first: { eq: [{ eq: 'a', properties: { A: {} } }] } } } },
87
+ ],
88
+ [
89
+ 'name{first=[{A}]}',
90
+ { name: { properties: { first: { eq: [{ properties: { A: {} } }] } } } },
91
+ ],
92
+ ['name=value {prop}', { name: { eq: 'value', properties: { prop: {} } } }],
93
+ [
94
+ 'name.prop={prop2}',
95
+ { name: { properties: { prop: { properties: { prop2: {} } } } } },
96
+ ],
97
+ ['no yes -no', { yes: {} }],
98
+ // TODO interesting behavior that removing a non-existant element, or the last element,
99
+ // does not remove the `properties`.
100
+ ['x -x.y', { x: { properties: {} } }],
101
+ ['x={y} -x.y', { x: { properties: {} } }],
102
+ ['x={y z} -x.y', { x: { properties: { z: {} } } }],
103
+ ['x={y z} x {-y}', { x: { properties: { z: {} } } }],
104
+ ['x=1 x {xx=11}', { x: { eq: '1', properties: { xx: { eq: '11' } } } }],
105
+ ['x.y=xx x=1 {...}', { x: { eq: '1', properties: { y: { eq: 'xx' } } } }],
106
+ ['a {b c} a=1', { a: { eq: '1' } }],
107
+ ['a=1 a=...{b}', { a: { eq: '1', properties: { b: {} } } }],
108
+ [
109
+ 'a=red { shade=dark } color=$(a) shade=$(a.shade)',
110
+ {
111
+ a: { eq: 'red', properties: { shade: { eq: 'dark' } } },
112
+ color: { eq: 'red', properties: { shade: { eq: 'dark' } } },
113
+ shade: { eq: 'dark' },
114
+ },
115
+ ],
116
+ ['x=.01', { x: { eq: '.01' } }],
117
+ ['x=-7', { x: { eq: '-7' } }],
118
+ ['x=7', { x: { eq: '7' } }],
119
+ ['x=7.0', { x: { eq: '7.0' } }],
120
+ ['x=.7', { x: { eq: '.7' } }],
121
+ ['x=.7e2', { x: { eq: '.7e2' } }],
122
+ ['x=7E2', { x: { eq: '7E2' } }],
123
+ ['`spacey name`=Zaphod', { 'spacey name': { eq: 'Zaphod' } }],
124
+ [
125
+ 'image { alt=hello { field=department } }',
126
+ {
127
+ image: {
128
+ properties: {
129
+ alt: { eq: 'hello', properties: { field: { eq: 'department' } } },
130
+ },
131
+ },
132
+ },
133
+ ],
134
+ [
135
+ 'image image.alt=hello image.alt.field=department',
136
+ {
137
+ image: {
138
+ properties: {
139
+ alt: { eq: 'hello', properties: { field: { eq: 'department' } } },
140
+ },
141
+ },
142
+ },
143
+ ],
144
+ ];
145
+ test.each(tagTests)('tag %s', (expression, expected) => {
146
+ expect(expression).tagsAre(expected);
147
+ });
148
+ test.skip('unskip to debug just one of the expressions', () => {
149
+ const x = ['x x.y', { x: { properties: { y: {} } } }];
150
+ expect(x[0]).tagsAre(x[1]);
151
+ });
152
+ test('inherits can be over-ridden', () => {
153
+ const loc1 = {
154
+ url: 'inherit-test',
155
+ range: { start: { line: 1, character: 0 }, end: { line: 1, character: 0 } },
156
+ };
157
+ const loc2 = {
158
+ url: 'inherit-test',
159
+ range: { start: { line: 2, character: 0 }, end: { line: 2, character: 0 } },
160
+ };
161
+ const nestedTags = malloy_1.Tag.annotationToTag({
162
+ inherits: { notes: [{ text: '## from=inherits\n', at: loc1 }] },
163
+ notes: [{ text: '## from=notes\n', at: loc2 }],
164
+ });
165
+ const fromVal = nestedTags.tag.text('from');
166
+ expect(fromVal).toEqual('notes');
167
+ });
168
+ });
169
+ describe('Tag access', () => {
170
+ test('just text', () => {
171
+ const strToParse = 'a=b';
172
+ const getTags = malloy_1.Tag.fromTagline(strToParse, undefined);
173
+ expect(getTags.log).toEqual([]);
174
+ const a = getTags.tag.tag('a');
175
+ expect(a).toBeDefined();
176
+ expect(a === null || a === void 0 ? void 0 : a.text()).toEqual('b');
177
+ });
178
+ test('tag path', () => {
179
+ const strToParse = 'a.b.c.d.e=f';
180
+ const tagParse = malloy_1.Tag.fromTagline(strToParse, undefined);
181
+ expect(tagParse.log).toEqual([]);
182
+ const abcde = tagParse.tag.tag('a', 'b', 'c', 'd', 'e');
183
+ expect(abcde).toBeDefined();
184
+ expect(abcde === null || abcde === void 0 ? void 0 : abcde.text()).toEqual('f');
185
+ });
186
+ test('just array', () => {
187
+ const strToParse = 'a=[b]';
188
+ const getTags = malloy_1.Tag.fromTagline(strToParse, undefined);
189
+ expect(getTags.log).toEqual([]);
190
+ const a = getTags.tag.tag('a');
191
+ const aval = a === null || a === void 0 ? void 0 : a.array();
192
+ expect(aval).toBeDefined();
193
+ if (aval) {
194
+ expect(aval.length).toEqual(1);
195
+ expect(aval[0].text()).toEqual('b');
196
+ }
197
+ });
198
+ test('array as text', () => {
199
+ const strToParse = 'a=[b]';
200
+ const getTags = malloy_1.Tag.fromTagline(strToParse, undefined);
201
+ expect(getTags.log).toEqual([]);
202
+ const a = getTags.tag.tag('a');
203
+ expect(a).toBeDefined();
204
+ expect(a === null || a === void 0 ? void 0 : a.text()).toBeUndefined();
205
+ });
206
+ test('text as array', () => {
207
+ const strToParse = 'a=b';
208
+ const getTags = malloy_1.Tag.fromTagline(strToParse, undefined);
209
+ expect(getTags.log).toEqual([]);
210
+ const a = getTags.tag.tag('a');
211
+ expect(a).toBeDefined();
212
+ expect(a === null || a === void 0 ? void 0 : a.array()).toBeUndefined();
213
+ });
214
+ test('just numeric', () => {
215
+ const strToParse = 'a=7';
216
+ const getTags = malloy_1.Tag.fromTagline(strToParse, undefined);
217
+ expect(getTags.log).toEqual([]);
218
+ const a = getTags.tag.tag('a');
219
+ expect(a).toBeDefined();
220
+ const n = a === null || a === void 0 ? void 0 : a.numeric();
221
+ expect(typeof n).toBe('number');
222
+ expect(n).toEqual(7);
223
+ });
224
+ test('text as numeric', () => {
225
+ const strToParse = 'a=seven';
226
+ const getTags = malloy_1.Tag.fromTagline(strToParse, undefined);
227
+ expect(getTags.log).toEqual([]);
228
+ const a = getTags.tag.tag('a');
229
+ expect(a).toBeDefined();
230
+ const n = a === null || a === void 0 ? void 0 : a.numeric();
231
+ expect(n).toBeUndefined();
232
+ });
233
+ test('array as numeric', () => {
234
+ const strToParse = 'a=[seven]';
235
+ const getTags = malloy_1.Tag.fromTagline(strToParse, undefined);
236
+ expect(getTags.log).toEqual([]);
237
+ const a = getTags.tag.tag('a');
238
+ expect(a).toBeDefined();
239
+ const n = a === null || a === void 0 ? void 0 : a.numeric();
240
+ expect(n).toBeUndefined();
241
+ });
242
+ test('full text array', () => {
243
+ const strToParse = 'a=[b,c]';
244
+ const getTags = malloy_1.Tag.fromTagline(strToParse, undefined);
245
+ expect(getTags.log).toEqual([]);
246
+ const a = getTags.tag.tag('a');
247
+ expect(a).toBeDefined();
248
+ const ais = a === null || a === void 0 ? void 0 : a.textArray();
249
+ expect(ais).toEqual(['b', 'c']);
250
+ });
251
+ test('filtered text array', () => {
252
+ const strToParse = 'a=[b,c,{d}]';
253
+ const getTags = malloy_1.Tag.fromTagline(strToParse, undefined);
254
+ expect(getTags.log).toEqual([]);
255
+ const a = getTags.tag.tag('a');
256
+ expect(a).toBeDefined();
257
+ const ais = a === null || a === void 0 ? void 0 : a.textArray();
258
+ expect(ais).toEqual(['b', 'c']);
259
+ });
260
+ test('full numeric array', () => {
261
+ const strToParse = 'a=[1,2]';
262
+ const getTags = malloy_1.Tag.fromTagline(strToParse, undefined);
263
+ expect(getTags.log).toEqual([]);
264
+ const a = getTags.tag.tag('a');
265
+ expect(a).toBeDefined();
266
+ const ais = a === null || a === void 0 ? void 0 : a.numericArray();
267
+ expect(ais).toEqual([1, 2]);
268
+ });
269
+ test('filtered numeric array', () => {
270
+ const strToParse = 'a=[1,2,three]';
271
+ const getTags = malloy_1.Tag.fromTagline(strToParse, undefined);
272
+ expect(getTags.log).toEqual([]);
273
+ const a = getTags.tag.tag('a');
274
+ expect(a).toBeDefined();
275
+ const ais = a === null || a === void 0 ? void 0 : a.numericArray();
276
+ expect(ais).toEqual([1, 2]);
277
+ });
278
+ test('has', () => {
279
+ const strToParse = 'a b.d';
280
+ const getTags = malloy_1.Tag.fromTagline(strToParse, undefined);
281
+ expect(getTags.log).toEqual([]);
282
+ expect(getTags.tag.has('a')).toBeTruthy();
283
+ expect(getTags.tag.has('b', 'd')).toBeTruthy();
284
+ expect(getTags.tag.has('c')).toBeFalsy();
285
+ });
286
+ });
287
+ describe('## top level', () => {
288
+ test('top level tags are available in the model def', async () => {
289
+ const model = await runtime
290
+ .loadModel(`
291
+ ## propertyTag
292
+ ##" Doc String
293
+ `)
294
+ .getModel();
295
+ const modelTagLine = model.tagParse().tag;
296
+ expect(modelTagLine.has('propertyTag')).toBeTruthy();
297
+ expect(model.getTaglines(/^##"/)).toEqual(['##" Doc String\n']);
298
+ });
299
+ });
300
+ describe('tags in results', () => {
301
+ test('nameless query', async () => {
302
+ const loaded = runtime.loadQuery(`
303
+ ## modelDef=ok
304
+ source: one is duckdb.sql("SELECT 1 as one")
305
+ # b4query
306
+ run: # afterQuery import=$(modelDef)
307
+ one -> { select: * }`);
308
+ const qTag = { b4query: {}, afterQuery: {}, import: { eq: 'ok' } };
309
+ const query = await loaded.getPreparedQuery();
310
+ expect(query).toBeDefined();
311
+ expect(query.tagParse().tag).tagsAre(qTag);
312
+ const result = await loaded.run();
313
+ expect(result.tagParse().tag).tagsAre(qTag);
314
+ });
315
+ const wantTag = { BQ: {}, AQ: {}, Bis: {}, Ais: {}, import: { eq: 'ok' } };
316
+ test('named query', async () => {
317
+ const loaded = runtime.loadQuery(`
318
+ ## modelDef=ok
319
+ source: one is duckdb.sql("SELECT 1 as one")
320
+ # BQ
321
+ query: # AQ
322
+ # import=$(modelDef)
323
+ theName
324
+ # Bis
325
+ is
326
+ # Ais
327
+ one -> { select: * }
328
+ run: theName
329
+ `);
330
+ const query = await loaded.getPreparedQuery();
331
+ expect(query).toBeDefined();
332
+ expect(query.tagParse().tag).tagsAre(wantTag);
333
+ const result = await loaded.run();
334
+ expect(result.tagParse().tag).tagsAre(wantTag);
335
+ });
336
+ test('turtle query', async () => {
337
+ const loaded = runtime.loadQuery(`
338
+ ## modelDef=ok
339
+ source: one is duckdb.sql("SELECT 1 as one") extend {
340
+ # BQ import=$(modelDef)
341
+ view: # AQ
342
+ in_one
343
+ # Bis
344
+ is
345
+ # Ais
346
+ { select: one }
347
+ }
348
+ run: one -> in_one
349
+ `);
350
+ const query = await loaded.getPreparedQuery();
351
+ expect(query).toBeDefined();
352
+ expect(query.tagParse().tag).tagsAre(wantTag);
353
+ const result = await loaded.run();
354
+ expect(result.tagParse().tag).tagsAre(wantTag);
355
+ });
356
+ test('field ref has tag', async () => {
357
+ const loaded = runtime.loadQuery(`run: duckdb.sql("select 1 as num") extend {
358
+ dimension: # sourceNote
359
+ one is num
360
+ } -> {
361
+ select: # queryNote
362
+ one
363
+ }`);
364
+ const result = await loaded.run();
365
+ const shape = result.resultExplore;
366
+ const one = shape.getFieldByName('one');
367
+ expect(one).toBeDefined();
368
+ const tp = one.tagParse();
369
+ expect(tp.log).toEqual([]);
370
+ expect(tp.tag).tagsAre({ sourceNote: {}, queryNote: {} });
371
+ });
372
+ test('atomic field model scope tag', async () => {
373
+ const loaded = runtime.loadQuery(`
374
+ ## modelDef=ok
375
+ source: one is duckdb.sql("SELECT 1 as one")
376
+ run: one -> {
377
+ select:
378
+ # note1 import=$(modelDef)
379
+ one
380
+ }`);
381
+ const result = await loaded.run();
382
+ const shape = result.resultExplore;
383
+ const one = shape.getFieldByName('one');
384
+ expect(one).toBeDefined();
385
+ const tp = one.tagParse();
386
+ expect(tp.log).toEqual([]);
387
+ expect(tp.tag).tagsAre({ note1: {}, import: { eq: 'ok' } });
388
+ });
389
+ test('nested query has tag', async () => {
390
+ const loaded = runtime.loadQuery(`
391
+ ## modelDef=ok
392
+ source: one is duckdb.sql("SELECT 1 as one")
393
+ source: malloy_one is one extend {
394
+ view: in_one is {
395
+ select: one
396
+ }
397
+ view: one_and_one is {
398
+ group_by: one
399
+ # note1
400
+ nest:
401
+ # note2 import=$(modelDef)
402
+ in_one
403
+ }
404
+ }
405
+ run: malloy_one -> one_and_one`);
406
+ const result = await loaded.run();
407
+ const shape = result.resultExplore;
408
+ const one = shape.getFieldByName('in_one');
409
+ expect(one).toBeDefined();
410
+ expect(one.tagParse().tag).tagsAre({
411
+ note1: {},
412
+ note2: {},
413
+ import: { eq: 'ok' },
414
+ });
415
+ });
416
+ test('render usage test case', async () => {
417
+ const loaded = runtime.loadQuery(`
418
+ source: ages is duckdb.sql('SELECT 1 as one') extend {
419
+ # name
420
+ dimension: name is 'John'
421
+ view: height
422
+ # barchart
423
+ is {
424
+ select: heightd is 10
425
+ }
426
+
427
+ view: age
428
+ # barchart
429
+ is {
430
+ select: aged is 20
431
+ }
432
+
433
+ }
434
+ run: ages -> {
435
+ group_by: name
436
+ nest: height
437
+ nest: age
438
+ }
439
+ `);
440
+ const result = await loaded.run();
441
+ const shape = result.resultExplore;
442
+ const height = shape.getFieldByName('height');
443
+ const age = shape.getFieldByName('age');
444
+ const name = shape.getFieldByName('name');
445
+ expect(height.tagParse().tag).tagsAre({ barchart: {} });
446
+ expect(age.tagParse().tag).tagsAre({ barchart: {} });
447
+ expect(name.tagParse().tag).tagsAre({ name: {} });
448
+ });
449
+ test('User defined scopes nest properly', async () => {
450
+ const loaded = runtime.loadQuery(`
451
+ ## scope=model
452
+ run: duckdb.sql("SELECT 1 as one") -> {
453
+ select:
454
+ # valueFrom=$(scope)
455
+ one
456
+ }`);
457
+ const result = await loaded.run();
458
+ const shape = result.resultExplore;
459
+ const field = shape.getFieldByName('one');
460
+ expect(field).toBeDefined();
461
+ let tp = field.tagParse().tag;
462
+ expect(tp).tagsAre({ valueFrom: { eq: 'model' } });
463
+ const sessionScope = malloy_1.Tag.fromTagline('# scope=session', undefined).tag;
464
+ tp = field.tagParse({ scopes: [sessionScope] }).tag;
465
+ expect(tp).tagsAre({ valueFrom: { eq: 'session' } });
466
+ const globalScope = malloy_1.Tag.fromTagline('# scope=global', undefined).tag;
467
+ tp = field.tagParse({ scopes: [globalScope, sessionScope] }).tag;
468
+ expect(tp).tagsAre({ valueFrom: { eq: 'global' } });
469
+ });
470
+ test('inherited model tags override', async () => {
471
+ const model = runtime.loadModel('## from=cell1\nsource: one is duckdb.sql("select 1")');
472
+ const model2 = model.extendModel('## from=cell2');
473
+ const query = model2.loadQuery('run: one -> {select: `1`}');
474
+ const result = await query.run();
475
+ const modelTags = result.modelTag;
476
+ expect(modelTags.text('from')).toEqual('cell2');
477
+ });
478
+ test('property access on existing tag (which does not yet have properties)', () => {
479
+ const parsePlot = malloy_1.Tag.fromTagline('# plot', undefined);
480
+ const parsed = malloy_1.Tag.fromTagline('# plot.x=2', parsePlot.tag);
481
+ const allTags = parsed.tag;
482
+ const plotTag = allTags.tag('plot');
483
+ const xTag = plotTag.tag('x');
484
+ const x = xTag.numeric();
485
+ expect(parsed.tag.numeric('plot', 'x')).toEqual(2);
486
+ expect(plotTag.numeric('x')).toEqual(2);
487
+ expect(x).toEqual(2);
488
+ });
489
+ });
490
+ //# sourceMappingURL=tags.spec.js.map