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); } }