File tree Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Expand file tree Collapse file tree 1 file changed +66
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { expect , test } from 'vitest' ;
2
2
import './index.js' ;
3
+ import './themes/theme-defaults.css' ;
3
4
4
5
const render = ( html ) => {
5
6
document . body . innerHTML = html ;
@@ -12,3 +13,68 @@ test('default attributes', async () => {
12
13
await expect . element ( element ) . toBeInTheDocument ( ) ;
13
14
expect ( element ) . toHaveAttribute ( 'tabindex' , '0' ) ;
14
15
} ) ;
16
+
17
+ test ( 'highlights' , async ( ) => {
18
+ render ( `<syntax-highlight language="js">// Comment
19
+ console.log('Hello World!');
20
+ </syntax-highlight>
21
+ ` ) ;
22
+
23
+ const element = document . querySelector ( 'syntax-highlight' ) ;
24
+ const highlights = Array . from ( element . highlights ) . map ( ( v ) => {
25
+ v . range = { startOffset : v . range . startOffset , endOffset : v . range . endOffset } ;
26
+ return v ;
27
+ } ) ;
28
+
29
+ expect ( highlights ) . toEqual ( [
30
+ {
31
+ tokenType : 'comment' ,
32
+ range : {
33
+ startOffset : 0 ,
34
+ endOffset : 10 ,
35
+ } ,
36
+ } ,
37
+ {
38
+ tokenType : 'punctuation' ,
39
+ range : {
40
+ startOffset : 18 ,
41
+ endOffset : 19 ,
42
+ } ,
43
+ } ,
44
+ {
45
+ tokenType : 'function' ,
46
+ range : {
47
+ startOffset : 19 ,
48
+ endOffset : 22 ,
49
+ } ,
50
+ } ,
51
+ {
52
+ tokenType : 'punctuation' ,
53
+ range : {
54
+ startOffset : 22 ,
55
+ endOffset : 23 ,
56
+ } ,
57
+ } ,
58
+ {
59
+ tokenType : 'string' ,
60
+ range : {
61
+ startOffset : 23 ,
62
+ endOffset : 37 ,
63
+ } ,
64
+ } ,
65
+ {
66
+ tokenType : 'punctuation' ,
67
+ range : {
68
+ startOffset : 37 ,
69
+ endOffset : 38 ,
70
+ } ,
71
+ } ,
72
+ {
73
+ tokenType : 'punctuation' ,
74
+ range : {
75
+ startOffset : 38 ,
76
+ endOffset : 39 ,
77
+ } ,
78
+ } ,
79
+ ] ) ;
80
+ } ) ;
You can’t perform that action at this time.
0 commit comments