1
1
import { ref } from 'vue'
2
2
import { MODIFIED_START_TAG , MODIFIED_CLOSE_TAG , getDiffType , getSplitLines , getUnifiedLines , renderLines , renderWords , setHighlightCode } from '../src/utils'
3
3
4
- describe ( 'Utils unit' , ( ) => {
5
- const added = {
6
- count : 1 ,
7
- added : true ,
8
- removed : undefined ,
9
- value : ''
10
- }
11
-
12
- const removed = {
13
- count : 1 ,
14
- added : undefined ,
15
- removed : true ,
16
- value : ''
17
- }
4
+ import type { Diff } from 'diff-match-patch'
18
5
19
- const equal = {
20
- count : 1 ,
21
- added : undefined ,
22
- removed : undefined ,
23
- value : ''
24
- }
25
-
26
- const disabled = {
27
- value : ''
28
- }
6
+ describe ( 'Utils unit' , ( ) => {
7
+ // diff-match-patch output
8
+ const added : Diff = [ 1 , '' ]
9
+ const removed : Diff = [ - 1 , '' ]
10
+ const equal : Diff = [ 0 , '' ]
11
+ // custom output
12
+ const disabled : Diff = [ 2 , '' ]
29
13
30
- const prev = 'a\nb'
31
- const curr = 'c'
14
+ const prev : Diff = [ - 1 , 'a\nb' ]
15
+ const curr : Diff = [ 1 , 'c' ]
32
16
33
- const diffsMap = [
34
- [
35
- {
36
- count : 2 ,
37
- added : undefined ,
38
- removed : true ,
39
- value : prev
40
- } ,
41
- {
42
- count : 1 ,
43
- added : true ,
44
- removed : undefined ,
45
- value : curr
46
- }
47
- ]
48
- ]
17
+ const diffsMap = [ [ prev , curr ] ]
49
18
50
19
it ( 'getDiffType' , ( ) => {
51
- expect ( getDiffType ( added ) ) . toBe ( 'added' )
52
- expect ( getDiffType ( removed ) ) . toBe ( 'removed' )
53
- expect ( getDiffType ( equal ) ) . toBe ( 'equal' )
54
- expect ( getDiffType ( disabled ) ) . toBe ( 'disabled' )
20
+ expect ( getDiffType ( added [ 0 ] ) ) . toBe ( 'added' )
21
+ expect ( getDiffType ( removed [ 0 ] ) ) . toBe ( 'removed' )
22
+ expect ( getDiffType ( equal [ 0 ] ) ) . toBe ( 'equal' )
23
+ expect ( getDiffType ( disabled [ 0 ] ) ) . toBe ( 'disabled' )
55
24
} )
56
25
57
26
it ( 'getSplitLines' , ( ) => {
@@ -60,7 +29,7 @@ describe('Utils unit', () => {
60
29
expect ( result [ 0 ] [ 0 ] . type ) . toBe ( 'removed' )
61
30
expect ( result [ 0 ] [ 0 ] . lineNum ) . toBe ( 1 )
62
31
expect ( result [ 0 ] [ 0 ] . value ) . toBe ( 'a' )
63
- expect ( result [ 0 ] [ 0 ] . chkWords ) . toBe ( false )
32
+ expect ( result [ 0 ] [ 0 ] . chkWords ) . toBe ( true )
64
33
} )
65
34
66
35
it ( 'getUnifiedLines' , ( ) => {
@@ -78,16 +47,15 @@ describe('Utils unit', () => {
78
47
} )
79
48
80
49
it ( 'getUnifiedLines' , ( ) => {
81
- const split = renderLines ( 'split' , prev , curr )
82
- const unified = renderLines ( 'unified' , prev , curr )
50
+ const split = renderLines ( 'split' , prev [ 1 ] , curr [ 1 ] )
51
+ const unified = renderLines ( 'unified' , prev [ 1 ] , curr [ 1 ] )
83
52
expect ( split . length ) . toBe ( 2 )
84
53
expect ( unified . length ) . toBe ( 3 )
85
54
} )
86
55
87
56
it ( 'renderWords' , ( ) => {
88
57
expect ( renderWords ( 'abc' , 'abc' ) ) . toBe ( 'abc' )
89
- expect ( renderWords ( 'abc' , 'acc' ) ) . toBe ( `${ MODIFIED_START_TAG } acc${ MODIFIED_CLOSE_TAG } ` )
90
- expect ( renderWords ( 'a b c' , 'a c c' ) ) . toBe ( `a ${ MODIFIED_START_TAG } c${ MODIFIED_CLOSE_TAG } c` )
58
+ expect ( renderWords ( 'abc' , 'acc' ) ) . toBe ( `a${ MODIFIED_START_TAG } c${ MODIFIED_CLOSE_TAG } c` )
91
59
} )
92
60
93
61
it ( 'setHighlightCode' , ( ) => {
0 commit comments