@@ -3,39 +3,94 @@ const {
33 dartLangWithSpacesNode,
44 typescriptLangNode,
55 typescriptWithLinesGroupNode,
6- } = require ( './tests/mocks' )
7- const { parseLanguageAndHighlightedLines } = require ( "./utils" ) ;
8-
9- /**
10- * Tests for Utils.js
11- */
12- test ( "detects the languages correctly" , ( ) => {
13- expect (
14- parseLanguageAndHighlightedLines ( dartLangNode ) . lang
15- ) . toBe ( 'dart' ) ;
16- expect (
17- parseLanguageAndHighlightedLines ( dartLangWithSpacesNode ) . lang
18- ) . toBe ( 'dart' ) ;
19- expect (
20- parseLanguageAndHighlightedLines ( typescriptLangNode ) . lang
21- ) . toBe ( 'typescript' ) ;
22- expect (
23- parseLanguageAndHighlightedLines ( typescriptWithLinesGroupNode ) . lang
24- ) . toBe ( 'typescript' ) ;
6+ } = require ( "./tests/mocks" ) ;
7+ const { parseLanguageAndHighlightedLines, parseNodeHtml } = require ( "./utils" ) ;
8+
9+ describe ( "parse node to html" , ( ) => {
10+ it ( "should parse no language and no highlight lines (default)" , ( ) => {
11+ const html = parseNodeHtml (
12+ {
13+ text : "<code>Hello World</code>" ,
14+ lang : "" ,
15+ } ,
16+ { }
17+ ) ;
18+
19+ expect ( html ) . toEqual ( `<deckgo-highlight-code >
20+ <code slot="code"></code>
21+ </deckgo-highlight-code>` ) ;
22+ } ) ;
23+
24+ it ( "should parse javascript" , ( ) => {
25+ const html = parseNodeHtml (
26+ {
27+ text : "<code>Hello World</code>" ,
28+ lang : "javascript" ,
29+ } ,
30+ { }
31+ ) ;
32+
33+ expect ( html ) . toEqual ( `<deckgo-highlight-code language="javascript" >
34+ <code slot="code"></code>
35+ </deckgo-highlight-code>` ) ;
36+ } ) ;
37+
38+ it ( "should parse a specific language" , ( ) => {
39+ const html = parseNodeHtml (
40+ {
41+ text : "<code>Hello World</code>" ,
42+ lang : "typescript" ,
43+ } ,
44+ { }
45+ ) ;
46+
47+ expect ( html ) . toEqual ( `<deckgo-highlight-code language="typescript" >
48+ <code slot="code"></code>
49+ </deckgo-highlight-code>` ) ;
50+ } ) ;
51+
52+ it ( "should parse highlighted lines" , ( ) => {
53+ const html = parseNodeHtml (
54+ {
55+ text : "<code>Hello World</code>" ,
56+ lang : "dart{3, 2, 5-9}" ,
57+ } ,
58+ { }
59+ ) ;
60+
61+ expect ( html ) . toEqual ( `<deckgo-highlight-code language="dart" highlight-lines="3 2 5,9">
62+ <code slot="code"></code>
63+ </deckgo-highlight-code>` ) ;
64+ } ) ;
2565} ) ;
2666
67+ describe ( "languages extraction" , ( ) => {
68+ test ( "detects the languages correctly" , ( ) => {
69+ expect ( parseLanguageAndHighlightedLines ( dartLangNode ) . lang ) . toBe ( "dart" ) ;
70+ expect ( parseLanguageAndHighlightedLines ( dartLangWithSpacesNode ) . lang ) . toBe (
71+ "dart"
72+ ) ;
73+ expect ( parseLanguageAndHighlightedLines ( typescriptLangNode ) . lang ) . toBe (
74+ "typescript"
75+ ) ;
76+ expect (
77+ parseLanguageAndHighlightedLines ( typescriptWithLinesGroupNode ) . lang
78+ ) . toBe ( "typescript" ) ;
79+ } ) ;
2780
28- test ( "detects the highlight-lines correctly" , ( ) => {
29- expect (
30- parseLanguageAndHighlightedLines ( dartLangNode ) . highlightLines
31- ) . toBe ( '3 4 5' ) ;
32- expect (
33- parseLanguageAndHighlightedLines ( dartLangWithSpacesNode ) . highlightLines
34- ) . toBe ( '5 9 34 39,44' ) ;
35- expect (
36- parseLanguageAndHighlightedLines ( typescriptLangNode ) . highlightLines
37- ) . toBe ( '' ) ;
38- expect (
39- parseLanguageAndHighlightedLines ( typescriptWithLinesGroupNode ) . highlightLines
40- ) . toBe ( '3 4 5,9 22,45' ) ;
81+ test ( "detects the highlight-lines correctly" , ( ) => {
82+ expect ( parseLanguageAndHighlightedLines ( dartLangNode ) . highlightLines ) . toBe (
83+ "3 4 5"
84+ ) ;
85+ expect (
86+ parseLanguageAndHighlightedLines ( dartLangWithSpacesNode ) . highlightLines
87+ ) . toBe ( "5 9 34 39,44" ) ;
88+ expect (
89+ parseLanguageAndHighlightedLines ( typescriptLangNode ) . highlightLines
90+ ) . toBe ( "" ) ;
91+ expect (
92+ parseLanguageAndHighlightedLines ( typescriptWithLinesGroupNode )
93+ . highlightLines
94+ ) . toBe ( "3 4 5,9 22,45" ) ;
95+ } ) ;
4196} ) ;
0 commit comments