File tree Expand file tree Collapse file tree 1 file changed +50
-1
lines changed Expand file tree Collapse file tree 1 file changed +50
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { assert , expect , test } from 'vitest'
2
- import { columnToRpgDefinition } from './codegen' ;
2
+ import { columnToRpgDefinition , queryResultToRpgDs } from './codegen' ;
3
+ import { QueryResult } from '@ibm/mapepire-js' ;
3
4
4
5
test ( 'Column to RPG definition' , ( ) => {
5
6
let rpgdef ;
@@ -41,3 +42,51 @@ test('Column to RPG definition', () => {
41
42
expect ( rpgdef ) . toBe ( '// type:SOME_UNKNOWN_TYPE precision:0 scale:0' ) ;
42
43
} ) ;
43
44
45
+ test ( 'QueryResult to RPG data structure' , ( ) => {
46
+ const queryResult : QueryResult < any > = {
47
+ metadata : {
48
+ column_count : 3 ,
49
+ columns : [
50
+ {
51
+ display_size : 0 ,
52
+ label : 'id' ,
53
+ name : 'id' ,
54
+ type : 'INTEGER' ,
55
+ precision : 0 ,
56
+ scale : 0
57
+ } ,
58
+ {
59
+ display_size : 0 ,
60
+ label : 'name' ,
61
+ name : 'name' ,
62
+ type : 'VARCHAR' ,
63
+ precision : 80 ,
64
+ scale : 0
65
+ } ,
66
+ {
67
+ display_size : 0 ,
68
+ label : 'salary' ,
69
+ name : 'salary' ,
70
+ type : 'DECIMAL' ,
71
+ precision : 13 ,
72
+ scale : 2
73
+ } ,
74
+ ]
75
+ } ,
76
+ is_done : true ,
77
+ has_results : true ,
78
+ update_count : 0 ,
79
+ data : [ ] ,
80
+ id : '' ,
81
+ success : true ,
82
+ sql_rc : 0 ,
83
+ sql_state : '' ,
84
+ execution_time : 0
85
+ } ;
86
+ const ds = queryResultToRpgDs ( queryResult ) ;
87
+ const lines = ds . split ( '\n' ) . filter ( l => l !== '' ) ;
88
+ expect ( lines . length ) . toBe ( 5 ) ;
89
+ expect ( lines . at ( 0 ) ) . toBe ( 'dcl-ds row_t qualified template;' ) ;
90
+ expect ( lines . at ( 4 ) ) . toBe ( 'end-ds;' ) ;
91
+ } ) ;
92
+
You can’t perform that action at this time.
0 commit comments