-
Notifications
You must be signed in to change notification settings - Fork 2
Range
bhsd edited this page Mar 14, 2024
·
1 revision
This is an internal document. For visitors, you can now go back to the home page.
// Range (main)
var {Range} = require('../lib/ranges');
var range = new Range(' odd '),
target = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
assert.deepStrictEqual({...range}, {
start: 1,
end: Infinity,
step: 2,
});
assert.deepStrictEqual(range.applyTo(target), [1, 3, 5, 7, 9]);
range = new Range(' even ');
assert.deepStrictEqual({...range}, {
start: 0,
end: Infinity,
step: 2,
});
assert.deepStrictEqual(range.applyTo(target), [0, 2, 4, 6, 8]);
range = new Range(' 1 : 3 : 2 ');
assert.deepStrictEqual({...range}, {
start: 1,
end: 3,
step: 2,
});
assert.deepStrictEqual(range.applyTo(target), [1]);
range = new Range(' 1 : 3 ');
assert.deepStrictEqual({...range}, {
start: 1,
end: 3,
step: 1,
});
assert.deepStrictEqual(range.applyTo(target), [1, 2]);
range = new Range(' 1 : : 2 ');
assert.deepStrictEqual({...range}, {
start: 1,
end: Infinity,
step: 2,
});
assert.deepStrictEqual(range.applyTo(target), [1, 3, 5, 7, 9]);
range = new Range(' : 3 : 2 ');
assert.deepStrictEqual({...range}, {
start: 0,
end: 3,
step: 2,
});
assert.deepStrictEqual(range.applyTo(target), [0, 2]);
range = new Range(' 1 : ');
assert.deepStrictEqual({...range}, {
start: 1,
end: Infinity,
step: 1,
});
assert.deepStrictEqual(range.applyTo(target), [1, 2, 3, 4, 5, 6, 7, 8, 9]);
range = new Range(' : 3 ');
assert.deepStrictEqual({...range}, {
start: 0,
end: 3,
step: 1,
});
assert.deepStrictEqual(range.applyTo(target), [0, 1, 2]);
range = new Range(' : : 2 ');
assert.deepStrictEqual({...range}, {
start: 0,
end: Infinity,
step: 2,
});
assert.deepStrictEqual(range.applyTo(target), [0, 2, 4, 6, 8]);
range = new Range(' 2n + 1 ');
assert.deepStrictEqual({...range}, {
start: 1,
end: Infinity,
step: 2,
});
assert.deepStrictEqual(range.applyTo(target), [1, 3, 5, 7, 9]);
range = new Range(' 3n - 4 ');
assert.deepStrictEqual({...range}, {
start: 2,
end: Infinity,
step: 3,
});
assert.deepStrictEqual(range.applyTo(target), [2, 5, 8]);
range = new Range(' -3n + 4 ');
assert.deepStrictEqual({...range}, {
start: 1,
end: 7,
step: 3,
});
assert.deepStrictEqual(range.applyTo(target), [1, 4]);
range = new Range(' -3n - 1 ');
assert.deepStrictEqual({...range}, {
start: 0,
end: 0,
step: 3,
});
assert.deepStrictEqual(range.applyTo(target), []);
range = new Range(' n + 1 ');
assert.deepStrictEqual({...range}, {
start: 1,
end: Infinity,
step: 1,
});
assert.deepStrictEqual(range.applyTo(target), [1, 2, 3, 4, 5, 6, 7, 8, 9]);
range = new Range(' n - 3 ');
assert.deepStrictEqual({...range}, {
start: 0,
end: Infinity,
step: 1,
});
assert.deepStrictEqual(range.applyTo(target), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
range = new Range(' -n + 2 ');
assert.deepStrictEqual({...range}, {
start: 0,
end: 3,
step: 1,
});
assert.deepStrictEqual(range.applyTo(target), [0, 1, 2]);
range = new Range(' -n - 1 ');
assert.deepStrictEqual({...range}, {
start: 0,
end: 0,
step: 1,
});
assert.deepStrictEqual(range.applyTo(target), []);
range = new Range(' 3n ');
assert.deepStrictEqual({...range}, {
start: 0,
end: Infinity,
step: 3,
});
assert.deepStrictEqual(range.applyTo(target), [0, 3, 6, 9]);
range = new Range(' -3n ');
assert.deepStrictEqual({...range}, {
start: 0,
end: 3,
step: 3,
});
assert.deepStrictEqual(range.applyTo(target), [0]);
range = new Range(' n ');
assert.deepStrictEqual({...range}, {
start: 0,
end: Infinity,
step: 1,
});
assert.deepStrictEqual(range.applyTo(target), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
range = new Range(' -n ');
assert.deepStrictEqual({...range}, {
start: 0,
end: 1,
step: 1,
});
assert.deepStrictEqual(range.applyTo(target), [0]);
对维基文本批量执行语法检查的命令行工具
用于维基文本的 ESLint 插件
A command-line tool that performs linting on Wikitext in bulk
ESLint plugin for Wikitext