mirror of
https://github.com/hanzoai/postcss.git
synced 2026-09-24 17:01:56 +00:00
* 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
21 lines
645 B
TypeScript
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 })
|
|
})
|