|
| 1 | +// Copyright 2025 The MathWorks, Inc. |
| 2 | + |
| 3 | +import { lineIndent } from '../indent-matlab'; |
| 4 | + |
| 5 | +describe('lineIndent', () => { |
| 6 | + const indentUnit = 4; |
| 7 | + |
| 8 | + test('should indent after an indent pattern', () => { |
| 9 | + const previousLineText = 'if foo'; |
| 10 | + const currentLineText = ''; |
| 11 | + const result = lineIndent(indentUnit, currentLineText, previousLineText); |
| 12 | + expect(result).toBe(indentUnit); |
| 13 | + }); |
| 14 | + |
| 15 | + test('should indent first case in a switch statement by a single indent', () => { |
| 16 | + const previousLineText = 'switch foo'; |
| 17 | + const currentLineText = 'case bar'; |
| 18 | + const result = lineIndent(indentUnit, currentLineText, previousLineText); |
| 19 | + expect(result).toBe(indentUnit); |
| 20 | + }); |
| 21 | + |
| 22 | + test('should dedent "end" after an indented block', () => { |
| 23 | + const previousLineText = 'for c = 1:s'; |
| 24 | + const currentLineText = 'end'; |
| 25 | + const result = lineIndent(indentUnit, currentLineText, previousLineText); |
| 26 | + expect(result).toBe(0); |
| 27 | + }); |
| 28 | + |
| 29 | + test('should not change indentation for lines not matching patterns', () => { |
| 30 | + const previousLineText = ' foo;'; |
| 31 | + const currentLineText = ''; |
| 32 | + const result = lineIndent(indentUnit, currentLineText, previousLineText); |
| 33 | + expect(result).toBe(4); |
| 34 | + }); |
| 35 | + |
| 36 | + test('should not indent after one-line statement', () => { |
| 37 | + const previousLineText = 'if foo A=1; else A=2; end;'; |
| 38 | + const currentLineText = ''; |
| 39 | + const result = lineIndent(indentUnit, currentLineText, previousLineText); |
| 40 | + expect(result).toBe(0); |
| 41 | + }); |
| 42 | + |
| 43 | + test('should not decrease indentation below zero', () => { |
| 44 | + const previousLineText = 'end'; |
| 45 | + const currentLineText = 'end'; |
| 46 | + const result = lineIndent(indentUnit, currentLineText, previousLineText); |
| 47 | + expect(result).toBe(0); |
| 48 | + }); |
| 49 | +}); |
0 commit comments