|
1 | 1 | import { assert, describe, expect, test } from 'vitest'
|
2 | 2 | import SQLTokeniser from '../tokens'
|
3 |
| -import Document from '../document'; |
4 |
| -import { ClauseType, StatementType } from '../types'; |
| 3 | +import Document, { getPositionData } from '../document'; |
| 4 | +import { CallableReference, ClauseType, StatementType } from '../types'; |
5 | 5 |
|
6 | 6 | const parserScenarios = describe.each([
|
7 | 7 | {newDoc: (content: string) => new Document(content)},
|
@@ -2003,6 +2003,112 @@ describe(`Parameter statement tests`, () => {
|
2003 | 2003 | expect(callableC.parentRef.object.schema).toBe(`qsys2`);
|
2004 | 2004 | expect(callableC.parentRef.object.name).toBe(`create_abcd`);
|
2005 | 2005 | });
|
| 2006 | + |
| 2007 | + test('Partial parameters 1: Position data for procedure call', () => { |
| 2008 | + const sql = `call qsys2.ifs_write('asdasd', )`; |
| 2009 | + |
| 2010 | + const document = new Document(sql); |
| 2011 | + const statements = document.statements; |
| 2012 | + |
| 2013 | + expect(statements.length).toBe(1); |
| 2014 | + |
| 2015 | + const callableReference: CallableReference = statements[0].getCallableDetail(29); |
| 2016 | + expect(callableReference).toBeDefined(); |
| 2017 | + expect(callableReference.parentRef.object.name).toBe(`ifs_write`); |
| 2018 | + expect(callableReference.parentRef.object.schema).toBe(`qsys2`); |
| 2019 | + |
| 2020 | + const positionData = getPositionData(callableReference, 29); |
| 2021 | + expect(positionData).toBeDefined(); |
| 2022 | + |
| 2023 | + expect(positionData.currentParm).toBe(1); |
| 2024 | + expect(positionData.currentCount).toBe(2); |
| 2025 | + }); |
| 2026 | + |
| 2027 | + test('Partial parameters 1.2: Position data for procedure call', () => { |
| 2028 | + const sql = `call qsys2.ifs_write('asdasd', )`; |
| 2029 | + |
| 2030 | + const document = new Document(sql); |
| 2031 | + const statements = document.statements; |
| 2032 | + |
| 2033 | + expect(statements.length).toBe(1); |
| 2034 | + |
| 2035 | + const callableReference: CallableReference = statements[0].getCallableDetail(31); |
| 2036 | + expect(callableReference).toBeDefined(); |
| 2037 | + expect(callableReference.parentRef.object.name).toBe(`ifs_write`); |
| 2038 | + expect(callableReference.parentRef.object.schema).toBe(`qsys2`); |
| 2039 | + |
| 2040 | + const positionData = getPositionData(callableReference, 31); |
| 2041 | + expect(positionData).toBeDefined(); |
| 2042 | + |
| 2043 | + expect(positionData.currentParm).toBe(1); |
| 2044 | + expect(positionData.currentCount).toBe(2); |
| 2045 | + }); |
| 2046 | + |
| 2047 | + test('Partial parameters 2: Position data for procedure call', () => { |
| 2048 | + const sql = `call qsys2.ifs_write('asdasd', 243)`; |
| 2049 | + |
| 2050 | + const document = new Document(sql); |
| 2051 | + const statements = document.statements; |
| 2052 | + |
| 2053 | + expect(statements.length).toBe(1); |
| 2054 | + |
| 2055 | + const callableReference: CallableReference = statements[0].getCallableDetail(25); |
| 2056 | + expect(callableReference).toBeDefined(); |
| 2057 | + expect(callableReference.parentRef.object.name).toBe(`ifs_write`); |
| 2058 | + expect(callableReference.parentRef.object.schema).toBe(`qsys2`); |
| 2059 | + |
| 2060 | + const positionData = getPositionData(callableReference, 25); |
| 2061 | + expect(positionData).toBeDefined(); |
| 2062 | + |
| 2063 | + expect(positionData.currentParm).toBe(0); |
| 2064 | + expect(positionData.currentCount).toBe(2); |
| 2065 | + }); |
| 2066 | + |
| 2067 | + test('Partial parameters 3: Position data for procedure call', () => { |
| 2068 | + const sql = `call qsys2.ifs_write('asdasd', 243, )`; |
| 2069 | + |
| 2070 | + const document = new Document(sql); |
| 2071 | + const statements = document.statements; |
| 2072 | + |
| 2073 | + expect(statements.length).toBe(1); |
| 2074 | + |
| 2075 | + const callableReference: CallableReference = statements[0].getCallableDetail(25); |
| 2076 | + expect(callableReference).toBeDefined(); |
| 2077 | + expect(callableReference.parentRef.object.name).toBe(`ifs_write`); |
| 2078 | + expect(callableReference.parentRef.object.schema).toBe(`qsys2`); |
| 2079 | + |
| 2080 | + const positionDataA = getPositionData(callableReference, 25); |
| 2081 | + expect(positionDataA).toBeDefined(); |
| 2082 | + |
| 2083 | + expect(positionDataA.currentParm).toBe(0); |
| 2084 | + expect(positionDataA.currentCount).toBe(3); |
| 2085 | + |
| 2086 | + const positionDataB = getPositionData(callableReference, 29); |
| 2087 | + expect(positionDataB).toBeDefined(); |
| 2088 | + |
| 2089 | + expect(positionDataB.currentParm).toBe(1); |
| 2090 | + expect(positionDataB.currentCount).toBe(3); |
| 2091 | + }); |
| 2092 | + |
| 2093 | + test('Partial parameters 4: Position data for procedure call', () => { |
| 2094 | + const sql = `call qsys2.ifs_write('asdasd', 'asdasd', overwrite => 'asdad')`; |
| 2095 | + |
| 2096 | + const document = new Document(sql); |
| 2097 | + const statements = document.statements; |
| 2098 | + |
| 2099 | + expect(statements.length).toBe(1); |
| 2100 | + |
| 2101 | + const callableReference: CallableReference = statements[0].getCallableDetail(50); |
| 2102 | + expect(callableReference).toBeDefined(); |
| 2103 | + expect(callableReference.parentRef.object.name).toBe(`ifs_write`); |
| 2104 | + expect(callableReference.parentRef.object.schema).toBe(`qsys2`); |
| 2105 | + |
| 2106 | + const positionDataA = getPositionData(callableReference, 50); |
| 2107 | + expect(positionDataA).toBeDefined(); |
| 2108 | + |
| 2109 | + expect(positionDataA.currentParm).toBe(2); |
| 2110 | + expect(positionDataA.currentCount).toBe(3); |
| 2111 | + }); |
2006 | 2112 | });
|
2007 | 2113 |
|
2008 | 2114 | describe(`Prefix tests`, () => {
|
|
0 commit comments