Skip to content

Commit

Permalink
add testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-ayf committed Jan 20, 2024
1 parent 2f31f35 commit 2aa9a10
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/micromark/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ export function attributeList(options?: Options): Construct {

if (code === codes.dot || code === codes.numberSign) {
if (options?.allowNoSpaceBeforeName) {
effects.exit('classNameAttributeName');
effects.exit('classNameAttribute');
return next(code);
}

Expand Down
70 changes: 70 additions & 0 deletions test/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import {test} from 'node:test';
import assert from 'node:assert';
import {unified} from 'unified';
import remarkParse from 'remark-parse';
import {removePosition} from 'unist-util-remove-position';
import {u} from 'unist-builder';
import remarkAttributeList from '../dist/index.js';

const processor = unified().use(remarkParse).use(remarkAttributeList, {
allowNoSpaceBeforeName: true,
allowUnderscoreInId: true,
});

/**
* @param {string} source
*/
function parse(source) {
const parsed = processor.parse(source);
removePosition(parsed, {force: true});
return parsed;
}

await test('parsing with options', async (t) => {
await t.test(
'should parse attribute list without space before name',
async () => {
assert.deepStrictEqual(
parse('{:name:.cls1.cls2}\n'),
u('root', [
u('attributeListDefinition', {name: 'name'}, [
u('classNameAttribute', {name: 'cls1'}),
u('classNameAttribute', {name: 'cls2'}),
]),
]),
);
assert.deepStrictEqual(
parse('{:#id.cls1}\n'),
u('root', [
u('blockInlineAttributeList', [
u('idNameAttribute', {name: 'id'}),
u('classNameAttribute', {name: 'cls1'}),
]),
]),
);
assert.deepStrictEqual(
parse('{:ref#id}\n'),
u('root', [
u('blockInlineAttributeList', [
u('referenceAttribute', {name: 'ref'}),
u('idNameAttribute', {name: 'id'}),
]),
]),
);
},
);

await t.test(
'should parse attribute list with underscore in ID',
async () => {
assert.deepStrictEqual(
parse('{:ref:#id_name}\n'),
u('root', [
u('attributeListDefinition', {name: 'ref'}, [
u('idNameAttribute', {name: 'id_name'}),
]),
]),
);
},
);
});

0 comments on commit 2aa9a10

Please sign in to comment.