|
| 1 | +/* |
| 2 | + * Copyright 2013-2023 Real Logic Limited. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package uk.co.real_logic.sbe.generation.java; |
| 17 | + |
| 18 | +import org.agrona.DirectBuffer; |
| 19 | +import org.agrona.MutableDirectBuffer; |
| 20 | +import org.agrona.generation.StringWriterOutputManager; |
| 21 | +import org.junit.jupiter.api.Test; |
| 22 | +import uk.co.real_logic.sbe.Tests; |
| 23 | +import uk.co.real_logic.sbe.ir.Ir; |
| 24 | +import uk.co.real_logic.sbe.xml.IrGenerator; |
| 25 | +import uk.co.real_logic.sbe.xml.MessageSchema; |
| 26 | +import uk.co.real_logic.sbe.xml.ParserOptions; |
| 27 | +import uk.co.real_logic.sbe.xml.XmlSchemaParser; |
| 28 | + |
| 29 | +import java.io.InputStream; |
| 30 | + |
| 31 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 32 | +import static org.hamcrest.core.StringContains.containsString; |
| 33 | + |
| 34 | +class ValueRefWithLowerCaseEnum |
| 35 | +{ |
| 36 | + private static final Class<?> BUFFER_CLASS = MutableDirectBuffer.class; |
| 37 | + private static final String BUFFER_NAME = BUFFER_CLASS.getName(); |
| 38 | + private static final Class<DirectBuffer> READ_ONLY_BUFFER_CLASS = DirectBuffer.class; |
| 39 | + private static final String READ_ONLY_BUFFER_NAME = READ_ONLY_BUFFER_CLASS.getName(); |
| 40 | + |
| 41 | + @Test |
| 42 | + void shouldGenerateConstCharArrayMethods() throws Exception |
| 43 | + { |
| 44 | + try (InputStream in = Tests.getLocalResource("value-ref-with-lower-case-enum.xml")) |
| 45 | + { |
| 46 | + final ParserOptions options = ParserOptions.builder().stopOnError(true).build(); |
| 47 | + final MessageSchema schema = XmlSchemaParser.parse(in, options); |
| 48 | + final IrGenerator irg = new IrGenerator(); |
| 49 | + final Ir ir = irg.generate(schema); |
| 50 | + |
| 51 | + final StringWriterOutputManager outputManager = new StringWriterOutputManager(); |
| 52 | + outputManager.setPackageName(ir.applicableNamespace()); |
| 53 | + final JavaGenerator generator = new JavaGenerator( |
| 54 | + ir, BUFFER_NAME, READ_ONLY_BUFFER_NAME, false, false, false, outputManager); |
| 55 | + |
| 56 | + generator.generate(); |
| 57 | + final String sources = outputManager.getSources().toString(); |
| 58 | + |
| 59 | + // Prior to the fix the generated body of the following method was |
| 60 | + // `return engineType.gas;` |
| 61 | + final String expected = |
| 62 | + " public EngineType engineType()\n" + |
| 63 | + " {\n" + |
| 64 | + " return EngineType.gas;\n" + |
| 65 | + " }"; |
| 66 | + assertThat(sources, containsString(expected)); |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments