1
+ const { isMarker, findNextLineBreak, solution } = require ( './main' ) ;
2
+
3
+ describe ( 'Check marker test' , ( ) => {
4
+ test ( 'a is not a marker of #' , ( ) => {
5
+ expect ( isMarker ( 'a' , [ '#' ] ) ) . toBe ( false ) ;
6
+ } ) ;
7
+
8
+ test ( '# is a marker of #' , ( ) => {
9
+ expect ( isMarker ( '#' , [ '#' ] ) ) . toBe ( true ) ;
10
+ } ) ;
11
+
12
+ test ( 'b is a not marker of #,!' , ( ) => {
13
+ expect ( isMarker ( 'b' , [ '#' , '!' ] ) ) . toBe ( false ) ;
14
+ } ) ;
15
+
16
+ test ( '! is a marker of #,!' , ( ) => {
17
+ expect ( isMarker ( '!' , [ '#' , '!' ] ) ) . toBe ( true ) ;
18
+ } ) ;
19
+ } ) ;
20
+
21
+ describe ( 'find the next index of \n' , ( ) => {
22
+ test ( 'the next index of abc\n is 3' , ( ) => {
23
+ expect ( findNextLineBreak ( 'abc\n' ) ) . toBe ( 3 ) ;
24
+ } ) ;
25
+
26
+ test ( 'the next index of abc is -1' , ( ) => {
27
+ expect ( findNextLineBreak ( 'abc' ) ) . toBe ( - 1 ) ;
28
+ } ) ;
29
+
30
+ test ( 'the next index of abcde\nabcde\n is 5' , ( ) => {
31
+ expect ( findNextLineBreak ( 'abcde\nabcde\n' ) ) . toBe ( 5 ) ;
32
+ } ) ;
33
+ } ) ;
34
+
35
+ describe ( 'Strip comments' , ( ) => {
36
+ test ( 'a returns a' , ( ) => {
37
+ expect ( solution ( 'a' , [ '#' ] ) ) . toBe ( 'a' ) ;
38
+ } ) ;
39
+
40
+ test ( '\n returns \n' , ( ) => {
41
+ expect ( solution ( '\n' , [ '#' ] ) ) . toBe ( '\n' ) ;
42
+ } ) ;
43
+
44
+ test ( 'a\n returns a\n' , ( ) => {
45
+ expect ( solution ( 'a\n' , [ '#' ] ) ) . toBe ( 'a\n' ) ;
46
+ } ) ;
47
+
48
+ test ( 'a# returns a' , ( ) => {
49
+ expect ( solution ( 'a#' , [ '#' ] ) ) . toBe ( 'a' ) ;
50
+ } ) ;
51
+
52
+ test ( 'a#hello returns a' , ( ) => {
53
+ expect ( solution ( 'a#hello' , [ '#' ] ) ) . toBe ( 'a' ) ;
54
+ } ) ;
55
+
56
+ test ( '#hello returns ' , ( ) => {
57
+ expect ( solution ( '#hello' , [ '#' ] ) ) . toBe ( '' ) ;
58
+ } ) ;
59
+
60
+ test ( 'a#hello\nh returns a\nh' , ( ) => {
61
+ expect ( solution ( 'a#hello\nh' , [ '#' ] ) ) . toBe ( 'a\nh' ) ;
62
+ } ) ;
63
+
64
+ test ( 'a#hello\nhello\n#hi returns ahello' , ( ) => {
65
+ expect ( solution ( 'a#hello\nhello\n#hi' , [ '#' ] ) ) . toBe ( 'a\nhello\n' ) ;
66
+ } ) ;
67
+
68
+ test ( 'aa bb cc returns ahello' , ( ) => {
69
+ expect ( solution ( 'aa bb cc ' , [ '#' ] ) ) . toBe ( 'aa bb cc' ) ;
70
+ } ) ;
71
+
72
+ test ( 'aa bb # cc returns aa bb' , ( ) => {
73
+ expect ( solution ( 'aa bb # cc' , [ '#' ] ) ) . toBe ( 'aa bb' ) ;
74
+ } ) ;
75
+
76
+ test ( 'aa# bb cc returns aa' , ( ) => {
77
+ expect ( solution ( 'aa# bb cc' , [ '#' ] ) ) . toBe ( 'aa' ) ;
78
+ } ) ;
79
+
80
+ test ( 'aa # bb\ncc dd return aa\ncc dd' , ( ) => {
81
+ expect ( solution ( 'aa # bb\ncc dd' , [ '#' ] ) ) . toBe ( 'aa\ncc dd' ) ;
82
+ } ) ;
83
+
84
+ test ( 'no markers return the original text' , ( ) => {
85
+ expect ( solution ( 'aa # bb # cc' , [ ] ) ) . toBe ( 'aa # bb # cc' ) ;
86
+ } ) ;
87
+
88
+ test ( 'apples, pears # and bananas\n returns apples, pears\n' , ( ) => {
89
+ expect ( solution ( 'apples, pears # and bananas\n' , [ '#' , '!' ] ) ) . toBe ( 'apples, pears\n' ) ;
90
+ } ) ;
91
+
92
+ test ( 'aa # bb # cc returns aa' , ( ) => {
93
+ expect ( solution ( 'aa # bb # cc' , [ '#' , '!' ] ) ) . toBe ( 'aa' ) ;
94
+ } ) ;
95
+
96
+ test ( 'apples, pears # and bananas\ngrapes\nbananas !apples returns apples, pears\ngrapes\nbananas' , ( ) => {
97
+ expect ( solution ( 'apples, pears # and bananas\ngrapes\nbananas !apples' , [ '#' , '!' ] ) ) . toBe ( 'apples, pears\ngrapes\nbananas' ) ;
98
+ } ) ;
99
+ } ) ;
0 commit comments