Files
postcss/test/input.test.ts
T
mizdraandGitHub 676f35fe97 Add Input#fromLineAndColumn, CssSyntaxError.input.offset and CssSyntaxError.input.endOffset (#2034)
* Test the current behavior of error location

* Fix missing jsdoc for `Input#error(message, start, end, opts)`

* Refactor `fromOffset`

* Add `Input#fromLineAndColumn`

* Add `Input#offset` and `Input#endOffset`

* Convert `_getLineToIndex` to function
2025-03-22 18:08:32 +01:00

21 lines
645 B
TypeScript

import { test } from 'uvu'
import { equal, is } from 'uvu/assert'
import { Input } from '../lib/postcss.js'
test('fromLineAndColumn() returns offset', () => {
let input = new Input('a {\n}')
is(input.fromLineAndColumn(1, 1), 0)
is(input.fromLineAndColumn(1, 3), 2)
is(input.fromLineAndColumn(2, 1), 4)
is(input.fromLineAndColumn(2, 2), 5)
})
test('fromOffset() returns line and column', () => {
let input = new Input('a {\n}')
equal(input.fromOffset(0), { col: 1, line: 1 })
equal(input.fromOffset(2), { col: 3, line: 1 })
equal(input.fromOffset(4), { col: 1, line: 2 })
equal(input.fromOffset(5), { col: 2, line: 2 })
})