11/*
2- * Copyright (c) 2016, 2024 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2016, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3030 */
3131
3232import java .net .URI ;
33+ import java .util .ArrayList ;
34+ import java .util .List ;
3335import java .util .Objects ;
3436
37+ import javax .tools .DiagnosticListener ;
3538import javax .tools .SimpleJavaFileObject ;
3639
3740import com .sun .tools .javac .parser .JavaTokenizer ;
@@ -101,17 +104,29 @@ public class JavaLexerTest {
101104 new TestTuple (ERROR , "\' \' " ),
102105 new TestTuple (ERROR , "\' \\ q\' " , "\' \\ q\' " ),
103106 new TestTuple (ERROR , "\' \\ {1+2}\' " , "\' \\ {1+2}\' " ),
107+ new TestTuple (ERROR , "'\uD83D \uDE0A '" ,
108+ List .of ("compiler.err.illegal.char.literal.multiple.surrogates" )),
104109 };
105110
106111 static class TestTuple {
107112 String input ;
108113 TokenKind kind ;
109114 String expected ;
115+ List <String > expectedErrors ;
110116
111- TestTuple (TokenKind kind , String input , String expected ) {
117+ TestTuple (TokenKind kind , String input , String expected , List < String > expectedErrors ) {
112118 this .input = input ;
113119 this .kind = kind ;
114120 this .expected = expected ;
121+ this .expectedErrors = expectedErrors ;
122+ }
123+
124+ TestTuple (TokenKind kind , String input , List <String > expectedErrors ) {
125+ this (kind , input , input , expectedErrors );
126+ }
127+
128+ TestTuple (TokenKind kind , String input , String expected ) {
129+ this (kind , input , expected , null );
115130 }
116131
117132 TestTuple (TokenKind kind , String input ) {
@@ -121,6 +136,12 @@ static class TestTuple {
121136
122137 void test (TestTuple test , boolean willFail ) throws Exception {
123138 Context ctx = new Context ();
139+ List <String > errors = new ArrayList ();
140+
141+ if (test .expectedErrors != null ) {
142+ ctx .put (DiagnosticListener .class , (DiagnosticListener ) d -> errors .add (d .getCode ()));
143+ }
144+
124145 Log log = Log .instance (ctx );
125146
126147 log .useSource (SimpleJavaFileObject .forSource (URI .create ("mem://Test.java" ),
@@ -149,6 +170,10 @@ void test(TestTuple test, boolean willFail) throws Exception {
149170 System .err .println ("input: " + test .input );
150171 throw new AssertionError ("Unexpected token content: " + actual );
151172 }
173+
174+ if (test .expectedErrors != null && !test .expectedErrors .equals (errors )) {
175+ throw new AssertionError ("Unexpected errors: " + errors );
176+ }
152177 }
153178
154179 void run () throws Exception {
0 commit comments