Skip to content

Commit

Permalink
fix: setSource uses correct startOffset AnWeber/httpbook#82
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Mar 17, 2023
1 parent 820b08d commit 69d9ae7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Fixes

- `# @import` imports variables of \*.http files (AnWeber/vscode-httpyac#184)
- setSource uses correct startOffset (AnWeber/httpbook#82)

## 6.3.1 (2023-03-16)

Expand Down
4 changes: 2 additions & 2 deletions src/store/httpRegion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class HttpRegion implements models.HttpRegion {
description: '-',
kind: models.HttpSymbolKind.request,
startLine: start,
startOffset: start,
startOffset: 0,
endLine: start,
endOffset: start,
endOffset: 0,
};
}

Expand Down
51 changes: 51 additions & 0 deletions src/test/parser/parser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { parseHttp, initFileProvider } from '../testUtils';

describe('parser', () => {
initFileProvider();
it('should parse 3 httpregion', async () => {
const httpFile = await parseHttp(`
GET https://httpbin.org/anything
GET https://httpbin.org/anything
GET https://httpbin.org/anything
`);
expect(await httpFile.fileName).toBe('any.http');
expect(await httpFile.httpRegions.length).toBe(3);
for (const httpRegion of httpFile.httpRegions) {
expect(httpRegion.request).toBeDefined();
expect(httpRegion.request?.method).toBe('GET');
expect(httpRegion.request?.url).toBe('https://httpbin.org/anything');

expect(httpRegion.symbol.source?.trim()).toBe('GET https://httpbin.org/anything');
}
});
it('should support header spread', async () => {
const httpFile = await parseHttp(`
{{+
const token = "test"
exports.defaultHeaders = {
'Content-Type': 'text/html',
'Authorization': \`Bearer \${token}\`
};
}}
###
GET https://httpbin.org/anything
...defaultHeaders
GET https://httpbin.org/anything
...defaultHeaders
`);
expect(await httpFile.fileName).toBe('any.http');
expect(await httpFile.httpRegions.length).toBe(3);

const globalRegion = httpFile.httpRegions.shift();
expect(globalRegion?.request).toBeUndefined();

for (const httpRegion of httpFile.httpRegions) {
expect(httpRegion.request).toBeDefined();
expect(httpRegion.request?.method).toBe('GET');
expect(httpRegion.request?.method).toBe('GET');
expect(httpRegion.request?.url).toBe('https://httpbin.org/anything');

expect(httpRegion.symbol.source?.trim()).toBe(`GET https://httpbin.org/anything\n ...defaultHeaders`);
}
});
});

0 comments on commit 69d9ae7

Please sign in to comment.