angular-cn/aio/tools/transforms/examples-package/services/region-matchers/html.spec.js

63 lines
2.0 KiB
JavaScript

const matcher = require('./html');
describe('html region-matcher', () => {
it('should match start annotations', () => {
let matches;
matches = matcher.regionStartMatcher.exec('<!-- #docregion A b c -->');
expect(matches).not.toBeNull();
expect(matches[1]).toEqual('A b c');
matches = matcher.regionStartMatcher.exec('<!--#docregion A b c-->');
expect(matches).not.toBeNull();
expect(matches[1]).toEqual('A b c');
matches = matcher.regionStartMatcher.exec('<!-- #docregion -->');
expect(matches).not.toBeNull();
expect(matches[1]).toEqual('');
});
it('should match end annotations', () => {
let matches;
matches = matcher.regionEndMatcher.exec('<!-- #enddocregion A b c -->');
expect(matches).not.toBeNull();
expect(matches[1]).toEqual('A b c');
matches = matcher.regionEndMatcher.exec('<!--#enddocregion A b c-->');
expect(matches).not.toBeNull();
expect(matches[1]).toEqual('A b c');
matches = matcher.regionEndMatcher.exec('<!-- #enddocregion -->');
expect(matches).not.toBeNull();
expect(matches[1]).toEqual('');
});
it('should handle annotations that do not close the comment on the same line', () => {
let matches;
matches = matcher.regionStartMatcher.exec('<!-- #docregion A b c');
expect(matches).not.toBeNull();
expect(matches[1]).toEqual('A b c');
});
it('should match plaster annotations', () => {
let matches;
matches = matcher.plasterMatcher.exec('<!-- #docplaster A b c -->');
expect(matches).not.toBeNull();
expect(matches[1]).toEqual('A b c');
matches = matcher.plasterMatcher.exec('<!--#docplaster A b c-->');
expect(matches).not.toBeNull();
expect(matches[1]).toEqual('A b c');
matches = matcher.plasterMatcher.exec('<!-- #docplaster -->');
expect(matches).not.toBeNull();
expect(matches[1]).toEqual('');
});
it('should create a plaster comment', () => {
expect(matcher.createPlasterComment('... elided ...')).toEqual('<!-- ... elided ... -->');
});
});