1
- import { Map , OrderedMap } from 'immutable' ;
1
+ import { Map } from 'immutable' ;
2
2
3
- import { remarkParseShortcodes , getLinesWithOffsets } from '../remarkShortcodes' ;
3
+ import { remarkParseShortcodes } from '../remarkShortcodes' ;
4
4
5
5
// Stub of Remark Parser
6
6
function process ( value , plugins , processEat = ( ) => { } ) {
@@ -26,14 +26,9 @@ function EditorComponent({ id = 'foo', fromBlock = jest.fn(), pattern }) {
26
26
describe ( 'remarkParseShortcodes' , ( ) => {
27
27
describe ( 'pattern matching' , ( ) => {
28
28
it ( 'should work' , ( ) => {
29
- const editorComponent = EditorComponent ( { pattern : / b a r / } ) ;
29
+ const editorComponent = EditorComponent ( { pattern : / ^ f o o / } ) ;
30
30
process ( 'foo bar' , Map ( { [ editorComponent . id ] : editorComponent } ) ) ;
31
- expect ( editorComponent . fromBlock ) . toHaveBeenCalledWith ( expect . arrayContaining ( [ 'bar' ] ) ) ;
32
- } ) ;
33
- it ( 'should match value surrounded in newlines' , ( ) => {
34
- const editorComponent = EditorComponent ( { pattern : / ^ b a r $ / } ) ;
35
- process ( 'foo\n\nbar\n' , Map ( { [ editorComponent . id ] : editorComponent } ) ) ;
36
- expect ( editorComponent . fromBlock ) . toHaveBeenCalledWith ( expect . arrayContaining ( [ 'bar' ] ) ) ;
31
+ expect ( editorComponent . fromBlock ) . toHaveBeenCalledWith ( expect . arrayContaining ( [ 'foo' ] ) ) ;
37
32
} ) ;
38
33
it ( 'should match multiline shortcodes' , ( ) => {
39
34
const editorComponent = EditorComponent ( { pattern : / ^ f o o \n b a r $ / } ) ;
@@ -47,60 +42,15 @@ describe('remarkParseShortcodes', () => {
47
42
expect . arrayContaining ( [ 'foo\n\nbar' ] ) ,
48
43
) ;
49
44
} ) ;
50
- it ( 'should match shortcodes based on order of occurrence in value' , ( ) => {
51
- const fooEditorComponent = EditorComponent ( { id : 'foo' , pattern : / f o o / } ) ;
52
- const barEditorComponent = EditorComponent ( { id : 'bar' , pattern : / b a r / } ) ;
53
- process (
54
- 'foo\n\nbar' ,
55
- OrderedMap ( [
56
- [ barEditorComponent . id , barEditorComponent ] ,
57
- [ fooEditorComponent . id , fooEditorComponent ] ,
58
- ] ) ,
59
- ) ;
60
- expect ( fooEditorComponent . fromBlock ) . toHaveBeenCalledWith ( expect . arrayContaining ( [ 'foo' ] ) ) ;
61
- } ) ;
62
- it ( 'should match shortcodes based on order of occurrence in value even when some use line anchors' , ( ) => {
63
- const barEditorComponent = EditorComponent ( { id : 'bar' , pattern : / b a r / } ) ;
64
- const bazEditorComponent = EditorComponent ( { id : 'baz' , pattern : / ^ b a z $ / } ) ;
65
- process (
66
- 'foo\n\nbar\n\nbaz' ,
67
- OrderedMap ( [
68
- [ bazEditorComponent . id , bazEditorComponent ] ,
69
- [ barEditorComponent . id , barEditorComponent ] ,
70
- ] ) ,
71
- ) ;
72
- expect ( barEditorComponent . fromBlock ) . toHaveBeenCalledWith ( expect . arrayContaining ( [ 'bar' ] ) ) ;
73
- } ) ;
74
45
} ) ;
75
46
describe ( 'output' , ( ) => {
76
47
it ( 'should be a remark shortcode node' , ( ) => {
77
48
const processEat = jest . fn ( ) ;
78
49
const shortcodeData = { bar : 'baz' } ;
79
50
const expectedNode = { type : 'shortcode' , data : { shortcode : 'foo' , shortcodeData } } ;
80
- const editorComponent = EditorComponent ( { pattern : / b a r / , fromBlock : ( ) => shortcodeData } ) ;
51
+ const editorComponent = EditorComponent ( { pattern : / ^ f o o / , fromBlock : ( ) => shortcodeData } ) ;
81
52
process ( 'foo bar' , Map ( { [ editorComponent . id ] : editorComponent } ) , processEat ) ;
82
53
expect ( processEat ) . toHaveBeenCalledWith ( expectedNode ) ;
83
54
} ) ;
84
55
} ) ;
85
56
} ) ;
86
-
87
- describe ( 'getLinesWithOffsets' , ( ) => {
88
- test ( 'should split into lines' , ( ) => {
89
- const value = ' line1\n\nline2 \n\n line3 \n\n' ;
90
-
91
- const lines = getLinesWithOffsets ( value ) ;
92
- expect ( lines ) . toEqual ( [
93
- { line : ' line1' , start : 0 } ,
94
- { line : 'line2' , start : 8 } ,
95
- { line : ' line3' , start : 16 } ,
96
- { line : '' , start : 30 } ,
97
- ] ) ;
98
- } ) ;
99
-
100
- test ( 'should return single item on no match' , ( ) => {
101
- const value = ' line1 ' ;
102
-
103
- const lines = getLinesWithOffsets ( value ) ;
104
- expect ( lines ) . toEqual ( [ { line : ' line1' , start : 0 } ] ) ;
105
- } ) ;
106
- } ) ;
0 commit comments