@@ -20,6 +20,14 @@ const testData = `[({(<(())[]>[[{[]{<()<>>
20
20
<{([([[(<>()){}]>(<<{{
21
21
<{([{{}}[<[[[<>{}]]]>[]]`
22
22
23
+ const autocomplete = {
24
+ '[({(<(())[]>[[{[]{<()<>>' : '}}]])})]' ,
25
+ '[(()[<>])]({[<{<<[]>>(' : ')}>]})' ,
26
+ '(((({<>}<{<{<>}{[]{[]{}' : '}}>}>))))' ,
27
+ '{<[[]]>}<{[{[{[]{()[[[]' : ']]}}]}]}>' ,
28
+ '<{([{{}}[<[[[<>{}]]]>[]]' : '])}>'
29
+ }
30
+
23
31
describe ( '--- Day 10: Syntax Scoring ---' , ( ) => {
24
32
describe ( 'Part 1' , ( ) => {
25
33
describe ( 'lintLine()' , ( ) => {
@@ -57,6 +65,7 @@ describe('--- Day 10: Syntax Scoring ---', () => {
57
65
describe ( 'lintAll' , ( ) => {
58
66
it ( 'finds all lines with linting errors' , ( ) => {
59
67
const errors = lintAll ( testData . split ( '\n' ) )
68
+ . filter ( ( err ) => ( err . char ) )
60
69
61
70
expect ( errors . length ) . to . equal ( 5 )
62
71
expect ( errors [ 0 ] ) . to . deep . equal ( {
@@ -90,6 +99,25 @@ describe('--- Day 10: Syntax Scoring ---', () => {
90
99
found : '>'
91
100
} )
92
101
} )
102
+ it ( 'provides autocomplete suggestions for incomplete lines' , ( ) => {
103
+ const data = testData . split ( '\n' )
104
+ const errors = lintAll ( data )
105
+ . filter ( ( err ) => ! ! err . suggestion )
106
+
107
+ expect ( errors . length ) . to . equal ( 5 )
108
+ errors . forEach ( ( err ) => {
109
+ expect ( err . suggestion ) . to . equal (
110
+ autocomplete [ data [ err . line ] ]
111
+ )
112
+ } )
113
+ } )
114
+ it ( 'skips lines without errors' , ( ) => {
115
+ const errors = lintAll ( [
116
+ '[]' ,
117
+ '[()]'
118
+ ] )
119
+ expect ( errors . length ) . to . equal ( 0 )
120
+ } )
93
121
} )
94
122
} )
95
123
} )
0 commit comments