| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- class TokenTests extends BaseTest {
- test_findFirstTokens() {
- const tokens = [
- new MDToken('Lorem', MDTokenType.Text),
- new MDToken(' ', MDTokenType.Whitespace),
- new MDToken('_', MDTokenType.Underscore),
- new MDToken('ipsum', MDTokenType.Text),
- new MDToken('_', MDTokenType.Underscore),
- new MDToken(' ', MDTokenType.Whitespace),
- new MDToken('dolor', MDTokenType.Text),
- new MDToken('_', MDTokenType.Underscore),
- new MDToken('sit', MDTokenType.Text),
- new MDToken('_', MDTokenType.Underscore),
- ];
- const pattern = [
- MDTokenType.Underscore,
- ];
- const actual = MDToken.findFirstTokens(tokens, pattern);
- const expected = {
- tokens: [ tokens[2] ],
- index: 2,
- };
- this.assertEqual(expected, actual);
- }
-
- test_findFirstTokens_optionalWhitespace1() {
- const tokens = [
- new MDToken('Lorem', MDTokenType.Text),
- new MDToken(' ', MDTokenType.Whitespace),
- new MDToken('[ipsum]', MDTokenType.Label, 'ipsum'),
- new MDToken('(link.html)', MDTokenType.URL, 'link.html'),
- new MDToken(' ', MDTokenType.Whitespace),
- new MDToken('dolor', MDTokenType.Text),
- ];
- const pattern = [
- MDTokenType.Label,
- MDTokenType.META_OptionalWhitespace,
- MDTokenType.URL,
- ];
- const actual = MDToken.findFirstTokens(tokens, pattern);
- const expected = {
- tokens: [ tokens[2], tokens[3] ],
- index: 2,
- };
- this.assertEqual(expected, actual);
- }
-
- test_findFirstTokens_optionalWhitespace2() {
- const tokens = [
- new MDToken('Lorem', MDTokenType.Text),
- new MDToken(' ', MDTokenType.Whitespace),
- new MDToken('[ipsum]', MDTokenType.Label, 'ipsum'),
- new MDToken(' ', MDTokenType.Whitespace),
- new MDToken('(link.html)', MDTokenType.URL, 'link.html'),
- new MDToken(' ', MDTokenType.Whitespace),
- new MDToken('dolor', MDTokenType.Text),
- ];
- const pattern = [
- MDTokenType.Label,
- MDTokenType.META_OptionalWhitespace,
- MDTokenType.URL,
- ];
- const actual = MDToken.findFirstTokens(tokens, pattern);
- const expected = {
- tokens: [ tokens[2], tokens[3], tokens[4] ],
- index: 2,
- };
- this.assertEqual(expected, actual);
- }
-
- test_findPairedTokens() {
- const tokens = [
- new MDToken('Lorem', MDTokenType.Text),
- new MDToken(' ', MDTokenType.Whitespace),
- new MDToken('_', MDTokenType.Underscore),
- new MDToken('ipsum', MDTokenType.Text),
- new MDToken('_', MDTokenType.Underscore),
- new MDToken(' ', MDTokenType.Whitespace),
- new MDToken('dolor', MDTokenType.Text),
- new MDToken('_', MDTokenType.Underscore),
- new MDToken('sit', MDTokenType.Text),
- new MDToken('_', MDTokenType.Underscore),
- ];
- const pattern = [
- MDTokenType.Underscore,
- ];
- const actual = MDToken.findPairedTokens(tokens, pattern, pattern);
- const expected = {
- startTokens: [ tokens[2] ],
- contentTokens: [ tokens[3] ],
- endTokens: [ tokens[4] ],
- startIndex: 2,
- contentIndex: 3,
- endIndex: 4,
- totalLength: 3,
- }
- this.assertEqual(expected, actual);
- }
- }
|