Skip to content

Commit

Permalink
Introduce MissingTexts type
Browse files Browse the repository at this point in the history
  • Loading branch information
PEZ committed Jun 25, 2023
1 parent f368d6d commit a434f65
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/cursor-doc/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as model from './model';

export function addMissingBrackets(text: string): { append: string; prepend: string } {
export type MissingTexts = {
append: string;
prepend: string;
};

export function getMissingBrackets(text: string): MissingTexts {
const doc = new model.StringDocument(text);
const cursor = doc.getTokenCursor(0);
const stack: string[] = [];
Expand Down
12 changes: 6 additions & 6 deletions src/extension-test/unit/cursor-doc/utilities-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ describe('Utilities that need cursor doc things', () => {
it('Adds missing brackets', () => {
const text = '(a b) (c {:d [1 2 3 "four"';
const append = ']})';
expect(utilities.addMissingBrackets(text)).toEqual({ append: append, prepend: '' });
expect(utilities.getMissingBrackets(text)).toEqual({ append: append, prepend: '' });
});
it('Closes strings', () => {
const text = '(a b) (c {:d [1 2 3 "four';
const append = '"]})';
expect(utilities.addMissingBrackets(text)).toEqual({ append: append, prepend: '' });
expect(utilities.getMissingBrackets(text)).toEqual({ append: append, prepend: '' });
});
it('Leaves non-broken structure alone', () => {
const text = '(a b) (c {:d [1 2 3 "four"] :e :f} g) h';
expect(utilities.addMissingBrackets(text)).toEqual({ append: '', prepend: '' });
expect(utilities.getMissingBrackets(text)).toEqual({ append: '', prepend: '' });
});
it('Adds missing opening brackets', () => {
const text = '(a b) (c {:d [1 2 3 "four"]}) extra ] closing } brackets)';
const prepend = '({[';
expect(utilities.addMissingBrackets(text)).toEqual({ append: '', prepend: prepend });
expect(utilities.getMissingBrackets(text)).toEqual({ append: '', prepend: prepend });
});
it('Ignores brackets in strings', () => {
const text = '(a b) "{{" (c {:d [1 2 3 "four([{" [';
const append = ']]})';
expect(utilities.addMissingBrackets(text)).toEqual({ append: append, prepend: '' });
expect(utilities.getMissingBrackets(text)).toEqual({ append: append, prepend: '' });
});
it('Ignores brackets in line comments', () => {
const text = '(a b) (c {:d \n; ( [ ( {\n[1 2 3 "four"';
const append = ']})';
expect(utilities.addMissingBrackets(text)).toEqual({ append: append, prepend: '' });
expect(utilities.getMissingBrackets(text)).toEqual({ append: append, prepend: '' });
});
});
});

0 comments on commit a434f65

Please sign in to comment.