@@ -3,22 +3,138 @@ import { formatCopyText } from "./copybutton_funcs";
33
44const parameters = [
55 {
6- description : 'no prompt' ,
6+ description : 'empty prompt' ,
77 text : 'hallo' ,
88 prompt : '' ,
9+ isRegexp : false ,
10+ onlyCopyPromptLines : true ,
11+ removePrompts : true ,
912 expected : 'hallo'
1013 } ,
1114 {
12- description : 'with prompt' ,
13- text : '>>> hallo' ,
15+ description : 'no prompt in text ' ,
16+ text : 'hallo' ,
1417 prompt : '>>> ' ,
18+ isRegexp : false ,
19+ onlyCopyPromptLines : true ,
20+ removePrompts : true ,
1521 expected : 'hallo'
22+ } ,
23+ {
24+ description : 'with non-regexp python prompt' ,
25+ text : `
26+ >>> first
27+ output
28+ >>> second` ,
29+ prompt : '>>> ' ,
30+ isRegexp : false ,
31+ onlyCopyPromptLines : true ,
32+ removePrompts : true ,
33+ expected : 'first\nsecond'
34+ } ,
35+ {
36+ description : 'with non-regexp console prompt' ,
37+ text : `
38+ $ first
39+ output
40+ $ second` ,
41+ prompt : '$ ' ,
42+ isRegexp : false ,
43+ onlyCopyPromptLines : true ,
44+ removePrompts : true ,
45+ expected : 'first\nsecond'
46+ } ,
47+ {
48+ description : 'with non-regexp prompt, keep prompt' ,
49+ text : `
50+ >>> first
51+ output
52+ >>> second` ,
53+ prompt : '>>> ' ,
54+ isRegexp : false ,
55+ onlyCopyPromptLines : true ,
56+ removePrompts : false ,
57+ expected : '>>> first\n>>> second'
58+ } ,
59+ {
60+ description : 'with non-regexp prompt, keep lines' ,
61+ text : `
62+ >>> first
63+ output
64+ >>> second` ,
65+ prompt : '>>> ' ,
66+ isRegexp : false ,
67+ onlyCopyPromptLines : false ,
68+ removePrompts : true ,
69+ expected : '\nfirst\noutput\nsecond'
70+ } ,
71+ {
72+ description : 'with non-regexp prompt, keep all' ,
73+ text : `
74+ >>> first
75+ output
76+ >>> second` ,
77+ prompt : '>>> ' ,
78+ isRegexp : false ,
79+ onlyCopyPromptLines : false ,
80+ removePrompts : false ,
81+ expected : '\n>>> first\noutput\n>>> second'
82+ } ,
83+ {
84+ description : 'with regexp python prompt' ,
85+ text : `
86+ >>> first
87+ output
88+ >>> second` ,
89+ prompt : '>>> ' ,
90+ isRegexp : true ,
91+ onlyCopyPromptLines : true ,
92+ removePrompts : true ,
93+ expected : 'first\nsecond'
94+ } ,
95+ {
96+ description : 'with regexp console prompt' ,
97+ text : `
98+ $ first
99+ output
100+ $ second` ,
101+ prompt : '\\$ ' ,
102+ isRegexp : true ,
103+ onlyCopyPromptLines : true ,
104+ removePrompts : true ,
105+ expected : 'first\nsecond'
106+ } ,
107+ {
108+ description : 'with ipython prompt regexp' ,
109+ text : `
110+ [1]: first
111+ ...: continuation
112+ output
113+ [2]: second` ,
114+ prompt : '[\d*]: |\.\.\.: ' ,
115+ isRegexp : true ,
116+ onlyCopyPromptLines : true ,
117+ removePrompts : true ,
118+ expected : 'first\ncontinuation\nsecond'
119+ } ,
120+ {
121+ description : 'with ipython prompt regexp, keep prompts' ,
122+ text : `
123+ [1]: first
124+ ...: continuation
125+ output
126+ [2]: second` ,
127+ prompt : '[\d*]: |\.\.\.: ' ,
128+ isRegexp : true ,
129+ onlyCopyPromptLines : true ,
130+ removePrompts : false ,
131+ expected : '[1]: first\n...: continuation\n[2]: second'
16132 }
17133]
18134
19- parameters . forEach ( ( parameter ) => {
20- test ( parameter . description , t => {
21- const text = formatCopyText ( parameter . text , parameter . prompt ) ;
22- t . is ( text , parameter . expected )
135+ parameters . forEach ( ( p ) => {
136+ test ( p . description , t => {
137+ const text = formatCopyText ( p . text , p . prompt , p . isRegexp , p . onlyCopyPromptLines , p . removePrompts ) ;
138+ t . is ( text , p . expected )
23139 } ) ;
24140} )
0 commit comments