@@ -133,14 +133,21 @@ void parseCallback() {
133133 @ Test
134134 @ DisplayName ("parse(timeout)" )
135135 void parseTimeout () {
136- assertThrows (IllegalStateException .class , () -> parser .parse ("" ));
136+ var source = "}" .repeat (1024 );
137+ // NOTE: can't use _ because of palantir/palantir-java-format#934
138+ ParseCallback callback = (offset , p ) -> source .substring (offset , Integer .min (source .length (), offset + 1 ));
139+
137140 parser .setLanguage (language ).setTimeoutMicros (2L );
138- assertTrue (parser .parse ("}" . repeat ( 1024 ) , InputEncoding .UTF_8 ).isEmpty ());
141+ assertTrue (parser .parse (callback , InputEncoding .UTF_8 ).isEmpty ());
139142 }
140143
141144 @ Test
142145 @ DisplayName ("parse(cancellation)" )
143146 void parseCancellation () {
147+ var source = "}" .repeat (1024 * 1024 );
148+ // NOTE: can't use _ because of palantir/palantir-java-format#934
149+ ParseCallback callback = (offset , p ) -> source .substring (offset , Integer .min (source .length (), offset + 1 ));
150+
144151 var flag = new Parser .CancellationFlag ();
145152 parser .setLanguage (language ).setCancellationFlag (flag );
146153 try (var service = Executors .newFixedThreadPool (2 )) {
@@ -153,7 +160,7 @@ void parseCancellation() {
153160 flag .set (1L );
154161 }
155162 });
156- var result = service .submit (() -> parser .parse ("}" . repeat ( 1024 * 1024 ) ));
163+ var result = service .submit (() -> parser .parse (callback , InputEncoding . UTF_8 ));
157164 assertTrue (result .get (30L , TimeUnit .MILLISECONDS ).isEmpty ());
158165 } catch (InterruptedException | CancellationException | ExecutionException | TimeoutException e ) {
159166 fail ("Parsing was not halted gracefully" , e );
0 commit comments